2 * Copyright (c) 2003-2008, Joseph Koshy
3 * Copyright (c) 2007 The FreeBSD Foundation
6 * Portions of this software were developed by A. Joseph Koshy under
7 * sponsorship from the FreeBSD Foundation and Google, Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <sys/param.h>
35 #include <sys/cpuset.h>
36 #include <sys/event.h>
37 #include <sys/queue.h>
38 #include <sys/socket.h>
40 #include <sys/sysctl.h>
42 #include <sys/ttycom.h>
70 * A given invocation of pmcstat(8) can manage multiple PMCs of both
71 * the system-wide and per-process variety. Each of these could be in
72 * 'counting mode' or in 'sampling mode'.
74 * For 'counting mode' PMCs, pmcstat(8) will periodically issue a
75 * pmc_read() at the configured time interval and print out the value
76 * of the requested PMCs.
78 * For 'sampling mode' PMCs it can log to a file for offline analysis,
79 * or can analyse sampling data "on the fly", either by converting
80 * samples to printed textual form or by creating gprof(1) compatible
81 * profiles, one per program executed. When creating gprof(1)
82 * profiles it can optionally merge entries from multiple processes
83 * for a given executable into a single profile file.
85 * pmcstat(8) can also execute a command line and attach PMCs to the
86 * resulting child process. The protocol used is as follows:
88 * - parent creates a socketpair for two way communication and
94 * - Wait for childs token.
96 * - Awaits signal to start.
97 * - Attaches PMCs to the child's pid
98 * and starts them. Sets up
99 * monitoring for the child.
100 * - Signals child to start.
101 * - Recieves signal, attempts exec().
103 * After this point normal processing can happen.
108 int pmcstat_interrupt = 0;
109 int pmcstat_displayheight = DEFAULT_DISPLAY_HEIGHT;
110 int pmcstat_displaywidth = DEFAULT_DISPLAY_WIDTH;
111 int pmcstat_sockpair[NSOCKPAIRFD];
114 struct kinfo_proc *pmcstat_plist;
115 struct pmcstat_args args;
118 pmcstat_clone_event_descriptor(struct pmcstat_ev *ev, const cpuset_t *cpumask)
121 struct pmcstat_ev *ev_clone;
123 mcpu = sizeof(*cpumask) * NBBY;
124 for (cpu = 0; cpu < mcpu; cpu++) {
125 if (!CPU_ISSET(cpu, cpumask))
128 if ((ev_clone = malloc(sizeof(*ev_clone))) == NULL)
129 errx(EX_SOFTWARE, "ERROR: Out of memory");
130 (void) memset(ev_clone, 0, sizeof(*ev_clone));
132 ev_clone->ev_count = ev->ev_count;
133 ev_clone->ev_cpu = cpu;
134 ev_clone->ev_cumulative = ev->ev_cumulative;
135 ev_clone->ev_flags = ev->ev_flags;
136 ev_clone->ev_mode = ev->ev_mode;
137 ev_clone->ev_name = strdup(ev->ev_name);
138 ev_clone->ev_pmcid = ev->ev_pmcid;
139 ev_clone->ev_saved = ev->ev_saved;
140 ev_clone->ev_spec = strdup(ev->ev_spec);
142 STAILQ_INSERT_TAIL(&args.pa_events, ev_clone, ev_next);
147 pmcstat_get_cpumask(const char *cpuspec, cpuset_t *cpumask)
157 cpu = strtol(s, &end, 0);
158 if (cpu < 0 || end == s)
160 "ERROR: Illegal CPU specification \"%s\".",
162 CPU_SET(cpu, cpumask);
163 s = end + strspn(end, ", \t");
168 pmcstat_attach_pmcs(void)
170 struct pmcstat_ev *ev;
171 struct pmcstat_target *pt;
174 /* Attach all process PMCs to target processes. */
176 STAILQ_FOREACH(ev, &args.pa_events, ev_next) {
177 if (PMC_IS_SYSTEM_MODE(ev->ev_mode))
179 SLIST_FOREACH(pt, &args.pa_targets, pt_next)
180 if (pmc_attach(ev->ev_pmcid, pt->pt_pid) == 0)
182 else if (errno != ESRCH)
184 "ERROR: cannot attach pmc \"%s\" to process %d",
185 ev->ev_name, (int)pt->pt_pid);
189 errx(EX_DATAERR, "ERROR: No processes were attached to.");
194 pmcstat_cleanup(void)
196 struct pmcstat_ev *ev, *tmp;
198 /* release allocated PMCs. */
199 STAILQ_FOREACH_SAFE(ev, &args.pa_events, ev_next, tmp)
200 if (ev->ev_pmcid != PMC_ID_INVALID) {
201 if (pmc_stop(ev->ev_pmcid) < 0)
202 err(EX_OSERR, "ERROR: cannot stop pmc 0x%x \"%s\"",
203 ev->ev_pmcid, ev->ev_name);
204 if (pmc_release(ev->ev_pmcid) < 0)
205 err(EX_OSERR, "ERROR: cannot release pmc 0x%x \"%s\"",
206 ev->ev_pmcid, ev->ev_name);
209 STAILQ_REMOVE(&args.pa_events, ev, pmcstat_ev, ev_next);
213 /* de-configure the log file if present. */
214 if (args.pa_flags & (FLAG_HAS_PIPE | FLAG_HAS_OUTPUT_LOGFILE))
215 (void) pmc_configure_logfile(-1);
217 if (args.pa_logparser) {
218 pmclog_close(args.pa_logparser);
219 args.pa_logparser = NULL;
222 pmcstat_shutdown_logging();
226 pmcstat_create_process(void)
231 struct pmcstat_target *pt;
233 if (socketpair(AF_UNIX, SOCK_STREAM, 0, pmcstat_sockpair) < 0)
234 err(EX_OSERR, "ERROR: cannot create socket pair");
236 switch (pid = fork()) {
238 err(EX_OSERR, "ERROR: cannot fork");
242 (void) close(pmcstat_sockpair[PARENTSOCKET]);
244 /* Write a token to tell our parent we've started executing. */
245 if (write(pmcstat_sockpair[CHILDSOCKET], "+", 1) != 1)
246 err(EX_OSERR, "ERROR (child): cannot write token");
248 /* Wait for our parent to signal us to start. */
249 if (read(pmcstat_sockpair[CHILDSOCKET], &token, 1) < 0)
250 err(EX_OSERR, "ERROR (child): cannot read token");
251 (void) close(pmcstat_sockpair[CHILDSOCKET]);
253 /* exec() the program requested */
254 execvp(*args.pa_argv, args.pa_argv);
255 /* and if that fails, notify the parent */
256 kill(getppid(), SIGCHLD);
257 err(EX_OSERR, "ERROR: execvp \"%s\" failed", *args.pa_argv);
260 default: /* parent */
261 (void) close(pmcstat_sockpair[CHILDSOCKET]);
265 /* Ask to be notified via a kevent when the target process exits. */
266 EV_SET(&kev, pid, EVFILT_PROC, EV_ADD|EV_ONESHOT, NOTE_EXIT, 0,
268 if (kevent(pmcstat_kq, &kev, 1, NULL, 0, NULL) < 0)
269 err(EX_OSERR, "ERROR: cannot monitor child process %d", pid);
271 if ((pt = malloc(sizeof(*pt))) == NULL)
272 errx(EX_SOFTWARE, "ERROR: Out of memory.");
275 SLIST_INSERT_HEAD(&args.pa_targets, pt, pt_next);
277 /* Wait for the child to signal that its ready to go. */
278 if (read(pmcstat_sockpair[PARENTSOCKET], &token, 1) < 0)
279 err(EX_OSERR, "ERROR (parent): cannot read token");
285 pmcstat_find_targets(const char *spec)
287 int n, nproc, pid, rv;
288 struct pmcstat_target *pt;
289 char errbuf[_POSIX2_LINE_MAX], *end;
290 static struct kinfo_proc *kp;
294 /* First check if we've been given a process id. */
295 pid = strtol(spec, &end, 0);
296 if (end != spec && pid >= 0) {
297 if ((pt = malloc(sizeof(*pt))) == NULL)
300 SLIST_INSERT_HEAD(&args.pa_targets, pt, pt_next);
304 /* Otherwise treat arg as a regular expression naming processes. */
305 if (pmcstat_kvm == NULL) {
306 if ((pmcstat_kvm = kvm_openfiles(NULL, "/dev/null", NULL, 0,
308 err(EX_OSERR, "ERROR: Cannot open kernel \"%s\"",
310 if ((pmcstat_plist = kvm_getprocs(pmcstat_kvm, KERN_PROC_PROC,
312 err(EX_OSERR, "ERROR: Cannot get process list: %s",
313 kvm_geterr(pmcstat_kvm));
317 if ((rv = regcomp(®, spec, REG_EXTENDED|REG_NOSUB)) != 0) {
318 regerror(rv, ®, errbuf, sizeof(errbuf));
319 err(EX_DATAERR, "ERROR: Failed to compile regex \"%s\": %s",
323 for (n = 0, kp = pmcstat_plist; n < nproc; n++, kp++) {
324 if ((rv = regexec(®, kp->ki_comm, 1, ®match, 0)) == 0) {
325 if ((pt = malloc(sizeof(*pt))) == NULL)
327 pt->pt_pid = kp->ki_pid;
328 SLIST_INSERT_HEAD(&args.pa_targets, pt, pt_next);
329 } else if (rv != REG_NOMATCH) {
330 regerror(rv, ®, errbuf, sizeof(errbuf));
331 errx(EX_SOFTWARE, "ERROR: Regex evalation failed: %s",
341 errx(EX_SOFTWARE, "Out of memory.");
346 pmcstat_kill_process(void)
348 struct pmcstat_target *pt;
350 assert(args.pa_flags & FLAG_HAS_COMMANDLINE);
353 * If a command line was specified, it would be the very first
354 * in the list, before any other processes specified by -t.
356 pt = SLIST_FIRST(&args.pa_targets);
359 if (kill(pt->pt_pid, SIGINT) != 0)
360 err(EX_OSERR, "ERROR: cannot signal child process");
364 pmcstat_start_pmcs(void)
366 struct pmcstat_ev *ev;
368 STAILQ_FOREACH(ev, &args.pa_events, ev_next) {
370 assert(ev->ev_pmcid != PMC_ID_INVALID);
372 if (pmc_start(ev->ev_pmcid) < 0) {
373 warn("ERROR: Cannot start pmc 0x%x \"%s\"",
374 ev->ev_pmcid, ev->ev_name);
383 pmcstat_print_headers(void)
385 struct pmcstat_ev *ev;
388 (void) fprintf(args.pa_printfile, PRINT_HEADER_PREFIX);
390 STAILQ_FOREACH(ev, &args.pa_events, ev_next) {
391 if (PMC_IS_SAMPLING_MODE(ev->ev_mode))
394 c = PMC_IS_SYSTEM_MODE(ev->ev_mode) ? 's' : 'p';
396 if (ev->ev_fieldskip != 0)
397 (void) fprintf(args.pa_printfile, "%*s",
398 ev->ev_fieldskip, "");
399 w = ev->ev_fieldwidth - ev->ev_fieldskip - 2;
402 (void) fprintf(args.pa_printfile, "s/%02d/%-*s ",
403 ev->ev_cpu, w-3, ev->ev_name);
405 (void) fprintf(args.pa_printfile, "p/%*s ", w,
409 (void) fflush(args.pa_printfile);
413 pmcstat_print_counters(void)
416 struct pmcstat_ev *ev;
419 extra_width = sizeof(PRINT_HEADER_PREFIX) - 1;
421 STAILQ_FOREACH(ev, &args.pa_events, ev_next) {
423 /* skip sampling mode counters */
424 if (PMC_IS_SAMPLING_MODE(ev->ev_mode))
427 if (pmc_read(ev->ev_pmcid, &value) < 0)
428 err(EX_OSERR, "ERROR: Cannot read pmc \"%s\"",
431 (void) fprintf(args.pa_printfile, "%*ju ",
432 ev->ev_fieldwidth + extra_width,
433 (uintmax_t) ev->ev_cumulative ? value :
434 (value - ev->ev_saved));
436 if (ev->ev_cumulative == 0)
437 ev->ev_saved = value;
441 (void) fflush(args.pa_printfile);
449 pmcstat_print_pmcs(void)
451 static int linecount = 0;
453 /* check if we need to print a header line */
454 if (++linecount > pmcstat_displayheight) {
455 (void) fprintf(args.pa_printfile, "\n");
459 pmcstat_print_headers();
460 (void) fprintf(args.pa_printfile, "\n");
462 pmcstat_print_counters();
468 * Do process profiling
470 * If a pid was specified, attach each allocated PMC to the target
471 * process. Otherwise, fork a child and attach the PMCs to the child,
472 * and have the child exec() the target program.
476 pmcstat_start_process(void)
478 /* Signal the child to proceed. */
479 if (write(pmcstat_sockpair[PARENTSOCKET], "!", 1) != 1)
480 err(EX_OSERR, "ERROR (parent): write of token failed");
482 (void) close(pmcstat_sockpair[PARENTSOCKET]);
486 pmcstat_show_usage(void)
489 "[options] [commandline]\n"
490 "\t Measure process and/or system performance using hardware\n"
491 "\t performance monitoring counters.\n"
492 "\t Options include:\n"
493 "\t -C\t\t (toggle) show cumulative counts\n"
494 "\t -D path\t create profiles in directory \"path\"\n"
495 "\t -E\t\t (toggle) show counts at process exit\n"
496 "\t -F file\t write a system-wide callgraph (Kcachegrind format)"
498 "\t -G file\t write a system-wide callgraph to \"file\"\n"
499 "\t -M file\t print executable/gmon file map to \"file\"\n"
500 "\t -N\t\t (toggle) capture callchains\n"
501 "\t -O file\t send log output to \"file\"\n"
502 "\t -P spec\t allocate a process-private sampling PMC\n"
503 "\t -R file\t read events from \"file\"\n"
504 "\t -S spec\t allocate a system-wide sampling PMC\n"
505 "\t -T\t\t start in top mode\n"
506 "\t -W\t\t (toggle) show counts per context switch\n"
507 "\t -c cpu-list\t set cpus for subsequent system-wide PMCs\n"
508 "\t -d\t\t (toggle) track descendants\n"
509 "\t -f spec\t pass \"spec\" to as plugin option\n"
510 "\t -g\t\t produce gprof(1) compatible profiles\n"
511 "\t -k dir\t\t set the path to the kernel\n"
512 "\t -n rate\t set sampling rate\n"
513 "\t -o file\t send print output to \"file\"\n"
514 "\t -p spec\t allocate a process-private counting PMC\n"
515 "\t -q\t\t suppress verbosity\n"
516 "\t -r fsroot\t specify FS root directory\n"
517 "\t -s spec\t allocate a system-wide counting PMC\n"
518 "\t -t process-spec attach to running processes matching "
520 "\t -v\t\t increase verbosity\n"
521 "\t -w secs\t set printing time interval\n"
522 "\t -z depth\t limit callchain display depth"
527 * At exit handler for top mode
531 pmcstat_topexit(void)
549 main(int argc, char **argv)
553 int hcpu, option, npmc, ncpu;
554 int c, check_driver_stats, current_cpu, current_sampling_count;
555 int do_callchain, do_descendants, do_logproccsw, do_logprocexit;
556 int do_print, do_read;
560 int use_cumulative_counts;
563 const char *errmsg, *graphfilename;
564 enum pmcstat_state runstate;
565 struct pmc_driverstats ds_start, ds_end;
566 struct pmcstat_ev *ev;
571 char buffer[PATH_MAX];
573 check_driver_stats = 0;
575 current_sampling_count = DEFAULT_SAMPLE_COUNT;
580 use_cumulative_counts = 0;
582 args.pa_required = 0;
584 args.pa_verbosity = 1;
587 args.pa_kernel = strdup("/boot/kernel");
588 args.pa_samplesdir = ".";
589 args.pa_printfile = stderr;
590 args.pa_graphdepth = DEFAULT_CALLGRAPH_DEPTH;
591 args.pa_graphfile = NULL;
592 args.pa_interval = DEFAULT_WAIT_INTERVAL;
593 args.pa_mapfilename = NULL;
594 args.pa_inputpath = NULL;
595 args.pa_outputpath = NULL;
596 args.pa_pplugin = PMCSTAT_PL_NONE;
597 args.pa_plugin = PMCSTAT_PL_NONE;
598 args.pa_ctdumpinstr = 1;
599 args.pa_topmode = PMCSTAT_TOP_DELTA;
601 args.pa_topcolor = 0;
602 args.pa_mergepmc = 0;
603 STAILQ_INIT(&args.pa_events);
604 SLIST_INIT(&args.pa_targets);
605 bzero(&ds_start, sizeof(ds_start));
606 bzero(&ds_end, sizeof(ds_end));
611 * The initial CPU mask specifies all non-halted CPUS in the
615 if (sysctlbyname("hw.ncpu", &ncpu, &dummy, NULL, 0) < 0)
616 err(EX_OSERR, "ERROR: Cannot determine the number of CPUs");
617 for (hcpu = 0; hcpu < ncpu; hcpu++)
618 CPU_SET(hcpu, &cpumask);
620 while ((option = getopt(argc, argv,
621 "CD:EF:G:M:NO:P:R:S:TWc:df:gk:m:n:o:p:qr:s:t:vw:z:")) != -1)
623 case 'C': /* cumulative values */
624 use_cumulative_counts = !use_cumulative_counts;
625 args.pa_required |= FLAG_HAS_COUNTING_PMCS;
630 if (optarg[0] == '*' && optarg[1] == '\0') {
631 for (hcpu = 0; hcpu < ncpu; hcpu++)
632 CPU_SET(hcpu, &cpumask);
634 pmcstat_get_cpumask(optarg, &cpumask);
636 args.pa_flags |= FLAGS_HAS_CPUMASK;
637 args.pa_required |= FLAG_HAS_SYSTEM_PMCS;
641 if (stat(optarg, &sb) < 0)
642 err(EX_OSERR, "ERROR: Cannot stat \"%s\"",
644 if (!S_ISDIR(sb.st_mode))
646 "ERROR: \"%s\" is not a directory.",
648 args.pa_samplesdir = optarg;
649 args.pa_flags |= FLAG_HAS_SAMPLESDIR;
650 args.pa_required |= FLAG_DO_GPROF;
653 case 'd': /* toggle descendents */
654 do_descendants = !do_descendants;
655 args.pa_required |= FLAG_HAS_PROCESS_PMCS;
658 case 'F': /* produce a system-wide calltree */
659 args.pa_flags |= FLAG_DO_CALLGRAPHS;
660 args.pa_plugin = PMCSTAT_PL_CALLTREE;
661 graphfilename = optarg;
664 case 'f': /* plugins options */
665 if (args.pa_plugin == PMCSTAT_PL_NONE)
666 err(EX_USAGE, "ERROR: Need -g/-G/-m/-T.");
667 pmcstat_pluginconfigure_log(optarg);
670 case 'G': /* produce a system-wide callgraph */
671 args.pa_flags |= FLAG_DO_CALLGRAPHS;
672 args.pa_plugin = PMCSTAT_PL_CALLGRAPH;
673 graphfilename = optarg;
676 case 'g': /* produce gprof compatible profiles */
677 args.pa_flags |= FLAG_DO_GPROF;
678 args.pa_pplugin = PMCSTAT_PL_CALLGRAPH;
679 args.pa_plugin = PMCSTAT_PL_GPROF;
682 case 'k': /* pathname to the kernel */
683 free(args.pa_kernel);
684 args.pa_kernel = strdup(optarg);
685 args.pa_required |= FLAG_DO_ANALYSIS;
686 args.pa_flags |= FLAG_HAS_KERNELPATH;
690 args.pa_flags |= FLAG_DO_ANNOTATE;
691 args.pa_plugin = PMCSTAT_PL_ANNOTATE;
692 graphfilename = optarg;
695 case 'E': /* log process exit */
696 do_logprocexit = !do_logprocexit;
697 args.pa_required |= (FLAG_HAS_PROCESS_PMCS |
698 FLAG_HAS_COUNTING_PMCS | FLAG_HAS_OUTPUT_LOGFILE);
701 case 'M': /* mapfile */
702 args.pa_mapfilename = optarg;
706 do_callchain = !do_callchain;
707 args.pa_required |= FLAG_HAS_SAMPLING_PMCS;
710 case 'p': /* process virtual counting PMC */
711 case 's': /* system-wide counting PMC */
712 case 'P': /* process virtual sampling PMC */
713 case 'S': /* system-wide sampling PMC */
714 if ((ev = malloc(sizeof(*ev))) == NULL)
715 errx(EX_SOFTWARE, "ERROR: Out of memory.");
718 case 'p': ev->ev_mode = PMC_MODE_TC; break;
719 case 's': ev->ev_mode = PMC_MODE_SC; break;
720 case 'P': ev->ev_mode = PMC_MODE_TS; break;
721 case 'S': ev->ev_mode = PMC_MODE_SS; break;
724 if (option == 'P' || option == 'p') {
725 args.pa_flags |= FLAG_HAS_PROCESS_PMCS;
726 args.pa_required |= (FLAG_HAS_COMMANDLINE |
730 if (option == 'P' || option == 'S') {
731 args.pa_flags |= FLAG_HAS_SAMPLING_PMCS;
732 args.pa_required |= (FLAG_HAS_PIPE |
733 FLAG_HAS_OUTPUT_LOGFILE);
736 if (option == 'p' || option == 's')
737 args.pa_flags |= FLAG_HAS_COUNTING_PMCS;
739 if (option == 's' || option == 'S')
740 args.pa_flags |= FLAG_HAS_SYSTEM_PMCS;
742 ev->ev_spec = strdup(optarg);
744 if (option == 'S' || option == 'P')
745 ev->ev_count = current_sampling_count;
749 if (option == 'S' || option == 's') {
750 hcpu = sizeof(cpumask) * NBBY;
751 for (hcpu--; hcpu >= 0; hcpu--)
752 if (CPU_ISSET(hcpu, &cpumask))
756 ev->ev_cpu = PMC_CPU_ANY;
760 ev->ev_flags |= PMC_F_CALLCHAIN;
762 ev->ev_flags |= PMC_F_DESCENDANTS;
764 ev->ev_flags |= PMC_F_LOG_PROCEXIT;
766 ev->ev_flags |= PMC_F_LOG_PROCCSW;
768 ev->ev_cumulative = use_cumulative_counts;
771 ev->ev_pmcid = PMC_ID_INVALID;
773 /* extract event name */
774 c = strcspn(optarg, ", \t");
775 ev->ev_name = malloc(c + 1);
776 (void) strncpy(ev->ev_name, optarg, c);
777 *(ev->ev_name + c) = '\0';
779 STAILQ_INSERT_TAIL(&args.pa_events, ev, ev_next);
781 if (option == 's' || option == 'S') {
782 hcpu = CPU_ISSET(ev->ev_cpu, &cpumask);
783 CPU_CLR(ev->ev_cpu, &cpumask);
784 pmcstat_clone_event_descriptor(ev, &cpumask);
786 CPU_SET(ev->ev_cpu, &cpumask);
791 case 'n': /* sampling count */
792 current_sampling_count = strtol(optarg, &end, 0);
793 if (*end != '\0' || current_sampling_count <= 0)
795 "ERROR: Illegal count value \"%s\".",
797 args.pa_required |= FLAG_HAS_SAMPLING_PMCS;
800 case 'o': /* outputfile */
801 if (args.pa_printfile != NULL &&
802 args.pa_printfile != stdout &&
803 args.pa_printfile != stderr)
804 (void) fclose(args.pa_printfile);
805 if ((args.pa_printfile = fopen(optarg, "w")) == NULL)
807 "ERROR: cannot open \"%s\" for writing.",
809 args.pa_flags |= FLAG_DO_PRINT;
812 case 'O': /* sampling output */
813 if (args.pa_outputpath)
815 "ERROR: option -O may only be specified once.");
816 args.pa_outputpath = optarg;
817 args.pa_flags |= FLAG_HAS_OUTPUT_LOGFILE;
820 case 'q': /* quiet mode */
821 args.pa_verbosity = 0;
824 case 'r': /* root FS path */
825 args.pa_fsroot = optarg;
828 case 'R': /* read an existing log file */
829 if (args.pa_inputpath != NULL)
831 "ERROR: option -R may only be specified once.");
832 args.pa_inputpath = optarg;
833 if (args.pa_printfile == stderr)
834 args.pa_printfile = stdout;
835 args.pa_flags |= FLAG_READ_LOGFILE;
838 case 't': /* target pid or process name */
839 pmcstat_find_targets(optarg);
841 args.pa_flags |= FLAG_HAS_TARGET;
842 args.pa_required |= FLAG_HAS_PROCESS_PMCS;
845 case 'T': /* top mode */
846 args.pa_flags |= FLAG_DO_TOP;
847 args.pa_plugin = PMCSTAT_PL_CALLGRAPH;
848 args.pa_ctdumpinstr = 0;
849 args.pa_mergepmc = 1;
850 if (args.pa_printfile == stderr)
851 args.pa_printfile = stdout;
854 case 'v': /* verbose */
858 case 'w': /* wait interval */
859 interval = strtod(optarg, &end);
860 if (*end != '\0' || interval <= 0)
862 "ERROR: Illegal wait interval value \"%s\".",
864 args.pa_flags |= FLAG_HAS_WAIT_INTERVAL;
865 args.pa_interval = interval;
868 case 'W': /* toggle LOG_CSW */
869 do_logproccsw = !do_logproccsw;
870 args.pa_required |= (FLAG_HAS_PROCESS_PMCS |
871 FLAG_HAS_COUNTING_PMCS | FLAG_HAS_OUTPUT_LOGFILE);
875 graphdepth = strtod(optarg, &end);
876 if (*end != '\0' || graphdepth <= 0)
878 "ERROR: Illegal callchain depth \"%s\".",
880 args.pa_graphdepth = graphdepth;
881 args.pa_required |= FLAG_DO_CALLGRAPHS;
886 pmcstat_show_usage();
891 args.pa_argc = (argc -= optind);
892 args.pa_argv = (argv += optind);
894 /* If we read from logfile and no specified CPU mask use
895 * the maximum CPU count.
897 if ((args.pa_flags & FLAG_READ_LOGFILE) &&
898 (args.pa_flags & FLAGS_HAS_CPUMASK) == 0)
901 args.pa_cpumask = cpumask; /* For selecting CPUs using -R. */
903 if (argc) /* command line present */
904 args.pa_flags |= FLAG_HAS_COMMANDLINE;
906 if (args.pa_flags & (FLAG_DO_GPROF | FLAG_DO_CALLGRAPHS |
907 FLAG_DO_ANNOTATE | FLAG_DO_TOP))
908 args.pa_flags |= FLAG_DO_ANALYSIS;
911 * Check invocation syntax.
914 /* disallow -O and -R together */
915 if (args.pa_outputpath && args.pa_inputpath)
917 "ERROR: options -O and -R are mutually exclusive.");
919 /* -m option is allowed with -R only. */
920 if (args.pa_flags & FLAG_DO_ANNOTATE && args.pa_inputpath == NULL)
921 errx(EX_USAGE, "ERROR: option -m requires an input file");
923 /* -m option is not allowed combined with -g or -G. */
924 if (args.pa_flags & FLAG_DO_ANNOTATE &&
925 args.pa_flags & (FLAG_DO_GPROF | FLAG_DO_CALLGRAPHS))
927 "ERROR: option -m and -g | -G are mutually exclusive");
929 if (args.pa_flags & FLAG_READ_LOGFILE) {
931 if (args.pa_flags & FLAG_HAS_COMMANDLINE)
932 errmsg = "a command line specification";
933 else if (args.pa_flags & FLAG_HAS_TARGET)
934 errmsg = "option -t";
935 else if (!STAILQ_EMPTY(&args.pa_events))
936 errmsg = "a PMC event specification";
939 "ERROR: option -R may not be used with %s.",
941 } else if (STAILQ_EMPTY(&args.pa_events))
942 /* All other uses require a PMC spec. */
943 pmcstat_show_usage();
945 /* check for -t pid without a process PMC spec */
946 if ((args.pa_required & FLAG_HAS_TARGET) &&
947 (args.pa_flags & FLAG_HAS_PROCESS_PMCS) == 0)
949 "ERROR: option -t requires a process mode PMC to be specified."
952 /* check for process-mode options without a command or -t pid */
953 if ((args.pa_required & FLAG_HAS_PROCESS_PMCS) &&
954 (args.pa_flags & (FLAG_HAS_COMMANDLINE | FLAG_HAS_TARGET)) == 0)
956 "ERROR: options -d, -E, -p, -P, and -W require a command line or target process."
959 /* check for -p | -P without a target process of some sort */
960 if ((args.pa_required & (FLAG_HAS_COMMANDLINE | FLAG_HAS_TARGET)) &&
961 (args.pa_flags & (FLAG_HAS_COMMANDLINE | FLAG_HAS_TARGET)) == 0)
963 "ERROR: options -P and -p require a target process or a command line."
966 /* check for process-mode options without a process-mode PMC */
967 if ((args.pa_required & FLAG_HAS_PROCESS_PMCS) &&
968 (args.pa_flags & FLAG_HAS_PROCESS_PMCS) == 0)
970 "ERROR: options -d, -E, and -W require a process mode PMC to be specified."
973 /* check for -c cpu with no system mode PMCs or logfile. */
974 if ((args.pa_required & FLAG_HAS_SYSTEM_PMCS) &&
975 (args.pa_flags & FLAG_HAS_SYSTEM_PMCS) == 0 &&
976 (args.pa_flags & FLAG_READ_LOGFILE) == 0)
978 "ERROR: option -c requires at least one system mode PMC to be specified."
981 /* check for counting mode options without a counting PMC */
982 if ((args.pa_required & FLAG_HAS_COUNTING_PMCS) &&
983 (args.pa_flags & FLAG_HAS_COUNTING_PMCS) == 0)
985 "ERROR: options -C, -W and -o require at least one counting mode PMC to be specified."
988 /* check for sampling mode options without a sampling PMC spec */
989 if ((args.pa_required & FLAG_HAS_SAMPLING_PMCS) &&
990 (args.pa_flags & FLAG_HAS_SAMPLING_PMCS) == 0)
992 "ERROR: options -N, -n and -O require at least one sampling mode PMC to be specified."
995 /* check if -g/-G/-m/-T are being used correctly */
996 if ((args.pa_flags & FLAG_DO_ANALYSIS) &&
997 !(args.pa_flags & (FLAG_HAS_SAMPLING_PMCS|FLAG_READ_LOGFILE)))
999 "ERROR: options -g/-G/-m/-T require sampling PMCs or -R to be specified."
1002 /* check if -O was spuriously specified */
1003 if ((args.pa_flags & FLAG_HAS_OUTPUT_LOGFILE) &&
1004 (args.pa_required & FLAG_HAS_OUTPUT_LOGFILE) == 0)
1006 "ERROR: option -O is used only with options -E, -P, -S and -W."
1009 /* -k kernel path require -g/-G/-m/-T or -R */
1010 if ((args.pa_flags & FLAG_HAS_KERNELPATH) &&
1011 (args.pa_flags & FLAG_DO_ANALYSIS) == 0 &&
1012 (args.pa_flags & FLAG_READ_LOGFILE) == 0)
1013 errx(EX_USAGE, "ERROR: option -k is only used with -g/-R/-m/-T.");
1015 /* -D only applies to gprof output mode (-g) */
1016 if ((args.pa_flags & FLAG_HAS_SAMPLESDIR) &&
1017 (args.pa_flags & FLAG_DO_GPROF) == 0)
1018 errx(EX_USAGE, "ERROR: option -D is only used with -g.");
1020 /* -M mapfile requires -g or -R */
1021 if (args.pa_mapfilename != NULL &&
1022 (args.pa_flags & FLAG_DO_GPROF) == 0 &&
1023 (args.pa_flags & FLAG_READ_LOGFILE) == 0)
1024 errx(EX_USAGE, "ERROR: option -M is only used with -g/-R.");
1027 * Disallow textual output of sampling PMCs if counting PMCs
1028 * have also been asked for, mostly because the combined output
1029 * is difficult to make sense of.
1031 if ((args.pa_flags & FLAG_HAS_COUNTING_PMCS) &&
1032 (args.pa_flags & FLAG_HAS_SAMPLING_PMCS) &&
1033 ((args.pa_flags & FLAG_HAS_OUTPUT_LOGFILE) == 0))
1035 "ERROR: option -O is required if counting and sampling PMCs are specified together."
1039 * Check if "-k kerneldir" was specified, and if whether
1040 * 'kerneldir' actually refers to a file. If so, use
1041 * `dirname path` to determine the kernel directory.
1043 if (args.pa_flags & FLAG_HAS_KERNELPATH) {
1044 (void) snprintf(buffer, sizeof(buffer), "%s%s", args.pa_fsroot,
1046 if (stat(buffer, &sb) < 0)
1047 err(EX_OSERR, "ERROR: Cannot locate kernel \"%s\"",
1049 if (!S_ISREG(sb.st_mode) && !S_ISDIR(sb.st_mode))
1050 errx(EX_USAGE, "ERROR: \"%s\": Unsupported file type.",
1052 if (!S_ISDIR(sb.st_mode)) {
1053 tmp = args.pa_kernel;
1054 args.pa_kernel = strdup(dirname(args.pa_kernel));
1056 (void) snprintf(buffer, sizeof(buffer), "%s%s",
1057 args.pa_fsroot, args.pa_kernel);
1058 if (stat(buffer, &sb) < 0)
1059 err(EX_OSERR, "ERROR: Cannot stat \"%s\"",
1061 if (!S_ISDIR(sb.st_mode))
1063 "ERROR: \"%s\" is not a directory.",
1069 * If we have a callgraph be created, select the outputfile.
1071 if (args.pa_flags & FLAG_DO_CALLGRAPHS) {
1072 if (strcmp(graphfilename, "-") == 0)
1073 args.pa_graphfile = args.pa_printfile;
1075 args.pa_graphfile = fopen(graphfilename, "w");
1076 if (args.pa_graphfile == NULL)
1078 "ERROR: cannot open \"%s\" for writing",
1082 if (args.pa_flags & FLAG_DO_ANNOTATE) {
1083 args.pa_graphfile = fopen(graphfilename, "w");
1084 if (args.pa_graphfile == NULL)
1085 err(EX_OSERR, "ERROR: cannot open \"%s\" for writing",
1089 /* if we've been asked to process a log file, skip init */
1090 if ((args.pa_flags & FLAG_READ_LOGFILE) == 0) {
1093 "ERROR: Initialization of the pmc(3) library failed"
1096 if ((npmc = pmc_npmc(0)) < 0) /* assume all CPUs are identical */
1098 "ERROR: Cannot determine the number of PMCs on CPU %d",
1102 /* Allocate a kqueue */
1103 if ((pmcstat_kq = kqueue()) < 0)
1104 err(EX_OSERR, "ERROR: Cannot allocate kqueue");
1106 /* Setup the logfile as the source. */
1107 if (args.pa_flags & FLAG_READ_LOGFILE) {
1109 * Print the log in textual form if we haven't been
1110 * asked to generate profiling information.
1112 if ((args.pa_flags & FLAG_DO_ANALYSIS) == 0)
1113 args.pa_flags |= FLAG_DO_PRINT;
1115 pmcstat_initialize_logging();
1116 rfd = pmcstat_open_log(args.pa_inputpath,
1117 PMCSTAT_OPEN_FOR_READ);
1118 if ((args.pa_logparser = pmclog_open(rfd)) == NULL)
1119 err(EX_OSERR, "ERROR: Cannot create parser");
1120 if (fcntl(rfd, F_SETFL, O_NONBLOCK) < 0)
1121 err(EX_OSERR, "ERROR: fcntl(2) failed");
1122 EV_SET(&kev, rfd, EVFILT_READ, EV_ADD,
1124 if (kevent(pmcstat_kq, &kev, 1, NULL, 0, NULL) < 0)
1125 err(EX_OSERR, "ERROR: Cannot register kevent");
1128 * Configure the specified log file or setup a default log
1129 * consumer via a pipe.
1131 if (args.pa_required & FLAG_HAS_OUTPUT_LOGFILE) {
1132 if (args.pa_outputpath)
1133 args.pa_logfd = pmcstat_open_log(args.pa_outputpath,
1134 PMCSTAT_OPEN_FOR_WRITE);
1137 * process the log on the fly by reading it in
1140 if (pipe(pipefd) < 0)
1141 err(EX_OSERR, "ERROR: pipe(2) failed");
1143 if (fcntl(pipefd[READPIPEFD], F_SETFL, O_NONBLOCK) < 0)
1144 err(EX_OSERR, "ERROR: fcntl(2) failed");
1146 EV_SET(&kev, pipefd[READPIPEFD], EVFILT_READ, EV_ADD,
1149 if (kevent(pmcstat_kq, &kev, 1, NULL, 0, NULL) < 0)
1150 err(EX_OSERR, "ERROR: Cannot register kevent");
1152 args.pa_logfd = pipefd[WRITEPIPEFD];
1154 args.pa_flags |= FLAG_HAS_PIPE;
1155 if ((args.pa_flags & FLAG_DO_TOP) == 0)
1156 args.pa_flags |= FLAG_DO_PRINT;
1157 args.pa_logparser = pmclog_open(pipefd[READPIPEFD]);
1160 if (pmc_configure_logfile(args.pa_logfd) < 0)
1161 err(EX_OSERR, "ERROR: Cannot configure log file");
1164 /* remember to check for driver errors if we are sampling or logging */
1165 check_driver_stats = (args.pa_flags & FLAG_HAS_SAMPLING_PMCS) ||
1166 (args.pa_flags & FLAG_HAS_OUTPUT_LOGFILE);
1169 if (args.pa_flags & FLAG_READ_LOGFILE) {
1173 STAILQ_FOREACH(ev, &args.pa_events, ev_next) {
1174 if (pmc_allocate(ev->ev_spec, ev->ev_mode,
1175 ev->ev_flags, ev->ev_cpu, &ev->ev_pmcid) < 0)
1177 "ERROR: Cannot allocate %s-mode pmc with specification \"%s\"",
1178 PMC_IS_SYSTEM_MODE(ev->ev_mode) ?
1179 "system" : "process", ev->ev_spec);
1181 if (PMC_IS_SAMPLING_MODE(ev->ev_mode) &&
1182 pmc_set(ev->ev_pmcid, ev->ev_count) < 0)
1184 "ERROR: Cannot set sampling count for PMC \"%s\"",
1188 /* compute printout widths */
1189 STAILQ_FOREACH(ev, &args.pa_events, ev_next) {
1194 (void) pmc_width(ev->ev_pmcid, &counter_width);
1195 header_width = strlen(ev->ev_name) + 2; /* prefix '%c/' */
1196 display_width = (int) floor(counter_width / 3.32193) + 1;
1198 if (PMC_IS_SYSTEM_MODE(ev->ev_mode))
1199 header_width += 3; /* 2 digit CPU number + '/' */
1201 if (header_width > display_width) {
1202 ev->ev_fieldskip = 0;
1203 ev->ev_fieldwidth = header_width;
1205 ev->ev_fieldskip = display_width -
1207 ev->ev_fieldwidth = display_width;
1212 * If our output is being set to a terminal, register a handler
1213 * for window size changes.
1216 if (isatty(fileno(args.pa_printfile))) {
1218 if (ioctl(fileno(args.pa_printfile), TIOCGWINSZ, &ws) < 0)
1219 err(EX_OSERR, "ERROR: Cannot determine window size");
1221 pmcstat_displayheight = ws.ws_row - 1;
1222 pmcstat_displaywidth = ws.ws_col - 1;
1224 EV_SET(&kev, SIGWINCH, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL);
1226 if (kevent(pmcstat_kq, &kev, 1, NULL, 0, NULL) < 0)
1228 "ERROR: Cannot register kevent for SIGWINCH");
1234 * Listen to key input in top mode.
1236 if (args.pa_flags & FLAG_DO_TOP) {
1237 EV_SET(&kev, fileno(stdin), EVFILT_READ, EV_ADD, 0, 0, NULL);
1238 if (kevent(pmcstat_kq, &kev, 1, NULL, 0, NULL) < 0)
1239 err(EX_OSERR, "ERROR: Cannot register kevent");
1242 EV_SET(&kev, SIGINT, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL);
1243 if (kevent(pmcstat_kq, &kev, 1, NULL, 0, NULL) < 0)
1244 err(EX_OSERR, "ERROR: Cannot register kevent for SIGINT");
1246 EV_SET(&kev, SIGIO, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL);
1247 if (kevent(pmcstat_kq, &kev, 1, NULL, 0, NULL) < 0)
1248 err(EX_OSERR, "ERROR: Cannot register kevent for SIGIO");
1251 * An exec() failure of a forked child is signalled by the
1252 * child sending the parent a SIGCHLD. We don't register an
1253 * actual signal handler for SIGCHLD, but instead use our
1254 * kqueue to pick up the signal.
1256 EV_SET(&kev, SIGCHLD, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL);
1257 if (kevent(pmcstat_kq, &kev, 1, NULL, 0, NULL) < 0)
1258 err(EX_OSERR, "ERROR: Cannot register kevent for SIGCHLD");
1261 * Setup a timer if we have counting mode PMCs needing to be printed or
1262 * top mode plugin is active.
1264 if (((args.pa_flags & FLAG_HAS_COUNTING_PMCS) &&
1265 (args.pa_required & FLAG_HAS_OUTPUT_LOGFILE) == 0) ||
1266 (args.pa_flags & FLAG_DO_TOP)) {
1267 EV_SET(&kev, 0, EVFILT_TIMER, EV_ADD, 0,
1268 args.pa_interval * 1000, NULL);
1270 if (kevent(pmcstat_kq, &kev, 1, NULL, 0, NULL) < 0)
1272 "ERROR: Cannot register kevent for timer");
1275 /* attach PMCs to the target process, starting it if specified */
1276 if (args.pa_flags & FLAG_HAS_COMMANDLINE)
1277 pmcstat_create_process();
1279 if (check_driver_stats && pmc_get_driver_stats(&ds_start) < 0)
1280 err(EX_OSERR, "ERROR: Cannot retrieve driver statistics");
1282 /* Attach process pmcs to the target process. */
1283 if (args.pa_flags & (FLAG_HAS_TARGET | FLAG_HAS_COMMANDLINE)) {
1284 if (SLIST_EMPTY(&args.pa_targets))
1286 "ERROR: No matching target processes.");
1287 if (args.pa_flags & FLAG_HAS_PROCESS_PMCS)
1288 pmcstat_attach_pmcs();
1291 kvm_close(pmcstat_kvm);
1296 /* start the pmcs */
1297 pmcstat_start_pmcs();
1299 /* start the (commandline) process if needed */
1300 if (args.pa_flags & FLAG_HAS_COMMANDLINE)
1301 pmcstat_start_process();
1303 /* initialize logging */
1304 pmcstat_initialize_logging();
1306 /* Handle SIGINT using the kqueue loop */
1307 sa.sa_handler = SIG_IGN;
1309 (void) sigemptyset(&sa.sa_mask);
1311 if (sigaction(SIGINT, &sa, NULL) < 0)
1312 err(EX_OSERR, "ERROR: Cannot install signal handler");
1315 * Setup the top mode display.
1317 if (args.pa_flags & FLAG_DO_TOP) {
1318 args.pa_flags &= ~FLAG_DO_PRINT;
1320 if (args.pa_toptty) {
1325 if(has_colors() == TRUE) {
1326 args.pa_topcolor = 1;
1328 use_default_colors();
1329 pair_content(0, &cf, &cb);
1330 init_pair(1, COLOR_RED, cb);
1331 init_pair(2, COLOR_YELLOW, cb);
1332 init_pair(3, COLOR_GREEN, cb);
1338 intrflush(stdscr, FALSE);
1339 keypad(stdscr, TRUE);
1341 /* Get terminal width / height with ncurses. */
1343 pmcstat_displayheight, pmcstat_displaywidth);
1344 pmcstat_displayheight--; pmcstat_displaywidth--;
1345 atexit(pmcstat_topexit);
1350 * loop till either the target process (if any) exits, or we
1351 * are killed by a SIGINT.
1353 runstate = PMCSTAT_RUNNING;
1354 do_print = do_read = 0;
1356 if ((c = kevent(pmcstat_kq, NULL, 0, &kev, 1, NULL)) <= 0) {
1358 err(EX_OSERR, "ERROR: kevent failed");
1363 if (kev.flags & EV_ERROR)
1364 errc(EX_OSERR, kev.data, "ERROR: kevent failed");
1366 switch (kev.filter) {
1367 case EVFILT_PROC: /* target has exited */
1368 runstate = pmcstat_close_log();
1372 case EVFILT_READ: /* log file data is present */
1373 if (kev.ident == (unsigned)fileno(stdin) &&
1374 (args.pa_flags & FLAG_DO_TOP)) {
1375 if (pmcstat_keypress_log())
1376 runstate = pmcstat_close_log();
1379 runstate = pmcstat_process_log();
1384 if (kev.ident == SIGCHLD) {
1386 * The child process sends us a
1387 * SIGCHLD if its exec() failed. We
1388 * wait for it to exit and then exit
1392 runstate = PMCSTAT_FINISHED;
1393 } else if (kev.ident == SIGIO) {
1395 * We get a SIGIO if a PMC loses all
1396 * of its targets, or if logfile
1397 * writes encounter an error.
1399 runstate = pmcstat_close_log();
1400 do_print = 1; /* print PMCs at exit */
1401 } else if (kev.ident == SIGINT) {
1402 /* Kill the child process if we started it */
1403 if (args.pa_flags & FLAG_HAS_COMMANDLINE)
1404 pmcstat_kill_process();
1405 runstate = pmcstat_close_log();
1406 } else if (kev.ident == SIGWINCH) {
1407 if (ioctl(fileno(args.pa_printfile),
1408 TIOCGWINSZ, &ws) < 0)
1410 "ERROR: Cannot determine window size");
1411 pmcstat_displayheight = ws.ws_row - 1;
1412 pmcstat_displaywidth = ws.ws_col - 1;
1418 case EVFILT_TIMER: /* print out counting PMCs */
1419 if ((args.pa_flags & FLAG_DO_TOP) &&
1420 pmc_flush_logfile() == 0)
1427 if (do_print && !do_read) {
1428 if ((args.pa_required & FLAG_HAS_OUTPUT_LOGFILE) == 0) {
1429 pmcstat_print_pmcs();
1430 if (runstate == PMCSTAT_FINISHED &&
1432 (args.pa_flags & FLAG_DO_PRINT) == 0)
1433 (void) fprintf(args.pa_printfile, "\n");
1435 if (args.pa_flags & FLAG_DO_TOP)
1436 pmcstat_display_log();
1440 } while (runstate != PMCSTAT_FINISHED);
1442 if ((args.pa_flags & FLAG_DO_TOP) && args.pa_toptty) {
1447 /* flush any pending log entries */
1448 if (args.pa_flags & (FLAG_HAS_OUTPUT_LOGFILE | FLAG_HAS_PIPE))
1449 pmc_close_logfile();
1453 free(args.pa_kernel);
1455 /* check if the driver lost any samples or events */
1456 if (check_driver_stats) {
1457 if (pmc_get_driver_stats(&ds_end) < 0)
1459 "ERROR: Cannot retrieve driver statistics");
1460 if (ds_start.pm_intr_bufferfull != ds_end.pm_intr_bufferfull &&
1461 args.pa_verbosity > 0)
1462 warnx("WARNING: some samples were dropped.\n"
1463 "Please consider tuning the \"kern.hwpmc.nsamples\" tunable."
1465 if (ds_start.pm_buffer_requests_failed !=
1466 ds_end.pm_buffer_requests_failed &&
1467 args.pa_verbosity > 0)
1468 warnx("WARNING: some events were discarded.\n"
1469 "Please consider tuning the \"kern.hwpmc.nbuffers\" tunable."