2 * Helper code to output instrumentation results
3 * @author Matthias Braun, Steven Schaefer
9 /* Prevent the compiler from mangling the name of this function. */
10 void __init_firmprof(const char*, unsigned int*, size_t)
11 asm("__init_firmprof");
13 typedef struct _profile_counter_t {
17 struct _profile_counter_t *next;
20 static profile_counter_t *counters = NULL;
22 static void write_profiles(void)
24 profile_counter_t *counter = counters;
25 while(counter != NULL) {
26 profile_counter_t *next = counter->next;
27 FILE *f = fopen(counter->filename, "wb");
29 perror("Warning: couldn't open file for writing profiling data");
32 fwrite(counter->counters, counter->len * sizeof(unsigned), 1, f);
41 * Register a new profile counter. This is called by separate constructors
42 * for each translation unit. Incidentally, referring to this function as
43 * "__init_firmprof" is perfectly linker friendly.
45 void __init_firmprof(const char *filename,
46 unsigned int *counts, size_t len)
48 static int initialized = 0;
49 profile_counter_t *counter;
53 atexit(write_profiles);
56 counter = (profile_counter_t*) malloc(sizeof(*counter));
60 counter->filename = filename;
61 counter->counters = counts;
62 counter->next = counters;