Skip to content

perf tool_pmu: Add procfs memory, network and schedstat events

Ian Rogers linux-perf-users lkml 2 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest4 patches 0 repliesNew
  2. v12 patches 6 repliesSuperseded

Changes in v2 from the cover letter

- 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.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4perf tool_pmu: Add memory eventstools/perf/builtin-stat.c tools/perf/pmu-events/arch/common/common/tool.json tools/perf/pmu-events/empty-pmu-events.c +2 more+954 -1870 replies
2/4perf tool_pmu: Add network eventstools/perf/pmu-events/arch/common/common/tool.json tools/perf/pmu-events/empty-pmu-events.c tools/perf/util/evsel.c +2 more+571 -1440 replies
3/4perf tool_pmu: Add schedstat eventstools/perf/pmu-events/arch/common/common/tool.json tools/perf/pmu-events/empty-pmu-events.c tools/perf/util/pmu.c +3 more+340 -1160 replies
4/4perf test tool_pmu: Add memory, network and schedstat teststools/perf/tests/tool_pmu.c+689 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

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

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/[email protected]/

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(-)
Signature · 1 line
2.56.1.703.gf848ed807c-goog