Skip to content

Commit 4383b37

Browse files
committed
ZJIT: Update trace-exits docs for Fuchsia trace format
The Stackprof-based documentation was outdated after the switch to Fuchsia Trace Format (.fxt) output. Update with Perfetto UI and trace_processor_shell workflow, including a working example and SQL query for finding hottest exit locations.
1 parent d4e3d70 commit 4383b37

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

doc/jit/zjit.md

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,18 +294,62 @@ This metric only appears when ZJIT is built with `--enable-zjit=stats` [or more]
294294

295295
### Tracing side exits
296296

297-
Through [Stackprof](https://github.com/tmm1/stackprof), detailed information about the methods that the JIT side-exits from can be displayed after some execution of a program. Optionally, you can use `--zjit-trace-exits-sample-rate=N` to sample every N-th occurrence. Enabling `--zjit-trace-exits-sample-rate=N` will automatically enable `--zjit-trace-exits`.
297+
`--zjit-trace-exits` records a backtrace every time compiled code takes a
298+
side exit. The output is a [Fuchsia Trace Format](https://fuchsia.dev/fuchsia-src/reference/tracing/trace-format)
299+
(`.fxt`) file written to `/tmp/perfetto-{pid}.fxt`, which can be opened
300+
directly in [Perfetto UI](https://ui.perfetto.dev/) or queried with the
301+
[Perfetto trace processor](https://perfetto.dev/docs/quickstart/trace-analysis).
298302

299303
```bash
300-
./miniruby --zjit-trace-exits script.rb
304+
$ ./miniruby --zjit-trace-exits -e '
305+
def poly(x)
306+
x.to_s
307+
end
308+
309+
30.times { poly(1) }
310+
30.times { poly("hello") }
311+
30.times { poly(:sym) }
312+
'
313+
ZJIT: writing trace exits to /tmp/perfetto-123456.fxt
301314
```
302315

303-
A file called `zjit_exits_{pid}.dump` will be created in the same directory as `script.rb`. Viewing the side exited methods can be done with Stackprof:
316+
To find the hottest side-exit locations, download `trace_processor_shell` and
317+
run an SQL query on the trace:
304318

305319
```bash
306-
stackprof path/to/zjit_exits_{pid}.dump
320+
curl -Lo /tmp/trace_processor_shell https://get.perfetto.dev/trace_processor
321+
chmod +x /tmp/trace_processor_shell
322+
323+
/tmp/trace_processor_shell /tmp/perfetto-123456.fxt -Q "
324+
SELECT reason, backtrace, count(*) AS exits FROM (
325+
SELECT
326+
s.id,
327+
s.name AS reason,
328+
group_concat(a.display_value, ' <- ') AS backtrace
329+
FROM slice s
330+
JOIN args a USING(arg_set_id)
331+
WHERE s.category = 'side_exit'
332+
GROUP BY s.id
333+
)
334+
GROUP BY reason, backtrace
335+
ORDER BY exits DESC
336+
LIMIT 30
337+
"
307338
```
308339

340+
Example output:
341+
342+
```
343+
"reason","backtrace","exits"
344+
"GuardType(Fixnum)","Object#poly (-e) <- block in <main> (-e) <- Integer#times (<internal:numeric>) <- <main> (-e)",60
345+
```
346+
347+
You can also trace a specific counter with `--zjit-trace-exits=<counter_name>`
348+
(e.g. `--zjit-trace-exits=exit_compile_error`), or downsample with
349+
`--zjit-trace-exits-sample-rate=N` to record every N-th exit.
350+
Enabling `--zjit-trace-exits-sample-rate=N` will automatically enable
351+
`--zjit-trace-exits`.
352+
309353
### Viewing HIR as text
310354

311355
The compiled ZJIT HIR can be viewed as text using the `--zjit-dump-hir` option. However, HIR will only be generated if the call threshold is reached (default 30). By setting the threshold to 1 you can easily view the HIR for code snippets such as `1 + 1`:

0 commit comments

Comments
 (0)