com.netflix.servo.util
Class ThreadCpuStats

java.lang.Object
  extended by com.netflix.servo.util.ThreadCpuStats

public final class ThreadCpuStats
extends java.lang.Object

Keep track of the cpu usage for threads in the jvm.


Nested Class Summary
static class ThreadCpuStats.CpuUsage
          Keeps track of the cpu usage for a single thread.
static class ThreadCpuStats.CpuUsageComparator
          Comparator for sorting cpu usage based on one of the columns.
 
Field Summary
static java.lang.String CURRENT_TIME
           
static java.lang.String FIFTEEN_MIN
           
static java.lang.String FIVE_MIN
           
static java.lang.String ID
           
static java.lang.String JVM_USAGE_PERCENT
           
static java.lang.String JVM_USAGE_TIME
           
static java.lang.String NAME
           
static java.lang.String ONE_MIN
           
static java.lang.String OVERALL
           
static java.lang.String THREADS
           
static java.lang.String UPTIME_MS
           
 
Method Summary
static ThreadCpuStats getInstance()
          Return the singleton instance.
 ThreadCpuStats.CpuUsage getOverallCpuUsage()
          Overall usage for the jvm.
 java.util.List<ThreadCpuStats.CpuUsage> getThreadCpuUsages()
          List of cpu usages for each thread.
 java.util.Map<java.lang.String,java.lang.Object> getThreadCpuUsages(ThreadCpuStats.CpuUsageComparator cmp)
          Utility function that returns a Map containing cpu usages for threads.
 boolean isRunning()
          Returns true if cpu status are currently being collected.
 void printThreadCpuUsages()
          Utility function that dumps the cpu usages for the threads to stdout.
 void printThreadCpuUsages(java.io.OutputStream out, ThreadCpuStats.CpuUsageComparator cmp)
          Utility function that dumps the cpu usages for the threads to stdout.
 void start()
          Start collecting cpu stats for the threads.
 void stop()
          Stop collecting cpu stats for the threads.
static java.lang.String toDuration(long inputTime)
          Convert time in nanoseconds to a duration string.
static double toPercent(long value, long total)
          Helper function for computing percentage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ONE_MIN

public static final java.lang.String ONE_MIN
See Also:
Constant Field Values

FIVE_MIN

public static final java.lang.String FIVE_MIN
See Also:
Constant Field Values

FIFTEEN_MIN

public static final java.lang.String FIFTEEN_MIN
See Also:
Constant Field Values

OVERALL

public static final java.lang.String OVERALL
See Also:
Constant Field Values

CURRENT_TIME

public static final java.lang.String CURRENT_TIME
See Also:
Constant Field Values

UPTIME_MS

public static final java.lang.String UPTIME_MS
See Also:
Constant Field Values

JVM_USAGE_TIME

public static final java.lang.String JVM_USAGE_TIME
See Also:
Constant Field Values

JVM_USAGE_PERCENT

public static final java.lang.String JVM_USAGE_PERCENT
See Also:
Constant Field Values

ID

public static final java.lang.String ID
See Also:
Constant Field Values

NAME

public static final java.lang.String NAME
See Also:
Constant Field Values

THREADS

public static final java.lang.String THREADS
See Also:
Constant Field Values
Method Detail

getInstance

public static ThreadCpuStats getInstance()
Return the singleton instance.


isRunning

public boolean isRunning()
Returns true if cpu status are currently being collected.


start

public void start()
Start collecting cpu stats for the threads.


stop

public void stop()
Stop collecting cpu stats for the threads.


getOverallCpuUsage

public ThreadCpuStats.CpuUsage getOverallCpuUsage()
Overall usage for the jvm.


getThreadCpuUsages

public java.util.List<ThreadCpuStats.CpuUsage> getThreadCpuUsages()
List of cpu usages for each thread.


toPercent

public static double toPercent(long value,
                               long total)
Helper function for computing percentage.


toDuration

public static java.lang.String toDuration(long inputTime)
Convert time in nanoseconds to a duration string. This is used to provide a more human readable order of magnitude for the duration. We assume standard fixed size quantites for all units.


printThreadCpuUsages

public void printThreadCpuUsages()
Utility function that dumps the cpu usages for the threads to stdout. Output will be sorted based on the 1-minute usage from highest to lowest.


getThreadCpuUsages

public java.util.Map<java.lang.String,java.lang.Object> getThreadCpuUsages(ThreadCpuStats.CpuUsageComparator cmp)
Utility function that returns a Map containing cpu usages for threads. Output will be sorted based on the ThreadCpuStats.CpuUsageComparator passed.

Parameters:
cmp - order to use for the results

printThreadCpuUsages

public void printThreadCpuUsages(java.io.OutputStream out,
                                 ThreadCpuStats.CpuUsageComparator cmp)
Utility function that dumps the cpu usages for the threads to stdout. Output will be sorted based on the 1-minute usage from highest to lowest.

Parameters:
out - stream where output will be written
cmp - order to use for the results