Class CpuRatioTimer
- java.lang.Object
-
- com.google.apphosting.runtime.timer.CpuRatioTimer
-
- All Implemented Interfaces:
Timer
public class CpuRatioTimer extends Object implements Timer
CpuRatioTimeris a compositeTimerthat is backed by two otherTimerobjects -- e.g. one that measures CPU time and one that measures wallclock time. When started or stopped, it will start and stop both underlyingTimerobjects. It also exposes additional methods to calculate a CPU usage ratio and cycle count (calculated from the CPU time and aCpuSpeedExtractor).
-
-
Constructor Summary
Constructors Constructor Description CpuRatioTimer(Timer cpuUsageTimer, Timer wallclockTimer, CpuSpeedExtractor cpuSpeedExtractor, Timer[] extraTimers)Create a newCpuRatioTimer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description doublegetCpuRatio()Returns a ratio (between 0 and 1) that represents the percentage of elapsed wallclock time which was spent executing CPU instructions.TimergetCpuUsageTimer()Returns the underlying CPU usageTimer.longgetCycleCount()Convert the number of CPU seconds elapsed into a CPU cycle count using the CPU speed reported by theCpuSpeedExtractor.longgetNanoseconds()Returns the number of CPU-nanoseconds used by the current request, plus a fraction of any background work (e.g.TimergetWallclockTimer()Returns the underlying wallclockTimer.voidstart()Start both timers.voidstop()Stop both timers.StringtoString()voidupdate()Update any internal state.
-
-
-
Constructor Detail
-
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 Detail
-
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
public Timer getCpuUsageTimer()
Returns the underlying CPU usageTimer.
-
getWallclockTimer
public Timer 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
-
-