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.
This commit is contained in:
parent
32721aad4f
commit
9018a5cb58
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=27085
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user