| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#pragma once |
|
2
|
|
|
|
|
|
|
#include |
|
3
|
|
|
|
|
|
|
#include |
|
4
|
|
|
|
|
|
|
#include |
|
5
|
|
|
|
|
|
|
#include |
|
6
|
|
|
|
|
|
|
#include |
|
7
|
|
|
|
|
|
|
#include |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
namespace test { |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
struct Tracer { |
|
12
|
|
|
|
|
|
|
static int copy_calls; |
|
13
|
|
|
|
|
|
|
static int ctor_calls; |
|
14
|
|
|
|
|
|
|
static int move_calls; |
|
15
|
|
|
|
|
|
|
static int dtor_calls; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
static void reset () { |
|
18
|
|
|
|
|
|
|
copy_calls = 0; |
|
19
|
|
|
|
|
|
|
ctor_calls = 0; |
|
20
|
|
|
|
|
|
|
move_calls = 0; |
|
21
|
|
|
|
|
|
|
dtor_calls = 0; |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
static void refresh () { reset(); } |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
static int ctor_total () { |
|
27
|
|
|
|
|
|
|
return move_calls + copy_calls + ctor_calls; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
int value; |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Tracer (int v = 0) : value(v) {ctor_calls++;} |
|
33
|
|
|
|
|
|
|
Tracer (const Tracer& oth) : value(oth.value) {copy_calls++;} |
|
34
|
|
|
|
|
|
|
Tracer (Tracer&& oth) : value(oth.value) {move_calls++;} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
virtual ~Tracer () {dtor_calls++;} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
int operator() (int a) { |
|
39
|
|
|
|
|
|
|
return a + value; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
int operator() (panda::CallbackDispatcher::Event&, int a) { |
|
43
|
|
|
|
|
|
|
return a + value; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
bool operator== (const Tracer& oth) const { |
|
47
|
|
|
|
|
|
|
return value == oth.value; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
}; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
struct Stat { |
|
52
|
|
|
|
|
|
|
int allocated; |
|
53
|
|
|
|
|
|
|
int allocated_cnt; |
|
54
|
|
|
|
|
|
|
int deallocated; |
|
55
|
|
|
|
|
|
|
int deallocated_cnt; |
|
56
|
|
|
|
|
|
|
int reallocated; |
|
57
|
|
|
|
|
|
|
int reallocated_cnt; |
|
58
|
|
|
|
|
|
|
int ext_deallocated; |
|
59
|
|
|
|
|
|
|
int ext_deallocated_cnt; |
|
60
|
|
|
|
|
|
|
int ext_shbuf_deallocated; |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
bool is_empty () const { |
|
63
|
|
|
|
|
|
|
return !allocated && !allocated_cnt && !deallocated && !deallocated_cnt && !reallocated && !reallocated_cnt && !ext_deallocated && |
|
64
|
|
|
|
|
|
|
!ext_deallocated_cnt && !ext_shbuf_deallocated; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
}; |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
extern Stat allocs; |
|
69
|
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
inline Stat get_allocs () { |
|
71
|
0
|
|
|
|
|
|
auto ret = allocs; |
|
72
|
0
|
|
|
|
|
|
std::memset(&allocs, 0, sizeof(Stat)); |
|
73
|
0
|
|
|
|
|
|
return ret; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
template |
|
77
|
|
|
|
|
|
|
struct Allocator { |
|
78
|
|
|
|
|
|
|
typedef T value_type; |
|
79
|
|
|
|
|
|
|
|
|
80
|
514
|
|
|
|
|
|
static T* allocate (size_t n) { |
|
81
|
|
|
|
|
|
|
//std::cout << "allocate " << n << std::endl; |
|
82
|
514
|
|
|
|
|
|
void* mem = malloc(n * sizeof(T)); |
|
83
|
514
|
50
|
|
|
|
|
if (!mem) throw std::bad_alloc(); |
|
|
|
50
|
|
|
|
|
|
|
84
|
514
|
|
|
|
|
|
allocs.allocated += n; |
|
85
|
514
|
|
|
|
|
|
allocs.allocated_cnt++; |
|
86
|
514
|
|
|
|
|
|
return (T*)mem; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
514
|
|
|
|
|
|
static void deallocate (T* mem, size_t n) { |
|
90
|
|
|
|
|
|
|
//std::cout << "deallocate " << n << std::endl; |
|
91
|
514
|
|
|
|
|
|
allocs.deallocated += n; |
|
92
|
514
|
|
|
|
|
|
allocs.deallocated_cnt++; |
|
93
|
514
|
|
|
|
|
|
free(mem); |
|
94
|
514
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
31
|
|
|
|
|
|
static T* reallocate (T* mem, size_t need, size_t old) { |
|
97
|
|
|
|
|
|
|
//std::cout << "reallocate need=" << need << " old=" << old << std::endl; |
|
98
|
31
|
|
|
|
|
|
void* new_mem = realloc(mem, need * sizeof(T)); |
|
99
|
31
|
|
|
|
|
|
allocs.reallocated += (need - old); |
|
100
|
31
|
|
|
|
|
|
allocs.reallocated_cnt++; |
|
101
|
31
|
|
|
|
|
|
return (T*)new_mem; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
112
|
|
|
|
|
|
static void ext_free (T* mem, size_t n) { |
|
105
|
112
|
|
|
|
|
|
allocs.ext_deallocated += n; |
|
106
|
112
|
|
|
|
|
|
allocs.ext_deallocated_cnt++; |
|
107
|
112
|
|
|
|
|
|
free(mem); |
|
108
|
112
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
4
|
|
|
|
|
|
static void shared_buf_free (T* mem, size_t size) { |
|
111
|
4
|
|
|
|
|
|
panda::DynamicMemoryPool::instance()->deallocate(mem, size * sizeof(T)); |
|
112
|
4
|
|
|
|
|
|
allocs.ext_shbuf_deallocated++; |
|
113
|
4
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
}; |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
} |