Add sinces
[lttng-docs.git] / contents / using-lttng / controlling-tracing / taking-a-snapshot.md
CommitLineData
5e0cbfb0
PP
1---
2id: taking-a-snapshot
86384750 3since: 2.3
5e0cbfb0
PP
4---
5
6The normal behavior of LTTng is to record trace data as trace files.
7This is ideal for keeping a long history of events that occurred on
8the target system and applications, but may be too much data in some
9situations. For example, you may wish to trace your application
10continuously until some critical situation happens, in which case you
11would only need the latest few recorded events to perform the desired
12analysis, not multi-gigabyte trace files.
13
14LTTng has an interesting feature called _snapshots_. When creating
15a tracing session in snapshot mode, no trace files are written; the
16tracers' sub-buffers are constantly overwriting the oldest recorded
17events with the newest. At any time, either when the tracers are started
18or stopped, you may take a snapshot of those sub-buffers.
19
20There is no difference between the format of a normal trace file and the
47bfcb75 21format of a snapshot: viewers of LTTng traces also support LTTng
5e0cbfb0
PP
22snapshots. By default, snapshots are written to disk, but they may also
23be sent over the network.
24
25To create a tracing session in snapshot mode, do:
26
27<pre class="term">
28lttng create --snapshot my-snapshot-session
29</pre>
30
31Next, enable channels, events and add context to channels as usual.
47bfcb75 32Once a tracing session is created in snapshot mode, channels are
6d30cd92
PP
33forced to use the
34[overwrite](#doc-channel-overwrite-mode-vs-discard-mode) mode
35(`--overwrite` option of the `enable-channel` command; also called
36_flight recorder mode_) and have an `mmap()` channel type
5e0cbfb0
PP
37(`--output mmap`).
38
39Start tracing. When you're ready to take a snapshot, do:
40
41<pre class="term">
42lttng snapshot record --name my-snapshot
43</pre>
44
47bfcb75 45This records a snapshot named `my-snapshot` of all channels of
5e0cbfb0
PP
46all domains of the current tracing session. By default, snapshots files
47are recorded in the path returned by `lttng snapshot list-output`. You
48may change this path or decide to send snapshots over the network
49using either:
50
51 1. an output path/URL specified when creating the tracing session
52 (`lttng create`)
53 2. an added snapshot output path/URL using
54 `lttng snapshot add-output`
55 3. an output path/URL provided directly to the
56 `lttng snapshot record` command
57
58Method 3 overrides method 2 which overrides method 1. When specifying
59a URL, a relay daemon must be listening on some machine (see
60[Sending trace data over the network](#doc-sending-trace-data-over-the-network)).
61
62If you need to make absolutely sure that the output file won't be
63larger than a certain limit, you can set a maximum snapshot size when
64taking it with the `--max-size` option:
65
66<pre class="term">
67lttng snapshot record --name my-snapshot --max-size 2M
68</pre>
69
47bfcb75 70Older recorded events are discarded in order to respect this
5e0cbfb0 71maximum size.
This page took 0.025619 seconds and 4 git commands to generate.