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);
30TEST(MemoryTree, Basics) {
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)));
49TEST(MemoryTree, DetailedNodesWithoutDetails) {
51 MT.detail(
"should_be_ignored").addUsage(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)));
61TEST(MemoryTree, DetailedNodesWithDetails) {
62 llvm::BumpPtrAllocator Alloc;
63 MemoryTree MT(&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)));
80TEST(MemoryTree, Record) {
81 trace::TestTracer Tracer;
82 static constexpr llvm::StringLiteral MetricName =
"memory_usage";
85 auto AddNodes = [](MemoryTree
Root) {
86 Root.child(
"leaf").addUsage(1);
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;
106 record(AddNodes(MemoryTree(&Alloc)),
"root", OutMetric);
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));
llvm::SmallString< 256U > Name
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++ -*-===//
std::string detail
Brief additional information, such as "||" for the particular operator.
@ Value
A number whose value is meaningful, and may vary over time.