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