Skip to content

Commit cdcd105

Browse files
committed
f
1 parent 6beda4a commit cdcd105

File tree

6 files changed

+86
-123
lines changed

6 files changed

+86
-123
lines changed

CHANGELOG

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Unreleased:
1919
starts daemons by default. Daemons must be running before capturing a
2020
trace. We recommend using the new `tracebox ctl` applet (e.g. `tracebox
2121
ctl start`) to manage persistent daemons. To restore the previous
22-
self-contained behavior, use the `--legacy` flag.
22+
self-contained behavior, use the `--autodaemonize` flag.
2323

2424
v53.0 - 2025-11-12:
2525
SDK:

docs/getting-started/ftrace.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,9 @@ from the command line using the config file we just created:
289289
./tracebox -c ticker.cfg --txt -o ticker.pftrace
290290
```
291291

292-
Alternatively using legacy mode:
292+
Alternatively using autodaemonize mode:
293293
```bash
294-
./tracebox --legacy -c ticker.cfg --txt -o ticker.pftrace
294+
./tracebox --autodaemonize -c ticker.cfg --txt -o ticker.pftrace
295295
```
296296

297297
Note: tracebox will take care of enabling tracing and our ticker events (as we

docs/getting-started/memory-profiling.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ Generate the heapprofd config and start the tracing session.
184184
./heap_profile -n trace_processor_shell --print-config | \
185185
./tracebox -c - --txt -o ~/trace_processor_memory.pftrace
186186
```
187-
Alternatively, use the legacy self-contained mode (no `ctl start` required):
187+
Alternatively, use the autodaemonize mode (no `ctl start` required):
188188
```bash
189189
./heap_profile -n trace_processor_shell --print-config | \
190-
./tracebox --legacy -c - --txt -o ~/trace_processor_memory.pftrace
190+
./tracebox --autodaemonize -c - --txt -o ~/trace_processor_memory.pftrace
191191
```
192192

193193
Open another terminal (or tab), start the process you want to profile,

docs/getting-started/system-tracing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ and running the following command:
174174
The scheduling information is captured using ftrace, so you may need to start
175175
the `tracebox` daemons with root privileges (e.g. `sudo ./tracebox ctl start`).
176176

177-
If you prefer the old behavior where tracebox starts temporary daemons for the duration of the trace, you can use the `--legacy` flag:
177+
If you prefer the old behavior where tracebox starts temporary daemons for the duration of the trace, you can use the `--autodaemonize` flag:
178178
```bash
179-
./tracebox --legacy -o trace_file.perfetto-trace --txt -c scheduling.cfg
179+
./tracebox --autodaemonize -o trace_file.perfetto-trace --txt -c scheduling.cfg
180180
```
181181

182182
</tabs?>

docs/reference/tracebox.md

Lines changed: 34 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ tracebox ctl start
1212
tracebox -t 10s -o trace.pftrace sched freq
1313
tracebox ctl stop
1414

15-
# Self-contained mode (legacy)
16-
tracebox --legacy -t 10s -o trace.pftrace sched
15+
# Autodaemonize mode (self-contained)
16+
tracebox --autodaemonize -t 10s -o trace.pftrace sched
1717

1818
# Invoke bundled applets
1919
tracebox [applet_name] [args ...]
@@ -24,15 +24,9 @@ tracebox [applet_name] [args ...]
2424
`tracebox` bundles the Perfetto tracing service (`traced`), system probes
2525
(`traced_probes`), and the `perfetto` command-line client into a single binary.
2626

27-
**Behavior change (2025):** `tracebox` now requires daemons to be running before
28-
capturing traces. Use `tracebox ctl` to manage daemons, or `--legacy` for
29-
the legacy self-contained mode.
30-
31-
If you are a user of `tracebox` in its default mode (i.e., you don't use
32-
`--legacy`), you should read the migration guide below. The new default
33-
behavior provides a more robust and predictable experience, especially for
34-
processes instrumented with the Perfetto SDK, but it requires a small change to
35-
your workflow.
27+
**Update (2025):** `tracebox` now prefers daemons to be managed explicitly via
28+
`tracebox ctl` for better SDK compatibility and performance. The classic
29+
self-contained behavior is still available via the `--autodaemonize` flag.
3630

3731
## DAEMON MANAGEMENT
3832

@@ -74,29 +68,24 @@ If systemd service files are detected:
7468
- As root: `ctl start` uses `systemctl start traced traced-probes`
7569
- As user: Instructs to use `sudo systemctl start traced traced-probes`
7670

77-
## LEGACY SELF-CONTAINED MODE
71+
## AUTODAEMONIZE MODE
7872

79-
The `--legacy` flag preserves the legacy behavior of `tracebox` where it
80-
spawns temporary daemons for the duration of a single trace session. This mode
81-
uses private, temporary sockets and is fully self-contained.
73+
The `--autodaemonize` flag (formerly default behavior) spawns temporary daemons for the
74+
duration of a single trace session. This mode uses private, temporary sockets
75+
and is fully self-contained.
8276

8377
**When to use:**
84-
- For quick one-off traces where you don't want to manage daemons.
78+
- For quick one-off traces where setup simplicity is prioritized over performance.
8579
- If you cannot or do not want to run persistent background daemons.
86-
- For scripts that rely on the old behavior and haven't been migrated yet.
80+
- For existing scripts or workflows that expect self-contained execution.
8781

88-
**Limitations:**
89-
- **SDK Incompatibility:** Processes instrumented with the Perfetto SDK (e.g.
90-
using `track_event`) will generally fail to connect to these temporary daemons
91-
because they listen on private, unpredictable socket addresses.
92-
- **Inefficiency:** Spawns and kills daemons for every trace, which is slower
93-
for repeated tracing.
94-
- **Concurrency:** Running multiple instances of `tracebox --legacy`
95-
concurrently can lead to resource conflicts (e.g. with ftrace).
82+
**Note:** SDK-instrumented apps (using `track_event`) may fail to connect to
83+
these temporary daemons due to private socket usage. For SDK tracing, the
84+
`tracebox ctl` workflow is strongly recommended.
9685

9786
**Example:**
9887
```bash
99-
tracebox --legacy -t 10s -o trace.pftrace sched freq
88+
tracebox --autodaemonize -t 10s -o trace.pftrace sched freq
10089
```
10190

10291
## APPLET MODE
@@ -130,7 +119,7 @@ tracebox ctl status # Check daemon status
130119

131120
If daemons aren't running:
132121
- Use `tracebox ctl start` to start them
133-
- Or use `--legacy` for self-contained mode
122+
- Or use `--autodaemonize` for self-contained mode
134123

135124
### Permission denied
136125

@@ -158,56 +147,24 @@ sudo systemctl stop traced traced-probes
158147
tracebox ctl start
159148
```
160149

161-
## MIGRATION GUIDE (2025)
162-
163-
The default behavior of `tracebox` has changed to require explicit daemon
164-
management. This change resolves long-standing issues with SDK connectivity and
165-
provides a more consistent experience.
166-
167-
### Why the change?
168-
In the old model, `tracebox` would silently spawn "ephemeral" daemons on private
169-
sockets. This often confused users because apps instrumented with the Perfetto
170-
SDK (e.g., Chrome, or your own apps) would fail to connect to these hidden
171-
daemons, resulting in traces missing all userspace data. The new model ensures
172-
daemons run on standard system sockets where SDK apps can find them.
173-
174-
### Migration Steps
175-
176-
**Scenario 1: You run interactive traces manually**
177-
178-
* **Old way:**
179-
```bash
180-
tracebox -t 10s -o trace.pftrace sched
181-
```
182-
* **New way (Recommended):**
183-
Run this once per boot (or when needed):
184-
```bash
185-
tracebox ctl start
186-
```
187-
Then run your traces as usual:
188-
```bash
189-
tracebox -t 10s -o trace.pftrace sched
190-
```
191-
When done (optional):
192-
```bash
193-
tracebox ctl stop
194-
```
195-
196-
**Scenario 2: You have scripts that wrap tracebox**
197-
198-
* **Option A (Better):** Update your scripts to ensure daemons are running
199-
using `tracebox ctl start` before tracing.
200-
* **Option B (Faster fix):** Update your scripts to use the `--legacy`
201-
flag to restore the old behavior.
202-
```bash
203-
tracebox --legacy -t 10s -o trace.pftrace sched
204-
```
205-
206-
**Scenario 3: You are tracing SDK-instrumented apps**
207-
208-
You **must** use the new explicit daemon mode. The legacy `--legacy` mode
209-
will likely not work because your app won't be able to discover the temporary
210-
sockets.
150+
## CHOOSING A WORKFLOW
151+
152+
`tracebox` supports two main workflows. Choose the one that best fits your needs.
153+
154+
### Option A: Persistent Daemons (Recommended)
155+
Best for: SDK tracing, repeated tracing, system-wide analysis.
156+
157+
1. Start daemons once: `tracebox ctl start`
158+
2. Record traces: `tracebox -t 10s ...`
159+
3. Stop (optional): `tracebox ctl stop`
160+
161+
### Option B: Autodaemonize Mode
162+
Best for: Quick ftrace-only debugging, scripts requiring self-contained binaries.
163+
164+
1. Record trace: `tracebox --autodaemonize -t 10s ...`
165+
166+
This mode behaves like older `tracebox` versions, spawning temporary daemons
167+
for the duration of the command.
211168

212169
## SEE ALSO
213170

src/tracebox/tracebox.cc

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,22 @@ void PrintTraceboxUsage() {
6060
printf(R"(Welcome to Perfetto tracing!
6161
6262
Tracebox is a bundle containing all the tracing services and the perfetto
63-
cmdline client in one binary.
63+
cmdline client in one binary. It can be used in two modes:
6464
65-
QUICK START (end-to-end workflow):
66-
tracebox ctl start # Start daemons
67-
tracebox -t 10s -o trace.pftrace sched # Capture trace
68-
tracebox ctl stop # Stop daemons (optional)
65+
MODE 1: Daemon mode (Recommended)
66+
Background daemons are started once and shared across multiple tracing sessions.
67+
This supports SDKs (track_event), reduces latency and is generally more robust.
68+
69+
> tracebox ctl start
70+
> tracebox -t 10s -o trace.pftrace sched
71+
> tracebox ctl stop
72+
73+
MODE 2: Autodaemonize mode
74+
Spawns temporary daemons only for the duration of the trace.
75+
Useful for quick ftrace debugging or self-contained scripts.
76+
Note: SDK apps (track_event) might not connect due to private sockets.
77+
78+
> tracebox --autodaemonize -t 10s -o trace.pftrace sched
6979
)");
7080

7181
PrintTraceboxCtlUsage();
@@ -75,13 +85,6 @@ QUICK START (end-to-end workflow):
7585
applets += " " + std::string(applet.name);
7686

7787
printf(R"(
78-
ADVANCED: --legacy (NOT RECOMMENDED)
79-
Example: tracebox --legacy -t 10s -o trace.pftrace sched
80-
81-
Spawns temporary daemons for one trace only.
82-
Limitations: SDK apps won't connect, inefficient for multiple traces.
83-
Use only for quick one-offs or when persistent daemons aren't feasible.
84-
8588
Available applets:%s
8689
8790
See also:
@@ -91,8 +94,9 @@ See also:
9194
applets.c_str());
9295
}
9396

94-
// Legacy mode: spawns temporary daemons with private sockets for one trace.
95-
int RunLegacy(int argc, char** argv) {
97+
// Autodaemonize mode: spawns temporary daemons with private sockets for one
98+
// trace.
99+
int RunAutodaemonize(int argc, char** argv) {
96100
auto* end = std::remove_if(argv, argv + argc, [](char* arg) {
97101
return !strcmp(arg, "--system-sockets");
98102
});
@@ -242,11 +246,11 @@ int TraceboxMain(int argc, char** argv) {
242246
return 1;
243247
}
244248

245-
bool legacy_mode = false;
249+
bool autodaemonize = false;
246250
bool use_system_sockets = false;
247251
for (int i = 1; i < argc;) {
248-
if (strcmp(argv[i], "--legacy") == 0) {
249-
legacy_mode = true;
252+
if (strcmp(argv[i], "--autodaemonize") == 0) {
253+
autodaemonize = true;
250254
memmove(static_cast<void*>(&argv[i]), static_cast<void*>(&argv[i + 1]),
251255
sizeof(char*) * static_cast<size_t>(argc - i - 1));
252256
argc--;
@@ -258,39 +262,41 @@ int TraceboxMain(int argc, char** argv) {
258262
}
259263
}
260264

261-
if (legacy_mode) {
265+
if (autodaemonize) {
266+
// If --system-sockets is passed with --autodaemonize, it's a valid (though
267+
// slightly contradictory in name) way to say "spawn daemons but use public
268+
// sockets". We warn if they try to mix them in a way that suggests they
269+
// expect the old default behavior without the flag.
262270
if (use_system_sockets) {
263271
PERFETTO_ELOG(
264-
"Legacy mode using system sockets is deprecated. Please prefer to "
265-
"start daemons separately with `tracebox ctl start` for better "
266-
"stability and compatibility. See "
267-
"https://perfetto.dev/docs/reference/tracebox for details.");
268-
} else {
269-
PERFETTO_ELOG(
270-
"Using legacy autodaemonize mode. This is fine for quick "
271-
"one-off traces, but for production use or SDK compatibility, please "
272-
"use `tracebox ctl start` followed by `tracebox`. See "
273-
"https://perfetto.dev/docs/reference/tracebox for details.");
272+
"Warning: --system-sockets with --autodaemonize is supported but "
273+
"deprecated. Prefer `tracebox ctl start` for persistent daemons.");
274274
}
275-
return RunLegacy(argc, argv);
275+
// We don't warn for plain --autodaemonize as it's a valid mode.
276+
return RunAutodaemonize(argc, argv);
276277
}
277278

278279
if (use_system_sockets) {
279280
PERFETTO_FATAL(
280-
"System sockets is not a valid option for the new mode. By default "
281-
"tracebox uses system sockets. If you want the old self-contained "
282-
"behavior (autostarting daemons), append --legacy.");
281+
"System sockets is the default. If you want the old self-contained "
282+
"behavior (spawning temporary daemons), use --autodaemonize.");
283283
}
284284

285285
ServiceSockets sockets = perfetto::GetRunningSockets();
286286
if (!sockets.IsValid()) {
287-
fprintf(stderr,
288-
"Error: Perfetto tracing daemons (traced, traced_probes) are not "
289-
"running.\n"
290-
"- To run daemons as the current user: `tracebox ctl start`\n"
291-
"- For a self-contained run: `tracebox --legacy ...` (Not "
292-
"Recommended)\n"
293-
"More info at: https://perfetto.dev/docs/reference/tracebox\n");
287+
fprintf(
288+
stderr,
289+
"Error: Perfetto tracing daemons (traced, traced_probes) are not "
290+
"running.\n\n"
291+
"Tracebox behavior has changed. It no longer spawns temporary daemons "
292+
"by default.\n"
293+
"You have two options:\n"
294+
"1. Start the daemons manually (Recommended):\n"
295+
" tracebox ctl start\n"
296+
" tracebox ...\n\n"
297+
"2. Use the --autodaemonize flag for the old behavior:\n"
298+
" tracebox --autodaemonize ...\n"
299+
"\nMore info at: https://perfetto.dev/docs/reference/tracebox\n");
294300
return 1;
295301
}
296302
perfetto::SetServiceSocketEnv(sockets);

0 commit comments

Comments
 (0)