c@174: #include c@174: #include c@174: #include c@174: #include c@174: #include c@174: c@174: #include "pstats.h" c@174: c@174: static struct tms tms_beg; c@174: static struct tms tms_end; c@174: static int has_times = 0; c@174: c@174: c@174: void pstats_init(void) c@174: { c@174: has_times = times(&tms_beg) != -1; c@174: } c@174: c@174: static void tms_report(void) c@174: { c@174: double cputime; c@174: if (! has_times ) c@174: return; c@174: times(&tms_end); c@174: cputime = ( ((float)tms_end.tms_utime + tms_end.tms_stime + tms_end.tms_cutime + tms_end.tms_cstime ) - c@174: ((float)tms_beg.tms_utime + tms_beg.tms_stime + tms_beg.tms_cutime + tms_beg.tms_cstime ) ) c@174: / sysconf(_SC_CLK_TCK); c@174: fprintf(stderr,"\tcputime=%.3f\n" , cputime); c@174: } c@174: c@174: static void ps_report(void) c@174: { c@174: char buf[1024]; c@174: #ifdef __APPLE__ /* MAC OS X */ c@174: sprintf(buf,"ps -o command,majflt,minflt,rss,pagein,vsz -p %d 1>&2",getpid() ); c@174: #else /* GNU/Linux */ c@174: sprintf(buf,"ps -o comm,majflt,minflt,rss,drs,pagein,sz,trs,vsz %d 1>&2",getpid() ); c@174: #endif c@174: if (system( buf )==-1) { c@174: perror("system call to ps failed"); c@174: } c@174: } c@174: c@174: void pstats_report() c@174: { c@174: ps_report(); c@174: tms_report(); c@174: } c@174: