[llvm] {BOLT} Add itrace aggregation for AUX data (PR #70426)

Jonathan Davies via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 27 01:53:32 PDT 2023


https://github.com/jonathandavies-arm created https://github.com/llvm/llvm-project/pull/70426

If you have a perf.data with Arm ETM data the only way to use perf2bolt with Branch Aggregation is to first run `perf inject --itrace=l64i1us -o perf-brstack.data` and then pass the new perf-brstack.data into perf2bolt. perf2bolt then runs `perf script -F pid,ip,brstack` to produce the brstacks.

This PR adds `--itrace` arg to perf2bolt to enable Itrace Aggregation. It takes a string which is what is passed to the `perf script -F pid,ip,brstack --itrace={0}`. This command produces the brstacks without having to run perf inject and creating a new perf.data file.

>From fe96ac5ec0a1cff1013cd2bb4f5fd14fc6484d2c Mon Sep 17 00:00:00 2001
From: Jonathan Davies <jonathan.davies at arm.com>
Date: Thu, 26 Oct 2023 15:24:00 +0100
Subject: [PATCH] {BOLT} Add itrace aggregation for AUX data

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

diff --git a/bolt/lib/Profile/DataAggregator.cpp b/bolt/lib/Profile/DataAggregator.cpp
index b72bd0edf1a2df2..837dbb6e89c5e5a 100644
--- a/bolt/lib/Profile/DataAggregator.cpp
+++ b/bolt/lib/Profile/DataAggregator.cpp
@@ -46,6 +46,11 @@ static cl::opt<bool>
                      cl::desc("aggregate basic samples (without LBR info)"),
                      cl::cat(AggregatorCategory));
 
+static cl::opt<std::string>
+    ITraceAggregation("itrace",
+                      cl::desc("Generate LBR info with perf itrace argument"),
+                      cl::cat(AggregatorCategory));
+
 static cl::opt<bool>
 FilterMemProfile("filter-mem-profile",
   cl::desc("if processing a memory profile, filter out stack or heap accesses "
@@ -155,6 +160,8 @@ void DataAggregator::findPerfExecutable() {
 }
 
 void DataAggregator::start() {
+  std::string ItracePerfScriptArgs;
+
   outs() << "PERF2BOLT: Starting data aggregation job for " << Filename << "\n";
 
   // Don't launch perf for pre-aggregated files
@@ -163,16 +170,23 @@ void DataAggregator::start() {
 
   findPerfExecutable();
 
-  if (opts::BasicAggregation)
+  if (opts::BasicAggregation) {
     launchPerfProcess("events without LBR",
                       MainEventsPPI,
                       "script -F pid,event,ip",
                       /*Wait = */false);
-  else
+  } else if (!opts::ITraceAggregation.empty()) {
+    ItracePerfScriptArgs = llvm::formatv(
+        "script -F pid,ip,brstack --itrace={0}", opts::ITraceAggregation);
+    launchPerfProcess("branch events with itrace", MainEventsPPI,
+                      ItracePerfScriptArgs.c_str(),
+                      /*Wait = */ false);
+  } else {
     launchPerfProcess("branch events",
                       MainEventsPPI,
                       "script -F pid,ip,brstack",
                       /*Wait = */false);
+  }
 
   // Note: we launch script for mem events regardless of the option, as the
   //       command fails fairly fast if mem events were not collected.



More information about the llvm-commits mailing list