1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 2018, Matthew Macy
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 */
28
29 #include <sys/cdefs.h>
30 #include <sys/param.h>
31 #include <sys/cpuset.h>
32 #include <sys/event.h>
33 #include <sys/queue.h>
34 #include <sys/socket.h>
35 #include <sys/stat.h>
36 #include <sys/sysctl.h>
37 #include <sys/time.h>
38 #include <sys/ttycom.h>
39 #include <sys/user.h>
40 #include <sys/wait.h>
41
42 #include <assert.h>
43 #include <curses.h>
44 #include <err.h>
45 #include <errno.h>
46 #include <fcntl.h>
47 #include <getopt.h>
48 #include <kvm.h>
49 #include <libgen.h>
50 #include <limits.h>
51 #include <locale.h>
52 #include <math.h>
53 #include <pmc.h>
54 #include <pmclog.h>
55 #include <regex.h>
56 #include <signal.h>
57 #include <stdarg.h>
58 #include <stdint.h>
59 #include <stdio.h>
60 #include <stdlib.h>
61 #include <string.h>
62 #include <sysexits.h>
63 #include <unistd.h>
64
65 #include <libpmcstat.h>
66 #include "cmd_pmc.h"
67
68
69 static struct option longopts[] = {
70 {"long-desc", no_argument, NULL, 'U'},
71 {"desc", no_argument, NULL, 'u'},
72 {"full", no_argument, NULL, 'f'},
73 {NULL, 0, NULL, 0}
74 };
75
76 static void __dead2
usage(void)77 usage(void)
78 {
79 errx(EX_USAGE,
80 "\t list events\n"
81 "\t -u, desc -- short description of event\n"
82 "\t -U, long-desc -- long description of event\n"
83 "\t -f, full -- full event details\n"
84 );
85 }
86
87 int
cmd_pmc_list_events(int argc,char ** argv)88 cmd_pmc_list_events(int argc, char **argv)
89 {
90 int do_long_descr, do_descr, do_full;
91 int option;
92
93 do_long_descr = do_descr = do_full = 0;
94 while ((option = getopt_long(argc, argv, "Uuf", longopts, NULL)) != -1) {
95 switch (option) {
96 case 'U':
97 do_long_descr = 1;
98 break;
99 case 'u':
100 do_descr = 1;
101 break;
102 case 'f':
103 do_full = 1;
104 break;
105 case '?':
106 default:
107 usage();
108 }
109 }
110 argc -= optind;
111 argv += optind;
112 if ((do_long_descr | do_descr | do_full) && argc == 0) {
113 warnx("event or event substring required when option provided\n");
114 usage();
115 }
116 if (do_full)
117 pmc_pmu_print_counter_full(argc ? argv[0] : NULL);
118 else if (do_long_descr)
119 pmc_pmu_print_counter_desc_long(argv[0]);
120 else if (do_descr)
121 pmc_pmu_print_counter_desc(argv[0]);
122 else
123 pmc_pmu_print_counters(argv[0]);
124
125 return (0);
126 }
127