|
Packit |
577717 |
/*
|
|
Packit |
577717 |
* showevtinfo.c - show event information
|
|
Packit |
577717 |
*
|
|
Packit |
577717 |
* Copyright (c) 2006 Hewlett-Packard Development Company, L.P.
|
|
Packit |
577717 |
* Contributed by Stephane Eranian <eranian@hpl.hp.com>
|
|
Packit |
577717 |
*
|
|
Packit |
577717 |
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
Packit |
577717 |
* of this software and associated documentation files (the "Software"), to deal
|
|
Packit |
577717 |
* in the Software without restriction, including without limitation the rights
|
|
Packit |
577717 |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
Packit |
577717 |
* of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
Packit |
577717 |
* subject to the following conditions:
|
|
Packit |
577717 |
*
|
|
Packit |
577717 |
* The above copyright notice and this permission notice shall be included in all
|
|
Packit |
577717 |
* copies or substantial portions of the Software.
|
|
Packit |
577717 |
*
|
|
Packit |
577717 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
Packit |
577717 |
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
Packit |
577717 |
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
Packit |
577717 |
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
|
Packit |
577717 |
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
|
Packit |
577717 |
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
Packit |
577717 |
*
|
|
Packit |
577717 |
* This file is part of libpfm, a performance monitoring support library for
|
|
Packit |
577717 |
* applications on Linux.
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
#include <sys/types.h>
|
|
Packit |
577717 |
#include <stdio.h>
|
|
Packit |
577717 |
#include <stdlib.h>
|
|
Packit |
577717 |
#include <inttypes.h>
|
|
Packit |
577717 |
#include <stdarg.h>
|
|
Packit |
577717 |
#include <errno.h>
|
|
Packit |
577717 |
#include <unistd.h>
|
|
Packit |
577717 |
#include <string.h>
|
|
Packit |
577717 |
#include <regex.h>
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#include <perfmon/pfmlib.h>
|
|
Packit |
577717 |
|
|
Packit |
577717 |
static void fatal_error(char *fmt,...) __attribute__((noreturn));
|
|
Packit |
577717 |
|
|
Packit |
577717 |
static size_t max_len;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
static void
|
|
Packit |
577717 |
fatal_error(char *fmt, ...)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
va_list ap;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
va_start(ap, fmt);
|
|
Packit |
577717 |
vfprintf(stderr, fmt, ap);
|
|
Packit |
577717 |
va_end(ap);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
exit(1);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
static void
|
|
Packit |
577717 |
show_event_info(char *name, unsigned int idx)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
pfmlib_regmask_t cnt, impl_cnt;
|
|
Packit |
577717 |
char *desc;
|
|
Packit |
577717 |
unsigned int n1, n2, i, c;
|
|
Packit |
577717 |
int code, prev_code = 0, first = 1;
|
|
Packit |
577717 |
int ret;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
pfm_get_event_counters(idx, &cnt);
|
|
Packit |
577717 |
pfm_get_num_counters(&n2;;
|
|
Packit |
577717 |
pfm_get_impl_counters(&impl_cnt);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
n1 = n2;
|
|
Packit |
577717 |
printf("#-----------------------------\n"
|
|
Packit |
577717 |
"Name : %s\n",
|
|
Packit |
577717 |
name);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
pfm_get_event_description(idx, &desc);
|
|
Packit |
577717 |
printf("Desc : %s\n", desc);
|
|
Packit |
577717 |
free(desc);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
printf("Code :");
|
|
Packit |
577717 |
for (i=0; n1; i++) {
|
|
Packit |
577717 |
if (pfm_regmask_isset(&impl_cnt, i))
|
|
Packit |
577717 |
n1--;
|
|
Packit |
577717 |
if (pfm_regmask_isset(&cnt, i)) {
|
|
Packit |
577717 |
pfm_get_event_code_counter(idx,i,&code);
|
|
Packit |
577717 |
if (first == 1 || code != prev_code) {
|
|
Packit |
577717 |
printf(" 0x%x", code);
|
|
Packit |
577717 |
first = 0;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
prev_code = code;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
putchar('\n');
|
|
Packit |
577717 |
|
|
Packit |
577717 |
n1 = n2;
|
|
Packit |
577717 |
printf("Counters : [ ");
|
|
Packit |
577717 |
for (i=0; n1; i++) {
|
|
Packit |
577717 |
if (pfm_regmask_isset(&impl_cnt, i))
|
|
Packit |
577717 |
n1--;
|
|
Packit |
577717 |
if (pfm_regmask_isset(&cnt, i))
|
|
Packit |
577717 |
printf("%d ", i);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
puts("]");
|
|
Packit |
577717 |
pfm_get_num_event_masks(idx, &n1;;
|
|
Packit |
577717 |
for (i = 0; i < n1; i++) {
|
|
Packit |
577717 |
ret = pfm_get_event_mask_name(idx, i, name, max_len+1);
|
|
Packit |
577717 |
if (ret != PFMLIB_SUCCESS)
|
|
Packit |
577717 |
continue;
|
|
Packit |
577717 |
pfm_get_event_mask_description(idx, i, &desc);
|
|
Packit |
577717 |
pfm_get_event_mask_code(idx, i, &c);
|
|
Packit |
577717 |
printf("Umask-%02u : 0x%02x : [%s] : %s\n", i, c, name, desc);
|
|
Packit |
577717 |
free(desc);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#define MAX_PMU_NAME_LEN 32
|
|
Packit |
577717 |
int
|
|
Packit |
577717 |
main(int argc, char **argv)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
unsigned int i, count, match;
|
|
Packit |
577717 |
int ret;
|
|
Packit |
577717 |
char *name;
|
|
Packit |
577717 |
regex_t preg;
|
|
Packit |
577717 |
char model[MAX_PMU_NAME_LEN];
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if (pfm_initialize() != PFMLIB_SUCCESS)
|
|
Packit |
577717 |
fatal_error("PMU model not supported by library\n");
|
|
Packit |
577717 |
|
|
Packit |
577717 |
pfm_get_max_event_name_len(&max_len);
|
|
Packit |
577717 |
name = malloc(max_len+1);
|
|
Packit |
577717 |
if (name == NULL)
|
|
Packit |
577717 |
fatal_error("cannot allocate name buffer\n");
|
|
Packit |
577717 |
|
|
Packit |
577717 |
pfm_get_num_events(&count);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if (argc == 1)
|
|
Packit |
577717 |
*argv = ".*"; /* match everything */
|
|
Packit |
577717 |
else
|
|
Packit |
577717 |
++argv;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
pfm_get_pmu_name(model, MAX_PMU_NAME_LEN);
|
|
Packit |
577717 |
printf("PMU model: %s\n", model);
|
|
Packit |
577717 |
while(*argv) {
|
|
Packit |
577717 |
if (regcomp(&preg, *argv, REG_ICASE|REG_NOSUB))
|
|
Packit |
577717 |
fatal_error("error in regular expression for event \"%s\"\n", *argv);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
match = 0;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
for(i=0; i < count; i++) {
|
|
Packit |
577717 |
ret = pfm_get_event_name(i, name, max_len+1);
|
|
Packit |
577717 |
/* skip unsupported events */
|
|
Packit |
577717 |
if (ret != PFMLIB_SUCCESS)
|
|
Packit |
577717 |
continue;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if (regexec(&preg, name, 0, NULL, 0) == 0) {
|
|
Packit |
577717 |
show_event_info(name, i);
|
|
Packit |
577717 |
match++;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
if (match == 0)
|
|
Packit |
577717 |
fatal_error("event %s not found\n", *argv);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
argv++;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
free(name);
|
|
Packit |
577717 |
return 0;
|
|
Packit |
577717 |
}
|