From 5dc3d40d7d1ef33b8fbf70964befab1e9e41f14d Mon Sep 17 00:00:00 2001 From: bde Date: Sun, 29 Jun 1997 22:43:01 +0000 Subject: Implemented `-c command'. Fixed bitrot (__dead went away; EOF is now wrong for the getopt failure value). Moved sleep command to the end of the main loop to avoid mismatch between main loop and the report loop. There is an extra iteration that could be used to calibrate the loop overhead, but was used to report wrong results. Fixed usage message. --- share/examples/perfmon/perfmon.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'share/examples/perfmon/perfmon.c') diff --git a/share/examples/perfmon/perfmon.c b/share/examples/perfmon/perfmon.c index 274a828..b6c9ff5 100644 --- a/share/examples/perfmon/perfmon.c +++ b/share/examples/perfmon/perfmon.c @@ -26,7 +26,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: perfmon.c,v 1.3 1997/02/22 13:55:58 peter Exp $ */ #include @@ -45,13 +45,14 @@ #include static int getnum(const char *, int, int); -static void __dead usage(const char *) __dead2; +static void usage(const char *) __dead2; int main(int argc, char **argv) { int c, fd, num; int loops, i, sleeptime; + char *cmd; struct pmc pmc; struct pmc_tstamp then, now; struct pmc_data value; @@ -63,10 +64,11 @@ main(int argc, char **argv) pmc.pmc_unit = 0; pmc.pmc_flags = 0; pmc.pmc_mask = 0; + cmd = NULL; loops = 50; sleeptime = 0; - while ((c = getopt(argc, argv, "s:l:uoeiU:m:")) != EOF) { + while ((c = getopt(argc, argv, "s:l:uoeiU:m:c:")) != -1) { switch(c) { case 'u': pmc.pmc_flags |= PMCF_USR; @@ -92,6 +94,9 @@ main(int argc, char **argv) case 's': sleeptime = getnum(optarg, 0, INT_MAX - 1); break; + case 'c': + cmd = optarg; + break; default: usage(argv[0]); } @@ -122,8 +127,6 @@ main(int argc, char **argv) value.pmcd_num = 0; for (i = 0; i < loops; i++) { - if (sleeptime) - sleep(sleeptime); if (ioctl(fd, PMIOSTOP, &num) < 0) err(1, "ioctl(PMIOSTOP)"); if (ioctl(fd, PMIOREAD, &value) < 0) @@ -133,6 +136,10 @@ main(int argc, char **argv) err(1, "ioctl(PMIORESET)"); if (ioctl(fd, PMIOSTART, &num) < 0) err(1, "ioctl(PMIOSTART)"); + if (sleeptime) + sleep(sleeptime); + if (cmd) + system(cmd); } if (ioctl(fd, PMIOSTOP, &num) < 0) @@ -181,7 +188,8 @@ static void usage(const char *pname) { fprintf(stderr, - "%s: usage:\n\t%s [-eiou] [-l nloops] [-U unit] [-m mask] " - "counter\n", pname, pname); + "usage: %s [-eiou] [-c command] [-l nloops] [-m mask] [-s sleeptime]\n" + " [-U unit] counter\n", + pname); exit(1); } -- cgit v1.1