[llvm] 3f7f446 - [llvm-profgen] Remove temporary perf script files (#86668)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 11 00:28:36 PDT 2024
Author: Haohai Wen
Date: 2024-04-11T15:28:32+08:00
New Revision: 3f7f446d3803a699f5964a7429c6e1de0d783452
URL: https://github.com/llvm/llvm-project/commit/3f7f446d3803a699f5964a7429c6e1de0d783452
DIFF: https://github.com/llvm/llvm-project/commit/3f7f446d3803a699f5964a7429c6e1de0d783452.diff
LOG: [llvm-profgen] Remove temporary perf script files (#86668)
The temporary perf script files converted from perf data will occupy
lots
of space for large project. This patch removes them when llvm-profgen
exits normally or receives signals.
Added:
Modified:
llvm/tools/llvm-profgen/PerfReader.cpp
llvm/tools/llvm-profgen/PerfReader.h
Removed:
################################################################################
diff --git a/llvm/tools/llvm-profgen/PerfReader.cpp b/llvm/tools/llvm-profgen/PerfReader.cpp
index 878147642aa6e7..e9442027aed3fa 100644
--- a/llvm/tools/llvm-profgen/PerfReader.cpp
+++ b/llvm/tools/llvm-profgen/PerfReader.cpp
@@ -11,6 +11,7 @@
#include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Process.h"
+#include "llvm/Support/ToolOutputFile.h"
#define DEBUG_TYPE "perf-reader"
@@ -375,6 +376,9 @@ PerfScriptReader::convertPerfDataToTrace(ProfiledBinary *Binary,
StringRef(ErrorFile)}; // Stderr
sys::ExecuteAndWait(PerfPath, ScriptMMapArgs, std::nullopt, Redirects);
+ PerfScriptReader::TempFileCleanups.emplace_back(PerfTraceFile);
+ PerfScriptReader::TempFileCleanups.emplace_back(ErrorFile);
+
// Collect the PIDs
TraceStream TraceIt(PerfTraceFile);
std::string PIDs;
@@ -1220,5 +1224,7 @@ void PerfScriptReader::parsePerfTraces() {
writeUnsymbolizedProfile(OutputFilename);
}
+SmallVector<CleanupInstaller, 2> PerfScriptReader::TempFileCleanups;
+
} // end namespace sampleprof
} // end namespace llvm
diff --git a/llvm/tools/llvm-profgen/PerfReader.h b/llvm/tools/llvm-profgen/PerfReader.h
index e9f619350bf970..b821cbe13efae6 100644
--- a/llvm/tools/llvm-profgen/PerfReader.h
+++ b/llvm/tools/llvm-profgen/PerfReader.h
@@ -21,6 +21,9 @@ using namespace llvm;
using namespace sampleprof;
namespace llvm {
+
+class CleanupInstaller;
+
namespace sampleprof {
// Stream based trace line iterator
@@ -604,6 +607,11 @@ class PerfScriptReader : public PerfReaderBase {
// Extract perf script type by peaking at the input
static PerfContent checkPerfScriptType(StringRef FileName);
+ // Cleanup installers for temporary files created by perf script command.
+ // Those files will be automatically removed when running destructor or
+ // receiving signals.
+ static SmallVector<CleanupInstaller, 2> TempFileCleanups;
+
protected:
// The parsed MMap event
struct MMapEvent {
More information about the llvm-commits
mailing list