[PATCH v2 0/4] perf tool_pmu: Add procfs memory, network and schedstat events

From: Ian Rogers

Date: Fri Nov 13 2026 - 18:37:57 EST


Add tool PMU events for memory usage, network activity, and scheduler
runqueue statistics based on procfs data in /proc/<pid>/statm,
/proc/<pid>/smaps_rollup, /proc/net/dev, and /proc/schedstat:

- Patch 1 adds 26 memory_* events (such as memory_rss, memory_pss,
memory_uss, memory_size, memory_swap) aggregated across processes in
system-wide mode or read per-process. Per-process mode holds a
/proc/<pid> directory descriptor and opens statm/smaps_rollup on each
read (observing post-exec address spaces without PID-reuse races),
deduplicates sibling threads sharing a Tgid, and falls back to wait4
rusage ru_maxrss for memory_rss when a forked workload has already
exited.
- Patch 2 adds 16 system-wide net_rx_* and net_tx_* events from
/proc/net/dev, tracking deltas across enable/disable transitions and
handling mixed CPU-map event groups safely. Per-process and cgroup
modes are rejected with -EINVAL since /proc/<pid>/net/dev reports
statistics for the entire network namespace rather than an individual
process.
- Patch 3 adds 8 per-CPU schedstat_* events from /proc/schedstat,
tracking per-CPU deltas across enable/disable transitions.
- Patch 4 extends the 'Tool PMU' unit test suite with tests for memory
events (including multi-threaded Tgid deduplication), network events,
schedstat events, and mixed CPU-map tool groups.

Because these events are exposed on tool_pmu with JSON descriptions,
they can be used in metrics, listed via 'perf list', and inspected in
the Python ilist application.

This series was developed and reviewed with assistance from an AI coding
agent (Gemini 3.1 Pro) and reviewed with Sashiko.

v2:
- Rebase onto perf-tools-next (adapting to reads_only_on_cpu_idx0 and
tool_pmu enable/disable support).
- Restrict net_* events to system-wide mode (-EINVAL on per-process or
cgroup open) and report deltas over the enabled interval rather than
cumulative boot totals (Namhyung Kim).
- Fix unpadded /proc/net/dev column parsing after ':' and fix memory
unit scaling and statm field offsets.
- Open /proc/<pid> with O_DIRECTORY for per-process memory_* events so
post-exec mm_struct changes are observed, deduplicate threads sharing
a Tgid, and refine the wait4 ru_maxrss fallback for memory_rss.
- Handle non-leader attr.disabled and mismatched CPU maps when single-
CPU and per-CPU tool events are grouped.
- Add per-CPU schedstat_* tool PMU events and 'Tool PMU' unit tests.

v1: https://lore.kernel.org/linux-perf-users/20260104011738.475680-1-irogers@xxxxxxxxxx/

Ian Rogers (4):
perf tool_pmu: Add memory events
perf tool_pmu: Add network events
perf tool_pmu: Add schedstat events
perf test tool_pmu: Add memory, network and schedstat tests

tools/perf/builtin-stat.c | 81 +-
.../pmu-events/arch/common/common/tool.json | 300 ++++++
tools/perf/pmu-events/empty-pmu-events.c | 422 +++++---
tools/perf/tests/tool_pmu.c | 689 +++++++++++++
tools/perf/util/evsel.c | 53 +-
tools/perf/util/pmu.c | 4 +-
tools/perf/util/stat-display.c | 8 +-
tools/perf/util/tool_pmu.c | 916 ++++++++++++++++--
tools/perf/util/tool_pmu.h | 52 +
9 files changed, 2316 insertions(+), 209 deletions(-)

--
2.56.1.703.gf848ed807c-goog