I had to refuse to install the shell in the function declaration, the solution was to install shells when calling the function using compound statements. Below are two macros that I created for this, one of them refers to calls that return void, the other with any call that returns a value:
({ \
hal_time_t stop, start; \
hal_getTime(&start); \
call; \
hal_getTime(&stop); \
__PROFILE_PRINT(call, hal_secondsElapsed_d(&stop, &start)); \
})
({ \
typeof(call) __ret; \
hal_time_t stop, start; \
__profile_nested_cnt++; \
hal_getTime(&start); \
__ret = call; \
hal_getTime(&stop); \
__profile_nested_cnt--; \
__PROFILE_PRINT(call, hal_secondsElapsed_d(&stop, &start)); \
__ret; \
})
Usage example:
PROFILE_VOID(func_returning_void(arg, arg2));
PROFILE(other_funcs());
PROFILE(x = func(x, y, z));
x = PROFILE(func(x, y, z));
if (PROFILE(func()) == 0) { }
if (PROFILE(func() == 0)) { }
source
share