-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnapshot.cpp
91 lines (54 loc) · 1.36 KB
/
Snapshot.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Snapshot.cpp
// Implements the Snapshot class, representing a single snapshot of the heap
#include "Globals.h"
#include "Snapshot.h"
#include "AllocationPath.h"
#include "Allocation.h"
Snapshot::Snapshot():
m_Timestamp(0),
m_HeapSize(0),
m_HeapExtraSize(0)
{
}
void Snapshot::setRootAllocation(AllocationPtr a_RootAllocation)
{
assert(m_RootAllocation == nullptr); // Only allow a single assignment to the root allocation
m_RootAllocation = a_RootAllocation;
}
AllocationPtr Snapshot::findAllocation(const AllocationPath & a_Path) const
{
auto a = m_RootAllocation;
const auto & segments = a_Path.getSegments();
for (const auto & s: segments)
{
if (a == nullptr)
{
return nullptr;
}
a = a->findCodeLocationChild(s);
}
return a;
}
void Snapshot::updateFlatSums()
{
// Calculate the total and child sizes:
m_FlatSums.clear();
if (m_RootAllocation != nullptr)
{
addChildrenToFlatSums(m_RootAllocation);
}
}
void Snapshot::addChildrenToFlatSums(const AllocationPtr & a_Allocation)
{
// Add to m_FlatSums, unless the code location is a nullptr:
auto codeLocation = a_Allocation->getCodeLocation().get();
if (codeLocation != nullptr)
{
m_FlatSums[codeLocation] += a_Allocation->getAllocationSize();
}
// Recurse the children:
for (const auto & ch: a_Allocation->getChildren())
{
addChildrenToFlatSums(ch);
}
}