annotate ext/kissfft/test/pstats.c @ 409:1f1999b0f577

Bring in kissfft into this repo (formerly a subrepo, but the remote is not responding)
author Chris Cannam <c.cannam@qmul.ac.uk>
date Tue, 21 Jul 2015 07:34:15 +0100
parents
children
rev   line source
c@409 1 #include <stdio.h>
c@409 2 #include <stdlib.h>
c@409 3 #include <sys/times.h>
c@409 4 #include <sys/types.h>
c@409 5 #include <unistd.h>
c@409 6
c@409 7 #include "pstats.h"
c@409 8
c@409 9 static struct tms tms_beg;
c@409 10 static struct tms tms_end;
c@409 11 static int has_times = 0;
c@409 12
c@409 13
c@409 14 void pstats_init(void)
c@409 15 {
c@409 16 has_times = times(&tms_beg) != -1;
c@409 17 }
c@409 18
c@409 19 static void tms_report(void)
c@409 20 {
c@409 21 double cputime;
c@409 22 if (! has_times )
c@409 23 return;
c@409 24 times(&tms_end);
c@409 25 cputime = ( ((float)tms_end.tms_utime + tms_end.tms_stime + tms_end.tms_cutime + tms_end.tms_cstime ) -
c@409 26 ((float)tms_beg.tms_utime + tms_beg.tms_stime + tms_beg.tms_cutime + tms_beg.tms_cstime ) )
c@409 27 / sysconf(_SC_CLK_TCK);
c@409 28 fprintf(stderr,"\tcputime=%.3f\n" , cputime);
c@409 29 }
c@409 30
c@409 31 static void ps_report(void)
c@409 32 {
c@409 33 char buf[1024];
c@409 34 #ifdef __APPLE__ /* MAC OS X */
c@409 35 sprintf(buf,"ps -o command,majflt,minflt,rss,pagein,vsz -p %d 1>&2",getpid() );
c@409 36 #else /* GNU/Linux */
c@409 37 sprintf(buf,"ps -o comm,majflt,minflt,rss,drs,pagein,sz,trs,vsz %d 1>&2",getpid() );
c@409 38 #endif
c@409 39 if (system( buf )==-1) {
c@409 40 perror("system call to ps failed");
c@409 41 }
c@409 42 }
c@409 43
c@409 44 void pstats_report()
c@409 45 {
c@409 46 ps_report();
c@409 47 tms_report();
c@409 48 }
c@409 49