Convert pmu/event-name/ to pmu/param1=N,param2=M/
| 114 | |
| 115 | // Convert pmu/event-name/ to pmu/param1=N,param2=M/ |
| 116 | static void resolvePmuEventName(const char* device, char* event, size_t size) { |
| 117 | char buf[256]; |
| 118 | if ((size_t)snprintf(buf, sizeof(buf), "/sys/bus/event_source/devices/%s/events/%s", device, event) >= sizeof(buf)) { |
| 119 | return; |
| 120 | } |
| 121 | |
| 122 | int fd = open(buf, O_RDONLY); |
| 123 | if (fd == -1) { |
| 124 | return; |
| 125 | } |
| 126 | |
| 127 | ssize_t r = read(fd, event, size); |
| 128 | if (r > 0 && (r == size || event[r - 1] == '\n')) { |
| 129 | event[r - 1] = 0; |
| 130 | } |
| 131 | close(fd); |
| 132 | } |
| 133 | |
| 134 | // Set a PMU parameter (such as umask) to the corresponding config field |
| 135 | static bool setPmuConfig(const char* device, const char* param, __u64* config, __u64 val) { |