Commit | Line | Data |
---|---|---|
6faa26ca | 1 | /* |
9d16b343 | 2 | * Copyright (C) 2016 Julien Desfossez <jdesfossez@efficios.com> |
6faa26ca | 3 | * |
9d16b343 | 4 | * SPDX-License-Identifier: GPL-2.0-only |
6faa26ca | 5 | * |
6faa26ca JD |
6 | */ |
7 | ||
8 | #include <stdio.h> | |
9 | #include <perfmon/pfmlib.h> | |
10 | #include <string.h> | |
11 | ||
12 | int main(int argc, char **argv) | |
13 | { | |
14 | int ret, i; | |
15 | unsigned int j; | |
16 | pfm_pmu_info_t pinfo; | |
17 | ||
18 | if (argc != 2) { | |
19 | fprintf(stderr, "Usage: %s <pmu counter to find>\n" | |
20 | "ex: %s UNHALTED_REFERENCE_CYCLES\n" | |
21 | "Returns the first occurence it finds with " | |
22 | "return code 0.\n" | |
23 | "If not found returns 1, on error returns -1\n", | |
24 | argv[0], argv[0]); | |
25 | ret = -1; | |
26 | goto end; | |
27 | } | |
28 | ||
29 | memset(&pinfo, 0, sizeof(pinfo)); | |
30 | pinfo.size = sizeof(pinfo); | |
31 | ||
32 | ret = pfm_initialize(); | |
33 | if (ret != PFM_SUCCESS) { | |
34 | fprintf(stderr, "Failed to initialise libpfm: %s", | |
35 | pfm_strerror(ret)); | |
36 | ret = -1; | |
37 | goto end; | |
38 | } | |
39 | ||
40 | pfm_for_all_pmus(j) { | |
41 | ret = pfm_get_pmu_info(j, &pinfo); | |
42 | if (ret != PFM_SUCCESS) { | |
43 | continue; | |
44 | } | |
45 | ||
46 | for (i = pinfo.first_event; i != -1; i = pfm_get_event_next(i)) { | |
47 | pfm_event_info_t info = | |
48 | { .size = sizeof(pfm_event_info_t) }; | |
49 | ||
50 | ret = pfm_get_event_info(i, PFM_OS_NONE, &info); | |
51 | if (ret != PFM_SUCCESS) { | |
52 | fprintf(stderr, "Cannot get event info: %s\n", | |
53 | pfm_strerror(ret)); | |
54 | ret = -1; | |
55 | goto end; | |
56 | } | |
57 | ||
58 | if (info.pmu != j) { | |
59 | continue; | |
60 | } | |
61 | ||
62 | if (strcmp(info.name, argv[1]) == 0) { | |
63 | fprintf(stdout, "r%" PRIx64 "\n", info.code); | |
64 | ret = 0; | |
65 | goto end; | |
66 | } | |
67 | } | |
68 | } | |
69 | ||
70 | ret = 1; | |
71 | ||
72 | end: | |
73 | return ret; | |
74 | } |