[llvm] [Perf2bolt] Support multi-PID filtering for multiple perf inputs (PR #215541)

Jinjie Huang via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 11 06:22:31 PDT 2026


https://github.com/Jinjie-Huang updated https://github.com/llvm/llvm-project/pull/215541

>From 5325002b7b8897a09c3b0808230200554970503a Mon Sep 17 00:00:00 2001
From: huangjinjie <huangjinjie at bytedance.com>
Date: Tue, 11 Aug 2026 21:22:12 +0800
Subject: [PATCH] Support multi-PID filtering for multiple perf inputs

---
 bolt/lib/Profile/DataAggregator.cpp | 43 +++++++++++++++++------------
 1 file changed, 25 insertions(+), 18 deletions(-)

diff --git a/bolt/lib/Profile/DataAggregator.cpp b/bolt/lib/Profile/DataAggregator.cpp
index abf35964240f3..bdce38cb64e3b 100644
--- a/bolt/lib/Profile/DataAggregator.cpp
+++ b/bolt/lib/Profile/DataAggregator.cpp
@@ -84,12 +84,11 @@ static cl::opt<bool> ParseMemProfile(
              "on by default unless `--itrace` is set."),
     cl::init(true), cl::cat(AggregatorCategory));
 
-static cl::opt<unsigned long long>
-FilterPID("pid",
-  cl::desc("only use samples from process with specified PID"),
-  cl::init(0),
-  cl::Optional,
-  cl::cat(AggregatorCategory));
+static cl::list<unsigned long long>
+    FilterPID("pid",
+              cl::desc("only use samples from process with specified PID(s) "
+                       "(comma-separated)"),
+              cl::CommaSeparated, cl::ZeroOrMore, cl::cat(AggregatorCategory));
 
 static cl::opt<bool> ImputeTraceFallthrough(
     "impute-trace-fall-through",
@@ -622,30 +621,38 @@ Error DataAggregator::generatePerfScriptData() {
 }
 
 Error DataAggregator::filterBinaryMMapInfo() {
-  if (opts::FilterPID) {
-    auto MMapInfoIter = BinaryMMapInfo.find(opts::FilterPID);
-    if (MMapInfoIter != BinaryMMapInfo.end()) {
-      MMapInfo MMap = MMapInfoIter->second;
-      BinaryMMapInfo.clear();
-      BinaryMMapInfo.insert(std::make_pair(MMap.PID, MMap));
-    } else {
+  if (!opts::FilterPID.empty()) {
+    std::unordered_map<uint64_t, MMapInfo> FilteredMMapInfo;
+    for (unsigned long long PID : opts::FilterPID) {
+      auto MMapInfoIter = BinaryMMapInfo.find(PID);
+      if (MMapInfoIter != BinaryMMapInfo.end())
+        FilteredMMapInfo.insert(*MMapInfoIter);
+    }
+    if (FilteredMMapInfo.empty()) {
       if (errs().has_colors())
         errs().changeColor(raw_ostream::RED);
-      errs() << "PERF2BOLT-ERROR: could not find a profile matching PID \""
-             << opts::FilterPID << "\""
-             << " for binary \"" << BC->getFilename() << "\".";
-      assert(!BinaryMMapInfo.empty() && "No memory map for matching binary");
+      errs() << "PERF2BOLT-ERROR: could not find a profile matching ";
+      if (opts::FilterPID.size() == 1) {
+        errs() << "PID \"" << opts::FilterPID[0] << "\"";
+      } else {
+        errs() << "any requested PID(s) \"";
+        for (size_t I = 0; I < opts::FilterPID.size(); ++I)
+          errs() << opts::FilterPID[I]
+                 << (I == opts::FilterPID.size() - 1 ? "" : ",");
+        errs() << "\"";
+      }
+      errs() << " for binary \"" << BC->getFilename() << "\".";
       errs() << " Profile for the following process is available:\n";
       for (std::pair<const uint64_t, MMapInfo> &MMI : BinaryMMapInfo)
         outs() << "  " << MMI.second.PID
                << (MMI.second.Forked ? " (forked)\n" : "\n");
-
       if (errs().has_colors())
         errs().resetColor();
 
       return createStringError(std::errc::not_supported,
                                "could not find a profile matching PID");
     }
+    BinaryMMapInfo = std::move(FilteredMMapInfo);
   }
   return Error::success();
 }



More information about the llvm-commits mailing list