[lttng-dev] [PATCH lttng-tools v3 3/3] Create a dedicated test suite for Perf
Julien Desfossez
jdesfossez at efficios.com
Wed Jul 6 16:06:24 UTC 2016
> diff --git a/tests/perf/find_event.c b/tests/perf/find_event.c
> new file mode 100644
> index 0000000..ae63800
> --- /dev/null
> +++ b/tests/perf/find_event.c
> @@ -0,0 +1,83 @@
> +/*
> + * Copyright (c) 2016 Julien Desfossez <jdesfossez at efficios.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * as published by the Free Software Foundation; only version 2
> + * of the License.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with this program; if not, write to the Free Software Foundation, Inc.,
> + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
> + */
> +
> +#include <stdio.h>
> +#include <perfmon/pfmlib.h>
> +#include <string.h>
> +
> +int main(int argc, char **argv)
> +{
> + int ret, i;
> + unsigned int j;
> + pfm_pmu_info_t pinfo;
> +
> + if (argc != 2) {
> + fprintf(stderr, "Usage: %s <pmu counter to find>\n"
> + "ex: %s UNHALTED_REFERENCE_CYCLES\n"
> + "Returns the first occurence it finds with "
> + "return code 0.\n"
> + "If not found returns 1, on error returns -1\n",
> + argv[0], argv[0]);
> + ret = -1;
> + goto end;
> + }
> +
> + memset(&pinfo, 0, sizeof(pinfo));
> + pinfo.size = sizeof(pinfo);
> +
> + ret = pfm_initialize();
> + if (ret != PFM_SUCCESS) {
> + fprintf(stderr, "Failed to initialise libpfm: %s",
> + pfm_strerror(ret));
> + ret = -1;
> + goto end;
> + }
> +
> + pfm_for_all_pmus(j) {
> + ret = pfm_get_pmu_info(j, &pinfo);
> + if (ret != PFM_SUCCESS) {
> + continue;
> + }
> +
> + for (i = pinfo.first_event; i != -1; i = pfm_get_event_next(i)) {
> + pfm_event_info_t info;
> +
> + ret = pfm_get_event_info(i, PFM_OS_NONE, &info);
> + if (ret != PFM_SUCCESS) {
> + fprintf(stderr, "Cannot get event info: %s\n",
> + pfm_strerror(ret));
> + ret = -1;
> + goto end;
> + }
> +
> + if (info.pmu != j)
> + continue;
> +
> + if (strcmp(info.name, argv[1]) == 0) {
> + fprintf(stdout, "r%lx\n", info.code);
This should be:
fprintf(stdout, "r%" PRIx64 "\n", info.code);
I will wait for other comments if any before resubmitting a new version
(or you can directly apply the fix when you merge).
Thanks,
Julien
More information about the lttng-dev
mailing list