[Lldb-commits] [lldb] [LLDB][Stats] Calculate active time to first Bt (PR #161604)

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Tue Oct 7 15:42:23 PDT 2025


================
@@ -513,6 +518,63 @@ llvm::json::Value DebuggerStats::ReportStatistics(
   return std::move(global_stats);
 }
 
+void TargetStats::SetFirstBtTime(lldb::ProcessSP process_sp, Thread &thread) {
+  if (m_first_bt_time_set)
+    return;
+
+  // Our goal here is to calculate the total active time to get to the first bt
+  // so this will be the target creation time, or the load core time plus all
+  // the time to load and index modules and their debug info.
+  double elapsed_time = 0.0;
+  // GetStackFrameCount can be expensive, but at this point we should
+  // have completed a BT successfully, so the frames should already
+  // exist.
+  for (size_t i = 0; i < thread.GetStackFrameCount(); ++i) {
+    lldb::StackFrameSP frame_sp = thread.GetStackFrameAtIndex(i);
+    if (!frame_sp)
+      continue;
+
+    lldb::ModuleSP module_sp =
+        frame_sp->GetSymbolContext(lldb::eSymbolContextModule).module_sp;
+    if (!module_sp)
+      continue;
+
+    // Add the time it took to load and index the module.
+    elapsed_time += module_sp->GetSymtabParseTime().get().count();
+    elapsed_time += module_sp->GetSymtabParseTime().get().count();
+
+    // Add the time it took to load and index the debug info. Can create
+    // false is very important here. We don't want this call to have any side
+    // effects.
+    SymbolFile *sym_file = module_sp->GetSymbolFile(/*can_create=*/false);
+    if (!sym_file)
+      continue;
+
+    elapsed_time += sym_file->GetDebugInfoParseTime().count();
+    elapsed_time += sym_file->GetDebugInfoIndexTime().count();
+
+    // Lastly, walk over all the symbol locators and add their time.
+    for (const auto &entry : module_sp->GetSymbolLocatorStatistics().map) {
+      elapsed_time += entry.second;
----------------
clayborg wrote:

This won't get executed if there is no symbol file as there is a "continue" up on line 551

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


More information about the lldb-commits mailing list