================
@@ -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
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to