Package org.h2.util

Class Profiler

java.lang.Object
org.h2.util.Profiler
All Implemented Interfaces:
Runnable

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

    • instrumentation

      private static Instrumentation instrumentation
    • LINE_SEPARATOR

      private static final String LINE_SEPARATOR
    • MAX_ELEMENTS

      private static final int MAX_ELEMENTS
      See Also:
    • 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 String[] ignoreLines
    • ignorePackages

      private final String[] ignorePackages
    • ignoreThreads

      private final String[] ignoreThreads
    • stop

      private volatile boolean stop
    • counts

      private final HashMap<String,Integer> counts
    • 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).
    • minCount

      private int minCount
    • total

      private int total
    • thread

      private Thread thread
    • start

      private long start
    • time

      private long time
    • threadDumps

      private int threadDumps
  • Constructor Details

    • Profiler

      public Profiler()
  • Method Details

    • premain

      public static void premain(String agentArgs, Instrumentation inst)
      This method is called when the agent is installed.
      Parameters:
      agentArgs - the agent arguments
      inst - the instrumentation object
    • getInstrumentation

      public static Instrumentation getInstrumentation()
      Get the instrumentation object if started as an agent.
      Returns:
      the instrumentation, or null
    • main

      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 - the process id of the process - if not set the java processes are listed
    • run

      private void run(String... args)
    • getRunnableStackTraces

      private static List<Object[]> getRunnableStackTraces()
    • readRunnableStackTraces

      private static List<Object[]> readRunnableStackTraces(int pid)
    • readStackTrace

      private static List<Object[]> readStackTrace(LineNumberReader r) throws IOException
      Throws:
      IOException
    • exec

      private static String exec(String... args)
    • copyInThread

      private static void copyInThread(InputStream in, 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:
      run in interface Runnable
    • tick

      private void tick()
    • processList

      private void processList(List<Object[]> list)
    • startsWithAny

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

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

      public String getTop(int count)
      Get the top stack traces.
      Parameters:
      count - the maximum number of stack traces
      Returns:
      the stack traces.
    • getTopTraces

      private String getTopTraces(int count)
    • appendTop

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