[Lldb-commits] [lldb] [LLDB][Data Formatters] Calculate average and total time for summary providers within lldb (PR #102708)
Michael Buch via lldb-commits
lldb-commits at lists.llvm.org
Fri Aug 23 01:27:31 PDT 2024
================
@@ -0,0 +1,64 @@
+#include "lldb/DataFormatters/TypeSummary.h"
+#include "lldb/Target/Statistics.h"
+#include "lldb/Utility/Stream.h"
+#include "lldb/lldb-forward.h"
+#include "lldb/lldb-private-enumerations.h"
+#include "lldb/lldb-private.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gtest/gtest.h"
+#include <thread>
+
+using namespace lldb_private;
+using Duration = std::chrono::duration<double>;
+
+class DummySummaryImpl : public lldb_private::TypeSummaryImpl {
+public:
+ DummySummaryImpl(Duration sleepTime)
+ : TypeSummaryImpl(TypeSummaryImpl::Kind::eSummaryString,
+ TypeSummaryImpl::Flags()),
+ m_sleepTime(sleepTime) {}
+
+ std::string GetName() override { return "DummySummary"; }
+
+ std::string GetSummaryKindName() override { return "dummy"; }
+
+ std::string GetDescription() override { return ""; }
+
+ bool FormatObject(ValueObject *valobj, std::string &dest,
+ const TypeSummaryOptions &options) override {
+ return false;
+ }
+
+ void FakeFormat() { std::this_thread::sleep_for(m_sleepTime); }
+
+private:
+ Duration m_sleepTime;
+};
+
+TEST(MultithreadFormatting, Multithread) {
+ SummaryStatisticsCache statistics_cache;
+ DummySummaryImpl summary(Duration(1));
+ std::vector<std::thread> threads;
+ for (int i = 0; i < 10; ++i) {
+ threads.emplace_back(std::thread([&statistics_cache, &summary]() {
+ auto sp = statistics_cache.GetSummaryStatisticsForProvider(summary);
+ {
+ SummaryStatistics::SummaryInvocation invocation(sp);
+ summary.FakeFormat();
----------------
Michael137 wrote:
Can we just call something like `std::this_thread::sleep_for(std::chrono::milliseconds(50))` here directly?
https://github.com/llvm/llvm-project/pull/102708
More information about the lldb-commits
mailing list