xref: /cloud-hypervisor/docs/tracing.md (revision 8803e4a2e7f8e9596b72f81d3c916390e5b10fbd)
1# Tracing
2
3Cloud Hypervisor has a basic tracing infrastructure, particularly focussed on
4the tracing of the initial VM setup.
5
6## Usage
7
8To enabling tracing, build with "tracing" feature. When compiled without the
9feature the tracing is compiled out.
10
11```bash
12cargo build --features "tracing"
13```
14
15And then run Cloud Hypervisor as you wish, the trace will be written to the current directory as `cloud-hypervisor-<pid>.trace`. This is JSON file which you can inspect yourself.
16
17Alternatively you can use the provided script in
18`scripts/ch-trace-visualiser.py` to generate an SVG:
19
20For example:
21
22```bash
23scripts/ch-trace-visualiser.py cloud-hypervisor-39466.trace output.svg
24```
25
26## Tracing in the codebase
27
28There are existing tracepoints in the code base; extra ones can be added for
29more detailed tracing.
30
31The `tracer::trace_scoped!()` macro is used to add the current existing scope
32appears as a block in the trace. Other than providing a useful name for the
33event nothing else is required from the developer.
34
35The `tracer::start()` and `tracer::end()` functions are already in place for
36generating traces of the boot. These can be relocated for focus tracing on a
37narrow part of the code base.
38
39A `tracer::trace_point!()` macro is also provided for an instantaneous trace
40point however this is neither in use in the code base currently nor is handled by
41the visualisation script due to the difficulty in representation in the SVG.
42
43