2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2018, Matthew Macy
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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
31 #include <sys/types.h>
32 #include <sys/errno.h>
33 #include <sys/sysctl.h>
41 #include <libpmcstat.h>
45 #include <libpmcstat.h>
48 int pmc_displayheight = DEFAULT_DISPLAY_HEIGHT;
49 int pmc_displaywidth = DEFAULT_DISPLAY_WIDTH;
51 struct pmcstat_args pmc_args;
53 struct pmcstat_pmcs pmcstat_pmcs = LIST_HEAD_INITIALIZER(pmcstat_pmcs);
55 struct pmcstat_image_hash_list pmcstat_image_hash[PMCSTAT_NHASH];
57 struct pmcstat_process_hash_list pmcstat_process_hash[PMCSTAT_NHASH];
64 static struct cmd_handler disp_table[] = {
65 {"stat", cmd_pmc_stat},
66 {"stat-system", cmd_pmc_stat_system},
67 {"list-events", cmd_pmc_list_events},
68 {"filter", cmd_pmc_filter},
69 {"summary", cmd_pmc_summary},
77 "\t pmc management utility\n"
78 "\t stat <program> run program and print stats\n"
79 "\t stat-system <program> run program and print system wide stats for duration of execution\n"
80 "\t list-events list PMC events available on host\n"
81 "\t filter filter records by lwp, pid, or event\n"
86 disp_lookup(char *name)
88 struct cmd_handler *hnd;
90 for (hnd = disp_table; hnd->ch_name != NULL; hnd++)
91 if (strcmp(hnd->ch_name, name) == 0)
97 main(int argc, char **argv)
101 pmc_args.pa_printfile = stderr;
102 STAILQ_INIT(&pmc_args.pa_events);
103 SLIST_INIT(&pmc_args.pa_targets);
106 if ((disp = disp_lookup(argv[1])) == NULL)
111 /* Allocate a kqueue */
112 if ((pmc_kq = kqueue()) < 0)
113 err(EX_OSERR, "ERROR: Cannot allocate kqueue");
116 "ERROR: Initialization of the pmc(3) library failed"
118 return (disp(argc, argv));