Top Description Fields Constructors Methods
org.h2.util

public Class Profiler

extends Object
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable
Imports
java.io.ByteArrayOutputStream, .IOException, .InputStream, .LineNumberReader, .OutputStream, .Reader, .StringReader, java.lang.instrument.Instrumentation, java.nio.charset.StandardCharsets, java.nio.file.Files, .Path, .Paths, java.util.ArrayList, .HashMap, .Iterator, .List, .Map, java.util.concurrent.TimeUnit

A 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

Modifier and TypeField and Description
private final HashMap<String, Integer>
public int
private final String[]
private final String[]
private final String[]
private static java.lang.instrument.Instrumentation
public int
private static final String
private static final int
private int
public boolean
private int
private long
private volatile boolean
public boolean
private final HashMap<String, Integer>
summary

The summary (usually one entry per package, unless sumClasses is enabled, in which case it's one entry per class).

public boolean
private Thread
private int
private long
private int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static void
appendTop(StringBuilder buff, HashMap<String, Integer> map, int count, int total, boolean table)

private static void
copyInThread(final InputStream in, final OutputStream out)

private static String
exec(String... args)

public static java.lang.instrument.Instrumentation

Returns:

the instrumentation, or null
getInstrumentation
()

Get the instrumentation object if started as an agent.

private static List<Object[]>
public String

Returns:

the stack traces.
getTop
(int
the maximum number of stack traces
count
)

Get the top stack traces.

private String
getTopTraces(int count)

private static int
increment(HashMap<String, Integer> map, String trace, int minCount)

public static void
main(String...
the process id of the process - if not set the java processes are listed
args
)

Run the command line version of the profiler.

public static void
premain(String
the agent arguments
agentArgs
,
java.lang.instrument.Instrumentation
the instrumentation object
inst
)

This method is called when the agent is installed.

private void
private static List<Object[]>
private static List<Object[]>
private void
run(String... args)

public void
run()

Implements java.lang.Runnable.run.

Runs this operation.

public Profiler

Returns:

this
startCollecting
()

Start collecting profiling data.

private static boolean
startsWithAny(String s, String[] prefixes)

public Profiler

Returns:

this
stopCollecting
()

Stop collecting.

private void
tick()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

countsback to summary
private final HashMap<String, Integer> counts
depthback to summary
public int depth
ignoreLinesback to summary
private final String[] ignoreLines
ignorePackagesback to summary
private final String[] ignorePackages
ignoreThreadsback to summary
private final String[] ignoreThreads
instrumentationback to summary
private static java.lang.instrument.Instrumentation instrumentation
intervalback to summary
public int interval
LINE_SEPARATORback to summary
private static final String LINE_SEPARATOR
MAX_ELEMENTSback to summary
private static final int MAX_ELEMENTS
minCountback to summary
private int minCount
pausedback to summary
public boolean paused
pidback to summary
private int pid
startback to summary
private long start
stopback to summary
private volatile boolean stop
sumClassesback to summary
public boolean sumClasses
summaryback to summary
private final HashMap<String, Integer> summary

The summary (usually one entry per package, unless sumClasses is enabled, in which case it's one entry per class).

sumMethodsback to summary
public boolean sumMethods
threadback to summary
private Thread thread
threadDumpsback to summary
private int threadDumps
timeback to summary
private long time
totalback to summary
private int total

Constructor Detail

Profilerback to summary
public Profiler()

Method Detail

appendTopback to summary
private static void appendTop(StringBuilder buff, HashMap<String, Integer> map, int count, int total, boolean table)
copyInThreadback to summary
private static void copyInThread(final InputStream in, final OutputStream out)
execback to summary
private static String exec(String... args)
getInstrumentationback to summary
public static java.lang.instrument.Instrumentation getInstrumentation()

Get the instrumentation object if started as an agent.

Returns:java.lang.instrument.Instrumentation

the instrumentation, or null

getRunnableStackTracesback to summary
private static List<Object[]> getRunnableStackTraces()
getTopback to summary
public String getTop(int count)

Get the top stack traces.

Parameters
count:int

the maximum number of stack traces

Returns:String

the stack traces.

getTopTracesback to summary
private String getTopTraces(int count)
incrementback to summary
private static int increment(HashMap<String, Integer> map, String trace, int minCount)
mainback to summary
public static void main(String... args)

Run the command line version of the profiler. The JDK (jps and jstack) need to be in the path.

Parameters
args:String[]

the process id of the process - if not set the java processes are listed

premainback to summary
public static void premain(String agentArgs, java.lang.instrument.Instrumentation inst)

This method is called when the agent is installed.

Parameters
agentArgs:String

the agent arguments

inst:java.lang.instrument.Instrumentation

the instrumentation object

processListback to summary
private void processList(List<Object[]> list)
readRunnableStackTracesback to summary
private static List<Object[]> readRunnableStackTraces(int pid)
readStackTraceback to summary
private static List<Object[]> readStackTrace(LineNumberReader r) throws IOException
runback to summary
private void run(String... args)
runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
startCollectingback to summary
public Profiler startCollecting()

Start collecting profiling data.

Returns:Profiler

this

startsWithAnyback to summary
private static boolean startsWithAny(String s, String[] prefixes)
stopCollectingback to summary
public Profiler stopCollecting()

Stop collecting.

Returns:Profiler

this

tickback to summary
private void tick()