clang-tools  14.0.0git
MemoryTree.cpp
Go to the documentation of this file.
1 #include "support/MemoryTree.h"
2 #include "Trace.h"
3 #include "llvm/ADT/STLExtras.h"
4 #include "llvm/ADT/StringRef.h"
5 #include <cstddef>
6 
7 namespace clang {
8 namespace clangd {
9 
10 namespace {
11 
12 size_t traverseTree(const MemoryTree &MT, std::string &ComponentName,
13  const trace::Metric &Out) {
14  size_t OriginalLen = ComponentName.size();
15  if (!ComponentName.empty())
16  ComponentName += '.';
17  size_t Total = MT.self();
18  for (const auto &Entry : MT.children()) {
19  ComponentName += Entry.first;
20  Total += traverseTree(Entry.getSecond(), ComponentName, Out);
21  ComponentName.resize(OriginalLen + 1);
22  }
23  ComponentName.resize(OriginalLen);
24  Out.record(Total, ComponentName);
25  return Total;
26 }
27 } // namespace
28 
29 MemoryTree &MemoryTree::createChild(llvm::StringRef Name) {
30  auto &Child = Children.try_emplace(Name, DetailAlloc).first->getSecond();
31  return Child;
32 }
33 
34 const llvm::DenseMap<llvm::StringRef, MemoryTree> &
36  return Children;
37 }
38 
39 size_t MemoryTree::total() const {
40  size_t Total = Size;
41  for (const auto &Entry : Children)
42  Total += Entry.getSecond().total();
43  return Total;
44 }
45 
46 void record(const MemoryTree &MT, std::string RootName,
47  const trace::Metric &Out) {
48  traverseTree(MT, RootName, Out);
49 }
50 } // namespace clangd
51 } // namespace clang
Total
unsigned Total
Definition: FunctionCognitiveComplexityCheck.cpp:145
Trace.h
clang::clangd::MemoryTree::total
size_t total() const
Returns total number of bytes used by this sub-tree. Performs a traversal.
Definition: MemoryTree.cpp:39
clang::clangd::MemoryTree
A tree that can be used to represent memory usage of nested components while preserving the hierarchy...
Definition: MemoryTree.h:32
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:28
clang::clangd::MemoryTree::children
const llvm::DenseMap< llvm::StringRef, MemoryTree > & children() const
Returns edges to direct children of this node.
Definition: MemoryTree.cpp:35
Entry
Definition: Modularize.cpp:428
clang::clangd::trace::Metric
Represents measurements of clangd events, e.g.
Definition: Trace.h:38
MemoryTree.h
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::clangd::record
void record(const MemoryTree &MT, std::string RootName, const trace::Metric &Out)
Records total memory usage of each node under Out.
Definition: MemoryTree.cpp:46
Out
CompiledFragmentImpl & Out
Definition: ConfigCompile.cpp:100