public class ThreadsCpuCounter extends NanoCounter implements ThreadsCpuMBean
Modifier and Type | Field and Description |
---|---|
private static java.util.function.Function<java.lang.Long,java.util.concurrent.atomic.AtomicLong> |
COUNTER_CREATOR
Creates long counters
|
private java.util.Map<java.lang.Long,java.util.concurrent.atomic.AtomicLong> |
cpuTotals
Total CPU times
|
private java.util.Map<java.lang.Long,java.util.concurrent.atomic.AtomicLong> |
cpuUserTotals
Total CPU times in a user mode
|
private long |
currentThreadId
Hold the current thread id for which this measurement is planned
|
private java.lang.management.ThreadMXBean |
jmxBean
The management interface for the JVM thread system
|
Constructor and Description |
---|
ThreadsCpuCounter() |
Modifier and Type | Method and Description |
---|---|
private java.lang.StringBuilder |
addTheadInfo(long tid,
java.lang.StringBuilder buffer) |
long |
getThreadElapsedCpuTime()
Gets the elapsed CPU time for the execution thread.
|
long |
getThreadElapsedCpuTime(long tid)
Gets the elapsed CPU time for the given thread.
|
long |
getThreadElapsedUserTime()
Gets the elapsed CPU time for the execution thread in a user mode.
|
long |
getThreadElapsedUserTime(long tid)
Gets the elapsed CPU time for the given thread in a user mode.
|
private static long |
ms(long ns)
Converts nanoseconds to milliseconds
|
void |
reset()
Reset counters
|
void |
setCurrentThread(long tid)
Sets the execution thread.
|
java.lang.String |
toString(java.lang.String ts,
java.lang.String comment)
Return the string representation of the counter
|
void |
updateThreadElapsedCpuTime(long tid,
long value)
Updates the elapsed CPU time spent the given thread by adding the given value.
|
void |
updateThreadElapsedUserTime(long tid,
long value)
Updates the elapsed CPU time spent the given thread in a user mode by adding the given value.
|
getCount, getTotalTimeMs, getTotalTimeNs, print, print, update
enable, getAnnotation, isEnabled, register, setAnnotation
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
dump, update
register
enable, getAnnotation, isEnabled, setAnnotation
private static final java.util.function.Function<java.lang.Long,java.util.concurrent.atomic.AtomicLong> COUNTER_CREATOR
private final java.lang.management.ThreadMXBean jmxBean
private final java.util.Map<java.lang.Long,java.util.concurrent.atomic.AtomicLong> cpuTotals
private final java.util.Map<java.lang.Long,java.util.concurrent.atomic.AtomicLong> cpuUserTotals
private long currentThreadId
public void reset()
reset
in interface NanoCounterMBean
reset
in class NanoCounter
private static long ms(long ns)
ns
- The given time interval in nanosecondsprivate java.lang.StringBuilder addTheadInfo(long tid, java.lang.StringBuilder buffer)
public java.lang.String toString(java.lang.String ts, java.lang.String comment) throws java.io.IOException
toString
in interface LongCounter
toString
in class NanoCounter
ts
- The measurement time stampcomment
- The commentjava.io.IOException
- If IO exception occurspublic long getThreadElapsedCpuTime(long tid)
getThreadElapsedCpuTime
in interface ThreadsCpuMBean
tid
- The given thread idpublic long getThreadElapsedUserTime(long tid)
getThreadElapsedUserTime
in interface ThreadsCpuMBean
tid
- The given thread idpublic void updateThreadElapsedCpuTime(long tid, long value)
updateThreadElapsedCpuTime
in interface ThreadsCpuMBean
tid
- The given thread idvalue
- The given valuepublic void updateThreadElapsedUserTime(long tid, long value)
updateThreadElapsedUserTime
in interface ThreadsCpuMBean
tid
- The given thread idvalue
- The given valuepublic void setCurrentThread(long tid)
setCurrentThread
in interface ThreadsCpuMBean
tid
- The thread idpublic long getThreadElapsedCpuTime()
getThreadElapsedCpuTime
in interface ThreadsCpuMBean
public long getThreadElapsedUserTime()
getThreadElapsedUserTime
in interface ThreadsCpuMBean