1 #include "lldb/DataFormatters/TypeSummary.h"
2 #include "lldb/Target/Statistics.h"
3 #include "lldb/Utility/Stream.h"
4 #include "lldb/lldb-forward.h"
5 #include "lldb/lldb-private-enumerations.h"
6 #include "lldb/lldb-private.h"
7 #include "llvm/Testing/Support/Error.h"
8 #include "gtest/gtest.h"
11 using namespace lldb_private
;
12 using Duration
= std::chrono::duration
<double>;
14 class DummySummaryImpl
: public lldb_private::TypeSummaryImpl
{
17 : TypeSummaryImpl(TypeSummaryImpl::Kind::eSummaryString
,
18 TypeSummaryImpl::Flags()) {}
20 std::string
GetName() override
{ return "DummySummary"; }
22 std::string
GetSummaryKindName() override
{ return "dummy"; }
24 std::string
GetDescription() override
{ return ""; }
26 bool FormatObject(ValueObject
*valobj
, std::string
&dest
,
27 const TypeSummaryOptions
&options
) override
{
32 TEST(MultithreadFormatting
, Multithread
) {
33 SummaryStatisticsCache statistics_cache
;
34 DummySummaryImpl summary
;
35 std::vector
<std::thread
> threads
;
36 for (int i
= 0; i
< 10; ++i
) {
37 threads
.emplace_back(std::thread([&statistics_cache
, &summary
]() {
38 auto sp
= statistics_cache
.GetSummaryStatisticsForProvider(summary
);
40 SummaryStatistics::SummaryInvocation
invocation(sp
);
41 std::this_thread::sleep_for(Duration(1));
46 for (auto &thread
: threads
)
49 auto sp
= statistics_cache
.GetSummaryStatisticsForProvider(summary
);
50 ASSERT_TRUE(sp
->GetDurationReference().get().count() > 10);
51 ASSERT_TRUE(sp
->GetSummaryCount() == 10);
53 std::string stats_as_json
;
54 llvm::raw_string_ostream
ss(stats_as_json
);
56 ASSERT_THAT(stats_as_json
, ::testing::HasSubstr("\"name\":\"DummySummary\""));
57 ASSERT_THAT(stats_as_json
, ::testing::HasSubstr("\"type\":\"dummy\""));