[PATCH v1 0/2] Add procfs based memory and network tool events

Ian Rogers posted 2 patches 1 month ago
tools/perf/builtin-stat.c                     |  10 +-
.../pmu-events/arch/common/common/tool.json   | 266 ++++++++-
tools/perf/pmu-events/empty-pmu-events.c      | 312 +++++++----
tools/perf/util/tool_pmu.c                    | 514 +++++++++++++++++-
tools/perf/util/tool_pmu.h                    |  44 ++
5 files changed, 1026 insertions(+), 120 deletions(-)
[PATCH v1 0/2] Add procfs based memory and network tool events
Posted by Ian Rogers 1 month ago
Add events for memory use and network activity based on data readily
available in /prod/pid/statm, /proc/pid/smaps_rollup and
/proc/pid/net/dev. For example the network usage of chrome processes
on a system may be gathered with:
```
$ perf stat -e net_rx_bytes,net_rx_compressed,net_rx_drop,net_rx_errors,net_rx_fifo,net_rx_frame,net_rx_multicast,net_rx_packets,net_tx_bytes,net_tx_carrier,net_tx_colls,net_tx_compressed,net_tx_drop,net_tx_errors,net_tx_fifo,net_tx_packets -p $(pidof -d, chrome) -I 1000
     1.001023475                  0      net_rx_bytes
     1.001023475                  0      net_rx_compressed
     1.001023475         42,647,328      net_rx_drop
     1.001023475        463,069,152      net_rx_errors
     1.001023475                  0      net_rx_fifo
     1.001023475                  0      net_rx_frame
     1.001023475                  0      net_rx_multicast
     1.001023475    423,195,831,744      net_rx_packets
     1.001023475                  0      net_tx_bytes
     1.001023475                  0      net_tx_carrier
     1.001023475                  0      net_tx_colls
     1.001023475                  0      net_tx_compressed
     1.001023475                  0      net_tx_drop
     1.001023475                  0      net_tx_errors
     1.001023475                  0      net_tx_fifo
     1.001023475                  0      net_tx_packets
```

As the events are in the tool_pmu they can be used in metrics. The
json descriptions they are exposed in `perf list` and the events can
be seen in the python ilist application.

Note, if a process terminates then the count reading returns an error
and this can expose what appear to be latent bugs in the aggregation
and display code.

Ian Rogers (2):
  perf tool_pmu: Add memory events
  perf tool_pmu: Add network events

 tools/perf/builtin-stat.c                     |  10 +-
 .../pmu-events/arch/common/common/tool.json   | 266 ++++++++-
 tools/perf/pmu-events/empty-pmu-events.c      | 312 +++++++----
 tools/perf/util/tool_pmu.c                    | 514 +++++++++++++++++-
 tools/perf/util/tool_pmu.h                    |  44 ++
 5 files changed, 1026 insertions(+), 120 deletions(-)

-- 
2.52.0.351.gbe84eed79e-goog
Re: [PATCH v1 0/2] Add procfs based memory and network tool events
Posted by Andi Kleen 3 weeks, 4 days ago
Ian Rogers <irogers@google.com> writes:

> Add events for memory use and network activity based on data readily
> available in /prod/pid/statm, /proc/pid/smaps_rollup and
> /proc/pid/net/dev. For example the network usage of chrome processes
> on a system may be gathered with:
> ```
> $ perf stat -e
> net_rx_bytes,net_rx_compressed,net_rx_drop,net_rx_errors,net_rx_fifo,net_rx_frame,net_rx_multicast,net_rx_packets,net_tx_bytes,net_tx_carrier,net_tx_colls,net_tx_compressed,net_tx_drop,net_tx_errors,net_tx_fifo,net_tx_packets
> -p $(pidof -d, chrome) -I 1000

But AFAIK that's for the complete network name space, not just the
process, thus highly misleading in perf context because the scope
is incompatible.

-Andi
Re: [PATCH v1 0/2] Add procfs based memory and network tool events
Posted by Ian Rogers 3 weeks, 4 days ago
On Mon, Jan 12, 2026 at 8:51 AM Andi Kleen <ak@linux.intel.com> wrote:
>
> Ian Rogers <irogers@google.com> writes:
>
> > Add events for memory use and network activity based on data readily
> > available in /prod/pid/statm, /proc/pid/smaps_rollup and
> > /proc/pid/net/dev. For example the network usage of chrome processes
> > on a system may be gathered with:
> > ```
> > $ perf stat -e
> > net_rx_bytes,net_rx_compressed,net_rx_drop,net_rx_errors,net_rx_fifo,net_rx_frame,net_rx_multicast,net_rx_packets,net_tx_bytes,net_tx_carrier,net_tx_colls,net_tx_compressed,net_tx_drop,net_tx_errors,net_tx_fifo,net_tx_packets
> > -p $(pidof -d, chrome) -I 1000
>
> But AFAIK that's for the complete network name space, not just the
> process, thus highly misleading in perf context because the scope
> is incompatible.

Yeah, we can point this out in the event descriptions or just not have
the events and try to do some per process BPF type thing. Given we
don't have the BPF thing it is still tempting to have these counters
as-is for the system-wide case.

Thanks,
Ian
Re: [PATCH v1 0/2] Add procfs based memory and network tool events
Posted by Namhyung Kim 3 weeks, 2 days ago
On Mon, Jan 12, 2026 at 10:08:20AM -0800, Ian Rogers wrote:
> On Mon, Jan 12, 2026 at 8:51 AM Andi Kleen <ak@linux.intel.com> wrote:
> >
> > Ian Rogers <irogers@google.com> writes:
> >
> > > Add events for memory use and network activity based on data readily
> > > available in /prod/pid/statm, /proc/pid/smaps_rollup and
> > > /proc/pid/net/dev. For example the network usage of chrome processes
> > > on a system may be gathered with:
> > > ```
> > > $ perf stat -e
> > > net_rx_bytes,net_rx_compressed,net_rx_drop,net_rx_errors,net_rx_fifo,net_rx_frame,net_rx_multicast,net_rx_packets,net_tx_bytes,net_tx_carrier,net_tx_colls,net_tx_compressed,net_tx_drop,net_tx_errors,net_tx_fifo,net_tx_packets
> > > -p $(pidof -d, chrome) -I 1000
> >
> > But AFAIK that's for the complete network name space, not just the
> > process, thus highly misleading in perf context because the scope
> > is incompatible.
> 
> Yeah, we can point this out in the event descriptions or just not have
> the events and try to do some per process BPF type thing. Given we
> don't have the BPF thing it is still tempting to have these counters
> as-is for the system-wide case.

You may want to make it fail to open for per-process mode.

Thanks,
Namhyung

Re: [PATCH v1 0/2] Add procfs based memory and network tool events
Posted by Namhyung Kim 1 month ago
Hi Ian,

On Sat, Jan 03, 2026 at 05:17:36PM -0800, Ian Rogers wrote:
> Add events for memory use and network activity based on data readily
> available in /prod/pid/statm, /proc/pid/smaps_rollup and
> /proc/pid/net/dev. For example the network usage of chrome processes
> on a system may be gathered with:
> ```
> $ perf stat -e net_rx_bytes,net_rx_compressed,net_rx_drop,net_rx_errors,net_rx_fifo,net_rx_frame,net_rx_multicast,net_rx_packets,net_tx_bytes,net_tx_carrier,net_tx_colls,net_tx_compressed,net_tx_drop,net_tx_errors,net_tx_fifo,net_tx_packets -p $(pidof -d, chrome) -I 1000
>      1.001023475                  0      net_rx_bytes
>      1.001023475                  0      net_rx_compressed
>      1.001023475         42,647,328      net_rx_drop
>      1.001023475        463,069,152      net_rx_errors
>      1.001023475                  0      net_rx_fifo
>      1.001023475                  0      net_rx_frame
>      1.001023475                  0      net_rx_multicast
>      1.001023475    423,195,831,744      net_rx_packets
>      1.001023475                  0      net_tx_bytes
>      1.001023475                  0      net_tx_carrier
>      1.001023475                  0      net_tx_colls
>      1.001023475                  0      net_tx_compressed
>      1.001023475                  0      net_tx_drop
>      1.001023475                  0      net_tx_errors
>      1.001023475                  0      net_tx_fifo
>      1.001023475                  0      net_tx_packets
> ```

Interesting.

> 
> As the events are in the tool_pmu they can be used in metrics. The
> json descriptions they are exposed in `perf list` and the events can
> be seen in the python ilist application.
> 
> Note, if a process terminates then the count reading returns an error
> and this can expose what appear to be latent bugs in the aggregation
> and display code.

How do you handle system-wide mode and sampling (perf record)?

Thanks,
Namhyung

> 
> Ian Rogers (2):
>   perf tool_pmu: Add memory events
>   perf tool_pmu: Add network events
> 
>  tools/perf/builtin-stat.c                     |  10 +-
>  .../pmu-events/arch/common/common/tool.json   | 266 ++++++++-
>  tools/perf/pmu-events/empty-pmu-events.c      | 312 +++++++----
>  tools/perf/util/tool_pmu.c                    | 514 +++++++++++++++++-
>  tools/perf/util/tool_pmu.h                    |  44 ++
>  5 files changed, 1026 insertions(+), 120 deletions(-)
> 
> -- 
> 2.52.0.351.gbe84eed79e-goog
>
Re: [PATCH v1 0/2] Add procfs based memory and network tool events
Posted by Ian Rogers 1 month ago
On Wed, Jan 7, 2026 at 12:08 AM Namhyung Kim <namhyung@kernel.org> wrote:
>
> Hi Ian,
>
> On Sat, Jan 03, 2026 at 05:17:36PM -0800, Ian Rogers wrote:
> > Add events for memory use and network activity based on data readily
> > available in /prod/pid/statm, /proc/pid/smaps_rollup and
> > /proc/pid/net/dev. For example the network usage of chrome processes
> > on a system may be gathered with:
> > ```
> > $ perf stat -e net_rx_bytes,net_rx_compressed,net_rx_drop,net_rx_errors,net_rx_fifo,net_rx_frame,net_rx_multicast,net_rx_packets,net_tx_bytes,net_tx_carrier,net_tx_colls,net_tx_compressed,net_tx_drop,net_tx_errors,net_tx_fifo,net_tx_packets -p $(pidof -d, chrome) -I 1000
> >      1.001023475                  0      net_rx_bytes
> >      1.001023475                  0      net_rx_compressed
> >      1.001023475         42,647,328      net_rx_drop
> >      1.001023475        463,069,152      net_rx_errors
> >      1.001023475                  0      net_rx_fifo
> >      1.001023475                  0      net_rx_frame
> >      1.001023475                  0      net_rx_multicast
> >      1.001023475    423,195,831,744      net_rx_packets
> >      1.001023475                  0      net_tx_bytes
> >      1.001023475                  0      net_tx_carrier
> >      1.001023475                  0      net_tx_colls
> >      1.001023475                  0      net_tx_compressed
> >      1.001023475                  0      net_tx_drop
> >      1.001023475                  0      net_tx_errors
> >      1.001023475                  0      net_tx_fifo
> >      1.001023475                  0      net_tx_packets
> > ```
>
> Interesting.

Thanks.

> >
> > As the events are in the tool_pmu they can be used in metrics. The
> > json descriptions they are exposed in `perf list` and the events can
> > be seen in the python ilist application.
> >
> > Note, if a process terminates then the count reading returns an error
> > and this can expose what appear to be latent bugs in the aggregation
> > and display code.
>
> How do you handle system-wide mode and sampling (perf record)?

So tool events don't support `perf record` and fail at opening due to
the invalid PMU type and config. This is the same as if you did `perf
record -e duration_time` with a perf today, which looks like:
```
$ perf record -e duration_time -a sleep 1
Error:
Failure to open event 'duration_time' on PMU 'tool' which will be removed.
No fallback found for 'duration_time' for error 0
Error:
Failure to open any events for recording.
```

For system-wide the behavior is hopefully intuitive in that the memory
and network counts are for the whole system rather than the given
processes. For the memory events the proc directory is scanned and all
processes counts aggregated. For network data /proc/net/dev is read
rather than /proc/pid/net/dev. There is more detail in the individual
commit messages on this.

Thanks,
Ian

> Thanks,
> Namhyung
>
> >
> > Ian Rogers (2):
> >   perf tool_pmu: Add memory events
> >   perf tool_pmu: Add network events
> >
> >  tools/perf/builtin-stat.c                     |  10 +-
> >  .../pmu-events/arch/common/common/tool.json   | 266 ++++++++-
> >  tools/perf/pmu-events/empty-pmu-events.c      | 312 +++++++----
> >  tools/perf/util/tool_pmu.c                    | 514 +++++++++++++++++-
> >  tools/perf/util/tool_pmu.h                    |  44 ++
> >  5 files changed, 1026 insertions(+), 120 deletions(-)
> >
> > --
> > 2.52.0.351.gbe84eed79e-goog
> >
Re: [PATCH v1 0/2] Add procfs based memory and network tool events
Posted by Ian Rogers 1 month ago
On Sat, Jan 3, 2026 at 5:17 PM Ian Rogers <irogers@google.com> wrote:
>
> Add events for memory use and network activity based on data readily
> available in /prod/pid/statm, /proc/pid/smaps_rollup and
> /proc/pid/net/dev. For example the network usage of chrome processes
> on a system may be gathered with:
> ```
> $ perf stat -e net_rx_bytes,net_rx_compressed,net_rx_drop,net_rx_errors,net_rx_fifo,net_rx_frame,net_rx_multicast,net_rx_packets,net_tx_bytes,net_tx_carrier,net_tx_colls,net_tx_compressed,net_tx_drop,net_tx_errors,net_tx_fifo,net_tx_packets -p $(pidof -d, chrome) -I 1000
>      1.001023475                  0      net_rx_bytes
>      1.001023475                  0      net_rx_compressed
>      1.001023475         42,647,328      net_rx_drop
>      1.001023475        463,069,152      net_rx_errors
>      1.001023475                  0      net_rx_fifo
>      1.001023475                  0      net_rx_frame
>      1.001023475                  0      net_rx_multicast
>      1.001023475    423,195,831,744      net_rx_packets
>      1.001023475                  0      net_tx_bytes
>      1.001023475                  0      net_tx_carrier
>      1.001023475                  0      net_tx_colls
>      1.001023475                  0      net_tx_compressed
>      1.001023475                  0      net_tx_drop
>      1.001023475                  0      net_tx_errors
>      1.001023475                  0      net_tx_fifo
>      1.001023475                  0      net_tx_packets
> ```
>
> As the events are in the tool_pmu they can be used in metrics. The
> json descriptions they are exposed in `perf list` and the events can
> be seen in the python ilist application.
>
> Note, if a process terminates then the count reading returns an error
> and this can expose what appear to be latent bugs in the aggregation
> and display code.

I forgot to mention there are also other events that could be added.
For example, from  /proc/self/status the signal information could be
useful as could voluntary vs involuntary context switch counts. What
is here is likely useful enough that a bigger patch series isn't
warranted.

Thanks,
Ian

> Ian Rogers (2):
>   perf tool_pmu: Add memory events
>   perf tool_pmu: Add network events
>
>  tools/perf/builtin-stat.c                     |  10 +-
>  .../pmu-events/arch/common/common/tool.json   | 266 ++++++++-
>  tools/perf/pmu-events/empty-pmu-events.c      | 312 +++++++----
>  tools/perf/util/tool_pmu.c                    | 514 +++++++++++++++++-
>  tools/perf/util/tool_pmu.h                    |  44 ++
>  5 files changed, 1026 insertions(+), 120 deletions(-)
>
> --
> 2.52.0.351.gbe84eed79e-goog
>