svn commit: r267411 - stable/9/usr.sbin/pmcstat
Ed Maste
emaste at FreeBSD.org
Thu Jun 12 16:45:37 UTC 2014
Author: emaste
Date: Thu Jun 12 16:45:35 2014
New Revision: 267411
URL: http://svnweb.freebsd.org/changeset/base/267411
Log:
MFC r266209 by gnn:
Add a command line argument (-l) to end event collection after some
number of seconds. The number of seconds may be a fraction.
Relnotes: yes
Approved by: re
Modified:
stable/9/usr.sbin/pmcstat/pmcstat.8
stable/9/usr.sbin/pmcstat/pmcstat.c
stable/9/usr.sbin/pmcstat/pmcstat.h
Directory Properties:
stable/9/usr.sbin/pmcstat/ (props changed)
Modified: stable/9/usr.sbin/pmcstat/pmcstat.8
==============================================================================
--- stable/9/usr.sbin/pmcstat/pmcstat.8 Thu Jun 12 16:41:52 2014 (r267410)
+++ stable/9/usr.sbin/pmcstat/pmcstat.8 Thu Jun 12 16:45:35 2014 (r267411)
@@ -51,6 +51,7 @@
.Op Fl f Ar pluginopt
.Op Fl g
.Op Fl k Ar kerneldir
+.Op Fl l Ar secs
.Op Fl m Ar pathname
.Op Fl n Ar rate
.Op Fl o Ar outputfile
@@ -258,6 +259,13 @@ This directory specifies where
should look for the kernel and its modules.
The default is
.Pa /boot/kernel .
+.It Fl l Ar secs
+Set system-wide performance measurement duration for
+.Ar secs
+seconds.
+The argument
+.Ar secs
+may be a fractional value.
.It Fl m Ar pathname
Print the sampled PCs with the name, the start and ending addresses
of the function within they live.
Modified: stable/9/usr.sbin/pmcstat/pmcstat.c
==============================================================================
--- stable/9/usr.sbin/pmcstat/pmcstat.c Thu Jun 12 16:41:52 2014 (r267410)
+++ stable/9/usr.sbin/pmcstat/pmcstat.c Thu Jun 12 16:45:35 2014 (r267411)
@@ -509,6 +509,7 @@ pmcstat_show_usage(void)
"\t -f spec\t pass \"spec\" to as plugin option\n"
"\t -g\t\t produce gprof(1) compatible profiles\n"
"\t -k dir\t\t set the path to the kernel\n"
+ "\t -l secs\t set duration time\n"
"\t -m file\t print sampled PCs to \"file\"\n"
"\t -n rate\t set sampling rate\n"
"\t -o file\t send print output to \"file\"\n"
@@ -551,6 +552,7 @@ main(int argc, char **argv)
{
cpuset_t cpumask;
double interval;
+ double duration;
int hcpu, option, npmc, ncpu;
int c, check_driver_stats, current_cpu, current_sampling_count;
int do_callchain, do_descendants, do_logproccsw, do_logprocexit;
@@ -601,6 +603,7 @@ main(int argc, char **argv)
args.pa_toptty = 0;
args.pa_topcolor = 0;
args.pa_mergepmc = 0;
+ args.pa_duration = 0.0;
STAILQ_INIT(&args.pa_events);
SLIST_INIT(&args.pa_targets);
bzero(&ds_start, sizeof(ds_start));
@@ -619,7 +622,7 @@ main(int argc, char **argv)
CPU_SET(hcpu, &cpumask);
while ((option = getopt(argc, argv,
- "CD:EF:G:M:NO:P:R:S:TWc:df:gk:m:n:o:p:qr:s:t:vw:z:")) != -1)
+ "CD:EF:G:M:NO:P:R:S:TWc:df:gk:l:m:n:o:p:qr:s:t:vw:z:")) != -1)
switch (option) {
case 'C': /* cumulative values */
use_cumulative_counts = !use_cumulative_counts;
@@ -687,6 +690,15 @@ main(int argc, char **argv)
args.pa_flags |= FLAG_HAS_KERNELPATH;
break;
+ case 'l': /* time duration in seconds */
+ duration = strtod(optarg, &end);
+ if (*end != '\0' || duration <= 0)
+ errx(EX_USAGE, "ERROR: Illegal duration time "
+ "value \"%s\".", optarg);
+ args.pa_flags |= FLAG_HAS_DURATION;
+ args.pa_duration = duration;
+ break;
+
case 'm':
args.pa_flags |= FLAG_DO_ANNOTATE;
args.pa_plugin = PMCSTAT_PL_ANNOTATE;
@@ -917,6 +929,12 @@ main(int argc, char **argv)
errx(EX_USAGE,
"ERROR: options -O and -R are mutually exclusive.");
+ /* disallow -T and -l together */
+ if ((args.pa_flags & FLAG_HAS_DURATION) &&
+ (args.pa_flags & FLAG_DO_TOP))
+ errx(EX_USAGE, "ERROR: options -T and -l are mutually "
+ "exclusive.");
+
/* -m option is allowed with -R only. */
if (args.pa_flags & FLAG_DO_ANNOTATE && args.pa_inputpath == NULL)
errx(EX_USAGE, "ERROR: option -m requires an input file");
@@ -1273,6 +1291,20 @@ main(int argc, char **argv)
"ERROR: Cannot register kevent for timer");
}
+ /*
+ * Setup a duration timer if we have sampling mode PMCs and
+ * a duration time is set
+ */
+ if ((args.pa_flags & FLAG_HAS_SAMPLING_PMCS) &&
+ (args.pa_flags & FLAG_HAS_DURATION)) {
+ EV_SET(&kev, 0, EVFILT_TIMER, EV_ADD, 0,
+ args.pa_duration * 1000, NULL);
+
+ if (kevent(pmcstat_kq, &kev, 1, NULL, 0, NULL) < 0)
+ err(EX_OSERR, "ERROR: Cannot register kevent for "
+ "time duration");
+ }
+
/* attach PMCs to the target process, starting it if specified */
if (args.pa_flags & FLAG_HAS_COMMANDLINE)
pmcstat_create_process();
@@ -1349,7 +1381,7 @@ main(int argc, char **argv)
/*
* loop till either the target process (if any) exits, or we
- * are killed by a SIGINT.
+ * are killed by a SIGINT or we reached the time duration.
*/
runstate = PMCSTAT_RUNNING;
do_print = do_read = 0;
@@ -1416,7 +1448,13 @@ main(int argc, char **argv)
break;
- case EVFILT_TIMER: /* print out counting PMCs */
+ case EVFILT_TIMER:
+ /* time duration reached, exit */
+ if (args.pa_flags & FLAG_HAS_DURATION) {
+ runstate = PMCSTAT_FINISHED;
+ break;
+ }
+ /* print out counting PMCs */
if ((args.pa_flags & FLAG_DO_TOP) &&
pmc_flush_logfile() == 0)
do_read = 1;
Modified: stable/9/usr.sbin/pmcstat/pmcstat.h
==============================================================================
--- stable/9/usr.sbin/pmcstat/pmcstat.h Thu Jun 12 16:41:52 2014 (r267410)
+++ stable/9/usr.sbin/pmcstat/pmcstat.h Thu Jun 12 16:45:35 2014 (r267411)
@@ -54,6 +54,7 @@
#define FLAG_DO_TOP 0x00010000 /* -T */
#define FLAG_DO_ANALYSIS 0x00020000 /* -g or -G or -m or -T */
#define FLAGS_HAS_CPUMASK 0x00040000 /* -c */
+#define FLAG_HAS_DURATION 0x00080000 /* -l secs */
#define DEFAULT_SAMPLE_COUNT 65536
#define DEFAULT_WAIT_INTERVAL 5.0
@@ -148,6 +149,7 @@ struct pmcstat_args {
int pa_toptty; /* output to tty or file */
int pa_topcolor; /* terminal support color */
int pa_mergepmc; /* merge PMC with same name */
+ double pa_duration; /* time duration */
int pa_argc;
char **pa_argv;
STAILQ_HEAD(, pmcstat_ev) pa_events;
More information about the svn-src-stable-9
mailing list