public final class MemoryTracer extends Object implements Closeable
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:
Contextcontext =Context.create();MemoryTracertracer =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()) { finalStringrootName = node.getRootName(); final long allocCount = node.getPayload().getTotalAllocations(); }
| Modifier and Type | Class and Description |
|---|---|
static class |
MemoryTracer.AllocationEventInfo
Stores informatino about a single
AllocationEvent. |
static class |
MemoryTracer.Payload
Used as a template parameter for
ProfilerNode. |
| Modifier and Type | Method and Description |
|---|---|
void |
clearData()
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)
Finds
MemoryTracer associated with given engine. |
Collection<ProfilerNode<MemoryTracer.Payload>> |
getRootNodes() |
int |
getStackLimit() |
Map<Thread,Collection<ProfilerNode<MemoryTracer.Payload>>> |
getThreadToNodesMap() |
boolean |
hasData() |
boolean |
hasStackOverflowed() |
boolean |
isCollecting() |
void |
setCollecting(boolean collecting)
Controls whether the tracer is collecting data or not.
|
void |
setFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter filter)
Sets the
filter for the sampler. |
void |
setStackLimit(int stackLimit)
Sets the size of the shadow stack.
|
public static MemoryTracer find(org.graalvm.polyglot.Engine engine)
MemoryTracer associated with given engine.engine - the engine to find debugger forMemoryTracerpublic void setCollecting(boolean collecting)
collecting - the new state of the tracer.public boolean isCollecting()
public Collection<ProfilerNode<MemoryTracer.Payload>> getRootNodes()
public Map<Thread,Collection<ProfilerNode<MemoryTracer.Payload>>> getThreadToNodesMap()
public void clearData()
public boolean hasData()
public int getStackLimit()
public void setStackLimit(int stackLimit)
stackLimit - the new size of the shadow stackpublic boolean hasStackOverflowed()
public void setFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter filter)
filter for the sampler. This allows the sampler to
observe only parts of the executed source code.filter - The new filter describing which part of the source code to samplepublic void close()
close in interface Closeableclose in interface AutoCloseable