Branch: Tag:

2001-05-16

2001-05-16 23:35:52 by Fredrik Hübinette (Hubbe) <hubbe@hubbe.net>

stack profiling code (use --with-profiling and then run pike -ps)

Rev: src/interpret.h:1.84
Rev: src/main.c:1.126
Rev: src/threads.c:1.156

5:   \*/   /**/   #include "global.h" - RCSID("$Id: main.c,v 1.125 2001/05/14 03:28:07 hubbe Exp $"); + RCSID("$Id: main.c,v 1.126 2001/05/16 23:35:52 hubbe Exp $");   #include "fdlib.h"   #include "backend.h"   #include "module.h"
92:    }   }    + #ifdef PROFILING + static unsigned int samples[8200]; + long record; +  + static void sample_stack(struct callback *cb,void *tmp,void *ignored) + { +  long stack_size=( ((char *)&cb) - Pike_interpreter.stack_bottom) * STACK_DIRECTION; +  stack_size>>=10; +  stack_size++; +  if(stack_size<0) stack_size=0; +  if(stack_size >= (long)NELEM(samples)) stack_size=NELEM(samples)-1; +  samples[stack_size]++; + #ifdef PIKE_DEBUG +  if(stack_size > record) +  { +  extern void gdb_break_on_stack_record(long); +  gdb_break_on_stack_record(stack_size); +  record=stack_size; +  } + #endif + } +  + #ifdef PIKE_DEBUG + void gdb_break_on_stack_record(long stack_size) + { +  ; + } + #endif + #endif +    static struct callback_list post_master_callbacks;      PMOD_EXPORT struct callback *add_post_master_callback(callback_func call,
403:    break;       case 'p': +  if(p[1]=='s') +  { + #ifdef PROFILING +  add_to_callback(&evaluator_callbacks, +  sample_stack, +  0,0); +  p+=strlen(p); + #endif +  }else{    if(p[1]>='0' && p[1]<='9')    p_flag+=STRTOL(p+1,&p,10);    else    p_flag++,p++; -  +  }    break;       case 'l':
447:    Pike_interpreter.stack_top -= ( ((size_t)Pike_interpreter.stack_top)) & 0xffff;   #endif /* STACK_DIRECTION < 0 */    + #ifdef PROFILING +  Pike_interpreter.stack_bottom=Pike_interpreter.stack_top; + #endif +    #if defined(HAVE_GETRLIMIT) && defined(RLIMIT_STACK)    {    struct rlimit lim;
633:    }   #endif    +  + #ifdef PROFILING +  { +  int q; +  for(q=0;q<(long)NELEM(samples);q++) +  if(samples[q]) +  fprintf(stderr,"STACK WAS %4d Kb %12u times\n",q-1,samples[q]); +  } + #endif +     exit(num);   }