Skip to content

WIP: perfetto reboot traces#3850

Draft
KirillTim wants to merge 40 commits intomainfrom
dev/ktimofeev/perfetto_recover_reboot_traces_9
Draft

WIP: perfetto reboot traces#3850
KirillTim wants to merge 40 commits intomainfrom
dev/ktimofeev/perfetto_recover_reboot_traces_9

Conversation

@KirillTim
Copy link
Copy Markdown
Member

@KirillTim KirillTim commented Nov 25, 2025

Tested:
atest CtsPerfettoReporterRebootTestCases
atest CtsPerfettoReporterTestCases

@github-actions
Copy link
Copy Markdown

github-actions bot commented Nov 25, 2025

@KirillTim KirillTim changed the title WIP: perfetto reboot traces: add perfetto_cmd logic and some tests WIP: perfetto reboot traces Dec 2, 2025
@KirillTim KirillTim requested a review from primiano January 9, 2026 16:54
Copy link
Copy Markdown
Member

@primiano primiano left a comment

Choose a reason for hiding this comment

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

as per offline discussion, let's keep this CL purely on the perfetto_cmd (and proto) changes.

let's split out the test and the .rc file, as I think i have a better proposal (Writing a doc now)

persistent_trace_out_path_ = std::string(kAndroidPersistentStateDir) + "/" +
trace_config_->unique_session_name() +
".pftrace";
PERFETTO_CHECK(trace_config_->output_path().empty());
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.

THis should be an ELOG+return like the ones above

--subscription-id : ID of the subscription that triggered this trace.
--upload : Upload trace.
--upload-after-reboot : Used by Android to upload the traces saved to a
special directory after the system reboot.
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.

can you say: [Android-only] Reports to the Android framework all the traces marked as persist_trace_after_reboot=true which haven't been cleanly terminated.

#endif
}
if (option == OPT_UPLOAD_AFTER_REBOOT) {
#if PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID)
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.

small thing. can you just set a boolean here, and move the logic below after the arg parsing?

I find a bit easier to reason about if the code here in the top does pure parsing and the logic happens below

break;
}
statsd_logging_ = ShouldLogStatsdEvents(
*trace_config_, /*unspecified_filed_value=*/upload_flag_);
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.

why this is called unspecified_field_value? call it upload_flag (also in the arg name)


// static
bool PerfettoCmd::ShouldLogStatsdEvents(const TraceConfig& cfg,
bool unspecified_filed_value) {
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.

s/unspecified_filed_value/upload_flag/ ?

bool all_reports_succeed = true;
for (base::ScopedFile& fd : fds) {
std::optional<uint64_t> maybe_file_size = base::GetFileSize(*fd);
if (!maybe_file_size.has_value()) {
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.

if (!maybe_file_size.has_value() || *maybe_file_size <= 0) {
PERFETTO_PLOG("Failed to stat persistent trace");
continue;
}
uint64_t file_size = maybe_file_size.value();

continue;
}
uint64_t file_size = maybe_file_size.value();
if (maybe_file_size == 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.

nit this should be file_size, i think the above is a cast of the bool operator actually (subtle bug i know). but if yuou follow my suggestion above this becomes more compact anyways.

base::ScopedMmap mmaped_file =
base::ScopedMmap::FromHandle(std::move(mmap_fd), file_size);
if (!mmaped_file.IsValid()) {
continue;
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.

PLOG failed to mmap

}

if (!trace_config.has_value()) {
continue;
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.

ELOG here (it shoul really never happen)

return false;
}

bool all_reports_succeed = true;
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 think rather than this, it's more error-proof to:

  • increment the counter of suceeded reports if you reach the end
  • then you return num_succeeded == fds_count (cache it at the beginning)

because here you are not accounting I think for weird cases like "the trace config could not be parsed" and so on

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.

2 participants