[llvm-branch-commits] [llvm] b37de2a - [Support] Untie the llvm::Signpost interface from llvm::Timer

Jonas Devlieghere via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Jan 6 15:20:27 PST 2021


Author: Jonas Devlieghere
Date: 2021-01-06T15:16:09-08:00
New Revision: b37de2afa30fe4312aa9b87b11208bd7e05c8fa1

URL: https://github.com/llvm/llvm-project/commit/b37de2afa30fe4312aa9b87b11208bd7e05c8fa1
DIFF: https://github.com/llvm/llvm-project/commit/b37de2afa30fe4312aa9b87b11208bd7e05c8fa1.diff

LOG: [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

Added: 
    

Modified: 
    llvm/include/llvm/Support/Signposts.h
    llvm/lib/Support/Signposts.cpp
    llvm/lib/Support/Timer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/Signposts.h b/llvm/include/llvm/Support/Signposts.h
index b5a8c3d61e3e..8036b1f53663 100644
--- a/llvm/include/llvm/Support/Signposts.h
+++ b/llvm/include/llvm/Support/Signposts.h
@@ -17,9 +17,10 @@
 #ifndef LLVM_SUPPORT_SIGNPOSTS_H
 #define LLVM_SUPPORT_SIGNPOSTS_H
 
+#include "llvm/ADT/StringRef.h"
+
 namespace llvm {
 class SignpostEmitterImpl;
-class Timer;
 
 /// Manages the emission of signposts into the recording method supported by
 /// the OS.
@@ -32,10 +33,10 @@ class SignpostEmitter {
 
   bool isEnabled() const;
 
-  /// Begin a signposted interval for the given timer.
-  void startTimerInterval(Timer *T);
-  /// End a signposted interval for the given timer.
-  void endTimerInterval(Timer *T);
+  /// Begin a signposted interval for a given object.
+  void startInterval(const void *O, StringRef Name);
+  /// End a signposted interval for a given object.
+  void endInterval(const void *O, StringRef Name);
 };
 
 } // end namespace llvm

diff  --git a/llvm/lib/Support/Signposts.cpp b/llvm/lib/Support/Signposts.cpp
index aa159e1da2ae..91ce909c7dcb 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 @@ class SignpostEmitterImpl {
 
   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 @@ class SignpostEmitterImpl {
 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
 }

diff  --git a/llvm/lib/Support/Timer.cpp b/llvm/lib/Support/Timer.cpp
index a3b86cfa6811..f5a512f9a22d 100644
--- a/llvm/lib/Support/Timer.cpp
+++ b/llvm/lib/Support/Timer.cpp
@@ -143,7 +143,7 @@ TimeRecord TimeRecord::getCurrentTime(bool Start) {
 void Timer::startTimer() {
   assert(!Running && "Cannot start a running timer");
   Running = Triggered = true;
-  Signposts->startTimerInterval(this);
+  Signposts->startInterval(this, getName());
   StartTime = TimeRecord::getCurrentTime(true);
 }
 
@@ -152,7 +152,7 @@ void Timer::stopTimer() {
   Running = false;
   Time += TimeRecord::getCurrentTime(false);
   Time -= StartTime;
-  Signposts->endTimerInterval(this);
+  Signposts->endInterval(this, getName());
 }
 
 void Timer::clear() {


        


More information about the llvm-branch-commits mailing list