Skip to content

Instantly share code, notes, and snippets.

@vtta
Last active May 16, 2022 08:14
Show Gist options
  • Select an option

  • Save vtta/0874cf27a7df6cd59dae61bb92552219 to your computer and use it in GitHub Desktop.

Select an option

Save vtta/0874cf27a7df6cd59dae61bb92552219 to your computer and use it in GitHub Desktop.
gcc perf_raw_event_code.c -lpfm -o perf_raw_event_code
#include <err.h>
#include <inttypes.h>
#include <perfmon/pfmlib.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
if (argc < 2) {
errx(1, "Usage: %s EVENT...\n", argv[0]);
}
int ret = pfm_initialize();
if (ret != PFM_SUCCESS) {
errx(1, "cannot initialize library %s", pfm_strerror(ret));
}
for (int i = 1; i < argc; ++i) {
printf("%s\n", argv[i]);
pfm_pmu_encode_arg_t arg = {};
ret = pfm_get_os_event_encoding(argv[i], PFM_PLM3, PFM_OS_NONE, &arg);
if (ret != PFM_SUCCESS) {
err(1, " cannot get encoding %s", pfm_strerror(ret));
}
for (int j = 0; j < arg.count; j++) {
printf("count[%d]=0x%" PRIx64 "\n", j, arg.codes[j]);
}
free(arg.codes);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment