Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions llvm/tools/llvm-profgen/PerfReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1220,5 +1224,7 @@ void PerfScriptReader::parsePerfTraces() {
writeUnsymbolizedProfile(OutputFilename);
}

SmallVector<CleanupInstaller, 2> PerfScriptReader::TempFileCleanups;

} // end namespace sampleprof
} // end namespace llvm
8 changes: 8 additions & 0 deletions llvm/tools/llvm-profgen/PerfReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ using namespace llvm;
using namespace sampleprof;

namespace llvm {

class CleanupInstaller;

namespace sampleprof {

// Stream based trace line iterator
Expand Down Expand Up @@ -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 {
Expand Down