Skip to content

Commit 48a3adc

Browse files
wkarnynamhyung
authored andcommitted
perf pmu: Fix perf stat output with correct scale and unit
The perf_pmu__parse_* functions for the sysfs files of pmu event’s scale, unit, per-pkg and snapshot were updated in commit 7b723db ("perf pmu: Be lazy about loading event info files from sysfs"). However, the paths for these sysfs files were incorrect. This resulted in perf stat reporting values with wrong scaling and missing units. This is fixed by correcting the paths for these sysfs files. Before this fix: $sudo perf stat -e power/energy-pkg/ -- sleep 2 Performance counter stats for 'system wide': 351,217,188,864 power/energy-pkg/ 2.004127961 seconds time elapsed After this fix: $sudo perf stat -e power/energy-pkg/ -- sleep 2 Performance counter stats for 'system wide': 80.58 Joules power/energy-pkg/ 2.004009749 seconds time elapsed Fixes: 7b723db ("perf pmu: Be lazy about loading event info files from sysfs") Signed-off-by: Wyes Karny <wyes.karny@amd.com> Reviewed-by: Ian Rogers <irogers@google.com> Cc: ravi.bangoria@amd.com Cc: sandipan.das@amd.com Cc: james.clark@arm.com Cc: kan.liang@linux.intel.com Link: https://lore.kernel.org/r/20230920122349.418673-1-wyes.karny@amd.com Signed-off-by: Namhyung Kim <namhyung@kernel.org>
1 parent e47749f commit 48a3adc

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

tools/perf/util/pmu.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ static int perf_pmu__parse_scale(struct perf_pmu *pmu, struct perf_pmu_alias *al
295295
len = perf_pmu__event_source_devices_scnprintf(path, sizeof(path));
296296
if (!len)
297297
return 0;
298-
scnprintf(path + len, sizeof(path) - len, "%s/%s.scale", pmu->name, alias->name);
298+
scnprintf(path + len, sizeof(path) - len, "%s/events/%s.scale", pmu->name, alias->name);
299299

300300
fd = open(path, O_RDONLY);
301301
if (fd == -1)
@@ -330,7 +330,7 @@ static int perf_pmu__parse_unit(struct perf_pmu *pmu, struct perf_pmu_alias *ali
330330
len = perf_pmu__event_source_devices_scnprintf(path, sizeof(path));
331331
if (!len)
332332
return 0;
333-
scnprintf(path + len, sizeof(path) - len, "%s/%s.unit", pmu->name, alias->name);
333+
scnprintf(path + len, sizeof(path) - len, "%s/events/%s.unit", pmu->name, alias->name);
334334

335335
fd = open(path, O_RDONLY);
336336
if (fd == -1)
@@ -364,7 +364,7 @@ perf_pmu__parse_per_pkg(struct perf_pmu *pmu, struct perf_pmu_alias *alias)
364364
len = perf_pmu__event_source_devices_scnprintf(path, sizeof(path));
365365
if (!len)
366366
return 0;
367-
scnprintf(path + len, sizeof(path) - len, "%s/%s.per-pkg", pmu->name, alias->name);
367+
scnprintf(path + len, sizeof(path) - len, "%s/events/%s.per-pkg", pmu->name, alias->name);
368368

369369
fd = open(path, O_RDONLY);
370370
if (fd == -1)
@@ -385,7 +385,7 @@ static int perf_pmu__parse_snapshot(struct perf_pmu *pmu, struct perf_pmu_alias
385385
len = perf_pmu__event_source_devices_scnprintf(path, sizeof(path));
386386
if (!len)
387387
return 0;
388-
scnprintf(path + len, sizeof(path) - len, "%s/%s.snapshot", pmu->name, alias->name);
388+
scnprintf(path + len, sizeof(path) - len, "%s/events/%s.snapshot", pmu->name, alias->name);
389389

390390
fd = open(path, O_RDONLY);
391391
if (fd == -1)

0 commit comments

Comments
 (0)