Package org.onlab.util
Class Counter
- java.lang.Object
-
- org.onlab.util.Counter
-
public class Counter extends java.lang.Object
Counting mechanism capable of tracking occurrences and rates.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(long count)
Adds the specified number of occurrences to the counter.double
duration()
Returns the duration expressed in fractional number of seconds.boolean
equals(java.lang.Object obj)
void
freeze()
Freezes the counter in the current state including the counts and times.int
hashCode()
void
reset()
Resets the counter, by zeroing out the count and restarting the timer.double
throughput()
Returns the number of occurrences per second.java.lang.String
toString()
long
total()
Returns the total number of occurrences counted.
-
-
-
Constructor Detail
-
Counter
public Counter()
Creates a new counter.
-
Counter
public Counter(long start, long total, long end)
Creates a new counter in a specific state. If non-zero end time is specified, the counter will be frozen.- Parameters:
start
- start timetotal
- total number of items to start withend
- end time; if non-ze
-
-
Method Detail
-
reset
public void reset()
Resets the counter, by zeroing out the count and restarting the timer.
-
freeze
public void freeze()
Freezes the counter in the current state including the counts and times.
-
add
public void add(long count)
Adds the specified number of occurrences to the counter. No-op if the counter has been frozen.- Parameters:
count
- number of occurrences
-
throughput
public double throughput()
Returns the number of occurrences per second.- Returns:
- throughput in occurrences per second
-
total
public long total()
Returns the total number of occurrences counted.- Returns:
- number of counted occurrences
-
duration
public double duration()
Returns the duration expressed in fractional number of seconds.- Returns:
- fractional number of seconds since the last reset
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-