public class CpuRatioTimer extends Object implements Timer
CpuRatioTimer is a composite Timer that is backed
by two other Timer objects -- e.g. one that measures CPU
time and one that measures wallclock time. When started or
stopped, it will start and stop both underlying Timer
objects.
It also exposes additional methods to calculate a CPU usage ratio
and cycle count (calculated from the CPU time and a CpuSpeedExtractor).| Constructor and Description |
|---|
CpuRatioTimer(Timer cpuUsageTimer,
Timer wallclockTimer,
CpuSpeedExtractor cpuSpeedExtractor,
Timer[] extraTimers)
Create a new
CpuRatioTimer. |
| Modifier and Type | Method and Description |
|---|---|
double |
getCpuRatio()
Returns a ratio (between 0 and 1) that represents the percentage
of elapsed wallclock time which was spent executing CPU
instructions.
|
Timer |
getCpuUsageTimer()
Returns the underlying CPU usage
Timer. |
long |
getCycleCount()
Convert the number of CPU seconds elapsed into a CPU cycle count
using the CPU speed reported by the
CpuSpeedExtractor. |
long |
getNanoseconds()
Returns the number of CPU-nanoseconds used by the current
request, plus a fraction of any background work (e.g.
|
Timer |
getWallclockTimer()
Returns the underlying wallclock
Timer. |
void |
start()
Start both timers.
|
void |
stop()
Stop both timers.
|
String |
toString() |
void |
update()
Update any internal state.
|
public CpuRatioTimer(Timer cpuUsageTimer, Timer wallclockTimer, CpuSpeedExtractor cpuSpeedExtractor, Timer[] extraTimers)
CpuRatioTimer.cpuUsageTimer - Tracks the CPU time used by the request.wallclockTimer - Tracks the total elapsed time of the request.cpuSpeedExtractor - converts CPU time to CPU cyclesextraTimers - includes timers for background work that is
added to the total return value of this timer (but do not affect
the CPU ratio).public void update()
TimerTimer
implementations may take snapshots of data that may be
unavailable in the future. Clients should call this method
periodically to qensure that any state is being updated. For an
example, see JmxThreadGroupCpuTimer.update().public Timer getCpuUsageTimer()
Timer.public Timer getWallclockTimer()
Timer.public double getCpuRatio()
public long getCycleCount()
CpuSpeedExtractor.
This value also includes a fraction of hotspot and GC times.public long getNanoseconds()
getNanoseconds in interface TimerCopyright © 2022. All rights reserved.