summaryrefslogtreecommitdiff
path: root/libguile/whippet/doc/tracepoints.md
blob: 18b7d8f2921bc88475618fd564e1e871750b0669 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Whippet performance tracing

Whippet includes support for run-time tracing via
[LTTng](https://LTTng.org) user-space tracepoints.  This allows you to
get a detailed look at how Whippet is performing on your system.
Tracing support is currently limited to Linux systems.

## Getting started

First, you need to build Whippet with LTTng support.  Usually this is as
easy as building it in an environment where the `lttng-ust` library is
present, as determined by `pkg-config --libs lttng-ust`.  You can know
if your Whippet has tracing support by seeing if the resulting binaries
are dynamically linked to `liblttng-ust`.

If we take as an example the `mt-gcbench` test in the Whippet source
tree, we would have:

```
$ ldd bin/mt-gcbench.pcc | grep lttng
...
liblttng-ust.so.1 => ...
...
```

### Capturing traces

Actually capturing traces is a little annoying; it's not as easy as
`perf run`.  The [LTTng
documentation](https://lttng.org/docs/v2.13/#doc-controlling-tracing) is
quite thorough, but here is a summary.

First, create your tracing session:

```
$ lttng create
Session auto-20250214-091153 created.
Traces will be output to ~/lttng-traces/auto-20250214-091153
```

You run all these commands as your own user; they don't require root
permissions or system-wide modifications, as all of the Whippet
tracepoints are user-space tracepoints (UST).

Just having an LTTng session created won't do anything though; you need
to configure the session.  Monotonic nanosecond-resolution timestamps
are already implicitly part of each event.  We also want to have process
and thread IDs for all events:

```
$ lttng add-context --userspace --type=vpid --type=vtid
ust context vpid added to all channels
ust context vtid added to all channels
```

Now enable Whippet events:

```
$ lttng enable-event --userspace 'whippet:*'
ust event whippet:* created in channel channel0
```

And now, start recording:

```
$ lttng start
Tracing started for session auto-20250214-091153
```

With this, traces will be captured for our program of interest:

```
$ bin/mt-gcbench.pcc 2.5 8
...
```

Now stop the trace:

```
$ lttng stop
Waiting for data availability
Tracing stopped for session auto-20250214-091153
```

Whew.  If we did it right, our data is now in
`~/lttng-traces/auto-20250214-091153`.

### Visualizing traces

LTTng produces traces in the [Common Trace Format
(CTF)](https://diamon.org/ctf/).  My favorite trace viewing tool is the
family of web-based trace viewers derived from `chrome://tracing`.  The
best of these appear to be [the Firefox
profiler](https://profiler.firefox.com) and
[Perfetto](https://ui.perfetto.dev).  Unfortunately neither of these can
work with CTF directly, so we instead need to run a trace converter.

Oddly, there is no trace converter that can read CTF and write something
that Perfetto (e.g.) can read.  However there is a [JSON-based tracing
format that these tools can
read](https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview?tab=t.0#heading=h.yr4qxyxotyw),
and [Python bindings for Babeltrace, a library that works with
CTF](https://babeltrace.org/), so that's what we do:

```
$ python3 ctf_to_json.py ~/lttng-traces/auto-20250214-091153 > trace.json
```

While Firefox Profiler can load this file, it works better on Perfetto,
as the Whippet events are visually rendered on their respective threads.

![Screenshot of part of Perfetto UI showing a minor GC](./perfetto-minor-gc.png)

### Expanding the set of events

As of February 2025,
the current set of tracepoints includes the [heap
events](https://github.com/wingo/whippet/blob/main/doc/manual.md#statistics)
and some detailed internals of the parallel tracer.  We expect this set
of tracepoints to expand over time.

### Overhead of tracepoints

When tracepoints are compiled in but no events are enabled, tracepoints
appear to have no impact on run-time.  When event collection is on, for
x86-64 hardware, [emitting a tracepoint event takes about
100ns](https://discuss.systems/@DesnoyersMa/113986344940256872).