Package org.h2.util

Class Profiler

  • All Implemented Interfaces:
    java.lang.Runnable

    public class Profiler
    extends java.lang.Object
    implements java.lang.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 Summary

      Fields 
      Modifier and Type Field Description
      private java.util.HashMap<java.lang.String,​java.lang.Integer> counts  
      int depth  
      private java.lang.String[] ignoreLines  
      private java.lang.String[] ignorePackages  
      private java.lang.String[] ignoreThreads  
      private static java.lang.instrument.Instrumentation instrumentation  
      int interval  
      private static java.lang.String LINE_SEPARATOR  
      private static int MAX_ELEMENTS  
      private int minCount  
      boolean paused  
      private int pid  
      private long start  
      private boolean stop  
      boolean sumClasses  
      private 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).
      boolean sumMethods  
      private java.lang.Thread thread  
      private int threadDumps  
      private long time  
      private int total  
    • Constructor Summary

      Constructors 
      Constructor Description
      Profiler()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static void appendTop​(java.lang.StringBuilder buff, java.util.HashMap<java.lang.String,​java.lang.Integer> map, int count, int total, boolean table)  
      private static void copyInThread​(java.io.InputStream in, java.io.OutputStream out)  
      private static java.lang.String exec​(java.lang.String... args)  
      static java.lang.instrument.Instrumentation getInstrumentation()
      Get the instrumentation object if started as an agent.
      private static java.util.List<java.lang.Object[]> getRunnableStackTraces()  
      java.lang.String getTop​(int count)
      Get the top stack traces.
      private java.lang.String getTopTraces​(int count)  
      private static int increment​(java.util.HashMap<java.lang.String,​java.lang.Integer> map, java.lang.String trace, int minCount)  
      static void main​(java.lang.String... args)
      Run the command line version of the profiler.
      static void premain​(java.lang.String agentArgs, java.lang.instrument.Instrumentation inst)
      This method is called when the agent is installed.
      private void processList​(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)  
      void run()  
      private void run​(java.lang.String... args)  
      Profiler startCollecting()
      Start collecting profiling data.
      private static boolean startsWithAny​(java.lang.String s, java.lang.String[] prefixes)  
      Profiler stopCollecting()
      Stop collecting.
      private void tick()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • instrumentation

        private static java.lang.instrument.Instrumentation instrumentation
      • LINE_SEPARATOR

        private static final java.lang.String LINE_SEPARATOR
      • 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
    • Constructor Detail

      • Profiler

        public Profiler()
    • 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 arguments
        inst - 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:
        run in interface java.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)