-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnapshot.h
107 lines (62 loc) · 2.99 KB
/
Snapshot.h
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Snapshot.h
// Declares the Snapshot class, representing a single snapshot of the heap
#ifndef SNAPSHOT_H
#define SNAPSHOT_H
#include <memory>
#include <unordered_map>
#include <assert.h>
#include <Qt>
// fwd:
class Allocation;
typedef std::shared_ptr<Allocation> AllocationPtr;
class AllocationPath;
class CodeLocation;
/** Contains the information provided by a single Massif snapshot. */
class Snapshot
{
public:
/** Type used for storing a flat sum of per-CodeLocation allocation size.
Since the allocation tree may contain the same entry in multiple instances, we need to represent
the sum of all such entries, in a per-CodeLocation way. */
typedef std::unordered_map<CodeLocation *, quint64> FlatSums;
/** Creates a new empty snapshot with zero time and sizes. */
Snapshot();
void setTimestamp(quint64 a_Timestamp) { m_Timestamp = a_Timestamp; }
void setHeapSize(quint64 a_HeapSize) { m_HeapSize = a_HeapSize; }
void setHeapExtraSize(quint64 a_HeapExtraSize) { m_HeapExtraSize = a_HeapExtraSize; }
/** Sets the root allocation to the specified one.
Cannot replace an allocation that has already been set (write-once).*/
void setRootAllocation(AllocationPtr a_RootAllocation);
quint64 getTimestamp() const { return m_Timestamp; }
quint64 getHeapSize() const { return m_HeapSize; }
quint64 getHeapExtraSize() const { return m_HeapExtraSize; }
quint64 getTotalSize() const { return m_HeapSize + m_HeapExtraSize; }
AllocationPtr getRootAllocation() { return m_RootAllocation; }
const AllocationPtr getRootAllocation() const { return m_RootAllocation; }
/** Returns the allocation specified by its full path.
Returns nullptr if no such allocation in this snapshot. */
AllocationPtr findAllocation(const AllocationPath & a_Path) const;
/** Returns true if the snapshot has detailed allocations attached to it. */
bool hasAllocations() const { return (m_RootAllocation != nullptr); }
/** Updates the flat sums of allocations.
Called by the parser after it finishes parsing the allocation tree. */
void updateFlatSums();
const FlatSums & getFlatSums() const { return m_FlatSums; }
protected:
/** The snapshot's timestamp, in whatever unit Massif used to generate the output (Project::m_TimeUnit) */
quint64 m_Timestamp;
/** The total amount of memory allocated by the program. */
quint64 m_HeapSize;
/** The amount of heap memory allocated but not used (fragmentation etc.) */
quint64 m_HeapExtraSize;
/** The root allocation element, if the snapshot has a detailed report.
The root element represents all the allocations,
its children are individual places on the stack which allocated memory, together with their stacktraces. */
AllocationPtr m_RootAllocation;
/** The sums of all CodeLocations' allocations within this snapshot. */
FlatSums m_FlatSums;
/** Recursively adds the specified allocation's children to m_FlatSums. */
void addChildrenToFlatSums(const AllocationPtr & a_Allocation);
};
typedef std::shared_ptr<Snapshot> SnapshotPtr;
#endif // SNAPSHOT_H