JDevlieghere updated this revision to Diff 401369.
JDevlieghere retitled this revision from "Instrument SBAPI with scoped timers" 
to "Instrument SB API with signposts".
JDevlieghere edited the summary of this revision.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117632/new/

https://reviews.llvm.org/D117632

Files:
  lldb/include/lldb/Utility/Instrumentation.h
  lldb/source/Utility/Instrumentation.cpp


Index: lldb/source/Utility/Instrumentation.cpp
===================================================================
--- lldb/source/Utility/Instrumentation.cpp
+++ lldb/source/Utility/Instrumentation.cpp
@@ -6,6 +6,8 @@
 
//===----------------------------------------------------------------------===//
 
 #include "lldb/Utility/Instrumentation.h"
+#include "llvm/Support/Signposts.h"
+
 #include <cstdio>
 #include <cstdlib>
 #include <limits>
@@ -16,6 +18,9 @@
 // Whether we're currently across the API boundary.
 static thread_local bool g_global_boundary = false;
 
+// Instrument SB API calls with singposts when supported.
+static llvm::ManagedStatic<llvm::SignpostEmitter> g_api_signposts;
+
 Instrumenter::Instrumenter() {
   if (!g_global_boundary) {
     g_global_boundary = true;
@@ -25,19 +30,22 @@
 
 Instrumenter::Instrumenter(llvm::StringRef pretty_func,
                            std::string &&pretty_args)
-    : m_local_boundary(false) {
+    : m_pretty_func(pretty_func), m_local_boundary(false) {
   if (!g_global_boundary) {
     g_global_boundary = true;
     m_local_boundary = true;
+    g_api_signposts->startInterval(this, m_pretty_func);
   }
   LLDB_LOG(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API), "[{0}] {1} ({2})",
-           m_local_boundary ? "external" : "internal", pretty_func,
+           m_local_boundary ? "external" : "internal", m_pretty_func,
            pretty_args);
 }
 
 Instrumenter::~Instrumenter() { UpdateBoundary(); }
 
 void Instrumenter::UpdateBoundary() {
-  if (m_local_boundary)
+  if (m_local_boundary) {
     g_global_boundary = false;
+    g_api_signposts->endInterval(this, m_pretty_func);
+  }
 }
Index: lldb/include/lldb/Utility/Instrumentation.h
===================================================================
--- lldb/include/lldb/Utility/Instrumentation.h
+++ lldb/include/lldb/Utility/Instrumentation.h
@@ -87,6 +87,8 @@
 private:
   void UpdateBoundary();
 
+  llvm::StringRef m_pretty_func;
+
   /// Whether this function call was the one crossing the API boundary.
   bool m_local_boundary = false;
 };


Index: lldb/source/Utility/Instrumentation.cpp
===================================================================
--- lldb/source/Utility/Instrumentation.cpp
+++ lldb/source/Utility/Instrumentation.cpp
@@ -6,6 +6,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "lldb/Utility/Instrumentation.h"
+#include "llvm/Support/Signposts.h"
+
 #include <cstdio>
 #include <cstdlib>
 #include <limits>
@@ -16,6 +18,9 @@
 // Whether we're currently across the API boundary.
 static thread_local bool g_global_boundary = false;
 
+// Instrument SB API calls with singposts when supported.
+static llvm::ManagedStatic<llvm::SignpostEmitter> g_api_signposts;
+
 Instrumenter::Instrumenter() {
   if (!g_global_boundary) {
     g_global_boundary = true;
@@ -25,19 +30,22 @@
 
 Instrumenter::Instrumenter(llvm::StringRef pretty_func,
                            std::string &&pretty_args)
-    : m_local_boundary(false) {
+    : m_pretty_func(pretty_func), m_local_boundary(false) {
   if (!g_global_boundary) {
     g_global_boundary = true;
     m_local_boundary = true;
+    g_api_signposts->startInterval(this, m_pretty_func);
   }
   LLDB_LOG(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API), "[{0}] {1} ({2})",
-           m_local_boundary ? "external" : "internal", pretty_func,
+           m_local_boundary ? "external" : "internal", m_pretty_func,
            pretty_args);
 }
 
 Instrumenter::~Instrumenter() { UpdateBoundary(); }
 
 void Instrumenter::UpdateBoundary() {
-  if (m_local_boundary)
+  if (m_local_boundary) {
     g_global_boundary = false;
+    g_api_signposts->endInterval(this, m_pretty_func);
+  }
 }
Index: lldb/include/lldb/Utility/Instrumentation.h
===================================================================
--- lldb/include/lldb/Utility/Instrumentation.h
+++ lldb/include/lldb/Utility/Instrumentation.h
@@ -87,6 +87,8 @@
 private:
   void UpdateBoundary();
 
+  llvm::StringRef m_pretty_func;
+
   /// Whether this function call was the one crossing the API boundary.
   bool m_local_boundary = false;
 };
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to