diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2021-01-06 14:35:07 -0800 |
---|---|---|
committer | Jonas Devlieghere <jonas@devlieghere.com> | 2021-01-06 15:16:09 -0800 |
commit | b37de2afa30fe4312aa9b87b11208bd7e05c8fa1 (patch) | |
tree | a277cbc27d8cea4ceffe7713510ad96bb4d7eb02 /llvm/lib/Support/Signposts.cpp | |
parent | 080943f7525f277579a000cf30364cc96fba6773 (diff) | |
download | llvm-b37de2afa30fe4312aa9b87b11208bd7e05c8fa1.zip llvm-b37de2afa30fe4312aa9b87b11208bd7e05c8fa1.tar.gz llvm-b37de2afa30fe4312aa9b87b11208bd7e05c8fa1.tar.bz2 |
[Support] Untie the llvm::Signpost interface from llvm::Timer
Make llvm::Signpost more generic by untying from llvm::Timer. This
allows signposts to be used in a different context.
My motivation for doing this is being able to use signposts in LLDB.
Differential revision: https://reviews.llvm.org/D93655
Diffstat (limited to 'llvm/lib/Support/Signposts.cpp')
-rw-r--r-- | llvm/lib/Support/Signposts.cpp | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/llvm/lib/Support/Signposts.cpp b/llvm/lib/Support/Signposts.cpp index aa159e1..91ce909 100644 --- a/llvm/lib/Support/Signposts.cpp +++ b/llvm/lib/Support/Signposts.cpp @@ -33,21 +33,20 @@ void LogDeleter(os_log_t *X) { namespace llvm { class SignpostEmitterImpl { - using LogPtrTy = - std::unique_ptr<os_log_t, std::function<void(os_log_t *)>>; + using LogPtrTy = std::unique_ptr<os_log_t, std::function<void(os_log_t *)>>; using LogTy = LogPtrTy::element_type; LogPtrTy SignpostLog; - DenseMap<const Timer *, os_signpost_id_t> Signposts; + DenseMap<const void *, os_signpost_id_t> Signposts; LogTy &getLogger() const { return *SignpostLog; } - os_signpost_id_t getSignpostForTimer(const Timer *T) { - const auto &I = Signposts.find(T); + os_signpost_id_t getSignpostForObject(const void *O) { + const auto &I = Signposts.find(O); if (I != Signposts.end()) return I->second; const auto &Inserted = Signposts.insert( - std::make_pair(T, os_signpost_id_make_with_pointer(getLogger(), T))); + std::make_pair(O, os_signpost_id_make_with_pointer(getLogger(), O))); return Inserted.first->second; } @@ -56,20 +55,19 @@ public: bool isEnabled() const { return os_signpost_enabled(*SignpostLog); } - void startTimerInterval(Timer *T) { + void startInterval(const void *O, llvm::StringRef Name) { if (isEnabled()) { - // Both strings used here are required to be constant literal strings - os_signpost_interval_begin(getLogger(), getSignpostForTimer(T), - "Pass Timers", "Begin %s", - T->getName().c_str()); + // Both strings used here are required to be constant literal strings. + os_signpost_interval_begin(getLogger(), getSignpostForObject(O), + "LLVM Timers", "Begin %s", Name.data()); } } - void endTimerInterval(Timer *T) { + void endInterval(const void *O, llvm::StringRef Name) { if (isEnabled()) { - // Both strings used here are required to be constant literal strings - os_signpost_interval_end(getLogger(), getSignpostForTimer(T), - "Pass Timers", "End %s", T->getName().c_str()); + // Both strings used here are required to be constant literal strings. + os_signpost_interval_end(getLogger(), getSignpostForObject(O), + "LLVM Timers", "End %s", Name.data()); } } }; @@ -85,7 +83,7 @@ public: SignpostEmitter::SignpostEmitter() { #if HAVE_ANY_SIGNPOST_IMPL Impl = new SignpostEmitterImpl(); -#else // if HAVE_ANY_SIGNPOST_IMPL +#else // if HAVE_ANY_SIGNPOST_IMPL Impl = nullptr; #endif // if !HAVE_ANY_SIGNPOST_IMPL } @@ -104,18 +102,18 @@ bool SignpostEmitter::isEnabled() const { #endif // if !HAVE_ANY_SIGNPOST_IMPL } -void SignpostEmitter::startTimerInterval(Timer *T) { +void SignpostEmitter::startInterval(const void *O, StringRef Name) { #if HAVE_ANY_SIGNPOST_IMPL if (Impl == nullptr) return; - return Impl->startTimerInterval(T); + return Impl->startInterval(O, Name); #endif // if !HAVE_ANY_SIGNPOST_IMPL } -void SignpostEmitter::endTimerInterval(Timer *T) { +void SignpostEmitter::endInterval(const void *O, StringRef Name) { #if HAVE_ANY_SIGNPOST_IMPL if (Impl == nullptr) return; - Impl->endTimerInterval(T); + Impl->endInterval(O, Name); #endif // if !HAVE_ANY_SIGNPOST_IMPL } |