xref: /cloud-hypervisor/docs/tracing.md (revision 42e9632c53d14cd0040db4952d40ba806c4b6ee9)
1e53419ecSRob Bradford# Tracing
2e53419ecSRob Bradford
37bf0cc1eSPhilipp SchusterCloud Hypervisor has a basic tracing infrastructure, particularly focussed on
4e53419ecSRob Bradfordthe tracing of the initial VM setup.
5e53419ecSRob Bradford
6e53419ecSRob Bradford## Usage
7e53419ecSRob Bradford
8e53419ecSRob BradfordTo enabling tracing, build with "tracing" feature. When compiled without the
9e53419ecSRob Bradfordfeature the tracing is compiled out.
10e53419ecSRob Bradford
11e53419ecSRob Bradford```bash
12e53419ecSRob Bradfordcargo build --features "tracing"
13e53419ecSRob Bradford```
14e53419ecSRob Bradford
15e53419ecSRob BradfordAnd 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.
16e53419ecSRob Bradford
17e53419ecSRob BradfordAlternatively you can use the provided script in
18e53419ecSRob Bradford`scripts/ch-trace-visualiser.py` to generate an SVG:
19e53419ecSRob Bradford
20e53419ecSRob BradfordFor example:
21e53419ecSRob Bradford
22e53419ecSRob Bradford```bash
23e53419ecSRob Bradfordscripts/ch-trace-visualiser.py cloud-hypervisor-39466.trace output.svg
24e53419ecSRob Bradford```
25e53419ecSRob Bradford
26e53419ecSRob Bradford## Tracing in the codebase
27e53419ecSRob Bradford
28e53419ecSRob BradfordThere are existing tracepoints in the code base; extra ones can be added for
29e53419ecSRob Bradfordmore detailed tracing.
30e53419ecSRob Bradford
31e53419ecSRob BradfordThe `tracer::trace_scoped!()` macro is used to add the current existing scope
32e53419ecSRob Bradfordappears as a block in the trace. Other than providing a useful name for the
33e53419ecSRob Bradfordevent nothing else is required from the developer.
34e53419ecSRob Bradford
35e53419ecSRob BradfordThe `tracer::start()` and `tracer::end()` functions are already in place for
36e53419ecSRob Bradfordgenerating traces of the boot. These can be relocated for focus tracing on a
37e53419ecSRob Bradfordnarrow part of the code base.
38e53419ecSRob Bradford
39e53419ecSRob BradfordA `tracer::trace_point!()` macro is also provided for an instantaneous trace
40*42e9632cSJosh Sorefpoint however this is neither in use in the code base currently nor is handled by
41e53419ecSRob Bradfordthe visualisation script due to the difficulty in representation in the SVG.
42e53419ecSRob Bradford
43