[clang] [llvm] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)
https://github.com/atetubou updated https://github.com/llvm/llvm-project/pull/83961 >From 6e2521733cdc49971529977cb81c731dd2816b42 Mon Sep 17 00:00:00 2001 From: Takuto Ikuta Date: Mon, 18 Mar 2024 18:03:00 +0900 Subject: [PATCH 1/2] git squash commit for support_new_trace. 90ebde07f7fa426a37dd4bdc362e1a809aaf0844 Expose TimeTraceProfiler for Async Events 8bf598f71d37f5404671dbb1840c7bed0ed87b42 assert --- llvm/include/llvm/Support/TimeProfiler.h| 34 +-- llvm/lib/Support/TimeProfiler.cpp | 101 ++-- llvm/unittests/Support/TimeProfilerTest.cpp | 11 +++ 3 files changed, 107 insertions(+), 39 deletions(-) diff --git a/llvm/include/llvm/Support/TimeProfiler.h b/llvm/include/llvm/Support/TimeProfiler.h index 454a65f70231f4..31f7df10916db9 100644 --- a/llvm/include/llvm/Support/TimeProfiler.h +++ b/llvm/include/llvm/Support/TimeProfiler.h @@ -86,6 +86,8 @@ class raw_pwrite_stream; struct TimeTraceProfiler; TimeTraceProfiler *getTimeTraceProfilerInstance(); +struct TimeTraceProfilerEntry; + /// Initialize the time trace profiler. /// This sets up the global \p TimeTraceProfilerInstance /// variable to be the profiler instance. @@ -120,19 +122,30 @@ Error timeTraceProfilerWrite(StringRef PreferredFileName, /// Profiler copies the string data, so the pointers can be given into /// temporaries. Time sections can be hierarchical; every Begin must have a /// matching End pair but they can nest. -void timeTraceProfilerBegin(StringRef Name, StringRef Detail); -void timeTraceProfilerBegin(StringRef Name, -llvm::function_ref Detail); +TimeTraceProfilerEntry *timeTraceProfilerBegin(StringRef Name, + StringRef Detail); +TimeTraceProfilerEntry * +timeTraceProfilerBegin(StringRef Name, + llvm::function_ref Detail); + +/// Manually begin a time section, with the given \p Name and \p Detail. +/// This starts Async Events having \p Name as a category which is shown +/// separately from other traces. See +/// https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview#heading=h.jh64i9l3vwa1 +/// for more details. +TimeTraceProfilerEntry *timeTraceAsyncProfilerBegin(StringRef Name, +StringRef Detail); /// Manually end the last time section. void timeTraceProfilerEnd(); +void timeTraceProfilerEnd(TimeTraceProfilerEntry *E); /// 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 /// the section; and when it is destroyed, it stops it. If the time profiler /// is not initialized, the overhead is a single branch. -struct TimeTraceScope { - +class TimeTraceScope { +public: TimeTraceScope() = delete; TimeTraceScope(const TimeTraceScope &) = delete; TimeTraceScope =(const TimeTraceScope &) = delete; @@ -141,20 +154,23 @@ struct TimeTraceScope { TimeTraceScope(StringRef Name) { if (getTimeTraceProfilerInstance() != nullptr) - timeTraceProfilerBegin(Name, StringRef("")); + Entry = timeTraceProfilerBegin(Name, StringRef("")); } TimeTraceScope(StringRef Name, StringRef Detail) { if (getTimeTraceProfilerInstance() != nullptr) - timeTraceProfilerBegin(Name, Detail); + Entry = timeTraceProfilerBegin(Name, Detail); } TimeTraceScope(StringRef Name, llvm::function_ref Detail) { if (getTimeTraceProfilerInstance() != nullptr) - timeTraceProfilerBegin(Name, Detail); + Entry = timeTraceProfilerBegin(Name, Detail); } ~TimeTraceScope() { if (getTimeTraceProfilerInstance() != nullptr) - timeTraceProfilerEnd(); + timeTraceProfilerEnd(Entry); } + +private: + TimeTraceProfilerEntry *Entry = nullptr; }; } // end namespace llvm diff --git a/llvm/lib/Support/TimeProfiler.cpp b/llvm/lib/Support/TimeProfiler.cpp index 4d625b3eb5b170..092028dd2a5b34 100644 --- a/llvm/lib/Support/TimeProfiler.cpp +++ b/llvm/lib/Support/TimeProfiler.cpp @@ -11,6 +11,7 @@ //===--===// #include "llvm/Support/TimeProfiler.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLFunctionalExtras.h" #include "llvm/ADT/StringMap.h" #include "llvm/Support/JSON.h" @@ -20,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -64,17 +66,19 @@ using CountAndDurationType = std::pair; using NameAndCountAndDurationType = std::pair; +} // anonymous namespace + /// Represents an open or completed time section entry to be captured. -struct TimeTraceProfilerEntry { +struct llvm::TimeTraceProfilerEntry { const TimePointType Start; TimePointType End; const std::string Name; const std::string Detail; - + const bool AsyncEvent = false; TimeTraceProfilerEntry(TimePointType &, TimePointType &, std::string &, -
[clang] [llvm] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)
ZequanWu wrote: > > > > IIUC, the approach you choose here is to let `SemaPPCallbacks` control > > > > the "entered file stack" and allow it to remove element (which is file) > > > > from middle of the internal stack in `TimeTraceProfiler`, but this > > > > creates async event which is not designed for this purpose. > > > > Can we let `SemaPPCallbacks` track the last push file into the stack > > > > and when exit file, pop all the elements from the stack until we popped > > > > the last pushed file? > > > > > > > > > As I wrote in [#56554 > > > (comment)](https://github.com/llvm/llvm-project/issues/56554#issuecomment-1975812398), > > > file level span and syntax tree level span should be handled > > > asynchronously. So using such implementation produces incorrect trace in > > > other edge cases. > > > > > > Can we choose to expose a handle (maybe an unique id for each entry) from > > `TimeTraceProfiler` instead of exposing the internal entry? > > I think pointer to `TimeTraceProfilerEntry` is already like handle as > definition of the struct is not written in header file. Having another handle > for that seems unnecessary indirection layer to me. Or better to change the > name of struct? Okay, make sense. Looks good for me. Adding @MaskRay to review in case he has something to say. https://github.com/llvm/llvm-project/pull/83961 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)
atetubou wrote: > > > IIUC, the approach you choose here is to let `SemaPPCallbacks` control > > > the "entered file stack" and allow it to remove element (which is file) > > > from middle of the internal stack in `TimeTraceProfiler`, but this > > > creates async event which is not designed for this purpose. > > > Can we let `SemaPPCallbacks` track the last push file into the stack and > > > when exit file, pop all the elements from the stack until we popped the > > > last pushed file? > > > > > > As I wrote in [#56554 > > (comment)](https://github.com/llvm/llvm-project/issues/56554#issuecomment-1975812398), > > file level span and syntax tree level span should be handled > > asynchronously. So using such implementation produces incorrect trace in > > other edge cases. > > Can we choose to expose a handle (maybe an unique id for each entry) from > `TimeTraceProfiler` instead of exposing the internal entry? I think pointer to `TimeTraceProfilerEntry` is already like handle as definition of the struct is not written in header file. Having another handle for that seems unnecessary indirection layer to me. Or better to change the name of struct? https://github.com/llvm/llvm-project/pull/83961 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)
@@ -102,23 +104,24 @@ struct llvm::TimeTraceProfiler { llvm::get_thread_name(ThreadName); } - void begin(std::string Name, llvm::function_ref Detail) { -Stack.emplace_back(ClockType::now(), TimePointType(), std::move(Name), - Detail()); + TimeTraceProfilerEntry *begin(std::string Name, +llvm::function_ref Detail, +bool AsyncEvent = false) { +Stack.emplace_back(std::make_unique( +ClockType::now(), TimePointType(), std::move(Name), Detail(), +AsyncEvent)); +return Stack.back().get(); } void end() { +TimeTraceProfilerEntry *E = Stack.back().get(); atetubou wrote: `Stack.back()` doesn't mutate `Stack`? https://github.com/llvm/llvm-project/pull/83961 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)
ZequanWu wrote: > > IIUC, the approach you choose here is to let `SemaPPCallbacks` control the > > "entered file stack" and allow it to remove element (which is file) from > > middle of the internal stack in `TimeTraceProfiler`, but this creates async > > event which is not designed for this purpose. > > Can we let `SemaPPCallbacks` track the last push file into the stack and > > when exit file, pop all the elements from the stack until we popped the > > last pushed file? > > As I wrote in [#56554 > (comment)](https://github.com/llvm/llvm-project/issues/56554#issuecomment-1975812398), > file level span and syntax tree level span should be handled asynchronously. > So using such implementation produces incorrect trace in other edge cases. Can we choose to expose a handle (maybe an unique id for each entry) from `TimeTraceProfiler` instead of exposing the internal entry? https://github.com/llvm/llvm-project/pull/83961 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)
@@ -102,23 +104,24 @@ struct llvm::TimeTraceProfiler { llvm::get_thread_name(ThreadName); } - void begin(std::string Name, llvm::function_ref Detail) { -Stack.emplace_back(ClockType::now(), TimePointType(), std::move(Name), - Detail()); + TimeTraceProfilerEntry *begin(std::string Name, +llvm::function_ref Detail, +bool AsyncEvent = false) { +Stack.emplace_back(std::make_unique( +ClockType::now(), TimePointType(), std::move(Name), Detail(), +AsyncEvent)); +return Stack.back().get(); } void end() { +TimeTraceProfilerEntry *E = Stack.back().get(); ZequanWu wrote: But that's assertion after the call to `Stack.back()`. https://github.com/llvm/llvm-project/pull/83961 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)
@@ -102,23 +104,24 @@ struct llvm::TimeTraceProfiler { llvm::get_thread_name(ThreadName); } - void begin(std::string Name, llvm::function_ref Detail) { -Stack.emplace_back(ClockType::now(), TimePointType(), std::move(Name), - Detail()); + TimeTraceProfilerEntry *begin(std::string Name, +llvm::function_ref Detail, +bool AsyncEvent = false) { +Stack.emplace_back(std::make_unique( +ClockType::now(), TimePointType(), std::move(Name), Detail(), +AsyncEvent)); +return Stack.back().get(); } void end() { +TimeTraceProfilerEntry *E = Stack.back().get(); atetubou wrote: But this function calls `end(TimeTraceProfilerEntry )` and that covers the assertion? https://github.com/llvm/llvm-project/pull/83961 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)
atetubou wrote: > IIUC, the approach you choose here is to let `SemaPPCallbacks` control the > "entered file stack" and allow it to remove element (which is file) from > middle of the internal stack in `TimeTraceProfiler`, but this creates async > event which is not designed for this purpose. > > Can we let `SemaPPCallbacks` track the last push file into the stack and when > exit file, pop all the elements from the stack until we popped the last > pushed file? As I wrote in https://github.com/llvm/llvm-project/issues/56554#issuecomment-1975812398, file level span and syntax tree level span should be handled asynchronously. So using such implementation produces incorrect trace in other edge cases. https://github.com/llvm/llvm-project/pull/83961 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)
https://github.com/atetubou updated https://github.com/llvm/llvm-project/pull/83961 >From 90ebde07f7fa426a37dd4bdc362e1a809aaf0844 Mon Sep 17 00:00:00 2001 From: Takuto Ikuta Date: Mon, 4 Mar 2024 19:12:31 +0900 Subject: [PATCH 1/3] Expose TimeTraceProfiler for Async Events --- llvm/include/llvm/Support/TimeProfiler.h| 34 +-- llvm/lib/Support/TimeProfiler.cpp | 101 ++-- llvm/unittests/Support/TimeProfilerTest.cpp | 11 +++ 3 files changed, 107 insertions(+), 39 deletions(-) diff --git a/llvm/include/llvm/Support/TimeProfiler.h b/llvm/include/llvm/Support/TimeProfiler.h index 454a65f70231f4..31f7df10916db9 100644 --- a/llvm/include/llvm/Support/TimeProfiler.h +++ b/llvm/include/llvm/Support/TimeProfiler.h @@ -86,6 +86,8 @@ class raw_pwrite_stream; struct TimeTraceProfiler; TimeTraceProfiler *getTimeTraceProfilerInstance(); +struct TimeTraceProfilerEntry; + /// Initialize the time trace profiler. /// This sets up the global \p TimeTraceProfilerInstance /// variable to be the profiler instance. @@ -120,19 +122,30 @@ Error timeTraceProfilerWrite(StringRef PreferredFileName, /// Profiler copies the string data, so the pointers can be given into /// temporaries. Time sections can be hierarchical; every Begin must have a /// matching End pair but they can nest. -void timeTraceProfilerBegin(StringRef Name, StringRef Detail); -void timeTraceProfilerBegin(StringRef Name, -llvm::function_ref Detail); +TimeTraceProfilerEntry *timeTraceProfilerBegin(StringRef Name, + StringRef Detail); +TimeTraceProfilerEntry * +timeTraceProfilerBegin(StringRef Name, + llvm::function_ref Detail); + +/// Manually begin a time section, with the given \p Name and \p Detail. +/// This starts Async Events having \p Name as a category which is shown +/// separately from other traces. See +/// https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview#heading=h.jh64i9l3vwa1 +/// for more details. +TimeTraceProfilerEntry *timeTraceAsyncProfilerBegin(StringRef Name, +StringRef Detail); /// Manually end the last time section. void timeTraceProfilerEnd(); +void timeTraceProfilerEnd(TimeTraceProfilerEntry *E); /// 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 /// the section; and when it is destroyed, it stops it. If the time profiler /// is not initialized, the overhead is a single branch. -struct TimeTraceScope { - +class TimeTraceScope { +public: TimeTraceScope() = delete; TimeTraceScope(const TimeTraceScope &) = delete; TimeTraceScope =(const TimeTraceScope &) = delete; @@ -141,20 +154,23 @@ struct TimeTraceScope { TimeTraceScope(StringRef Name) { if (getTimeTraceProfilerInstance() != nullptr) - timeTraceProfilerBegin(Name, StringRef("")); + Entry = timeTraceProfilerBegin(Name, StringRef("")); } TimeTraceScope(StringRef Name, StringRef Detail) { if (getTimeTraceProfilerInstance() != nullptr) - timeTraceProfilerBegin(Name, Detail); + Entry = timeTraceProfilerBegin(Name, Detail); } TimeTraceScope(StringRef Name, llvm::function_ref Detail) { if (getTimeTraceProfilerInstance() != nullptr) - timeTraceProfilerBegin(Name, Detail); + Entry = timeTraceProfilerBegin(Name, Detail); } ~TimeTraceScope() { if (getTimeTraceProfilerInstance() != nullptr) - timeTraceProfilerEnd(); + timeTraceProfilerEnd(Entry); } + +private: + TimeTraceProfilerEntry *Entry = nullptr; }; } // end namespace llvm diff --git a/llvm/lib/Support/TimeProfiler.cpp b/llvm/lib/Support/TimeProfiler.cpp index 4d625b3eb5b170..3114f8e7ded598 100644 --- a/llvm/lib/Support/TimeProfiler.cpp +++ b/llvm/lib/Support/TimeProfiler.cpp @@ -11,6 +11,7 @@ //===--===// #include "llvm/Support/TimeProfiler.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLFunctionalExtras.h" #include "llvm/ADT/StringMap.h" #include "llvm/Support/JSON.h" @@ -20,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -64,17 +66,19 @@ using CountAndDurationType = std::pair; using NameAndCountAndDurationType = std::pair; +} // anonymous namespace + /// Represents an open or completed time section entry to be captured. -struct TimeTraceProfilerEntry { +struct llvm::TimeTraceProfilerEntry { const TimePointType Start; TimePointType End; const std::string Name; const std::string Detail; - + const bool AsyncEvent = false; TimeTraceProfilerEntry(TimePointType &, TimePointType &, std::string &, - std::string &) + std::string &, bool Ae) : Start(std::move(S)), End(std::move(E)), Name(std::move(N)),
[clang] [llvm] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)
@@ -132,15 +135,18 @@ struct llvm::TimeTraceProfiler { // happens to be the ones that don't have any currently open entries above // itself. if (llvm::none_of(llvm::drop_begin(llvm::reverse(Stack)), - [&](const TimeTraceProfilerEntry ) { -return Val.Name == E.Name; + [&](const std::unique_ptr ) { +return Val->Name == E.Name; })) { auto = CountAndTotalPerName[E.Name]; CountAndTotal.first++; CountAndTotal.second += Duration; -} +}; ZequanWu wrote: Unnecessary change. ```suggestion } ``` https://github.com/llvm/llvm-project/pull/83961 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)
https://github.com/ZequanWu commented: IIUC, the approach you choose here is to let `SemaPPCallbacks` control the "entered file stack" and allow it to remove element (which is file) from middle of the internal stack in `TimeTraceProfiler`, but this creates async event which is not designed for this purpose. Can we let `SemaPPCallbacks` track the last push file into the stack and when exit file, pop all the elements from the stack until we popped the last pushed file? https://github.com/llvm/llvm-project/pull/83961 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)
https://github.com/ZequanWu edited https://github.com/llvm/llvm-project/pull/83961 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)
@@ -102,23 +104,24 @@ struct llvm::TimeTraceProfiler { llvm::get_thread_name(ThreadName); } - void begin(std::string Name, llvm::function_ref Detail) { -Stack.emplace_back(ClockType::now(), TimePointType(), std::move(Name), - Detail()); + TimeTraceProfilerEntry *begin(std::string Name, +llvm::function_ref Detail, +bool AsyncEvent = false) { +Stack.emplace_back(std::make_unique( +ClockType::now(), TimePointType(), std::move(Name), Detail(), +AsyncEvent)); +return Stack.back().get(); } void end() { +TimeTraceProfilerEntry *E = Stack.back().get(); ZequanWu wrote: If we extract end(TimeTraceProfilerEntry ) to a separate function, probably want to move the assertion to here as well https://github.com/llvm/llvm-project/pull/83961 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)
atetubou wrote: @ZequanWu could you take a look this? https://github.com/llvm/llvm-project/pull/83961 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)
llvmbot wrote: @llvm/pr-subscribers-llvm-support Author: Takuto Ikuta (atetubou) Changes This fixes incorrect trace for https://github.com/llvm/llvm-project/issues/56554. This shows trace like https://ui.perfetto.dev/#!/?s=aa809778dc50f2b155b062317fa18bbe2bb2fb9175e6282add8121c7c178214e for the case shown in https://github.com/llvm/llvm-project/issues/83236. https://github.com/llvm/llvm-project/pull/83778 is preparing PR. Fix #56554 --- Full diff: https://github.com/llvm/llvm-project/pull/83961.diff 4 Files Affected: - (modified) clang/lib/Sema/Sema.cpp (+6-4) - (modified) llvm/include/llvm/Support/TimeProfiler.h (+25-9) - (modified) llvm/lib/Support/TimeProfiler.cpp (+71-30) - (modified) llvm/unittests/Support/TimeProfilerTest.cpp (+11) ``diff diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index cfb653e665ea03..2fb12e327c304d 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -135,6 +135,7 @@ namespace sema { class SemaPPCallbacks : public PPCallbacks { Sema *S = nullptr; llvm::SmallVector IncludeStack; + llvm::SmallVector ProfilerStack; public: void set(Sema ) { this->S = } @@ -153,8 +154,8 @@ class SemaPPCallbacks : public PPCallbacks { if (IncludeLoc.isValid()) { if (llvm::timeTraceProfilerEnabled()) { OptionalFileEntryRef FE = SM.getFileEntryRefForID(SM.getFileID(Loc)); - llvm::timeTraceProfilerBegin("Source", FE ? FE->getName() -: StringRef("")); + ProfilerStack.push_back(llvm::timeTraceAsyncProfilerBegin( + "Source", FE ? FE->getName() : StringRef(""))); } IncludeStack.push_back(IncludeLoc); @@ -166,8 +167,9 @@ class SemaPPCallbacks : public PPCallbacks { } case ExitFile: if (!IncludeStack.empty()) { -if (llvm::timeTraceProfilerEnabled()) - llvm::timeTraceProfilerEnd(); +if (llvm::timeTraceProfilerEnabled()) { + llvm::timeTraceProfilerEnd(ProfilerStack.pop_back_val()); +} S->DiagnoseNonDefaultPragmaAlignPack( Sema::PragmaAlignPackDiagnoseKind::ChangedStateAtExit, diff --git a/llvm/include/llvm/Support/TimeProfiler.h b/llvm/include/llvm/Support/TimeProfiler.h index 454a65f70231f4..31f7df10916db9 100644 --- a/llvm/include/llvm/Support/TimeProfiler.h +++ b/llvm/include/llvm/Support/TimeProfiler.h @@ -86,6 +86,8 @@ class raw_pwrite_stream; struct TimeTraceProfiler; TimeTraceProfiler *getTimeTraceProfilerInstance(); +struct TimeTraceProfilerEntry; + /// Initialize the time trace profiler. /// This sets up the global \p TimeTraceProfilerInstance /// variable to be the profiler instance. @@ -120,19 +122,30 @@ Error timeTraceProfilerWrite(StringRef PreferredFileName, /// Profiler copies the string data, so the pointers can be given into /// temporaries. Time sections can be hierarchical; every Begin must have a /// matching End pair but they can nest. -void timeTraceProfilerBegin(StringRef Name, StringRef Detail); -void timeTraceProfilerBegin(StringRef Name, -llvm::function_ref Detail); +TimeTraceProfilerEntry *timeTraceProfilerBegin(StringRef Name, + StringRef Detail); +TimeTraceProfilerEntry * +timeTraceProfilerBegin(StringRef Name, + llvm::function_ref Detail); + +/// Manually begin a time section, with the given \p Name and \p Detail. +/// This starts Async Events having \p Name as a category which is shown +/// separately from other traces. See +/// https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview#heading=h.jh64i9l3vwa1 +/// for more details. +TimeTraceProfilerEntry *timeTraceAsyncProfilerBegin(StringRef Name, +StringRef Detail); /// Manually end the last time section. void timeTraceProfilerEnd(); +void timeTraceProfilerEnd(TimeTraceProfilerEntry *E); /// 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 /// the section; and when it is destroyed, it stops it. If the time profiler /// is not initialized, the overhead is a single branch. -struct TimeTraceScope { - +class TimeTraceScope { +public: TimeTraceScope() = delete; TimeTraceScope(const TimeTraceScope &) = delete; TimeTraceScope =(const TimeTraceScope &) = delete; @@ -141,20 +154,23 @@ struct TimeTraceScope { TimeTraceScope(StringRef Name) { if (getTimeTraceProfilerInstance() != nullptr) - timeTraceProfilerBegin(Name, StringRef("")); + Entry = timeTraceProfilerBegin(Name, StringRef("")); } TimeTraceScope(StringRef Name, StringRef Detail) { if (getTimeTraceProfilerInstance() != nullptr) - timeTraceProfilerBegin(Name, Detail); + Entry = timeTraceProfilerBegin(Name, Detail); } TimeTraceScope(StringRef
[clang] [llvm] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)
https://github.com/atetubou ready_for_review https://github.com/llvm/llvm-project/pull/83961 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)
https://github.com/atetubou edited https://github.com/llvm/llvm-project/pull/83961 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits