Class MemoryTracer
java.lang.Object
com.oracle.truffle.tools.profiler.MemoryTracer
- All Implemented Interfaces:
Closeable
,AutoCloseable
Implementation of a memory tracing 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.) allocates memory, as well as meta data about the allocated object. It keeps a shadow stack
during execution, and listens for allocation events
. On each event, the
allocation information is associated to the top of the stack.
NOTE: This profiler is still experimental with limited capabilities.
Usage example:
Context context = Context.create();
MemoryTracer tracer = MemoryTracer.find(context.getEngine());
tracer.setCollecting(true);
context.eval("...", "...");
tracer.setCollecting(false);
// rootNodes is the recorded profile of the execution in tree form.
tracer.close();
// Prints information about the roots of the tree.
for (ProfilerNode<MemoryTracer.Payload> node : tracer.getRootNodes()) {
final String rootName = node.getRootName();
final long allocCount = node.getPayload().getTotalAllocations();
}
- Since:
- 0.30
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Stores informatino about a singleAllocationEvent
.static final class
Used as a template parameter forProfilerNode
. -
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 MemoryTracer
find
(org.graalvm.polyglot.Engine engine) FindsMemoryTracer
associated with given engine.int
boolean
hasData()
boolean
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 sampler.void
setStackLimit
(int stackLimit) Sets the size of the shadow stack.
-
Method Details
-
find
FindsMemoryTracer
associated with given engine.- Parameters:
engine
- the engine to find debugger for- Returns:
- an instance of associated
MemoryTracer
- 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 sampler is currently collecting data.
- Since:
- 0.30
-
getRootNodes
- Returns:
- The roots of the trees representing the profile of the execution.
- Since:
- 0.30
-
getThreadToNodesMap
- Returns:
- The roots of the trees representing the profile of the execution per thread.
- Since:
- 19.0
-
clearData
public void clearData()Erases all the data gathered by the tracer.- Since:
- 0.30
-
hasData
public boolean hasData()- Returns:
- whether or not the sampler has collected any data so far.
- Since:
- 0.30
-
getStackLimit
public int getStackLimit()- Returns:
- size of the shadow stack
- Since:
- 0.30
-
setStackLimit
public void setStackLimit(int stackLimit) Sets the size of the shadow stack. Whether or not the shadow stack grew more than the provided size during execution can be checked with hasStackOverflowed()- Parameters:
stackLimit
- the new size of the shadow stack- Since:
- 0.30
-
hasStackOverflowed
public boolean hasStackOverflowed()- Returns:
- was the shadow stack size insufficient for the execution.
- Since:
- 0.30
-
setFilter
public void setFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter filter) Sets thefilter
for the sampler. This allows the sampler to observe only parts of the executed source code.- Parameters:
filter
- The new filter describing which part of the source code to sample- 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
-