summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbde <bde@FreeBSD.org>1997-06-29 22:43:01 +0000
committerbde <bde@FreeBSD.org>1997-06-29 22:43:01 +0000
commit5dc3d40d7d1ef33b8fbf70964befab1e9e41f14d (patch)
tree73ea03228ab39eae134e17e978525e2a2c1b2cf4
parent35c5c5c6c3c425011eb29c4af3136730ce57c76c (diff)
downloadFreeBSD-src-5dc3d40d7d1ef33b8fbf70964befab1e9e41f14d.zip
FreeBSD-src-5dc3d40d7d1ef33b8fbf70964befab1e9e41f14d.tar.gz
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.
-rw-r--r--share/examples/perfmon/perfmon.c22
1 files changed, 15 insertions, 7 deletions
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 <sys/types.h>
@@ -45,13 +45,14 @@
#include <errno.h>
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);
}
OpenPOWER on IntegriCloud