-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose TimeTraceProfiler for Async Events #83778
Conversation
@llvm/pr-subscribers-llvm-support Author: Takuto Ikuta (atetubou) ChangesTo avoid issue like #56554 and #83236 due to no guarantees for nested relationships between file level span and syntax tree level span, I'd like to have a llvm-project/clang/lib/Sema/Sema.cpp Lines 153 to 170 in 8715f25
This is a preparation patch to do that in following PR. Full diff: https://github.com/llvm/llvm-project/pull/83778.diff 2 Files Affected:
diff --git a/llvm/include/llvm/Support/TimeProfiler.h b/llvm/include/llvm/Support/TimeProfiler.h
index 454a65f70231f4..cef4110c10deae 100644
--- a/llvm/include/llvm/Support/TimeProfiler.h
+++ b/llvm/include/llvm/Support/TimeProfiler.h
@@ -86,6 +86,9 @@ class raw_pwrite_stream;
struct TimeTraceProfiler;
TimeTraceProfiler *getTimeTraceProfilerInstance();
+TimeTraceProfiler *newTimeTraceProfiler(unsigned TimeTraceGranularity = 0,
+ StringRef ProcName = "");
+
/// Initialize the time trace profiler.
/// This sets up the global \p TimeTraceProfilerInstance
/// variable to be the profiler instance.
@@ -123,9 +126,12 @@ Error timeTraceProfilerWrite(StringRef PreferredFileName,
void timeTraceProfilerBegin(StringRef Name, StringRef Detail);
void timeTraceProfilerBegin(StringRef Name,
llvm::function_ref<std::string()> Detail);
+void timeTraceProfilerBegin(TimeTraceProfiler *Profiler, StringRef Name,
+ StringRef Detail);
/// Manually end the last time section.
void timeTraceProfilerEnd();
+void timeTraceProfilerEnd(TimeTraceProfiler *Profiler);
/// The TimeTraceScope is a helper class to call the begin and end functions
/// of the time trace profiler. When the object is constructed, it begins
diff --git a/llvm/lib/Support/TimeProfiler.cpp b/llvm/lib/Support/TimeProfiler.cpp
index 4d625b3eb5b170..9cd5ea6d81758f 100644
--- a/llvm/lib/Support/TimeProfiler.cpp
+++ b/llvm/lib/Support/TimeProfiler.cpp
@@ -293,6 +293,16 @@ void llvm::timeTraceProfilerInitialize(unsigned TimeTraceGranularity,
TimeTraceGranularity, llvm::sys::path::filename(ProcName));
}
+TimeTraceProfiler *llvm::newTimeTraceProfiler(unsigned TimeTraceGranularity,
+ StringRef ProcName) {
+ TimeTraceProfiler *Profiler =
+ new TimeTraceProfiler(TimeTraceGranularity, ProcName);
+ auto &Instances = getTimeTraceProfilerInstances();
+ std::lock_guard<std::mutex> Lock(Instances.Lock);
+ Instances.List.push_back(Profiler);
+ return Profiler;
+}
+
// Removes all TimeTraceProfilerInstances.
// Called from main thread.
void llvm::timeTraceProfilerCleanup() {
@@ -353,7 +363,18 @@ void llvm::timeTraceProfilerBegin(StringRef Name,
TimeTraceProfilerInstance->begin(std::string(Name), Detail);
}
+void llvm::timeTraceProfilerBegin(TimeTraceProfiler *Profiler, StringRef Name,
+ StringRef Detail) {
+ if (Profiler != nullptr)
+ Profiler->begin(std::string(Name), [&]() { return std::string(Detail); });
+}
+
void llvm::timeTraceProfilerEnd() {
if (TimeTraceProfilerInstance != nullptr)
TimeTraceProfilerInstance->end();
}
+
+void llvm::timeTraceProfilerEnd(TimeTraceProfiler *Profiler) {
+ if (Profiler != nullptr)
+ Profiler->end();
+}
|
f069b2a
to
c4adfd4
Compare
c4adfd4
to
90ebde0
Compare
@ZequanWu could you take a look this? |
90ebde0 Expose TimeTraceProfiler for Async Events 8bf598f71d37f5404671dbb1840c7bed0ed87b42 assert
90ebde0
to
6e25217
Compare
To avoid issue like llvm#56554 and llvm#83236 due to no guarantees for nested relationships between file level span and syntax tree level span, I'd like to have a `timeTraceAsyncProfilerBegin` specific to trace handling only `Source` spans around https://github.com/llvm/llvm-project/blob/8715f256911786520bb727ce067098d7082ac45c/clang/lib/Sema/Sema.cpp#L153-L170. This is a preparation PR to do that in [following PR](llvm#83961).
This fixes incorrect trace for #56554. This shows trace like https://ui.perfetto.dev/#!/?s=aa809778dc50f2b155b062317fa18bbe2bb2fb9175e6282add8121c7c178214e for the case shown in #83236. #83778 is preparing PR. Fix #56554
To avoid issue like #56554 and #83236 due to no guarantees for nested relationships between file level span and syntax tree level span, I'd like to have a
timeTraceAsyncProfilerBegin
specific to trace handling onlySource
spans aroundllvm-project/clang/lib/Sema/Sema.cpp
Lines 153 to 170 in 8715f25
This is a preparation PR to do that in following PR.