[llvm] 1b212d1 - [llvm-profgen] Fix perf script parsing issues

via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 8 15:52:18 PDT 2022


Author: wlei
Date: 2022-08-08T15:51:07-07:00
New Revision: 1b212d1098d264f2d5ccc17cde5492f9f2338df6

URL: https://github.com/llvm/llvm-project/commit/1b212d1098d264f2d5ccc17cde5492f9f2338df6
DIFF: https://github.com/llvm/llvm-project/commit/1b212d1098d264f2d5ccc17cde5492f9f2338df6.diff

LOG: [llvm-profgen] Fix perf script parsing issues

Fix two perf script parsing issues:

1) Redirect the error message to a new file. (the error message mixed in the perfscript could screw up the MMAP event line and cause a parsing failure)

2) Changed the MMap parsing error message to warning since the perfscript can still be parsed using the preferred address as base address.

Reviewed By: hoy, wenlei

Differential Revision: https://reviews.llvm.org/D131449

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 f28a852fad64a..613e5305e9a86 100644
--- a/llvm/tools/llvm-profgen/PerfReader.cpp
+++ b/llvm/tools/llvm-profgen/PerfReader.cpp
@@ -367,12 +367,13 @@ PerfInputFile PerfScriptReader::convertPerfDataToTrace(
   }
   std::string PerfPath = *PerfExecutable;
   std::string PerfTraceFile = PerfData.str() + ".script.tmp";
+  std::string ErrorFile = PerfData.str() + ".script.err.tmp";
   StringRef ScriptMMapArgs[] = {PerfPath, "script",   "--show-mmap-events",
                                 "-F",     "comm,pid", "-i",
                                 PerfData};
-  Optional<StringRef> Redirects[] = {llvm::None,                // Stdin
-                                     StringRef(PerfTraceFile),  // Stdout
-                                     StringRef(PerfTraceFile)}; // Stderr
+  Optional<StringRef> Redirects[] = {llvm::None,               // Stdin
+                                     StringRef(PerfTraceFile), // Stdout
+                                     StringRef(ErrorFile)};    // Stderr
   sys::ExecuteAndWait(PerfPath, ScriptMMapArgs, llvm::None, Redirects);
 
   // Collect the PIDs
@@ -950,8 +951,8 @@ bool PerfScriptReader::extractMMap2EventForBinary(ProfiledBinary *Binary,
   SmallVector<StringRef, 6> Fields;
   bool R = RegMmap2.match(Line, &Fields);
   if (!R) {
-    std::string ErrorMsg = "Cannot parse mmap event: " + Line.str() + " \n";
-    exitWithError(ErrorMsg);
+    std::string WarningMsg = "Cannot parse mmap event: " + Line.str() + " \n";
+    WithColor::warning() << WarningMsg;
   }
   Fields[PID].getAsInteger(10, MMap.PID);
   Fields[MMAPPED_ADDRESS].getAsInteger(0, MMap.Address);


        


More information about the llvm-commits mailing list