Class CpuRatioTimer

java.lang.Object
com.google.apphosting.runtime.timer.CpuRatioTimer
All Implemented Interfaces:
Timer

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 Details

    • CpuRatioTimer

      public CpuRatioTimer(Timer cpuUsageTimer, Timer wallclockTimer, CpuSpeedExtractor cpuSpeedExtractor, Timer[] extraTimers)
      Create a new CpuRatioTimer.
      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 cycles
      extraTimers - 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.
      Specified by:
      start in interface Timer
    • stop

      public void stop()
      Stop both timers.
      Specified by:
      stop in interface Timer
    • update

      public void update()
      Description copied from interface: Timer
      Update any internal state. For example, some Timer 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 Timer.update().
      Specified by:
      update in interface Timer
    • getCpuUsageTimer

      public Timer getCpuUsageTimer()
      Returns the underlying CPU usage Timer.
    • getWallclockTimer

      public Timer getWallclockTimer()
      Returns the underlying wallclock Timer.
    • 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 the CpuSpeedExtractor. 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:
      getNanoseconds in interface Timer
    • toString

      public String toString()
      Overrides:
      toString in class Object