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 <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Ananth Narayan <ananth.narayan@amd.com> Cc: Bjorn Helgaas <bhelgaas@google.com> Cc: Dhananjay Ugwekar <Dhananjay.Ugwekar@amd.com> Cc: Dominique Martinet <asmadeus@codewreck.org> Cc: Gautham Shenoy <gautham.shenoy@amd.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@arm.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Jonathan Corbet <corbet@lwn.net> Cc: K Prateek Nayak <kprateek.nayak@amd.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ravi Bangoria <ravi.bangoria@amd.com> Cc: Sandipan Das <sandipan.das@amd.com> Link: https://lore.kernel.org/r/20240718003025.1486232-2-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
9b3a48bbe2
commit
beef8fb2af
@ -367,8 +367,8 @@ error:
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
perf_pmu__parse_per_pkg(struct perf_pmu *pmu, struct perf_pmu_alias *alias)
|
||||
static bool perf_pmu__parse_event_source_bool(const char *pmu_name, const char *event_name,
|
||||
const char *suffix)
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
size_t len;
|
||||
@ -376,37 +376,36 @@ perf_pmu__parse_per_pkg(struct perf_pmu *pmu, struct perf_pmu_alias *alias)
|
||||
|
||||
len = perf_pmu__event_source_devices_scnprintf(path, sizeof(path));
|
||||
if (!len)
|
||||
return 0;
|
||||
scnprintf(path + len, sizeof(path) - len, "%s/events/%s.per-pkg", pmu->name, alias->name);
|
||||
return false;
|
||||
|
||||
scnprintf(path + len, sizeof(path) - len, "%s/events/%s.%s", pmu_name, event_name, suffix);
|
||||
|
||||
fd = open(path, O_RDONLY);
|
||||
if (fd == -1)
|
||||
return -1;
|
||||
return false;
|
||||
|
||||
#ifndef NDEBUG
|
||||
{
|
||||
char buf[8];
|
||||
|
||||
len = read(fd, buf, sizeof(buf));
|
||||
assert(len == 1 || len == 2);
|
||||
assert(buf[0] == '1');
|
||||
}
|
||||
#endif
|
||||
|
||||
close(fd);
|
||||
|
||||
alias->per_pkg = true;
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int perf_pmu__parse_snapshot(struct perf_pmu *pmu, struct perf_pmu_alias *alias)
|
||||
static void perf_pmu__parse_per_pkg(struct perf_pmu *pmu, struct perf_pmu_alias *alias)
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
size_t len;
|
||||
int fd;
|
||||
alias->per_pkg = perf_pmu__parse_event_source_bool(pmu->name, alias->name, "per-pkg");
|
||||
}
|
||||
|
||||
len = perf_pmu__event_source_devices_scnprintf(path, sizeof(path));
|
||||
if (!len)
|
||||
return 0;
|
||||
scnprintf(path + len, sizeof(path) - len, "%s/events/%s.snapshot", pmu->name, alias->name);
|
||||
|
||||
fd = open(path, O_RDONLY);
|
||||
if (fd == -1)
|
||||
return -1;
|
||||
|
||||
alias->snapshot = true;
|
||||
close(fd);
|
||||
return 0;
|
||||
static void perf_pmu__parse_snapshot(struct perf_pmu *pmu, struct perf_pmu_alias *alias)
|
||||
{
|
||||
alias->snapshot = perf_pmu__parse_event_source_bool(pmu->name, alias->name, "snapshot");
|
||||
}
|
||||
|
||||
/* Delete an alias entry. */
|
||||
|
Loading…
Reference in New Issue
Block a user