Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You tagged your question with static-analysis, but this is a problem that is difficult to solve through static-analysis. The stack usage depends on the program's runtime profile, especially, if you're using recursion or alloca. Given that this is an embedded platform I guess it's also difficult to run something like <em>ps</em> or <em>top</em> and see how much stack your application is using.</p> <p>An interesting approach is to use the address of the current stack frame in order to determine how much stack is used. You can do this by taking the address of a function's argument or local variable. Do that for the <em>main</em> function and for functions you think are using the most stack. The difference will tell you the amount of stack your application requires. Here is an example (assuming customary high-to-low stack growth).</p> <pre><code>char *stack_top, stack_bottom; int main(int argc, char *argv[]) { stack_top = (char *)&amp;argc; // ... printf("Stack usage: %d\n", stack_top - stack_bottom); } void deeply_nested_function(void) { int a; stack_bottom = (char *)&amp;a; // ... } </code></pre> <p>If your compiler allows you to specify a custom function prologue (many do it to allow graph-based program profiling), you can even arrange for all functions to call such measuring code. Then your measurement function mecomes something like</p> <pre><code>void stack_measurement_function(void) { int a; stack_bottom = min(stack_bottom, (char *)&amp;a); // ... } </code></pre> <p>I used an approach similar to what I've described to generate <a href="http://www.spinellis.gr/codequality/stack.gif" rel="noreferrer">these charts</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload