From df142880e86418dad6b40fddb001ebd897919595 Mon Sep 17 00:00:00 2001 From: Ryan Zuklie Date: Fri, 20 May 2022 17:53:01 +0000 Subject: populate attributes when re-writing perf data JoinCallChains, PostUnwindRecords, and MergeMapRecords all flush the current data to file and start a new data file using MoveRecordFile. Normally, creating the file fills in the attributes from the event selection set. However, DoRecording recently added CloseEventFiles calls which clear the event_fds which are used to populate the attrs. This change fixes the issue by copying the attrs from the old file. Test: ran simpleperf on device $ adb shell $ cd /data/local/tmp $ simpleperf record -a --exclude-perf --duration 2 -g \ -e power:sugov_next_freq -e power:sugov_util_update $ simpleperf report Before the fix, all samples would be attributed to the first event type. With this fix, the samples are correctly attributed. Bug: 231357972 Change-Id: Id077e3c6f6c4460df595fad04c355717985a914e (cherry picked from commit 62fe04581f910f5a847ad0653908a3e57b6ed8a2) Merged-In: Id077e3c6f6c4460df595fad04c355717985a914e --- simpleperf/cmd_record.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/simpleperf/cmd_record.cpp b/simpleperf/cmd_record.cpp index 4b79eedc..e69355d4 100644 --- a/simpleperf/cmd_record.cpp +++ b/simpleperf/cmd_record.cpp @@ -352,7 +352,8 @@ RECORD_FILTER_OPTION_HELP_MSG_FOR_RECORDING bool TraceOffCpu(); bool SetEventSelectionFlags(); bool CreateAndInitRecordFile(); - std::unique_ptr CreateRecordFile(const std::string& filename); + std::unique_ptr CreateRecordFile( + const std::string& filename, const std::vector& override_attrs); bool DumpKernelSymbol(); bool DumpTracingData(); bool DumpMaps(); @@ -1280,7 +1281,8 @@ bool RecordCommand::SetEventSelectionFlags() { } bool RecordCommand::CreateAndInitRecordFile() { - record_file_writer_ = CreateRecordFile(record_filename_); + record_file_writer_ = + CreateRecordFile(record_filename_, event_selection_set_.GetEventAttrWithId()); if (record_file_writer_ == nullptr) { return false; } @@ -1294,13 +1296,14 @@ bool RecordCommand::CreateAndInitRecordFile() { return DumpKernelSymbol() && DumpTracingData() && DumpMaps() && DumpAuxTraceInfo(); } -std::unique_ptr RecordCommand::CreateRecordFile(const std::string& filename) { +std::unique_ptr RecordCommand::CreateRecordFile( + const std::string& filename, const std::vector& attrs) { std::unique_ptr writer = RecordFileWriter::CreateInstance(filename); if (writer == nullptr) { return nullptr; } - if (!writer->WriteAttrSection(event_selection_set_.GetEventAttrWithId())) { + if (!writer->WriteAttrSection(attrs)) { return nullptr; } return writer; @@ -1697,11 +1700,17 @@ std::unique_ptr RecordCommand::MoveRecordFile(const std::strin return nullptr; } } - record_file_writer_ = CreateRecordFile(record_filename_); + + auto reader = RecordFileReader::CreateInstance(old_filename); + if (!reader) { + return nullptr; + } + + record_file_writer_ = CreateRecordFile(record_filename_, reader->AttrSection()); if (!record_file_writer_) { return nullptr; } - return RecordFileReader::CreateInstance(old_filename); + return reader; } bool RecordCommand::MergeMapRecords() { -- cgit v1.2.3