[llvm] da4e5fc - [llvm-profgen] Deduplicate PID when processing perf input
Wenlei He via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 10 13:43:38 PDT 2021
Author: Wenlei He
Date: 2021-10-10T13:30:17-07:00
New Revision: da4e5fc86158c669ddcb335d151fffd7c6e2ed4b
URL: https://github.com/llvm/llvm-project/commit/da4e5fc86158c669ddcb335d151fffd7c6e2ed4b
DIFF: https://github.com/llvm/llvm-project/commit/da4e5fc86158c669ddcb335d151fffd7c6e2ed4b.diff
LOG: [llvm-profgen] Deduplicate PID when processing perf input
When parsing mmap to retrieve PID, deduplicate them before passing PID list to perf script. Perf script would error out when there's duplicated PID in the input, however raw perf data may main duplicated PID for large binary where more than one mmap is needed to load executable segment.
Differential Revision: https://reviews.llvm.org/D111384
Added:
Modified:
llvm/tools/llvm-profgen/PerfReader.cpp
Removed:
################################################################################
diff --git a/llvm/tools/llvm-profgen/PerfReader.cpp b/llvm/tools/llvm-profgen/PerfReader.cpp
index 019ca5ab46512..2aa66832a051a 100644
--- a/llvm/tools/llvm-profgen/PerfReader.cpp
+++ b/llvm/tools/llvm-profgen/PerfReader.cpp
@@ -322,18 +322,26 @@ std::string PerfReaderBase::convertPerfDataToTrace(ProfiledBinary *Binary,
// Collect the PIDs
TraceStream TraceIt(PerfTraceFile);
std::string PIDs;
+ std::unordered_set<uint32_t> PIDSet;
while (!TraceIt.isAtEoF()) {
MMapEvent MMap;
if (isMMap2Event(TraceIt.getCurrentLine()) &&
extractMMap2EventForBinary(Binary, TraceIt.getCurrentLine(), MMap)) {
- if (!PIDs.empty()) {
- PIDs.append(",");
+ auto It = PIDSet.emplace(MMap.PID);
+ if (It.second) {
+ if (!PIDs.empty()) {
+ PIDs.append(",");
+ }
+ PIDs.append(utostr(MMap.PID));
}
- PIDs.append(utostr(MMap.PID));
}
TraceIt.advance();
}
+ if (PIDs.empty()) {
+ exitWithError("No relevant mmap event is found in perf data.");
+ }
+
// Run perf script again to retrieve events for PIDs collected above
StringRef ScriptSampleArgs[] = {PerfPath, "script", "--show-mmap-events",
"-F", "ip,brstack", "--pid",
More information about the llvm-commits
mailing list