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
d52d20ae
Commit
d52d20ae
authored
Dec 13, 2017
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup update loop
Use range and then trim the meters slice later. It's *much* easier to read.
parent
6c16cea2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
7 deletions
+10
-7
sweeper.go
sweeper.go
+10
-7
No files found.
sweeper.go
View file @
d52d20ae
...
...
@@ -83,8 +83,9 @@ func (sw *sweeper) update() {
sw
.
lastUpdateTime
=
now
timeMultiplier
:=
float64
(
time
.
Second
)
/
float64
(
tdiff
)
for
i
:=
0
;
i
<
len
(
sw
.
meters
);
i
++
{
m
:=
sw
.
meters
[
i
]
newLen
:=
len
(
sw
.
meters
)
for
i
,
m
:=
range
sw
.
meters
{
total
:=
atomic
.
LoadUint64
(
&
m
.
accumulator
)
instant
:=
timeMultiplier
*
float64
(
total
-
m
.
snapshot
.
Total
)
...
...
@@ -135,13 +136,15 @@ func (sw *sweeper) update() {
// Reset the rate, keep the total.
m
.
snapshot
.
Rate
=
0
newLen
--
sw
.
meters
[
i
]
=
sw
.
meters
[
newLen
]
}
// remove it and repeat `i`
sw
.
meters
[
i
]
=
sw
.
meters
[
len
(
sw
.
meters
)
-
1
]
sw
.
meters
[
len
(
sw
.
meters
)
-
1
]
=
nil
sw
.
meters
=
sw
.
meters
[
:
len
(
sw
.
meters
)
-
1
]
i
--
// trim the meter list
for
i
:=
newLen
;
i
<
len
(
sw
.
meters
);
i
++
{
sw
.
meters
[
i
]
=
nil
}
sw
.
meters
=
sw
.
meters
[
:
newLen
]
}
func
(
sw
*
sweeper
)
Register
(
m
*
Meter
)
{
...
...
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