aboutsummaryrefslogtreecommitdiff
path: root/share/examples/perfmon
diff options
context:
space:
mode:
authorBruce Evans <bde@FreeBSD.org>1997-06-29 22:43:01 +0000
committerBruce Evans <bde@FreeBSD.org>1997-06-29 22:43:01 +0000
commit9018a5cb58b1d06d6dcc30cf33cbdefa40f38460 (patch)
tree20738dedd5a8feca5a5f9320a186c2bed3e12297 /share/examples/perfmon
parent32721aad4f78e7d7bac6ad8e7424c48c0c63d703 (diff)
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.
Notes
Notes: svn path=/head/; revision=27085
Diffstat (limited to 'share/examples/perfmon')
-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 274a828af99c..b6c9ff5d8ce4 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);
}