[Lldb-commits] [lldb] c5073ed - Add auto source map deduce count statistics

Jeffrey Tan via lldb-commits lldb-commits at lists.llvm.org
Thu Sep 22 14:53:18 PDT 2022


Author: Jeffrey Tan
Date: 2022-09-22T14:52:58-07:00
New Revision: c5073ed5f92900bbbe9f6a30bbfc9507df54749d

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

LOG: Add auto source map deduce count statistics

This patch adds auto source map deduce count as a target level statistics.
This will help telemetry to track how many debug sessions benefit from this feature.

Differential Revision: https://reviews.llvm.org/D134483

Added: 
    

Modified: 
    lldb/include/lldb/Target/PathMappingList.h
    lldb/include/lldb/Target/Statistics.h
    lldb/source/Breakpoint/BreakpointResolverFileLine.cpp
    lldb/source/Target/PathMappingList.cpp
    lldb/source/Target/Statistics.cpp
    lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Target/PathMappingList.h b/lldb/include/lldb/Target/PathMappingList.h
index 413809ba3f5d2..2f7ee535de3a7 100644
--- a/lldb/include/lldb/Target/PathMappingList.h
+++ b/lldb/include/lldb/Target/PathMappingList.h
@@ -37,7 +37,9 @@ class PathMappingList {
 
   void Append(const PathMappingList &rhs, bool notify);
 
-  void AppendUnique(llvm::StringRef path, llvm::StringRef replacement,
+  /// Append <path, replacement> pair without duplication.
+  /// \return whether appending suceeds without duplication or not.
+  bool AppendUnique(llvm::StringRef path, llvm::StringRef replacement,
                     bool notify);
 
   void Clear(bool notify);

diff  --git a/lldb/include/lldb/Target/Statistics.h b/lldb/include/lldb/Target/Statistics.h
index 9c0b3ea5ec053..2a8fc5be0e05f 100644
--- a/lldb/include/lldb/Target/Statistics.h
+++ b/lldb/include/lldb/Target/Statistics.h
@@ -133,6 +133,7 @@ class TargetStats {
   void SetLaunchOrAttachTime();
   void SetFirstPrivateStopTime();
   void SetFirstPublicStopTime();
+  void IncreaseSourceMapDeduceCount();
 
   StatsDuration &GetCreateTime() { return m_create_time; }
   StatsSuccessFail &GetExpressionStats() { return m_expr_eval; }
@@ -146,6 +147,7 @@ class TargetStats {
   StatsSuccessFail m_expr_eval{"expressionEvaluation"};
   StatsSuccessFail m_frame_var{"frameVariable"};
   std::vector<intptr_t> m_module_identifiers;
+  uint32_t m_source_map_deduce_count = 0;
   void CollectStats(Target &target);
 };
 

diff  --git a/lldb/source/Breakpoint/BreakpointResolverFileLine.cpp b/lldb/source/Breakpoint/BreakpointResolverFileLine.cpp
index 7c94cde9d85ca..f911697f5ddc5 100644
--- a/lldb/source/Breakpoint/BreakpointResolverFileLine.cpp
+++ b/lldb/source/Breakpoint/BreakpointResolverFileLine.cpp
@@ -261,8 +261,10 @@ void BreakpointResolverFileLine::DeduceSourceMapping(
     if (!new_mapping_from.empty() && !new_mapping_to.empty()) {
       LLDB_LOG(log, "generating auto source map from {0} to {1}",
                new_mapping_from, new_mapping_to);
-      target.GetSourcePathMap().AppendUnique(new_mapping_from, new_mapping_to,
-                                             /*notify*/ true);
+      if (target.GetSourcePathMap().AppendUnique(new_mapping_from,
+                                                 new_mapping_to,
+                                                 /*notify*/ true))
+        target.GetStatistics().IncreaseSourceMapDeduceCount();
     }
   }
 }

diff  --git a/lldb/source/Target/PathMappingList.cpp b/lldb/source/Target/PathMappingList.cpp
index 8cd59d8fefe40..d2d60822b237e 100644
--- a/lldb/source/Target/PathMappingList.cpp
+++ b/lldb/source/Target/PathMappingList.cpp
@@ -76,16 +76,17 @@ void PathMappingList::Append(const PathMappingList &rhs, bool notify) {
   }
 }
 
-void PathMappingList::AppendUnique(llvm::StringRef path,
+bool PathMappingList::AppendUnique(llvm::StringRef path,
                                    llvm::StringRef replacement, bool notify) {
   auto normalized_path = NormalizePath(path);
   auto normalized_replacement = NormalizePath(replacement);
   for (const auto &pair : m_pairs) {
     if (pair.first.GetStringRef().equals(normalized_path) &&
         pair.second.GetStringRef().equals(normalized_replacement))
-      return;
+      return false;
   }
   Append(path, replacement, notify);
+  return true;
 }
 
 void PathMappingList::Insert(llvm::StringRef path, llvm::StringRef replacement,

diff  --git a/lldb/source/Target/Statistics.cpp b/lldb/source/Target/Statistics.cpp
index b8ad25e71f064..894552cecc516 100644
--- a/lldb/source/Target/Statistics.cpp
+++ b/lldb/source/Target/Statistics.cpp
@@ -136,6 +136,7 @@ json::Value TargetStats::ToJSON(Target &target) {
   target_metrics_json.try_emplace("breakpoints", std::move(breakpoints_array));
   target_metrics_json.try_emplace("totalBreakpointResolveTime",
                                   totalBreakpointResolveTime);
+  target_metrics_json.try_emplace("sourceMapDeduceCount", m_source_map_deduce_count);
 
   return target_metrics_json;
 }
@@ -161,6 +162,10 @@ void TargetStats::SetFirstPublicStopTime() {
     m_first_public_stop_time = StatsClock::now();
 }
 
+void TargetStats::IncreaseSourceMapDeduceCount() {
+  ++m_source_map_deduce_count;
+}
+
 bool DebuggerStats::g_collecting_stats = false;
 
 llvm::json::Value DebuggerStats::ReportStatistics(Debugger &debugger,

diff  --git a/lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py b/lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py
index 9024a7001283c..ed1d0b1479bfa 100644
--- a/lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py
+++ b/lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py
@@ -445,6 +445,18 @@ def verify_source_map_entry_pair(self, entry, original, replacement):
         self.assertEquals(entry[1], replacement,
             "source map entry 'replacement' does not match")
 
+    def verify_source_map_deduce_statistics(self, target, expected_count):
+        stream = lldb.SBStream()
+        res = target.GetStatistics().GetAsJSON(stream)
+        self.assertTrue(res.Success())
+        debug_stats = json.loads(stream.GetData())
+        self.assertEqual('targets' in debug_stats, True,
+                'Make sure the "targets" key in in target.GetStatistics()')
+        target_stats = debug_stats['targets'][0]
+        self.assertNotEqual(target_stats, None)
+        self.assertEqual(target_stats['sourceMapDeduceCount'], expected_count)
+
+
     @skipIf(oslist=["windows"])
     @no_debug_info_test
     def test_breakpoints_auto_source_map_relative(self):
@@ -471,6 +483,7 @@ def test_breakpoints_auto_source_map_relative(self):
 
         source_map_json = self.get_source_map_json()
         self.assertEquals(len(source_map_json), 0, "source map should be empty initially")
+        self.verify_source_map_deduce_statistics(target, 0)
 
         # Verify auto deduced source map when file path in debug info
         # is a suffix of request breakpoint file path
@@ -483,6 +496,7 @@ def test_breakpoints_auto_source_map_relative(self):
         source_map_json = self.get_source_map_json()
         self.assertEquals(len(source_map_json), 1, "source map should not be empty")
         self.verify_source_map_entry_pair(source_map_json[0], ".", "/x/y")
+        self.verify_source_map_deduce_statistics(target, 1)
 
         # Reset source map.
         self.runCmd("settings clear target.source-map")


        


More information about the lldb-commits mailing list