Package one.profiler
Class AsyncProfiler
java.lang.Object
one.profiler.AsyncProfiler
- All Implemented Interfaces:
AsyncProfilerMXBean
Java API for in-process profiling. Serves as a wrapper around
async-profiler native library. This class is a singleton.
The first call to
getInstance() initiates loading of
libasyncProfiler.so.-
Method Summary
Modifier and TypeMethodDescriptionvoidAdd the given thread to the set of profiled threads.dumpCollapsed(Counter counter) Dump profile in 'collapsed stacktraces' formatdumpFlat(int maxMethods) Dump flat profile, i.e.dumpTraces(int maxTraces) Dump collected stack tracesExecute an agent-compatible profiling command - the comma-separated list of arguments described in arguments.cppstatic AsyncProfilerstatic AsyncProfilergetInstance(String libPath) longGet the number of samples collected during the profiling sessionGet profiler agent version, e.g.voidremoveThread(Thread thread) Remove the given thread from the set of profiled threads.voidStart or resume profiling without resetting collected data.voidStart profilingvoidstop()Stop profiling (without dumping results)
-
Method Details
-
getInstance
-
getInstance
-
start
Start profiling- Specified by:
startin interfaceAsyncProfilerMXBean- Parameters:
event- Profiling event, seeEventsinterval- Sampling interval, e.g. nanoseconds for Events.CPU- Throws:
IllegalStateException- If profiler is already running
-
resume
Start or resume profiling without resetting collected data. Note that event and interval may change since the previous profiling session.- Specified by:
resumein interfaceAsyncProfilerMXBean- Parameters:
event- Profiling event, seeEventsinterval- Sampling interval, e.g. nanoseconds for Events.CPU- Throws:
IllegalStateException- If profiler is already running
-
stop
Stop profiling (without dumping results)- Specified by:
stopin interfaceAsyncProfilerMXBean- Throws:
IllegalStateException- If profiler is not running
-
getSamples
public long getSamples()Get the number of samples collected during the profiling session- Specified by:
getSamplesin interfaceAsyncProfilerMXBean- Returns:
- Number of samples
-
getVersion
Get profiler agent version, e.g. "1.0"- Specified by:
getVersionin interfaceAsyncProfilerMXBean- Returns:
- Version string
-
execute
public String execute(String command) throws IllegalArgumentException, IllegalStateException, IOException Execute an agent-compatible profiling command - the comma-separated list of arguments described in arguments.cpp- Specified by:
executein interfaceAsyncProfilerMXBean- Parameters:
command- Profiling command- Returns:
- The command result
- Throws:
IllegalArgumentException- If failed to parse the commandIOException- If failed to create output fileIllegalStateException
-
dumpCollapsed
Dump profile in 'collapsed stacktraces' format- Specified by:
dumpCollapsedin interfaceAsyncProfilerMXBean- Parameters:
counter- Which counter to display in the output- Returns:
- Textual representation of the profile
-
dumpTraces
Dump collected stack traces- Specified by:
dumpTracesin interfaceAsyncProfilerMXBean- Parameters:
maxTraces- Maximum number of stack traces to dump. 0 means no limit- Returns:
- Textual representation of the profile
-
dumpFlat
Dump flat profile, i.e. the histogram of the hottest methods- Specified by:
dumpFlatin interfaceAsyncProfilerMXBean- Parameters:
maxMethods- Maximum number of methods to dump. 0 means no limit- Returns:
- Textual representation of the profile
-
addThread
Add the given thread to the set of profiled threads. 'filter' option must be enabled to use this method.- Parameters:
thread- Thread to include in profiling
-
removeThread
Remove the given thread from the set of profiled threads. 'filter' option must be enabled to use this method.- Parameters:
thread- Thread to exclude from profiling
-