Package org.h2.util
Class Profiler
- java.lang.Object
-
- org.h2.util.Profiler
-
- All Implemented Interfaces:
java.lang.Runnable
public class Profiler extends java.lang.Object implements java.lang.RunnableA simple CPU profiling tool similar to java -Xrunhprof. It can be used in-process (to profile the current application) or as a standalone program (to profile a different process, or files containing full thread dumps).
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.HashMap<java.lang.String,java.lang.Integer>countsintdepthprivate java.lang.String[]ignoreLinesprivate java.lang.String[]ignorePackagesprivate java.lang.String[]ignoreThreadsprivate static java.lang.instrument.Instrumentationinstrumentationintintervalprivate static java.lang.StringLINE_SEPARATORprivate static intMAX_ELEMENTSprivate intminCountbooleanpausedprivate intpidprivate longstartprivate booleanstopbooleansumClassesprivate java.util.HashMap<java.lang.String,java.lang.Integer>summaryThe summary (usually one entry per package, unless sumClasses is enabled, in which case it's one entry per class).booleansumMethodsprivate java.lang.Threadthreadprivate intthreadDumpsprivate longtimeprivate inttotal
-
Constructor Summary
Constructors Constructor Description Profiler()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static voidappendTop(java.lang.StringBuilder buff, java.util.HashMap<java.lang.String,java.lang.Integer> map, int count, int total, boolean table)private static voidcopyInThread(java.io.InputStream in, java.io.OutputStream out)private static java.lang.Stringexec(java.lang.String... args)static java.lang.instrument.InstrumentationgetInstrumentation()Get the instrumentation object if started as an agent.private static java.util.List<java.lang.Object[]>getRunnableStackTraces()java.lang.StringgetTop(int count)Get the top stack traces.private java.lang.StringgetTopTraces(int count)private static intincrement(java.util.HashMap<java.lang.String,java.lang.Integer> map, java.lang.String trace, int minCount)static voidmain(java.lang.String... args)Run the command line version of the profiler.static voidpremain(java.lang.String agentArgs, java.lang.instrument.Instrumentation inst)This method is called when the agent is installed.private voidprocessList(java.util.List<java.lang.Object[]> list)private static java.util.List<java.lang.Object[]>readRunnableStackTraces(int pid)private static java.util.List<java.lang.Object[]>readStackTrace(java.io.LineNumberReader r)voidrun()private voidrun(java.lang.String... args)ProfilerstartCollecting()Start collecting profiling data.private static booleanstartsWithAny(java.lang.String s, java.lang.String[] prefixes)ProfilerstopCollecting()Stop collecting.private voidtick()
-
-
-
Field Detail
-
instrumentation
private static java.lang.instrument.Instrumentation instrumentation
-
LINE_SEPARATOR
private static final java.lang.String LINE_SEPARATOR
-
MAX_ELEMENTS
private static final int MAX_ELEMENTS
- See Also:
- Constant Field Values
-
interval
public int interval
-
depth
public int depth
-
paused
public boolean paused
-
sumClasses
public boolean sumClasses
-
sumMethods
public boolean sumMethods
-
pid
private int pid
-
ignoreLines
private final java.lang.String[] ignoreLines
-
ignorePackages
private final java.lang.String[] ignorePackages
-
ignoreThreads
private final java.lang.String[] ignoreThreads
-
stop
private volatile boolean stop
-
counts
private final java.util.HashMap<java.lang.String,java.lang.Integer> counts
-
summary
private final java.util.HashMap<java.lang.String,java.lang.Integer> summary
The summary (usually one entry per package, unless sumClasses is enabled, in which case it's one entry per class).
-
minCount
private int minCount
-
total
private int total
-
thread
private java.lang.Thread thread
-
start
private long start
-
time
private long time
-
threadDumps
private int threadDumps
-
-
Method Detail
-
premain
public static void premain(java.lang.String agentArgs, java.lang.instrument.Instrumentation inst)This method is called when the agent is installed.- Parameters:
agentArgs- the agent argumentsinst- the instrumentation object
-
getInstrumentation
public static java.lang.instrument.Instrumentation getInstrumentation()
Get the instrumentation object if started as an agent.- Returns:
- the instrumentation, or null
-
main
public static void main(java.lang.String... args)
Run the command line version of the profiler. The JDK (jps and jstack) need to be in the path.- Parameters:
args- the process id of the process - if not set the java processes are listed
-
run
private void run(java.lang.String... args)
-
getRunnableStackTraces
private static java.util.List<java.lang.Object[]> getRunnableStackTraces()
-
readRunnableStackTraces
private static java.util.List<java.lang.Object[]> readRunnableStackTraces(int pid)
-
readStackTrace
private static java.util.List<java.lang.Object[]> readStackTrace(java.io.LineNumberReader r) throws java.io.IOException- Throws:
java.io.IOException
-
exec
private static java.lang.String exec(java.lang.String... args)
-
copyInThread
private static void copyInThread(java.io.InputStream in, java.io.OutputStream out)
-
startCollecting
public Profiler startCollecting()
Start collecting profiling data.- Returns:
- this
-
stopCollecting
public Profiler stopCollecting()
Stop collecting.- Returns:
- this
-
run
public void run()
- Specified by:
runin interfacejava.lang.Runnable
-
tick
private void tick()
-
processList
private void processList(java.util.List<java.lang.Object[]> list)
-
startsWithAny
private static boolean startsWithAny(java.lang.String s, java.lang.String[] prefixes)
-
increment
private static int increment(java.util.HashMap<java.lang.String,java.lang.Integer> map, java.lang.String trace, int minCount)
-
getTop
public java.lang.String getTop(int count)
Get the top stack traces.- Parameters:
count- the maximum number of stack traces- Returns:
- the stack traces.
-
getTopTraces
private java.lang.String getTopTraces(int count)
-
appendTop
private static void appendTop(java.lang.StringBuilder buff, java.util.HashMap<java.lang.String,java.lang.Integer> map, int count, int total, boolean table)
-
-