2005-04-19 04:01:25 +00:00
|
|
|
/*-
|
2017-11-27 15:37:16 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2005-04-19 04:01:25 +00:00
|
|
|
* Copyright (c) 2003,2004 Joseph Koshy
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2011-05-06 15:31:27 +00:00
|
|
|
#include <sys/param.h>
|
2005-04-19 04:01:25 +00:00
|
|
|
#include <sys/queue.h>
|
2011-07-15 11:46:54 +00:00
|
|
|
#include <sys/cpuset.h>
|
2005-04-19 04:01:25 +00:00
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <pmc.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sysexits.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
/* Compile time defaults */
|
|
|
|
|
|
|
|
#define PMCC_PRINT_USAGE 0
|
|
|
|
#define PMCC_PRINT_EVENTS 1
|
|
|
|
#define PMCC_LIST_STATE 2
|
|
|
|
#define PMCC_ENABLE_DISABLE 3
|
|
|
|
#define PMCC_SHOW_STATISTICS 4
|
|
|
|
|
|
|
|
#define PMCC_CPU_ALL -1
|
|
|
|
#define PMCC_CPU_WILDCARD '*'
|
|
|
|
|
|
|
|
#define PMCC_PMC_ALL -1
|
|
|
|
#define PMCC_PMC_WILDCARD '*'
|
|
|
|
|
|
|
|
#define PMCC_OP_IGNORE 0
|
|
|
|
#define PMCC_OP_DISABLE 1
|
|
|
|
#define PMCC_OP_ENABLE 2
|
|
|
|
|
|
|
|
#define PMCC_PROGRAM_NAME "pmccontrol"
|
|
|
|
|
2012-10-19 14:49:42 +00:00
|
|
|
static STAILQ_HEAD(pmcc_op_list, pmcc_op) head = STAILQ_HEAD_INITIALIZER(head);
|
2005-04-19 04:01:25 +00:00
|
|
|
|
|
|
|
struct pmcc_op {
|
|
|
|
char op_cpu;
|
|
|
|
char op_pmc;
|
|
|
|
char op_op;
|
|
|
|
STAILQ_ENTRY(pmcc_op) op_next;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Function Prototypes */
|
|
|
|
#if DEBUG
|
|
|
|
static void pmcc_init_debug(void);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int pmcc_do_list_state(void);
|
|
|
|
static int pmcc_do_enable_disable(struct pmcc_op_list *);
|
|
|
|
static int pmcc_do_list_events(void);
|
|
|
|
|
|
|
|
/* Globals */
|
|
|
|
|
|
|
|
static char usage_message[] =
|
|
|
|
"Usage:\n"
|
2005-06-24 15:43:13 +00:00
|
|
|
" " PMCC_PROGRAM_NAME " -L\n"
|
2005-04-19 04:01:25 +00:00
|
|
|
" " PMCC_PROGRAM_NAME " -l\n"
|
|
|
|
" " PMCC_PROGRAM_NAME " -s\n"
|
|
|
|
" " PMCC_PROGRAM_NAME " [-e pmc | -d pmc | -c cpu] ...";
|
|
|
|
|
|
|
|
#if DEBUG
|
2012-10-19 14:49:42 +00:00
|
|
|
static FILE *debug_stream = NULL;
|
2005-04-19 04:01:25 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
#define DEBUG_MSG(...) \
|
|
|
|
(void) fprintf(debug_stream, "[pmccontrol] " __VA_ARGS__);
|
|
|
|
#else
|
|
|
|
#define DEBUG_MSG(m) /* */
|
|
|
|
#endif /* !DEBUG */
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
/* log debug messages to a separate file */
|
|
|
|
static void
|
|
|
|
pmcc_init_debug(void)
|
|
|
|
{
|
|
|
|
char *fn;
|
|
|
|
|
|
|
|
fn = getenv("PMCCONTROL_DEBUG");
|
|
|
|
if (fn != NULL)
|
|
|
|
{
|
|
|
|
debug_stream = fopen(fn, "w");
|
|
|
|
if (debug_stream == NULL)
|
|
|
|
debug_stream = stderr;
|
|
|
|
} else
|
|
|
|
debug_stream = stderr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int
|
|
|
|
pmcc_do_enable_disable(struct pmcc_op_list *op_list)
|
|
|
|
{
|
|
|
|
int c, error, i, j, ncpu, npmc, t;
|
|
|
|
struct pmcc_op *np;
|
|
|
|
unsigned char *map;
|
2008-11-09 08:36:35 +00:00
|
|
|
unsigned char op;
|
|
|
|
int cpu, pmc;
|
2005-04-19 04:01:25 +00:00
|
|
|
|
|
|
|
if ((ncpu = pmc_ncpu()) < 0)
|
|
|
|
err(EX_OSERR, "Unable to determine the number of cpus");
|
|
|
|
|
2008-11-09 08:36:35 +00:00
|
|
|
/* Determine the maximum number of PMCs in any CPU. */
|
2005-04-19 04:01:25 +00:00
|
|
|
npmc = 0;
|
|
|
|
for (c = 0; c < ncpu; c++) {
|
|
|
|
if ((t = pmc_npmc(c)) < 0)
|
2011-11-15 06:44:07 +00:00
|
|
|
err(EX_OSERR,
|
|
|
|
"Unable to determine the number of PMCs in CPU %d",
|
|
|
|
c);
|
2016-04-22 05:07:59 +00:00
|
|
|
npmc = MAX(t, npmc);
|
2005-04-19 04:01:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (npmc == 0)
|
|
|
|
errx(EX_CONFIG, "No PMCs found");
|
|
|
|
|
2015-02-22 14:45:00 +00:00
|
|
|
if ((map = calloc(npmc, ncpu)) == NULL)
|
2005-04-19 04:01:25 +00:00
|
|
|
err(EX_SOFTWARE, "Out of memory");
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
STAILQ_FOREACH(np, op_list, op_next) {
|
|
|
|
|
|
|
|
cpu = np->op_cpu;
|
|
|
|
pmc = np->op_pmc;
|
|
|
|
op = np->op_op;
|
|
|
|
|
|
|
|
if (cpu >= ncpu)
|
|
|
|
errx(EX_DATAERR, "CPU id too large: \"%d\"", cpu);
|
|
|
|
|
|
|
|
if (pmc >= npmc)
|
|
|
|
errx(EX_DATAERR, "PMC id too large: \"%d\"", pmc);
|
|
|
|
|
|
|
|
#define MARKMAP(M,C,P,V) do { \
|
|
|
|
*((M) + (C)*npmc + (P)) = (V); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define SET_PMCS(C,P,V) do { \
|
|
|
|
if ((P) == PMCC_PMC_ALL) { \
|
|
|
|
for (j = 0; j < npmc; j++) \
|
|
|
|
MARKMAP(map, (C), j, (V)); \
|
|
|
|
} else \
|
|
|
|
MARKMAP(map, (C), (P), (V)); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define MAP(M,C,P) (*((M) + (C)*npmc + (P)))
|
|
|
|
|
|
|
|
if (cpu == PMCC_CPU_ALL)
|
2008-11-09 08:36:35 +00:00
|
|
|
for (i = 0; i < ncpu; i++) {
|
2011-07-15 11:30:41 +00:00
|
|
|
SET_PMCS(i, pmc, op);
|
2008-11-09 08:36:35 +00:00
|
|
|
}
|
2005-04-19 04:01:25 +00:00
|
|
|
else
|
|
|
|
SET_PMCS(cpu, pmc, op);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Configure PMCS */
|
|
|
|
for (i = 0; i < ncpu; i++)
|
|
|
|
for (j = 0; j < npmc; j++) {
|
|
|
|
unsigned char b;
|
|
|
|
|
|
|
|
b = MAP(map, i, j);
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
if (b == PMCC_OP_ENABLE)
|
|
|
|
error = pmc_enable(i, j);
|
|
|
|
else if (b == PMCC_OP_DISABLE)
|
|
|
|
error = pmc_disable(i, j);
|
|
|
|
|
|
|
|
if (error < 0)
|
|
|
|
err(EX_OSERR, "%s of PMC %d on CPU %d failed",
|
2011-11-15 06:44:07 +00:00
|
|
|
b == PMCC_OP_ENABLE ? "Enable" : "Disable",
|
|
|
|
j, i);
|
2005-04-19 04:01:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pmcc_do_list_state(void)
|
|
|
|
{
|
2011-07-15 11:46:54 +00:00
|
|
|
cpuset_t logical_cpus_mask;
|
|
|
|
long cpusetsize;
|
|
|
|
size_t setsize;
|
2005-04-19 04:01:25 +00:00
|
|
|
int c, cpu, n, npmc, ncpu;
|
|
|
|
struct pmc_info *pd;
|
2005-06-09 19:45:09 +00:00
|
|
|
struct pmc_pmcinfo *pi;
|
|
|
|
const struct pmc_cpuinfo *pc;
|
2005-04-19 04:01:25 +00:00
|
|
|
|
|
|
|
if (pmc_cpuinfo(&pc) != 0)
|
|
|
|
err(EX_OSERR, "Unable to determine CPU information");
|
|
|
|
|
2010-10-11 14:31:24 +00:00
|
|
|
printf("%d %s CPUs present, with %d PMCs per CPU\n", pc->pm_ncpu,
|
|
|
|
pmc_name_of_cputype(pc->pm_cputype),
|
|
|
|
pc->pm_npmc);
|
|
|
|
|
2011-07-15 11:46:54 +00:00
|
|
|
/* Determine the set of logical CPUs. */
|
|
|
|
cpusetsize = sysconf(_SC_CPUSET_SIZE);
|
|
|
|
if (cpusetsize == -1 || (u_long)cpusetsize > sizeof(cpuset_t))
|
|
|
|
err(EX_OSERR, "Cannot determine which CPUs are logical");
|
|
|
|
CPU_ZERO(&logical_cpus_mask);
|
|
|
|
setsize = (size_t)cpusetsize;
|
2005-04-19 04:01:25 +00:00
|
|
|
if (sysctlbyname("machdep.logical_cpus_mask", &logical_cpus_mask,
|
2011-07-15 11:46:54 +00:00
|
|
|
&setsize, NULL, 0) < 0)
|
|
|
|
CPU_ZERO(&logical_cpus_mask);
|
2005-04-19 04:01:25 +00:00
|
|
|
|
|
|
|
ncpu = pc->pm_ncpu;
|
|
|
|
|
|
|
|
for (c = cpu = 0; cpu < ncpu; cpu++) {
|
2006-02-27 14:25:32 +00:00
|
|
|
#if defined(__i386__) || defined(__amd64__)
|
2005-04-19 04:01:25 +00:00
|
|
|
if (pc->pm_cputype == PMC_CPU_INTEL_PIV &&
|
2011-07-15 11:46:54 +00:00
|
|
|
CPU_ISSET(cpu, &logical_cpus_mask))
|
2005-04-19 04:01:25 +00:00
|
|
|
continue; /* skip P4-style 'logical' cpus */
|
|
|
|
#endif
|
2008-11-16 04:26:38 +00:00
|
|
|
if (pmc_pmcinfo(cpu, &pi) < 0) {
|
|
|
|
if (errno == ENXIO)
|
|
|
|
continue;
|
2005-04-19 04:01:25 +00:00
|
|
|
err(EX_OSERR, "Unable to get PMC status for CPU %d",
|
|
|
|
cpu);
|
2008-11-16 04:26:38 +00:00
|
|
|
}
|
2005-04-19 04:01:25 +00:00
|
|
|
|
|
|
|
printf("#CPU %d:\n", c++);
|
|
|
|
npmc = pmc_npmc(cpu);
|
|
|
|
printf("#N NAME CLASS STATE ROW-DISP\n");
|
|
|
|
|
|
|
|
for (n = 0; n < npmc; n++) {
|
|
|
|
pd = &pi->pm_pmcs[n];
|
|
|
|
|
|
|
|
printf(" %-2d %-16s %-6s %-8s %-10s",
|
|
|
|
n,
|
|
|
|
pd->pm_name,
|
|
|
|
pmc_name_of_class(pd->pm_class),
|
|
|
|
pd->pm_enabled ? "ENABLED" : "DISABLED",
|
|
|
|
pmc_name_of_disposition(pd->pm_rowdisp));
|
|
|
|
|
|
|
|
if (pd->pm_ownerpid != -1) {
|
|
|
|
printf(" (pid %d)", pd->pm_ownerpid);
|
|
|
|
printf(" %-32s",
|
|
|
|
pmc_name_of_event(pd->pm_event));
|
|
|
|
if (PMC_IS_SAMPLING_MODE(pd->pm_mode))
|
|
|
|
printf(" (reload count %jd)",
|
|
|
|
pd->pm_reloadcount);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
free(pi);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pmcc_do_list_events(void)
|
|
|
|
{
|
|
|
|
enum pmc_class c;
|
|
|
|
unsigned int i, j, nevents;
|
|
|
|
const char **eventnamelist;
|
2005-06-09 19:45:09 +00:00
|
|
|
const struct pmc_cpuinfo *ci;
|
2005-04-19 04:01:25 +00:00
|
|
|
|
|
|
|
if (pmc_cpuinfo(&ci) != 0)
|
|
|
|
err(EX_OSERR, "Unable to determine CPU information");
|
|
|
|
|
|
|
|
eventnamelist = NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < ci->pm_nclass; i++) {
|
2005-05-01 14:11:49 +00:00
|
|
|
c = ci->pm_classes[i].pm_class;
|
2005-04-19 04:01:25 +00:00
|
|
|
|
|
|
|
printf("%s\n", pmc_name_of_class(c));
|
|
|
|
if (pmc_event_names_of_class(c, &eventnamelist, &nevents) < 0)
|
2011-11-15 06:44:07 +00:00
|
|
|
err(EX_OSERR,
|
|
|
|
"ERROR: Cannot find information for event class \"%s\"",
|
|
|
|
pmc_name_of_class(c));
|
2005-04-19 04:01:25 +00:00
|
|
|
|
|
|
|
for (j = 0; j < nevents; j++)
|
|
|
|
printf("\t%s\n", eventnamelist[j]);
|
|
|
|
|
|
|
|
free(eventnamelist);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pmcc_show_statistics(void)
|
|
|
|
{
|
|
|
|
|
2005-06-09 19:45:09 +00:00
|
|
|
struct pmc_driverstats gms;
|
2005-04-19 04:01:25 +00:00
|
|
|
|
|
|
|
if (pmc_get_driver_stats(&gms) < 0)
|
|
|
|
err(EX_OSERR, "ERROR: cannot retrieve driver statistics");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print statistics.
|
|
|
|
*/
|
|
|
|
|
2005-06-09 19:45:09 +00:00
|
|
|
#define PRINT(N,V) (void) printf("%-40s %d\n", (N), gms.pm_##V)
|
|
|
|
PRINT("interrupts processed:", intr_processed);
|
|
|
|
PRINT("non-PMC interrupts:", intr_ignored);
|
2005-09-29 01:40:03 +00:00
|
|
|
PRINT("sampling stalls due to space shortages:", intr_bufferfull);
|
2005-06-09 19:45:09 +00:00
|
|
|
PRINT("system calls:", syscalls);
|
|
|
|
PRINT("system calls with errors:", syscall_errors);
|
|
|
|
PRINT("buffer requests:", buffer_requests);
|
|
|
|
PRINT("buffer requests failed:", buffer_requests_failed);
|
|
|
|
PRINT("sampling log sweeps:", log_sweeps);
|
2005-04-19 04:01:25 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Main
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int error, command, currentcpu, option, pmc;
|
|
|
|
char *dummy;
|
|
|
|
struct pmcc_op *p;
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
pmcc_init_debug();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* parse args */
|
|
|
|
|
|
|
|
currentcpu = PMCC_CPU_ALL;
|
|
|
|
command = PMCC_PRINT_USAGE;
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
STAILQ_INIT(&head);
|
|
|
|
|
|
|
|
while ((option = getopt(argc, argv, ":c:d:e:lLs")) != -1)
|
|
|
|
switch (option) {
|
|
|
|
case 'L':
|
|
|
|
if (command != PMCC_PRINT_USAGE) {
|
|
|
|
error = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
command = PMCC_PRINT_EVENTS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'c':
|
|
|
|
if (command != PMCC_PRINT_USAGE &&
|
|
|
|
command != PMCC_ENABLE_DISABLE) {
|
|
|
|
error = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
command = PMCC_ENABLE_DISABLE;
|
|
|
|
|
|
|
|
if (*optarg == PMCC_CPU_WILDCARD)
|
|
|
|
currentcpu = PMCC_CPU_ALL;
|
|
|
|
else {
|
|
|
|
currentcpu = strtoul(optarg, &dummy, 0);
|
|
|
|
if (*dummy != '\0' || currentcpu < 0)
|
|
|
|
errx(EX_DATAERR,
|
|
|
|
"\"%s\" is not a valid CPU id",
|
|
|
|
optarg);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'd':
|
|
|
|
case 'e':
|
|
|
|
if (command != PMCC_PRINT_USAGE &&
|
|
|
|
command != PMCC_ENABLE_DISABLE) {
|
|
|
|
error = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
command = PMCC_ENABLE_DISABLE;
|
|
|
|
|
|
|
|
if (*optarg == PMCC_PMC_WILDCARD)
|
|
|
|
pmc = PMCC_PMC_ALL;
|
|
|
|
else {
|
|
|
|
pmc = strtoul(optarg, &dummy, 0);
|
|
|
|
if (*dummy != '\0' || pmc < 0)
|
|
|
|
errx(EX_DATAERR,
|
|
|
|
"\"%s\" is not a valid PMC id",
|
|
|
|
optarg);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((p = malloc(sizeof(*p))) == NULL)
|
|
|
|
err(EX_SOFTWARE, "Out of memory");
|
|
|
|
|
|
|
|
p->op_cpu = currentcpu;
|
|
|
|
p->op_pmc = pmc;
|
|
|
|
p->op_op = option == 'd' ? PMCC_OP_DISABLE :
|
|
|
|
PMCC_OP_ENABLE;
|
|
|
|
|
|
|
|
STAILQ_INSERT_TAIL(&head, p, op_next);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'l':
|
|
|
|
if (command != PMCC_PRINT_USAGE) {
|
|
|
|
error = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
command = PMCC_LIST_STATE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 's':
|
|
|
|
if (command != PMCC_PRINT_USAGE) {
|
|
|
|
error = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
command = PMCC_SHOW_STATISTICS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ':':
|
|
|
|
errx(EX_USAGE,
|
|
|
|
"Missing argument to option '-%c'", optopt);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '?':
|
|
|
|
warnx("Unrecognized option \"-%c\"", optopt);
|
2011-12-17 23:39:13 +00:00
|
|
|
errx(EX_USAGE, "%s", usage_message);
|
2005-04-19 04:01:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (command == PMCC_PRINT_USAGE)
|
2011-12-17 23:39:13 +00:00
|
|
|
(void) errx(EX_USAGE, "%s", usage_message);
|
2005-04-19 04:01:25 +00:00
|
|
|
|
|
|
|
if (error)
|
|
|
|
exit(EX_USAGE);
|
|
|
|
|
|
|
|
if (pmc_init() < 0)
|
|
|
|
err(EX_UNAVAILABLE,
|
|
|
|
"Initialization of the pmc(3) library failed");
|
|
|
|
|
|
|
|
switch (command) {
|
|
|
|
case PMCC_LIST_STATE:
|
|
|
|
error = pmcc_do_list_state();
|
|
|
|
break;
|
|
|
|
case PMCC_PRINT_EVENTS:
|
|
|
|
error = pmcc_do_list_events();
|
|
|
|
break;
|
|
|
|
case PMCC_SHOW_STATISTICS:
|
|
|
|
error = pmcc_show_statistics();
|
|
|
|
break;
|
|
|
|
case PMCC_ENABLE_DISABLE:
|
|
|
|
if (STAILQ_EMPTY(&head))
|
2011-11-15 06:44:07 +00:00
|
|
|
errx(EX_USAGE,
|
|
|
|
"No PMCs specified to enable or disable");
|
2005-04-19 04:01:25 +00:00
|
|
|
error = pmcc_do_enable_disable(&head);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error != 0)
|
|
|
|
err(EX_OSERR, "Command failed");
|
|
|
|
exit(0);
|
|
|
|
}
|