Skip to content

Add perfetto tracing to host tooling#2502

Open
jmacnak wants to merge 1 commit into
google:mainfrom
jmacnak:perfetto
Open

Add perfetto tracing to host tooling#2502
jmacnak wants to merge 1 commit into
google:mainfrom
jmacnak:perfetto

Conversation

@jmacnak

@jmacnak jmacnak commented May 1, 2026

Copy link
Copy Markdown
Member

@jmacnak jmacnak force-pushed the perfetto branch 7 times, most recently from e958a29 to 8330f27 Compare May 6, 2026 17:15
@jmacnak jmacnak added the kokoro:force-run Trigger a presubmit build unconditionally. label May 6, 2026
@GoogleCuttlefishTesterBot GoogleCuttlefishTesterBot removed the kokoro:force-run Trigger a presubmit build unconditionally. label May 6, 2026
@jmacnak jmacnak force-pushed the perfetto branch 4 times, most recently from 19542bf to 6e9eaf0 Compare May 7, 2026 18:24
@jmacnak jmacnak force-pushed the perfetto branch 5 times, most recently from 1d90f66 to 1727b13 Compare May 15, 2026 20:30
@jmacnak jmacnak requested a review from Databean May 18, 2026 14:54
@jmacnak

jmacnak commented May 18, 2026

Copy link
Copy Markdown
Member Author

This needs a couple upstream changes to Perfetto but generally ready for a first look.

@Databean Databean left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not finished reviewing, but I'll leave the comments I have so far.

Comment thread base/cvd/cuttlefish/host/commands/run_cvd/server_loop_impl.cpp
Comment thread base/cvd/cuttlefish/host/commands/run_cvd/main.cc
Comment thread base/cvd/cuttlefish/host/libs/tracing/tracing.h Outdated
Comment thread base/cvd/cuttlefish/host/libs/tracing/tracing.cpp Outdated
Comment thread base/cvd/cuttlefish/host/libs/tracing/tracing.h Outdated
Comment thread base/cvd/cuttlefish/host/libs/tracing/tracing.cpp Outdated
Comment thread base/cvd/cuttlefish/host/libs/tracing/tracing.cpp Outdated
Comment thread base/cvd/cuttlefish/host/libs/tracing/tracing.cpp Outdated
Comment thread base/cvd/cuttlefish/host/libs/tracing/tracing.cpp Outdated
Comment thread base/cvd/cuttlefish/host/libs/tracing/tracing.cpp Outdated
LalitMaganti pushed a commit to google/perfetto that referenced this pull request May 19, 2026
Bug: b/378560215

This would be useful for
google/android-cuttlefish#2502 where we could
eliminate most of
https://github.com/google/android-cuttlefish/pull/2502/changes#diff-d28a094890e585d0e9bec027b845e31c3c15ebd9c2262dd814dd6e7537ab2af8
when using the c library via `dlopen()` and we do not want to directly
depend on the library itself.
@jmacnak jmacnak force-pushed the perfetto branch 5 times, most recently from 7be473c to 7e57fd5 Compare May 19, 2026 20:19

@Databean Databean left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, still not finished: I haven't fully reviewed TracingState, but have looked at everything else.

Comment thread base/cvd/cuttlefish/host/commands/assemble_cvd/disk_builder.cpp Outdated
Comment thread base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_context.cc Outdated
Comment thread base/cvd/cuttlefish/host/commands/start/main.cc Outdated
Comment thread base/cvd/cuttlefish/host/libs/feature/feature.cpp Outdated
Comment thread base/cvd/cuttlefish/host/libs/tracing/tracing_state.cpp Outdated
Comment thread base/cvd/cuttlefish/host/libs/tracing/perfetto_functions.h Outdated
Comment thread base/cvd/cuttlefish/host/libs/tracing/perfetto_worker_thread.cpp Outdated
Comment thread base/cvd/cuttlefish/host/libs/tracing/perfetto_worker_thread.cpp Outdated
Comment thread base/cvd/cuttlefish/host/libs/tracing/perfetto_functions.h Outdated
Comment thread base/cvd/cuttlefish/host/libs/tracing/tracing.cpp Outdated
Comment thread base/cvd/cuttlefish/host/libs/tracing/tracing_state.cpp Outdated
Comment thread base/cvd/cuttlefish/host/libs/tracing/tracing_state.h Outdated
Comment thread base/cvd/cuttlefish/host/libs/tracing/tracing_state.h Outdated
Comment thread base/cvd/cuttlefish/host/libs/tracing/tracing_state.cpp Outdated
Comment thread base/cvd/cuttlefish/host/libs/tracing/tracing_state.cpp Outdated
Comment thread base/cvd/cuttlefish/host/libs/tracing/tracing_state.cpp Outdated
Comment thread base/cvd/cuttlefish/host/libs/tracing/tracing_state.cpp Outdated
@jmacnak jmacnak force-pushed the perfetto branch 3 times, most recently from c7146ac to fc5b377 Compare May 28, 2026 16:22
jmacnak added a commit to jmacnak/android-cuttlefish that referenced this pull request May 28, 2026
google#2502 was incorrect.
The previous behavior was to prefer `--gpu_mode=gfxstream` over
`--gpu_mode=guest_swiftshader` prior to the Jolt changes.

Bug: b/513229182
return *sCached;
}

uint64_t GetThreadId() { return gettid(); }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to flip from my earlier comment on this, but I saw that the internal libc may not include gettid: b/456374254

Comment thread base/cvd/cuttlefish/host/libs/tracing/tracing_utils.cpp
Comment thread base/cvd/cuttlefish/host/libs/tracing/tracing_utils.cpp Outdated
Comment thread base/cvd/cuttlefish/host/libs/tracing/tracing_server.cpp Outdated
Comment thread base/cvd/cuttlefish/host/libs/tracing/tracing_client.h Outdated
Comment thread base/cvd/cuttlefish/host/libs/tracing/tracing_session.cpp Outdated
Comment thread base/cvd/cuttlefish/host/libs/tracing/tracing.proto Outdated
Comment thread base/cvd/cuttlefish/host/libs/tracing/tracing_state.h
Comment thread base/cvd/cuttlefish/host/libs/tracing/tracing_session.cpp Outdated
Comment thread base/cvd/cuttlefish/host/commands/cvd/main.cc
Example cvd create trace:
https://ui.perfetto.dev/#!/?s=b1b38a42593f61ee34c230f344e62f8c883ec747

Example cvd fetch trace:
https://ui.perfetto.dev/#!/?s=cd5028170d015f9dd026228c7fd7dd81027b680e

Perfetto uses a shared memory buffer between producer processes and the
traced consumer daemon. `fork()` is problematic for this as the parent
and child processes would end up clobbering each other when the shared
memory buffer is inherited by the child. To prevent this, we introduce
a "perfetto forwarder" (see TracingSession) that runs in the top level
`cvd` process and that forwards trace events from child processes.

Bug: b/378560215

@Databean Databean left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, lost track of this change.

sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGTERM);
CF_EXPECT_EQ(pthread_sigmask(SIG_BLOCK, &set, nullptr), 0,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example for pthread_sigmask includes the comment

/* Block SIGQUIT and SIGUSR1; other threads created by main()
   will inherit a copy of the signal mask.  */

Should the pthread_sigmask call be made before TracingServer::StartBlocking launches additional threads, so the threads have a chance to inherit the altered mask?

shutting_down_ = true;
}

socket_->Shutdown(SHUT_RDWR);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find anything authoritative, but I think it's correct that shutdown will interrupt the read happening below? close is explicitly documented to not interrupt the read.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants