Class CPUTracer

java.lang.Object
com.oracle.truffle.tools.profiler.CPUTracer
All Implemented Interfaces:
Closeable, AutoCloseable

public final class CPUTracer extends Object implements Closeable
Implementation of a tracing based profiler for Truffle languages built on top of the Truffle instrumentation framework.

The tracer counts how many times each of the elements of interest (e.g. functions, statements, etc.) are executed.

Usage example:

Context context = Context.create();
CPUTracer tracer = CPUTracer.find(context.getEngine());
tracer.setCollecting(true);
context.eval("...", "...");
tracer.setCollecting(false);
tracer.close();
// Read information about execution counts of elements.
for (CPUTracer.Payload p : tracer.getPayloads()) {
    final String rootName = p.getRootName();
    final long count = p.getCount();
}
Since:
0.30
  • Method Details

    • find

      public static CPUTracer find(org.graalvm.polyglot.Engine engine)
      Finds CPUTracer associated with given engine.
      Parameters:
      engine - the engine to find debugger for
      Returns:
      an instance of associated CPUTracer
      Since:
      19.0
    • setCollecting

      public void setCollecting(boolean collecting)
      Controls whether the tracer is collecting data or not.
      Parameters:
      collecting - the new state of the tracer.
      Since:
      0.30
    • isCollecting

      public boolean isCollecting()
      Returns:
      whether or not the tracer is currently collecting data.
      Since:
      0.30
    • setFilter

      public void setFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter filter)
      Sets the filter for the tracer. This allows the tracer to trace only parts of the executed source code.
      Parameters:
      filter - The filter describing which part of the source code to trace
      Since:
      0.30
    • getFilter

      public com.oracle.truffle.api.instrumentation.SourceSectionFilter getFilter()
      Returns:
      The filter describing which part of the source code to sample
      Since:
      0.30
    • getPayloads

      public Collection<CPUTracer.Payload> getPayloads()
      Returns:
      All the payloads the tracer has gathered as an unmodifiable collection
      Since:
      0.30
    • clearData

      public void clearData()
      Erases all the data gathered by the tracer.
      Since:
      0.30
    • close

      public void close()
      Closes the tracer for fuhrer use, deleting all the gathered data.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Since:
      0.30