multithreading - Measuring stack usage for Linux multi-threaded app -


i'm developing multi-threaded app linux embedded platform.

at moment i'm setting stack size each thread (via pthread_set_attr) large default value. fine tune value each thread smaller reduce application's memory usage. go through trial , error route of setting each thread's stack size progressively smaller values until program crashed, application uses ~15 threads each different functionality/attributes approach extremely time consuming.

i rather prefer being able directly measure each thread's stack usage. there utility people can recommend this? (for example, come vxworks background , using 'ti' command vxworks shell directly gives stats on stack usage other useful info on task status.)

thanks

i not know tools last resort include code in application check it, similar following:

__thread void* stack_start; __thread long stack_max_size = 0l;  void check_stack_size() {   // address of 'nowhere' approximates end of stack   char nowhere;   void* stack_end = (void*)&nowhere;   // may want double check stack grows downward on platform   long stack_size = (long)stack_start - (long)stack_end;   // update max_stack_size thread   if (stack_size > stack_max_size)     stack_max_size = stack_size; } 

the check_stack_size() function have called in of functions nested.

then last statement in thread output stack_max_size somewhere.

the stack_start variable have initialized @ start of thread:

void thread_proc() {   char nowhere;   stack_start = (void*)&nowhere;   // stuff including calls check_stack_size()   // in nested functions   // output stack_max_size here } 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -