Class CpuRatioTimer
java.lang.Object
com.google.apphosting.runtime.timer.CpuRatioTimer
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionCpuRatioTimer(Timer cpuUsageTimer, Timer wallclockTimer, CpuSpeedExtractor cpuSpeedExtractor, Timer[] extraTimers) Create a newCpuRatioTimer. -
Method Summary
Modifier and TypeMethodDescriptiondoubleReturns a ratio (between 0 and 1) that represents the percentage of elapsed wallclock time which was spent executing CPU instructions.Returns the underlying CPU usageTimer.longConvert the number of CPU seconds elapsed into a CPU cycle count using the CPU speed reported by theCpuSpeedExtractor.longReturns the number of CPU-nanoseconds used by the current request, plus a fraction of any background work (e.g.Returns the underlying wallclockTimer.voidstart()Start both timers.voidstop()Stop both timers.toString()voidupdate()Update any internal state.
-
Constructor Details
-
CpuRatioTimer
public CpuRatioTimer(Timer cpuUsageTimer, Timer wallclockTimer, CpuSpeedExtractor cpuSpeedExtractor, Timer[] extraTimers) Create a newCpuRatioTimer.- Parameters:
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).
-
-
Method Details
-
start
public void start()Start both timers. -
stop
public void stop()Stop both timers. -
update
public void update()Description copied from interface:TimerUpdate any internal state. For example, someTimerimplementations 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, seeTimer.update(). -
getCpuUsageTimer
Returns the underlying CPU usageTimer. -
getWallclockTimer
Returns the underlying wallclockTimer. -
getCpuRatio
public double getCpuRatio()Returns a ratio (between 0 and 1) that represents the percentage of elapsed wallclock time which was spent executing CPU instructions. -
getCycleCount
public long getCycleCount()Convert the number of CPU seconds elapsed into a CPU cycle count using the CPU speed reported by theCpuSpeedExtractor. This value also includes a fraction of hotspot and GC times. -
getNanoseconds
public long getNanoseconds()Returns the number of CPU-nanoseconds used by the current request, plus a fraction of any background work (e.g. hotspot, GC) done by the JVM while this request was executing.- Specified by:
getNanosecondsin interfaceTimer
-
toString
-