Skip to content

Commit beef8fb

Browse files
captain5050acmel
authored andcommitted
perf pmu: Merge boolean sysfs event option parsing
Merge perf_pmu__parse_per_pkg() and perf_pmu__parse_snapshot() that do the same parsing except for the file suffix used. Signed-off-by: Ian Rogers <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Ananth Narayan <[email protected]> Cc: Bjorn Helgaas <[email protected]> Cc: Dhananjay Ugwekar <[email protected]> Cc: Dominique Martinet <[email protected]> Cc: Gautham Shenoy <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: James Clark <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: K Prateek Nayak <[email protected]> Cc: Kan Liang <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Ravi Bangoria <[email protected]> Cc: Sandipan Das <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 9b3a48b commit beef8fb

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

tools/perf/util/pmu.c

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -367,46 +367,45 @@ static int perf_pmu__parse_unit(struct perf_pmu *pmu, struct perf_pmu_alias *ali
367367
return -1;
368368
}
369369

370-
static int
371-
perf_pmu__parse_per_pkg(struct perf_pmu *pmu, struct perf_pmu_alias *alias)
370+
static bool perf_pmu__parse_event_source_bool(const char *pmu_name, const char *event_name,
371+
const char *suffix)
372372
{
373373
char path[PATH_MAX];
374374
size_t len;
375375
int fd;
376376

377377
len = perf_pmu__event_source_devices_scnprintf(path, sizeof(path));
378378
if (!len)
379-
return 0;
380-
scnprintf(path + len, sizeof(path) - len, "%s/events/%s.per-pkg", pmu->name, alias->name);
379+
return false;
380+
381+
scnprintf(path + len, sizeof(path) - len, "%s/events/%s.%s", pmu_name, event_name, suffix);
381382

382383
fd = open(path, O_RDONLY);
383384
if (fd == -1)
384-
return -1;
385+
return false;
385386

386-
close(fd);
387+
#ifndef NDEBUG
388+
{
389+
char buf[8];
387390

388-
alias->per_pkg = true;
389-
return 0;
391+
len = read(fd, buf, sizeof(buf));
392+
assert(len == 1 || len == 2);
393+
assert(buf[0] == '1');
394+
}
395+
#endif
396+
397+
close(fd);
398+
return true;
390399
}
391400

392-
static int perf_pmu__parse_snapshot(struct perf_pmu *pmu, struct perf_pmu_alias *alias)
401+
static void perf_pmu__parse_per_pkg(struct perf_pmu *pmu, struct perf_pmu_alias *alias)
393402
{
394-
char path[PATH_MAX];
395-
size_t len;
396-
int fd;
397-
398-
len = perf_pmu__event_source_devices_scnprintf(path, sizeof(path));
399-
if (!len)
400-
return 0;
401-
scnprintf(path + len, sizeof(path) - len, "%s/events/%s.snapshot", pmu->name, alias->name);
402-
403-
fd = open(path, O_RDONLY);
404-
if (fd == -1)
405-
return -1;
403+
alias->per_pkg = perf_pmu__parse_event_source_bool(pmu->name, alias->name, "per-pkg");
404+
}
406405

407-
alias->snapshot = true;
408-
close(fd);
409-
return 0;
406+
static void perf_pmu__parse_snapshot(struct perf_pmu *pmu, struct perf_pmu_alias *alias)
407+
{
408+
alias->snapshot = perf_pmu__parse_event_source_bool(pmu->name, alias->name, "snapshot");
410409
}
411410

412411
/* Delete an alias entry. */

0 commit comments

Comments
 (0)