Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
4466c7b9
Commit
4466c7b9
authored
Oct 16, 2018
by
holisticode
Committed by
Anton Evangelatov
Oct 16, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
metrics: added NewCounterForced (#17919)
parent
2868acd8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
1 deletion
+33
-1
counter.go
metrics/counter.go
+33
-1
No files found.
metrics/counter.go
View file @
4466c7b9
package
metrics
import
"sync/atomic"
import
(
"sync/atomic"
)
// Counters hold an int64 value that can be incremented and decremented.
type
Counter
interface
{
...
...
@@ -20,6 +22,17 @@ func GetOrRegisterCounter(name string, r Registry) Counter {
return
r
.
GetOrRegister
(
name
,
NewCounter
)
.
(
Counter
)
}
// GetOrRegisterCounterForced returns an existing Counter or constructs and registers a
// new Counter no matter the global switch is enabled or not.
// Be sure to unregister the counter from the registry once it is of no use to
// allow for garbage collection.
func
GetOrRegisterCounterForced
(
name
string
,
r
Registry
)
Counter
{
if
nil
==
r
{
r
=
DefaultRegistry
}
return
r
.
GetOrRegister
(
name
,
NewCounterForced
)
.
(
Counter
)
}
// NewCounter constructs a new StandardCounter.
func
NewCounter
()
Counter
{
if
!
Enabled
{
...
...
@@ -28,6 +41,12 @@ func NewCounter() Counter {
return
&
StandardCounter
{
0
}
}
// NewCounterForced constructs a new StandardCounter and returns it no matter if
// the global switch is enabled or not.
func
NewCounterForced
()
Counter
{
return
&
StandardCounter
{
0
}
}
// NewRegisteredCounter constructs and registers a new StandardCounter.
func
NewRegisteredCounter
(
name
string
,
r
Registry
)
Counter
{
c
:=
NewCounter
()
...
...
@@ -38,6 +57,19 @@ func NewRegisteredCounter(name string, r Registry) Counter {
return
c
}
// NewRegisteredCounterForced constructs and registers a new StandardCounter
// and launches a goroutine no matter the global switch is enabled or not.
// Be sure to unregister the counter from the registry once it is of no use to
// allow for garbage collection.
func
NewRegisteredCounterForced
(
name
string
,
r
Registry
)
Counter
{
c
:=
NewCounterForced
()
if
nil
==
r
{
r
=
DefaultRegistry
}
r
.
Register
(
name
,
c
)
return
c
}
// CounterSnapshot is a read-only copy of another Counter.
type
CounterSnapshot
int64
...
...
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