-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstrumenter.c
35 lines (28 loc) · 1.02 KB
/
instrumenter.c
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
// instrumenter.c - File containing instrumentation functions
#include <stdio.h>
static int total = 0; /* total # of enters/exits */
static int depth = 0; /* current stack depth */
static int levels[100] = { 0 };
// we add the `no_instrument_function'
// so our instrument functions don't
// get instrumented
void __attribute__((no_instrument_function)) __cyg_profile_func_enter(void *this_fn, void *call_site);
void __attribute__((no_instrument_function)) __cyg_profile_func_exit(void *this_fn, void *call_site);
void __cyg_profile_func_enter(void *this_fn, void *call_site)
{
levels[total++] = ++depth;
}
void __cyg_profile_func_exit(void *this_fn, void *call_site)
{
levels[total++] = --depth;
/* print the results as we exit main... */
if (depth == 0) {
int i;
printf("Total enters/exits: %d\n", total);
printf("Total function calls: %d\n", total / 2);
printf("Stack depth level trace:\n");
for (i = 0; i < total; i++) {
printf("%d\n", levels[i]);
}
}
}