getMaxUsedStack() - stack usage reseach mini progress

This commit is contained in:
rusefi 2019-02-12 18:47:16 -05:00
parent b7b5c28be7
commit 0eb2470a61
3 changed files with 18 additions and 0 deletions

View File

@ -101,6 +101,7 @@ typedef unsigned int time_t;
/*
* Stack debugging
* See also getMaxUsedStack()
*/
int getRemainingStack(thread_t *otp);

View File

@ -39,3 +39,16 @@ efitime_t Overflow64Counter::update(uint32_t value) {
return state.highBits + state.lowBits;
}
#endif
int getMaxUsedStack(uint8_t *ptr, int size) {
/**
* maximum used stack size total stack buffer size minus position of first modified byte
*/
int used = 0;
for (int i = 0; i < size; i++) {
if (ptr[i] != CH_DBG_STACK_FILL_VALUE) {
return size - i;
}
}
return 0;
}

View File

@ -17,6 +17,10 @@ typedef struct {
} State64;
void updateAndSet(State64 *state, uint32_t value);
/**
* @return for a given stack memory region returns how much stack was ever used
*/
int getMaxUsedStack(uint8_t *ptr, int size);
class Overflow64Counter
{