[cpu arm_common profiling]

* some fixes and more documentation
dev/timer
Oliver Hahm 12 years ago
parent 012adcf28b
commit a6257e5236

@ -3,8 +3,8 @@
#include <cpu.h>
#include <ltc4150.h>
#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);

Loading…
Cancel
Save