Class HistogramInstructionTracer
- All Implemented Interfaces:
InstructionTracer
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 aHistogramInstructionTracer
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder forHistogramInstructionTracer.static interfaceA grouping function that maps aBytecodeNode, the currentThread, and the compilation tier to an arbitrary grouping key.static final classRepresents a hierarchical histogram that can group instruction counts by arbitrary attributes.Nested classes/interfaces inherited from interface InstructionTracer
InstructionTracer.InstructionAccess -
Method Summary
Modifier and TypeMethodDescriptionRenders the current histogram snapshot into a string usingprintHistogram(PrintStream).BytecodeDescriptor<?, ?, ?> Returns theBytecodeDescriptorthat this tracer is attached to.Creates a hierarchical histogram snapshot of the recorded counters without resetting them.Creates a hierarchical histogram snapshot of the recorded counters and atomically resets the underlying counters to zero.Returns a builder forHistogramInstructionTracerthat allows configuring a filter and one or more grouping clauses.voidonInstructionEnter(InstructionTracer.InstructionAccess access, BytecodeNode bytecode, int bytecodeIndex, Frame frame) Records the execution of an instruction.voidPrints the current histogram snapshot to the givenPrintStream.voidreset()Resets all counters to zero and discards previously recorded data.
-
Method Details
-
onInstructionEnter
public void onInstructionEnter(InstructionTracer.InstructionAccess access, BytecodeNode bytecode, int bytecodeIndex, Frame frame) Records the execution of an instruction. This method is not intended to be called directly, but by the bytecode DSL framework as part of instruction tracing.- Specified by:
onInstructionEnterin interfaceInstructionTracer- Parameters:
access- accessor to query information about the current instruction, valid only during this callbytecode- theBytecodeNodecurrently being interpretedbytecodeIndex- the bytecode index (BCI) of the instruction to be executedframe- the current frame for the root being interpreted- Since:
- 25.1
-
getExclusiveBytecodeDescriptor
Returns theBytecodeDescriptorthat this tracer is attached to.- Specified by:
getExclusiveBytecodeDescriptorin interfaceInstructionTracer- Returns:
- the descriptor used to resolve instruction metadata and opcodes
-
getHistogram
Creates a hierarchical histogram snapshot of the recorded counters without resetting them.Use this to inspect cumulative counts. If you need interval semantics, prefer
getHistogramAndReset().- Returns:
- a
HistogramInstructionTracer.Histogramview of the current counters, possibly grouped - Since:
- 25.1
-
getHistogramAndReset
Creates a hierarchical histogram snapshot of the recorded counters and atomically resets the underlying counters to zero.Use this to obtain interval counts in long running applications. The reset is performed atomically per-counter, increments that occur after the swap will be visible in the next interval.
- Returns:
- a
HistogramInstructionTracer.Histogramview of the counts since the previous reset - Since:
- 25.1
-
dumpHistogram
Renders the current histogram snapshot into a string usingprintHistogram(PrintStream).- Returns:
- a human readable histogram table as UTF-8 text
- Since:
- 25.1
- See Also:
-
printHistogram
Prints the current histogram snapshot to the givenPrintStream.The output is a single table with aligned numeric columns. Groups, if present, are printed as indented pseudo rows followed by their leaves.
- Parameters:
out- the stream to print to- Since:
- 25.1
- See Also:
-
reset
public void reset()Resets all counters to zero and discards previously recorded data.Do not mix this with
getHistogram()if you need interval correctness, usegetHistogramAndReset()instead.- Since:
- 25.1
-
newBuilder
Returns a builder forHistogramInstructionTracerthat allows configuring a filter and one or more grouping clauses.- Returns:
- a new builder instance
- Since:
- 25.1
-