public final class Counter extends Object
grouped
for printing.
Currently there is no shutdown hook in Substrate VM that is invoked automatically, so
Counter.logValues()
needs to be called manually at the end of the application to print
counter values.
Use this class in the following way:
@Option(help = "Count foo")// @RuntimeOption// public static final StableOptionValue<Boolean> FooCounters = new StableOptionValue<>(false); private static final Counter.Group fooCounters = new Counter.Group(FooCounters, "Foo Counters"); private static final Counter fooCount = new Counter(fooCounters, "foo", "number of times foo was invoked"); void foo() { fooCount.inc(); }
Modifier and Type | Class and Description |
---|---|
static class |
Counter.Group
A group of related counters.
|
Modifier and Type | Field and Description |
---|---|
protected String |
description |
protected Counter.Group |
group |
protected String |
name |
protected long |
value |
static Field |
VALUE_FIELD |
Constructor and Description |
---|
Counter(Counter.Group group,
String name,
String description)
Creates a counter.
|
Modifier and Type | Method and Description |
---|---|
void |
add(long increment)
Increments the value of this counter.
|
String |
getName() |
long |
getValue()
Returns the value of this counter.
|
void |
inc()
Increments the value of this counter.
|
static void |
logValues()
Prints all counters of all enabled groups to the
Log . |
void |
reset()
Resets the value of this counter to 0.
|
protected final Counter.Group group
protected final String name
protected final String description
protected long value
public static final Field VALUE_FIELD
public Counter(Counter.Group group, String name, String description)
group
- the group to which the counter belongs.name
- the name of the counterdescription
- a brief comment describing the metric represented by the counterpublic long getValue()
public String getName()
public void inc()
public void add(long increment)
public void reset()
public static void logValues()
Log
.