[Lldb-commits] [lldb] [LLDB][Data Formatters] Calculate average and total time for summary providers within lldb (PR #102708)

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Mon Aug 12 10:48:28 PDT 2024


================
@@ -408,3 +410,23 @@ llvm::json::Value DebuggerStats::ReportStatistics(
 
   return std::move(global_stats);
 }
+
+llvm::json::Value SummaryStatistics::ToJSON() const {
+  json::Object body {{
+      {"invocationCount", GetSummaryCount()},
+      {"totalTime", GetTotalTime()},
+      {"averageTime", GetAverageTime()}
+    }};
+  return json::Object{{GetName().AsCString(), std::move(body)}};
+}
+
+
+json::Value SummaryStatisticsCache::ToJSON() {
+  m_map_mutex.lock();
----------------
clayborg wrote:

We always want to use `std::lock_guard`. Why? Because the are exception safe. If some code anywhere throws an exception, the `std::lock_guard` will unlock the mutex.
```
std::lock_guard<std::recursive_mutex> guard(m_map_mutex);
```

https://github.com/llvm/llvm-project/pull/102708


More information about the lldb-commits mailing list