-
Notifications
You must be signed in to change notification settings - Fork 0
/
trace_full.c
87 lines (76 loc) · 1.69 KB
/
trace_full.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
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
struct data {
unsigned long int sec;
unsigned int usec;
void* func;
void* caller;
unsigned short state;
struct data* next;
};
static struct data* start = NULL;
static struct data* last = NULL;
static struct data* out;
static struct timeval current_time;
/*
void
__attribute__ ((constructor))
trace_begin (void) {
}
*/
void
__attribute__ ((destructor))
trace_end (void) {
FILE* test = fopen("out.txt", "w");
FILE* temp = fopen("temp.txt", "w");
if(test != NULL) {
struct data* stack = start;
while(stack != NULL) {
if(!stack->state) {
fprintf(test, "e %p %p %lu %d\n", stack->func, stack->caller, stack->sec, stack->usec );
fprintf(temp, "e %p\n", stack->func);
} else {
fprintf(test, "x %p %p %lu %d\n", stack->func, stack->caller, stack->sec, stack->usec );
fprintf(temp, "x %p\n", stack->func);
}
struct data* prev = stack;
stack = stack->next;
free(prev);
}
fclose(test);
}
}
void
__cyg_profile_func_enter (void *func, void *caller) {
out = malloc(sizeof(struct data));
out->func = func;
out->caller = caller;
gettimeofday( ¤t_time, NULL);
out->sec = current_time.tv_sec;
out->usec = current_time.tv_usec;
out->state = 0;
out->next = NULL;
if(start == NULL) {
start = out;
last = out;
} else {
last->next = out;
last = out;
}
}
void
__cyg_profile_func_exit (void *func, void *caller) {
gettimeofday( ¤t_time, NULL);
out = malloc(sizeof(struct data));
out->func = func;
out->caller = caller;
out->sec = current_time.tv_sec;
out->usec = current_time.tv_usec;
out->state = 1;
out->next = NULL;
last->next = out;
last = out;
}