Package one.profiler

Class AsyncProfiler

java.lang.Object
one.profiler.AsyncProfiler
All Implemented Interfaces:
AsyncProfilerMXBean

public class AsyncProfiler extends Object implements 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 Details

    • getInstance

      public static AsyncProfiler getInstance()
    • getInstance

      public static AsyncProfiler getInstance(String libPath)
    • start

      public void start(String event, long interval) throws IllegalStateException
      Start profiling
      Specified by:
      start in interface AsyncProfilerMXBean
      Parameters:
      event - Profiling event, see Events
      interval - Sampling interval, e.g. nanoseconds for Events.CPU
      Throws:
      IllegalStateException - If profiler is already running
    • resume

      public void resume(String event, long interval) throws IllegalStateException
      Start or resume profiling without resetting collected data. Note that event and interval may change since the previous profiling session.
      Specified by:
      resume in interface AsyncProfilerMXBean
      Parameters:
      event - Profiling event, see Events
      interval - Sampling interval, e.g. nanoseconds for Events.CPU
      Throws:
      IllegalStateException - If profiler is already running
    • stop

      public void stop() throws IllegalStateException
      Stop profiling (without dumping results)
      Specified by:
      stop in interface AsyncProfilerMXBean
      Throws:
      IllegalStateException - If profiler is not running
    • getSamples

      public long getSamples()
      Get the number of samples collected during the profiling session
      Specified by:
      getSamples in interface AsyncProfilerMXBean
      Returns:
      Number of samples
    • getVersion

      public String getVersion()
      Get profiler agent version, e.g. "1.0"
      Specified by:
      getVersion in interface AsyncProfilerMXBean
      Returns:
      Version string
    • execute

      Execute an agent-compatible profiling command - the comma-separated list of arguments described in arguments.cpp
      Specified by:
      execute in interface AsyncProfilerMXBean
      Parameters:
      command - Profiling command
      Returns:
      The command result
      Throws:
      IllegalArgumentException - If failed to parse the command
      IOException - If failed to create output file
      IllegalStateException
    • dumpCollapsed

      public String dumpCollapsed(Counter counter)
      Dump profile in 'collapsed stacktraces' format
      Specified by:
      dumpCollapsed in interface AsyncProfilerMXBean
      Parameters:
      counter - Which counter to display in the output
      Returns:
      Textual representation of the profile
    • dumpTraces

      public String dumpTraces(int maxTraces)
      Dump collected stack traces
      Specified by:
      dumpTraces in interface AsyncProfilerMXBean
      Parameters:
      maxTraces - Maximum number of stack traces to dump. 0 means no limit
      Returns:
      Textual representation of the profile
    • dumpFlat

      public String dumpFlat(int maxMethods)
      Dump flat profile, i.e. the histogram of the hottest methods
      Specified by:
      dumpFlat in interface AsyncProfilerMXBean
      Parameters:
      maxMethods - Maximum number of methods to dump. 0 means no limit
      Returns:
      Textual representation of the profile
    • addThread

      public void addThread(Thread thread)
      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

      public void removeThread(Thread thread)
      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