-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack_element.h
92 lines (66 loc) · 2.03 KB
/
stack_element.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
#pragma once
#include <algorithm>
#include "function_info.h"
#include "dynamic_array.h"
namespace muitv
{
struct function_info;
struct stack_element
{
stack_element()
{
pos = ~0u;
updateMark = ~0u;
fInfo = 0;
objectCount = 0;
objectSize = 0;
allocCount = 0;
freeCount = 0;
allocSize = 0;
}
size_t pos; // Position in the global array
size_t updateMark;
function_info *fInfo;
size_t objectCount; // How many objects are alive at this path segment
size_t objectSize; // How much memory is alive at this path segment
// How many operations were performed at this path segment (note that an object is deallocated from the same path it was allocated
size_t allocCount;
size_t freeCount;
// How much memory in total was allocated at this path segment
unsigned long long allocSize;
dynamic_array<stack_element*> children;
const char* get_name()
{
if(fInfo)
return fInfo->functionInfo->Name;
return "`unknown`";
}
typedef bool (*sort_func)(const stack_element* lhs, const stack_element* rhs);
void sort_children(sort_func sortFunction)
{
std::sort(children.begin(), children.end(), sortFunction);
for(size_t i = 0; i < children.size(); i++)
children[i]->sort_children(sortFunction);
}
friend bool compare_object_count(const stack_element* lhs, const stack_element* rhs)
{
return lhs->objectCount > rhs->objectCount;
}
friend bool compare_object_size(const stack_element* lhs, const stack_element* rhs)
{
return lhs->objectSize > rhs->objectSize;
}
friend bool compare_alloc_count(const stack_element* lhs, const stack_element* rhs)
{
return lhs->allocCount > rhs->allocCount;
}
friend bool compare_alloc_size(const stack_element* lhs, const stack_element* rhs)
{
return lhs->allocSize > rhs->allocSize;
}
friend bool compare_free_count(const stack_element* lhs, const stack_element* rhs)
{
return lhs->freeCount > rhs->freeCount;
}
};
}