aboutsummaryrefslogtreecommitdiff
path: root/instrument.c
blob: da6df3edde69bfe46ac54cb0de01a296c610622c (plain)
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
/********************************************************************
 * File: instrument.c
 *
 * Instrumentation source -- link this with your application, and
 *  then execute to build trace data file (trace.txt).
 *
 * Author: M. Tim Jones <mtj@mtjones.com>
 *
 */

#include <stdio.h>
#include <stdlib.h>

/* Function prototypes with attributes */
void main_constructor(void) __attribute__((no_instrument_function, constructor));
void main_destructor(void) __attribute__((no_instrument_function, destructor));
void __cyg_profile_func_enter(void *, void *) __attribute__((no_instrument_function));
void __cyg_profile_func_exit(void *, void *) __attribute__((no_instrument_function));
static FILE *fp;

void
main_constructor(void)
{
	fp = fopen("trace.txt", "w");
	if (fp == NULL)
		exit(-1);
}

void
main_deconstructor(void)
{
	fclose(fp);
}

void
__cyg_profile_func_enter(void *this, void *callsite)
{
	fprintf(fp, "E%p\n", (int *) this);
}

void
__cyg_profile_func_exit(void *this, void *callsite)
{
	fprintf(fp, "X%p\n", (int *) this);
}