[SBAPI/Target] Expose SetStatistics(bool enable)/GetStatistics().
authorDavide Italiano <davide@freebsd.org>
Fri, 28 Sep 2018 23:27:54 +0000 (23:27 +0000)
committerDavide Italiano <davide@freebsd.org>
Fri, 28 Sep 2018 23:27:54 +0000 (23:27 +0000)
<rdar://problem/44875808>

llvm-svn: 343368

lldb/include/lldb/API/SBTarget.h
lldb/packages/Python/lldbsuite/test/functionalities/stats_api/TestStatisticsAPI.py
lldb/scripts/interface/SBTarget.i
lldb/source/API/SBTarget.cpp

index b9a6829..6655d75 100644 (file)
@@ -75,6 +75,31 @@ public:
 
   lldb::SBProcess GetProcess();
 
+  //------------------------------------------------------------------
+  /// Sets whether we should collect statistics on lldb or not.
+  ///
+  /// @param[in] v
+  ///     A boolean to control the collection.
+  /// @return
+  ///     void
+  //------------------------------------------------------------------
+  void SetCollectingStats(bool v);
+
+  //------------------------------------------------------------------
+  /// Returns whether statistics collection are enabled.
+  ///
+  /// @return
+  ///     true if statistics are currently being collected, false
+  ///     otherwise.
+  //------------------------------------------------------------------
+  bool GetCollectingStats();
+
+  //------------------------------------------------------------------
+  /// Returns a dump of the collected statistics.
+  ///
+  /// @return
+  ///     A SBStructuredData with the statistics collected.
+  //------------------------------------------------------------------
   lldb::SBStructuredData GetStatistics();
 
   //------------------------------------------------------------------
index a6c38ca..f2027eb 100644 (file)
@@ -17,6 +17,15 @@ class TestStatsAPI(TestBase):
         self.build()
         exe = self.getBuildArtifact("a.out")
         target = self.dbg.CreateTarget(exe)
+
+        # Test enabling/disabling stats
+        self.assertFalse(target.GetCollectingStats())
+        target.SetCollectingStats(True)
+        self.assertTrue(target.GetCollectingStats())
+        target.SetCollectingStats(False)
+        self.assertFalse(target.GetCollectingStats())
+
+        # Test the function to get the statistics in JSON'ish.
         stats = target.GetStatistics()
         stream = lldb.SBStream()
         res = stats.GetAsJSON(stream)
index 1743b4d..1cc806d 100644 (file)
@@ -1019,6 +1019,10 @@ public:
     void
     SetLaunchInfo (const lldb::SBLaunchInfo &launch_info);
 
+    void SetCollectingStats(bool v);
+
+    bool GetCollectingStats();
+
     lldb::SBStructuredData GetStatistics();
 
     bool
index 4d2417c..d550de1 100644 (file)
@@ -202,6 +202,21 @@ SBStructuredData SBTarget::GetStatistics() {
   return data;
 }
 
+void SBTarget::SetCollectingStats(bool v) {
+  TargetSP target_sp(GetSP());
+  if (!target_sp)
+    return;
+  return target_sp->SetCollectingStats(v);
+}
+
+bool SBTarget::GetCollectingStats() {
+  TargetSP target_sp(GetSP());
+  if (!target_sp)
+    return false;
+  return target_sp->GetCollectingStats();
+}
+
+
 SBProcess SBTarget::LoadCore(const char *core_file) {
   lldb::SBError error; // Ignored
   return LoadCore(core_file, error);