[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
This commit is contained in:
Wenlei He 2021-10-07 21:27:17 -07:00
parent b07ea8a967
commit da4e5fc861

View File

@ -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",