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
edeb2d90
Commit
edeb2d90
authored
Nov 01, 2019
by
Roman Proskuryakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent Meter from being added twice
parent
f120cc70
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
4 deletions
+11
-4
meter.go
meter.go
+10
-4
sweeper.go
sweeper.go
+1
-0
No files found.
meter.go
View file @
edeb2d90
...
@@ -32,6 +32,7 @@ func (s Snapshot) String() string {
...
@@ -32,6 +32,7 @@ func (s Snapshot) String() string {
// Meter is a meter for monitoring a flow.
// Meter is a meter for monitoring a flow.
type
Meter
struct
{
type
Meter
struct
{
accumulator
uint64
accumulator
uint64
registered
int32
// atomic bool
// Take lock.
// Take lock.
snapshot
Snapshot
snapshot
Snapshot
...
@@ -39,10 +40,15 @@ type Meter struct {
...
@@ -39,10 +40,15 @@ type Meter struct {
// Mark updates the total.
// Mark updates the total.
func
(
m
*
Meter
)
Mark
(
count
uint64
)
{
func
(
m
*
Meter
)
Mark
(
count
uint64
)
{
if
count
>
0
&&
atomic
.
AddUint64
(
&
m
.
accumulator
,
count
)
==
count
{
if
count
>
0
{
// I'm the first one to bump this above 0.
if
atomic
.
AddUint64
(
&
m
.
accumulator
,
count
)
==
count
{
// Register it.
just_registered
:=
atomic
.
CompareAndSwapInt32
(
&
m
.
registered
,
0
,
1
)
globalSweeper
.
Register
(
m
)
if
just_registered
{
// I'm the first one to bump this above 0.
// Register it.
globalSweeper
.
Register
(
m
)
}
}
}
}
}
}
...
...
sweeper.go
View file @
edeb2d90
...
@@ -113,6 +113,7 @@ func (sw *sweeper) update() {
...
@@ -113,6 +113,7 @@ func (sw *sweeper) update() {
// Mark this as idle by zeroing the accumulator.
// Mark this as idle by zeroing the accumulator.
swappedTotal
:=
atomic
.
SwapUint64
(
&
m
.
accumulator
,
0
)
swappedTotal
:=
atomic
.
SwapUint64
(
&
m
.
accumulator
,
0
)
atomic
.
StoreInt32
(
&
m
.
registered
,
0
)
// So..., are we really idle?
// So..., are we really idle?
if
swappedTotal
>
total
{
if
swappedTotal
>
total
{
...
...
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