public final class CPUSampler extends Object implements Closeable
The sampler keeps a shadow stack during execution. This shadow stack is sampled at regular intervals, i.e. the state of the stack is copied and saved into trees of nodes, which represent the profile of the execution.
Usage example:
Contextcontext =Context.create();CPUSamplersampler =CPUSampler.find(context.getEngine()); sampler.setCollecting(true); context.eval("...", "..."); sampler.setCollecting(false); sampler.close(); // Read information about the roots of the tree per thread. for (Collection<ProfilerNode<CPUSampler.Payload>> nodes : sampler.getThreadToNodesMap().values()) { for (ProfilerNode<CPUSampler.Payload> node : nodes) { finalStringrootName = node.getRootName(); final int selfHitCount = node.getPayload().getSelfHitCount(); // ... } }
| Modifier and Type | Class and Description |
|---|---|
static class |
CPUSampler.Mode
Describes the different modes in which the CPU sampler can operate.
|
static class |
CPUSampler.Payload
Wrapper for information on how many times an element was seen on the shadow stack.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clearData()
Erases all the data gathered by the sampler and resets the sample count to 0.
|
void |
close()
Closes the sampler for further use, deleting all the gathered data.
|
static CPUSampler |
find(org.graalvm.polyglot.Engine engine)
Finds
CPUSampler associated with given engine. |
com.oracle.truffle.api.instrumentation.SourceSectionFilter |
getFilter() |
long |
getPeriod() |
Collection<ProfilerNode<CPUSampler.Payload>> |
getRootNodes()
Merges all the 'per thread' profiles into one set of nodes and returns it.
|
long |
getSampleCount() |
int |
getStackLimit() |
Map<Thread,Collection<ProfilerNode<CPUSampler.Payload>>> |
getThreadToNodesMap() |
boolean |
hasData() |
boolean |
hasStackOverflowed() |
boolean |
isCollecting() |
boolean |
isGatherSelfHitTimes() |
void |
setCollecting(boolean collecting)
Controls whether the sampler is collecting data or not.
|
void |
setDelay(long delay)
Sets the delay period i.e.
|
void |
setDelaySamplingUntilNonInternalLangInit(boolean delaySamplingUntilNonInternalLangInit)
Sets the option to delay sampling until a non-internal language is initialized.
|
void |
setFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter filter)
Sets the
filter for the sampler. |
void |
setGatherSelfHitTimes(boolean gatherSelfHitTimes)
Sets whether or not to gather timestamp information for the element at the top of the stack
for each sample.
|
void |
setMode(CPUSampler.Mode mode)
Sets the
mode for the sampler. |
void |
setPeriod(long samplePeriod)
Sets the sampling period i.e.
|
void |
setStackLimit(int stackLimit)
Sets the maximum amount of stack frames that are sampled.
|
Map<Thread,List<StackTraceEntry>> |
takeSample()
Sample all threads and gather their current stack trace entries.
|
public static CPUSampler find(org.graalvm.polyglot.Engine engine)
CPUSampler associated with given engine.public void setCollecting(boolean collecting)
collecting - the new state of the sampler.public boolean isCollecting()
public void setMode(CPUSampler.Mode mode)
mode for the sampler.mode - the new mode for the sampler.public void setPeriod(long samplePeriod)
samplePeriod - the new sampling period.public long getPeriod()
public void setDelay(long delay)
delay - the delay period.public void setStackLimit(int stackLimit)
stackLimit - the new size of the shadow stackpublic int getStackLimit()
public void setFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter filter)
filter for the sampler. The sampler will only observe
parts of the executed source code that is specified by the filter.filter - The new filter describing which part of the source code to samplepublic void setDelaySamplingUntilNonInternalLangInit(boolean delaySamplingUntilNonInternalLangInit)
delaySamplingUntilNonInternalLangInit - Enable or disable this option.public com.oracle.truffle.api.instrumentation.SourceSectionFilter getFilter()
public long getSampleCount()
public boolean hasStackOverflowed()
public Collection<ProfilerNode<CPUSampler.Payload>> getRootNodes()
public Map<Thread,Collection<ProfilerNode<CPUSampler.Payload>>> getThreadToNodesMap()
public void clearData()
public boolean hasData()
public void close()
close in interface Closeableclose in interface AutoCloseablepublic boolean isGatherSelfHitTimes()
public void setGatherSelfHitTimes(boolean gatherSelfHitTimes)
gatherSelfHitTimes - new value for whether or not to gather timestampspublic Map<Thread,List<StackTraceEntry>> takeSample()