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