[Lldb-commits] [lldb] 156b997 - [lldb] Instrument SB API with signposts

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Thu Jan 20 18:06:27 PST 2022


Author: Jonas Devlieghere
Date: 2022-01-20T18:06:14-08:00
New Revision: 156b997251db6d87636fa300d7654989caa01dea

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

LOG: [lldb] Instrument SB API with signposts

Instrument the SB API with signposts on Darwin. This gives us a time
profile on whose behalf LLDB spends time (particularly when run via the
SBAPI from an IDE).

Differential revision: https://reviews.llvm.org/D117632

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Utility/Instrumentation.h b/lldb/include/lldb/Utility/Instrumentation.h
index 6962270bb89d..ff6591d63437 100644
--- a/lldb/include/lldb/Utility/Instrumentation.h
+++ b/lldb/include/lldb/Utility/Instrumentation.h
@@ -86,6 +86,8 @@ class Instrumenter {
 private:
   void UpdateBoundary();
 
+  llvm::StringRef m_pretty_func;
+
   /// Whether this function call was the one crossing the API boundary.
   bool m_local_boundary = false;
 };

diff  --git a/lldb/source/Utility/Instrumentation.cpp b/lldb/source/Utility/Instrumentation.cpp
index d375fcea58c0..861789810e1a 100644
--- a/lldb/source/Utility/Instrumentation.cpp
+++ b/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>
@@ -17,21 +19,25 @@ using namespace lldb_private::instrumentation;
 // 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(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)
+Instrumenter::~Instrumenter() {
+  if (m_local_boundary) {
     g_global_boundary = false;
+    g_api_signposts->endInterval(this, m_pretty_func);
+  }
 }


        


More information about the lldb-commits mailing list