Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
galene
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
galene
Commits
a6db6b10
Commit
a6db6b10
authored
May 31, 2020
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Keep track of total numbers sent.
parent
8fb8f7b7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
3 deletions
+21
-3
estimator/estimator.go
estimator/estimator.go
+13
-3
estimator/estimator_test.go
estimator/estimator_test.go
+8
-0
No files found.
estimator/estimator.go
View file @
a6db6b10
...
...
@@ -10,9 +10,11 @@ type Estimator struct {
interval
time
.
Duration
count
uint32
mu
sync
.
Mutex
rate
uint32
time
time
.
Time
mu
sync
.
Mutex
totalBytes
uint32
totalPackets
uint32
rate
uint32
time
time
.
Time
}
func
New
(
interval
time
.
Duration
)
*
Estimator
{
...
...
@@ -34,6 +36,8 @@ func (e *Estimator) swap(now time.Time) {
}
func
(
e
*
Estimator
)
Accumulate
(
count
uint32
)
{
atomic
.
AddUint32
(
&
e
.
totalBytes
,
count
)
atomic
.
AddUint32
(
&
e
.
totalPackets
,
1
)
atomic
.
AddUint32
(
&
e
.
count
,
count
)
}
...
...
@@ -52,3 +56,9 @@ func (e *Estimator) Estimate() uint32 {
defer
e
.
mu
.
Unlock
()
return
e
.
estimate
(
now
)
}
func
(
e
*
Estimator
)
Totals
()
(
uint32
,
uint32
)
{
b
:=
atomic
.
LoadUint32
(
&
e
.
totalBytes
)
p
:=
atomic
.
LoadUint32
(
&
e
.
totalPackets
)
return
p
,
b
}
estimator/estimator_test.go
View file @
a6db6b10
...
...
@@ -18,4 +18,12 @@ func TestEstimator(t *testing.T) {
if
rate
!=
42
+
128
{
t
.
Errorf
(
"Expected %v, got %v"
,
42
+
128
,
rate
)
}
totalP
,
totalB
:=
e
.
Totals
()
if
totalP
!=
2
{
t
.
Errorf
(
"Expected 2, got %v"
,
totalP
)
}
if
totalB
!=
42
+
128
{
t
.
Errorf
(
"Expected %v, got %v"
,
42
+
128
,
totalB
)
}
}
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