12#include "llvm/Support/Allocator.h"
13#include "gmock/gmock.h"
14#include "gtest/gtest.h"
20using testing::Contains;
21using testing::ElementsAre;
22using testing::IsEmpty;
23using testing::UnorderedElementsAre;
26 return arg.first == Name &&
27 arg.getSecond().total() ==
static_cast<size_t>(Size);
32 EXPECT_EQ(MT.total(), 0U);
33 EXPECT_THAT(MT.children(), IsEmpty());
36 EXPECT_EQ(MT.total(), 42U);
37 EXPECT_THAT(MT.children(), IsEmpty());
39 MT.child(
"leaf").addUsage(1);
40 EXPECT_EQ(MT.total(), 43U);
41 EXPECT_THAT(MT.children(), UnorderedElementsAre(WithNameAndSize(
"leaf", 1)));
44 MT.child(
"leaf").addUsage(1);
45 EXPECT_EQ(MT.total(), 44U);
46 EXPECT_THAT(MT.children(), UnorderedElementsAre(WithNameAndSize(
"leaf", 2)));
52 EXPECT_THAT(MT.children(), IsEmpty());
53 EXPECT_EQ(MT.total(), 2U);
56 MT.detail(
"first_detail").child(
"leaf").addUsage(1);
57 MT.detail(
"second_detail").child(
"leaf").addUsage(1);
58 EXPECT_THAT(MT.children(), Contains(WithNameAndSize(
"leaf", 2)));
62 llvm::BumpPtrAllocator Alloc;
66 auto &Detail = MT.detail(
"first_detail");
67 Detail.child(
"leaf").addUsage(1);
68 EXPECT_THAT(MT.children(), Contains(WithNameAndSize(
"first_detail", 1)));
69 EXPECT_THAT(Detail.children(), Contains(WithNameAndSize(
"leaf", 1)));
73 auto &Detail = MT.detail(
"second_detail");
74 Detail.child(
"leaf").addUsage(1);
75 EXPECT_THAT(MT.children(), Contains(WithNameAndSize(
"second_detail", 1)));
76 EXPECT_THAT(Detail.children(), Contains(WithNameAndSize(
"leaf", 1)));
82 static constexpr llvm::StringLiteral MetricName =
"memory_usage";
86 Root.child(
"leaf").addUsage(1);
89 auto &Detail = Root.detail(
"detail");
91 Detail.child(
"leaf").addUsage(1);
92 auto &Child = Detail.child(
"child");
94 Child.child(
"leaf").addUsage(1);
98 auto &Child = Root.child(
"child");
100 Child.child(
"leaf").addUsage(1);
105 llvm::BumpPtrAllocator Alloc;
107 EXPECT_THAT(Tracer.takeMetric(MetricName,
"root"), ElementsAre(7));
108 EXPECT_THAT(Tracer.takeMetric(MetricName,
"root.leaf"), ElementsAre(1));
109 EXPECT_THAT(Tracer.takeMetric(MetricName,
"root.detail"), ElementsAre(4));
110 EXPECT_THAT(Tracer.takeMetric(MetricName,
"root.detail.leaf"),
112 EXPECT_THAT(Tracer.takeMetric(MetricName,
"root.detail.child"),
114 EXPECT_THAT(Tracer.takeMetric(MetricName,
"root.detail.child.leaf"),
116 EXPECT_THAT(Tracer.takeMetric(MetricName,
"root.child"), ElementsAre(2));
117 EXPECT_THAT(Tracer.takeMetric(MetricName,
"root.child.leaf"), ElementsAre(1));
A RAII Tracer that can be used by tests.
FIXME: Skip testing on windows temporarily due to the different escaping code mode.
void record(const MemoryTree &MT, std::string RootName, const trace::Metric &Out)
Records total memory usage of each node under Out.
MATCHER_P2(hasFlag, Flag, Path, "")
TEST(BackgroundQueueTest, Priority)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
A tree that can be used to represent memory usage of nested components while preserving the hierarchy...
void addUsage(size_t Increment)
Increases size of current node by Increment.
MemoryTree & detail(llvm::StringRef Name)
Makes a copy of the Name in detailed mode, returns current node otherwise.
Represents measurements of clangd events, e.g.
@ Value
A number whose value is meaningful, and may vary over time.