---
title: "PrintInstructionTracer"
description: "An InstructionTracer implementation that prints a textual trace of executed bytecode instructions."
kind: "class"
id: "com.oracle.truffle.api.bytecode.debug.PrintInstructionTracer"
module: "truffle-api"
version: "25.6.0-elide.4"
canonical: "https://graalvm.elide.help/25.6.0-elide.4/api/truffle-api/com/oracle/truffle/api/bytecode/debug/PrintInstructionTracer.html"
---

# ◆ PrintInstructionTracer

[truffle-api](../../../../../../index.md) › [com.oracle.truffle.api.bytecode.debug](index.md) · Every page: [llms.txt](../../../../../../llms.txt)

Class in [`com.oracle.truffle.api.bytecode.debug`](index.md). Since 25.1.

```java
public final class PrintInstructionTracer implements InstructionTracer
```

Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `PrintInstructionTracer`

Implements: [`InstructionTracer`](../InstructionTracer.md)

An [`InstructionTracer`](../InstructionTracer.md) implementation that prints a textual trace of executed bytecode instructions.

Each time an instruction is about to execute, this tracer formats a single line containing:

- a monotonically increasing instruction counter,
- the qualified root name of the [`BytecodeNode`](../BytecodeNode.md) being interpreted, and
- a human readable representation of the instruction at the current bytecode index.

Output is delivered to a user-supplied [`Consumer`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/function/Consumer.html)\<String\> (for example, `System.out::println`) or to a [`java.io.PrintStream`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/io/PrintStream.html) via the [`newBuilder(PrintStream)`](PrintInstructionTracer.md#newBuilder%28java.io.PrintStream%29) convenience factory.

A tracer may optionally be restricted to a subset of bytecode roots by installing a filter predicate. If a [`BytecodeNode`](../BytecodeNode.md) does not match the filter, its instructions are skipped.

This tracer is intended for debugging and profiling during development. It runs on the language execution thread and executes on the hot path before every instruction; it should not be left enabled in production code.

## Nested types

- [`PrintInstructionTracer.Builder`](PrintInstructionTracer.Builder.md) (class): Builder for PrintInstructionTracer instances.

## Methods

### onInstructionEnter(InstructionTracer.InstructionAccess, BytecodeNode, …)
<a id="onInstructionEnter(com.oracle.truffle.api.bytecode.InstructionTracer.InstructionAccess,com.oracle.truffle.api.bytecode.BytecodeNode,int,com.oracle.truffle.api.frame.Frame)"></a>`public void onInstructionEnter(InstructionTracer.InstructionAccess access, BytecodeNode bytecode, int bytecodeIndex, Frame frame)`. Since 25.1. Called immediately before executing the instruction at `bytecodeIndex` of the given `bytecode` node. This implementation formats and emits a single trace line for the current instruction, unless the `BytecodeNode` is excluded by the active filter. Parameters: `access` `InstructionTracer.InstructionAccess`: accessor to query information about the current instruction, valid only during this call. `bytecode` `BytecodeNode`: the `BytecodeNode` currently being interpreted. `bytecodeIndex` `int`: the bytecode index (BCI) of the instruction to be executed. `frame` `Frame`: the current frame for the root being interpreted. Overrides `onInstructionEnter()`. Cite: `com/oracle/truffle/api/bytecode/debug/PrintInstructionTracer.html#onInstructionEnter(com.oracle.truffle.api.bytecode.InstructionTracer.InstructionAccess,com.oracle.truffle.api.bytecode.BytecodeNode,int,com.oracle.truffle.api.frame.Frame)`

### reset()
<a id="reset()"></a>`public void reset()`. Since 25.1. Resets the internal instruction counter back to zero. This only affects the counter included in the printed trace lines. It does not clear any output sink or filter configuration. Cite: `com/oracle/truffle/api/bytecode/debug/PrintInstructionTracer.html#reset()`

### newBuilder(Consumer)
<a id="newBuilder(java.util.function.Consumer)"></a>`public static PrintInstructionTracer.Builder newBuilder(Consumer<String> out)`. Since 25.1. Creates a new `Builder` that will emit trace lines to the given consumer. Each generated line is already formatted. The consumer is typically a logger or `System.out::println`, but any [`Consumer`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/function/Consumer.html) is accepted. Parameters: `out` `Consumer<String>`: sink for formatted trace lines. Returns `PrintInstructionTracer.Builder`: a new builder. Cite: `com/oracle/truffle/api/bytecode/debug/PrintInstructionTracer.html#newBuilder(java.util.function.Consumer)`

### newBuilder(PrintStream)
<a id="newBuilder(java.io.PrintStream)"></a>`public static PrintInstructionTracer.Builder newBuilder(PrintStream out)`. Since 25.1. Convenience overload of `newBuilder(Consumer)` that writes to a [`PrintStream`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/io/PrintStream.html). The resulting tracer will call [`PrintStream.println(String)`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/io/PrintStream.html#println%28java.lang.String%29) for every traced instruction. Parameters: `out` `PrintStream`: a print stream (for example `System.out`). Returns `PrintInstructionTracer.Builder`: a new builder. Cite: `com/oracle/truffle/api/bytecode/debug/PrintInstructionTracer.html#newBuilder(java.io.PrintStream)`

## Inherited members

- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#hashCode%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#toString%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
- From interface [`InstructionTracer`](../InstructionTracer.md): [`getExclusiveBytecodeDescriptor`](../InstructionTracer.md#getExclusiveBytecodeDescriptor%28%29)
