Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-flow-metrics
Commits
45424fab
Commit
45424fab
authored
Nov 08, 2019
by
vyzo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bug in meter traversal logic
parent
c3e55399
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
6 deletions
+9
-6
sweeper.go
sweeper.go
+9
-6
No files found.
sweeper.go
View file @
45424fab
...
@@ -89,7 +89,6 @@ func (sw *sweeper) update() {
...
@@ -89,7 +89,6 @@ func (sw *sweeper) update() {
timeMultiplier
:=
float64
(
time
.
Second
)
/
float64
(
tdiff
)
timeMultiplier
:=
float64
(
time
.
Second
)
/
float64
(
tdiff
)
// Calculate the bandwidth for all active meters.
// Calculate the bandwidth for all active meters.
newLen
:=
len
(
sw
.
meters
)
for
i
,
m
:=
range
sw
.
meters
[
:
sw
.
activeMeters
]
{
for
i
,
m
:=
range
sw
.
meters
[
:
sw
.
activeMeters
]
{
total
:=
atomic
.
LoadUint64
(
&
m
.
accumulator
)
total
:=
atomic
.
LoadUint64
(
&
m
.
accumulator
)
diff
:=
total
-
m
.
snapshot
.
Total
diff
:=
total
-
m
.
snapshot
.
Total
...
@@ -147,8 +146,7 @@ func (sw *sweeper) update() {
...
@@ -147,8 +146,7 @@ func (sw *sweeper) update() {
// Reset the rate, keep the total.
// Reset the rate, keep the total.
m
.
registered
=
false
m
.
registered
=
false
m
.
snapshot
.
Rate
=
0
m
.
snapshot
.
Rate
=
0
newLen
--
sw
.
meters
[
i
]
=
nil
sw
.
meters
[
i
]
=
sw
.
meters
[
newLen
]
}
}
// Re-add the total to all the newly active accumulators and set the snapshot to the total.
// Re-add the total to all the newly active accumulators and set the snapshot to the total.
...
@@ -162,10 +160,15 @@ func (sw *sweeper) update() {
...
@@ -162,10 +160,15 @@ func (sw *sweeper) update() {
m
.
snapshot
.
Total
=
total
m
.
snapshot
.
Total
=
total
}
}
// trim the meter list
// compress and trim the meter list
for
i
:=
newLen
;
i
<
len
(
sw
.
meters
);
i
++
{
var
newLen
int
sw
.
meters
[
i
]
=
nil
for
_
,
m
:=
range
sw
.
meters
{
if
m
!=
nil
{
sw
.
meters
[
newLen
]
=
m
newLen
++
}
}
}
sw
.
meters
=
sw
.
meters
[
:
newLen
]
sw
.
meters
=
sw
.
meters
[
:
newLen
]
// Finally, mark all meters still in the list as "active".
// Finally, mark all meters still in the list as "active".
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment