[RFC] perf stat: add rusage utime and stime events

From: Florian Fischer
Date: Tue Apr 05 2022 - 20:50:50 EST



Hallo everyone,

this is my first time sending out patches to the linux kernel repo so I am not
really confident in doing the correct thing.

This patch adds new internal events to perf stat exposing the ru_utime and
ru_stime reported by rusage.

During some benchmarking using perf it bothered me that I could not easily
retrieve the times spent in user or kernel mode from perf stat when using the
machine readable output.

But perf definitely knows about those values because in the human readable output
they are present.

Therefore I exposed the times reported by rusage via the new tool events:
rusage_user_time and rusage_system_time.

tools/perf/builtin-stat.c | 41 ++++++++++++++++++++++++++++++++---------
tools/perf/util/evsel.c | 19 ++++++++++++-------
tools/perf/util/evsel.h | 4 ++++
tools/perf/util/parse-events.c | 44 ++++++++++++++++++++++++++++++++++++++------
tools/perf/util/parse-events.l | 2 ++
tools/perf/util/stat-shadow.c | 2 ++
tools/perf/util/stat.h | 19 +++++++++++++++++++
7 files changed, 109 insertions(+), 22 deletions(-)

The changes are mostly inspired by the code for the only other available tool
event 'duration_time'.

For now rusage_* events are not usable with metrics (as far as I understand).

The patch applies cleanly on linux-next/next-20220405.

And I send this emails to anyone mentioned in the MAINTAINERS file.
Sorry for the possible unnecessary email spam :)

Florian Fischer