From a6257e52362e437f32bd8af61a578694452f1103 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Wed, 28 Dec 2011 11:18:11 +0100 Subject: [PATCH] [cpu arm_common profiling] * some fixes and more documentation --- cpu/arm_common/profiling.c | 41 ++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/cpu/arm_common/profiling.c b/cpu/arm_common/profiling.c index fbdf6282f..c06f48dab 100644 --- a/cpu/arm_common/profiling.c +++ b/cpu/arm_common/profiling.c @@ -3,8 +3,8 @@ #include #include -#define MAX_TRACED_FUNCTIONS (32) -#define PROFILING_STACK_SIZE (16) +#define MAX_TRACED_FUNCTIONS (256) +#define PROFILING_STACK_SIZE (256) typedef struct { uint32_t address; @@ -16,14 +16,15 @@ typedef struct { } profiling_info_t; static profiling_info_t functions[MAX_TRACED_FUNCTIONS]; -static uint8_t profiling_stack[PROFILING_STACK_SIZE]; -static uint8_t profiling_sp = 0; +static uint16_t profiling_stack[PROFILING_STACK_SIZE]; +static uint16_t profiling_sp = 0; +static uint8_t function_pending = 0; -static uint8_t traced_functions = 0; +static uint16_t traced_functions = 0; static uint8_t profiling = 0; void __attribute__((__no_instrument_function__)) profiling_init(void) { - uint8_t i; + uint16_t i; for (i = 0; i < MAX_TRACED_FUNCTIONS; i++) { functions[i].address = 0; functions[i].time = 0; @@ -40,7 +41,7 @@ void __attribute__((__no_instrument_function__)) profiling_init(void) { } static int16_t __attribute__((__no_instrument_function__)) get_function_index(uint32_t addr) { - uint8_t i; + uint16_t i; for (i = 0; i < MAX_TRACED_FUNCTIONS; i++) { if (functions[i].address == addr) { return i; @@ -54,13 +55,28 @@ void __attribute__((__no_instrument_function__)) __cyg_profile_func_enter (void return; } int16_t idx = get_function_index((uint32_t) func); + /* if function is not yet on traced */ if ((idx < 0) && (traced_functions < MAX_TRACED_FUNCTIONS)) { idx = traced_functions++; functions[idx].address = (uint32_t) func; } + /* maximu of traceable functions reached */ else if (idx < 0) { return; } + + /* check if a profiled function is pending */ + if (function_pending && (profiling_stack[profiling_sp] != idx)) { + functions[idx].time += T0TC - functions[idx].start_time; + //functions[idx].consumption += ltc4150_get_intcount() - functions[idx].consumption_start; + functions[idx].consumption += ltc4150_get_total_mAh() - functions[idx].consumption_start; + } + + /* push current function on profile stack */ + profiling_sp++; + profiling_stack[profiling_sp] = idx; + + /* save stats for current function */ functions[idx].start_time = T0TC; functions[idx].counter++; functions[idx].consumption_start = ltc4150_get_total_mAh(); @@ -77,10 +93,19 @@ void __attribute__((__no_instrument_function__)) __cyg_profile_func_exit (void * //functions[idx].consumption += ltc4150_get_intcount() - functions[idx].consumption_start; functions[idx].consumption += ltc4150_get_total_mAh() - functions[idx].consumption_start; } + /* reset pending flag */ + function_pending = 0; + /* if another function is pending */ + if (profiling_sp) { + if (--profiling_sp) { + functions[profiling_stack[profiling_sp]].start_time = T0TC; + functions[profiling_stack[profiling_sp]].consumption_start = ltc4150_get_total_mAh(); + } + } } void profiling_stats(void) { - uint8_t i; + uint16_t i; for (i = 0; i < traced_functions; i++) { // printf("Function @%04lX was running %u times for %lu ticks, consuming %li ltc-ticks\n", functions[i].address, functions[i].counter, functions[i].time, functions[i].consumption); printf("Function @%04lX was running %u times for %lu ticks, consuming %lf mAh\n", functions[i].address, functions[i].counter, functions[i].time, functions[i].consumption);