-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmalloc_stats.c
More file actions
141 lines (108 loc) · 3.87 KB
/
malloc_stats.c
File metadata and controls
141 lines (108 loc) · 3.87 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include "malloc_stats.h"
void malloc_stats() {
int i,a;
struct mem_seg * p_itr;
lock_all(); //lock all mutexes
snprintf(printBuff,1024,"-------------------MALLOC_STATS\n");
write(STDOUT_FILENO,printBuff,strlen(printBuff)+1);
snprintf(printBuff,1024,
"Size of .data region used for allocation %ldB\n"
"Program Break at start of run %p\n"
"End of area used for allocation %p\n"
"Current Program Break position %p\n",
END_ALC-START_ALC,START_ALC,END_ALC,BREAK_PTR);
write(STDOUT_FILENO,printBuff,strlen(printBuff)+1);
for(a=0; a<n_arenas; a+=1){
snprintf(printBuff,1024,"--------Arena %d\n",a);
write(STDOUT_FILENO,printBuff,strlen(printBuff)+1);
snprintf(printBuff,1024,
"Total number of bins: 4\n");
write(STDOUT_FILENO,printBuff,strlen(printBuff)+1);
snprintf(printBuff,1024,
"free_bin_64: \n");
write(STDOUT_FILENO,printBuff,strlen(printBuff)+1);
i=0;
p_itr = arena_list[a].free_bin_64.lh_first;
while (p_itr != NULL) {
p_itr = p_itr->con.le_next;
i+=1;
}
snprintf(printBuff,1024,
"\t#blocks %d\n",i);
write(STDOUT_FILENO,printBuff,strlen(printBuff)+1);
snprintf(printBuff,1024,
"\t#free reqs %ld\n",arena_list[a].num_free_reqs_64);
write(STDOUT_FILENO,printBuff,strlen(printBuff)+1);
snprintf(printBuff,1024,
"free_bin_128: \n");
write(STDOUT_FILENO,printBuff,strlen(printBuff)+1);
i=0;
p_itr = arena_list[a].free_bin_128.lh_first;
while (p_itr != NULL) {
p_itr = p_itr->con.le_next;
i+=1;
}
snprintf(printBuff,1024,
"\t#blocks %d\n",i);
write(STDOUT_FILENO,printBuff,strlen(printBuff)+1);
snprintf(printBuff,1024,
"\t#free reqs %ld\n",arena_list[a].num_free_reqs_128);
write(STDOUT_FILENO,printBuff,strlen(printBuff)+1);
snprintf(printBuff,1024,
"free_bin_512: \n");
write(STDOUT_FILENO,printBuff,strlen(printBuff)+1);
i=0;
p_itr = arena_list[a].free_bin_512.lh_first;
while (p_itr != NULL) {
p_itr = p_itr->con.le_next;
i+=1;
}
snprintf(printBuff,1024,
"\t#blocks %d\n",i);
write(STDOUT_FILENO,printBuff,strlen(printBuff)+1);
snprintf(printBuff,1024,
"\t#free reqs %ld\n",arena_list[a].num_free_reqs_512);
write(STDOUT_FILENO,printBuff,strlen(printBuff)+1);
snprintf(printBuff,1024,
"alloc_bin: \n");
write(STDOUT_FILENO,printBuff,strlen(printBuff)+1);
i=0;
p_itr = arena_list[a].alloc_bin.lh_first;
while (p_itr != NULL) {
p_itr = p_itr->con.le_next;
i+=1;
}
snprintf(printBuff,1024,
"\t#blocks %d\n",i);
write(STDOUT_FILENO,printBuff,strlen(printBuff)+1);
snprintf(printBuff,1024,
"\t#blocks of 64B %ld\n",
arena_list[a].num_malloc_reqs_64 - arena_list[a].num_free_reqs_64);
write(STDOUT_FILENO,printBuff,strlen(printBuff)+1);
snprintf(printBuff,1024,
"\t#malloc reqs for x<=64B %ld\n",arena_list[a].num_malloc_reqs_64);
write(STDOUT_FILENO,printBuff,strlen(printBuff)+1);
snprintf(printBuff,1024,
"\t#blocks of 128B %ld\n",
arena_list[a].num_malloc_reqs_128 - arena_list[a].num_free_reqs_128);
write(STDOUT_FILENO,printBuff,strlen(printBuff)+1);
snprintf(printBuff,1024,
"\t#malloc reqs for 64B<x<=128B %ld\n",arena_list[a].num_malloc_reqs_128);
write(STDOUT_FILENO,printBuff,strlen(printBuff)+1);
snprintf(printBuff,1024,
"\t#blocks of 512B %ld\n",
arena_list[a].num_malloc_reqs_512 - arena_list[a].num_free_reqs_512);
write(STDOUT_FILENO,printBuff,strlen(printBuff)+1);
snprintf(printBuff,1024,
"\t#malloc reqs for 128B<x<=512B %ld\n",arena_list[a].num_malloc_reqs_512);
write(STDOUT_FILENO,printBuff,strlen(printBuff)+1);
snprintf(printBuff,1024,
"\t#blocks of >512B %ld\n",
arena_list[a].num_malloc_reqs_big - arena_list[a].num_free_reqs_big);
write(STDOUT_FILENO,printBuff,strlen(printBuff)+1);
snprintf(printBuff,1024,
"\t#malloc reqs for >512B %ld\n",arena_list[a].num_malloc_reqs_big);
write(STDOUT_FILENO,printBuff,strlen(printBuff)+1);
}
unlock_all();//release all locks
}