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
14e99aa1
Commit
14e99aa1
authored
Jan 19, 2021
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Document estimator.go.
parent
48de81d8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
2 deletions
+11
-2
estimator/estimator.go
estimator/estimator.go
+11
-2
No files found.
estimator/estimator.go
View file @
14e99aa1
// Package estimator implements a packet and byte rate estimator.
package
estimator
import
(
...
...
@@ -18,6 +20,7 @@ type Estimator struct {
packetRate
uint32
}
// New creates a new estimator that estimates rate over the last interval.
func
New
(
interval
time
.
Duration
)
*
Estimator
{
return
&
Estimator
{
interval
:
rtptime
.
FromDuration
(
interval
,
rtptime
.
JiffiesPerSec
),
...
...
@@ -44,8 +47,9 @@ func (e *Estimator) swap(now uint64) {
atomic
.
StoreUint64
(
&
e
.
time
,
now
)
}
func
(
e
*
Estimator
)
Accumulate
(
count
uint32
)
{
atomic
.
AddUint32
(
&
e
.
bytes
,
count
)
// Accumulate records one packet of size bytes
func
(
e
*
Estimator
)
Accumulate
(
bytes
uint32
)
{
atomic
.
AddUint32
(
&
e
.
bytes
,
bytes
)
atomic
.
AddUint32
(
&
e
.
packets
,
1
)
}
...
...
@@ -58,10 +62,15 @@ func (e *Estimator) estimate(now uint64) (uint32, uint32) {
return
atomic
.
LoadUint32
(
&
e
.
rate
),
atomic
.
LoadUint32
(
&
e
.
packetRate
)
}
// Estimate returns an estimate of the rate over the last interval.
// It starts a new interval if the last interval is larger than the value
// passed to New. It returns the byte rate and the packet rate, in units
// per second.
func
(
e
*
Estimator
)
Estimate
()
(
uint32
,
uint32
)
{
return
e
.
estimate
(
rtptime
.
Now
(
rtptime
.
JiffiesPerSec
))
}
// Totals returns the total number of bytes and packets accumulated.
func
(
e
*
Estimator
)
Totals
()
(
uint32
,
uint32
)
{
b
:=
atomic
.
LoadUint32
(
&
e
.
totalBytes
)
+
atomic
.
LoadUint32
(
&
e
.
bytes
)
p
:=
atomic
.
LoadUint32
(
&
e
.
totalPackets
)
+
atomic
.
LoadUint32
(
&
e
.
packets
)
...
...
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