Skip to content

Commit f069b2a

Browse files
committed
Expose TimeTraceProfiler for multiple traces
1 parent 23bc5b6 commit f069b2a

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

llvm/include/llvm/Support/TimeProfiler.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ class raw_pwrite_stream;
8686
struct TimeTraceProfiler;
8787
TimeTraceProfiler *getTimeTraceProfilerInstance();
8888

89+
TimeTraceProfiler *newTimeTraceProfiler(unsigned TimeTraceGranularity = 0,
90+
StringRef ProcName = "");
91+
8992
/// Initialize the time trace profiler.
9093
/// This sets up the global \p TimeTraceProfilerInstance
9194
/// variable to be the profiler instance.
@@ -123,9 +126,12 @@ Error timeTraceProfilerWrite(StringRef PreferredFileName,
123126
void timeTraceProfilerBegin(StringRef Name, StringRef Detail);
124127
void timeTraceProfilerBegin(StringRef Name,
125128
llvm::function_ref<std::string()> Detail);
129+
void timeTraceProfilerBegin(TimeTraceProfiler *Profiler, StringRef Name,
130+
StringRef Detail);
126131

127132
/// Manually end the last time section.
128133
void timeTraceProfilerEnd();
134+
void timeTraceProfilerEnd(TimeTraceProfiler *Profiler);
129135

130136
/// The TimeTraceScope is a helper class to call the begin and end functions
131137
/// of the time trace profiler. When the object is constructed, it begins

llvm/lib/Support/TimeProfiler.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,16 @@ void llvm::timeTraceProfilerInitialize(unsigned TimeTraceGranularity,
293293
TimeTraceGranularity, llvm::sys::path::filename(ProcName));
294294
}
295295

296+
TimeTraceProfiler *llvm::newTimeTraceProfiler(unsigned TimeTraceGranularity,
297+
StringRef ProcName) {
298+
TimeTraceProfiler *Profiler =
299+
new TimeTraceProfiler(TimeTraceGranularity, ProcName);
300+
auto &Instances = getTimeTraceProfilerInstances();
301+
std::lock_guard<std::mutex> Lock(Instances.Lock);
302+
Instances.List.push_back(Profiler);
303+
return Profiler;
304+
}
305+
296306
// Removes all TimeTraceProfilerInstances.
297307
// Called from main thread.
298308
void llvm::timeTraceProfilerCleanup() {
@@ -353,7 +363,18 @@ void llvm::timeTraceProfilerBegin(StringRef Name,
353363
TimeTraceProfilerInstance->begin(std::string(Name), Detail);
354364
}
355365

366+
void llvm::timeTraceProfilerBegin(TimeTraceProfiler *Profiler, StringRef Name,
367+
StringRef Detail) {
368+
if (Profiler != nullptr)
369+
Profiler->begin(std::string(Name), [&]() { return std::string(Detail); });
370+
}
371+
356372
void llvm::timeTraceProfilerEnd() {
357373
if (TimeTraceProfilerInstance != nullptr)
358374
TimeTraceProfilerInstance->end();
359375
}
376+
377+
void llvm::timeTraceProfilerEnd(TimeTraceProfiler *Profiler) {
378+
if (Profiler != nullptr)
379+
Profiler->end();
380+
}

0 commit comments

Comments
 (0)