[Lldb-commits] [lldb] [lldb] Don't assume a category dump order in TimeTest (PR #213100)

Charles Zablit via lldb-commits lldb-commits at lists.llvm.org
Wed Aug 12 09:48:04 PDT 2026


================
@@ -6,13 +6,44 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "lldb/Utility/StreamString.h"
 #include "lldb/Utility/Timer.h"
+#include "lldb/Utility/StreamString.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "gtest/gtest.h"
+#include <optional>
+#include <string>
 #include <thread>
 
 using namespace lldb_private;
 
+namespace {
+struct CategoryStats {
+  double seconds;
+  double total;
+  double child;
+  int count;
+};
+
+/// Finds the line describing \p category in a DumpCategoryTimes() dump and
+/// parses its statistics.
+std::optional<CategoryStats> ParseCategory(llvm::StringRef dump,
+                                           llvm::StringRef category) {
+  const std::string suffix = " for " + category.str();
+  for (llvm::StringRef line : llvm::split(dump, '\n')) {
+    if (!line.rtrim("\r").ends_with(suffix))
+      continue;
+    CategoryStats stats;
+    if (sscanf(line.str().c_str(),
+               "%lf sec (total: %lfs; child: %lfs; count: %d)", &stats.seconds,
+               &stats.total, &stats.child, &stats.count) == 4)
+      return stats;
+    return std::nullopt;
----------------
charles-zablit wrote:

FileCheck does not work here because it can't capture floats and has no tolerance operator for the float value.

To address the fragile parts of the test, I dropped the `sscanf` for a regex + `getAsDouble`/`getAsInteger`, which also makes the category name part of the match instead of a suffix check.

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


More information about the lldb-commits mailing list