Class CPUTracer
java.lang.Object
com.oracle.truffle.tools.profiler.CPUTracer
- All Implemented Interfaces:
Closeable
,AutoCloseable
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
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Holds data on how many times a section of source code was executed. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Erases all the data gathered by the tracer.void
close()
Closes the tracer for fuhrer use, deleting all the gathered data.static CPUTracer
find
(org.graalvm.polyglot.Engine engine) FindsCPUTracer
associated with given engine.com.oracle.truffle.api.instrumentation.SourceSectionFilter
boolean
void
setCollecting
(boolean collecting) Controls whether the tracer is collecting data or not.void
setFilter
(com.oracle.truffle.api.instrumentation.SourceSectionFilter filter) Sets thefilter
for the tracer.
-
Method Details
-
find
FindsCPUTracer
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 thefilter
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
- 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 interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Since:
- 0.30
-