Class HistogramInstructionTracer

java.lang.Object
com.oracle.truffle.api.bytecode.debug.HistogramInstructionTracer
All Implemented Interfaces:
InstructionTracer

public final class HistogramInstructionTracer extends Object implements InstructionTracer
Instruction tracer that records per-opcode execution counts and optionally aggregates them into hierarchical histograms by user defined group clauses.

The tracer is optimized for the no-filter, no-group case. In that mode the hot path avoids boundary calls and can be partially evaluated. When grouping or filtering is enabled, a small LRU cache avoids repeated evaluation of the grouping and filtering functions for the same BytecodeNode, current thread, and compilation tier.

Thread safety: increments are performed via atomic counters and are safe under concurrent execution. Histogram creation is a snapshot that can be performed concurrently with counting. For interval semantics, prefer getHistogramAndReset() over mixing getHistogram() with reset().

Basic usage

The example below shows how to attach a HistogramInstructionTracer directly to a generated bytecode root, execute code, then collect and print a histogram snapshot.

var root = MyRootNodeGen.BYTECODE.create(language, BytecodeConfig.DEFAULT, b -> {
    b.beginRoot();
    b.beginReturn();
    b.emitLoadArgument(0);
    b.endReturn();
    b.endRoot();
}).getNode(0);

// Create and attach the histogram tracer to the root.
var tracer = HistogramInstructionTracer.newBuilder().build(MyRootNodeGen.BYTECODE);
root.getRootNodes().addInstructionTracer(tracer);

// Execute your program as usual.
Object result = root.getCallTarget().call(42);

// Take a consistent snapshot and reset counters for the next interval.
var histogram = tracer.getHistogramAndReset();

// Inspect or print the histogram.
long total = histogram.getInstructionsExecuted();
histogram.print(System.out);

// Detach the tracer when done.
root.getRootNodes().removeInstructionTracer(tracer);
Since:
25.1
  • Method Details