On Sat, Feb 18, 2023 at 10:13:25PM -0800, Namhyung Kim wrote: > When it uses bpf filters, event might drop some samples. It'd be nice > if it can report how many samples it lost. As LOST_SAMPLES event can > carry the similar information, let's use it for bpf filters. > > To indicate it's from BPF filters, add a new misc flag for that and > do not display cpu load warnings. > > Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx> > --- > tools/lib/perf/include/perf/event.h | 2 ++ > tools/perf/builtin-record.c | 37 ++++++++++++++++++----------- > tools/perf/util/bpf-filter.c | 7 ++++++ > tools/perf/util/bpf-filter.h | 5 ++++ > tools/perf/util/session.c | 3 ++- > 5 files changed, 39 insertions(+), 15 deletions(-) > > diff --git a/tools/lib/perf/include/perf/event.h b/tools/lib/perf/include/perf/event.h > index ad47d7b31046..51b9338f4c11 100644 > --- a/tools/lib/perf/include/perf/event.h > +++ b/tools/lib/perf/include/perf/event.h > @@ -70,6 +70,8 @@ struct perf_record_lost { > __u64 lost; > }; > > +#define PERF_RECORD_MISC_LOST_SAMPLES_BPF (1 << 15) > + > struct perf_record_lost_samples { > struct perf_event_header header; > __u64 lost; SNIP > @@ -1914,6 +1907,7 @@ static void record__read_lost_samples(struct record *rec) > > evlist__for_each_entry(session->evlist, evsel) { > struct xyarray *xy = evsel->core.sample_id; > + u64 lost_count; > > if (xy == NULL || evsel->core.fd == NULL) > continue; > @@ -1925,12 +1919,27 @@ static void record__read_lost_samples(struct record *rec) > > for (int x = 0; x < xyarray__max_x(xy); x++) { > for (int y = 0; y < xyarray__max_y(xy); y++) { > - __record__read_lost_samples(rec, evsel, lost, x, y); > + struct perf_counts_values count; > + > + if (perf_evsel__read(&evsel->core, x, y, &count) < 0) { > + pr_err("read LOST count failed\n"); > + goto out; > + } > + > + if (count.lost) { > + __record__save_lost_samples(rec, evsel, lost, > + x, y, count.lost, 0); > + } > } > } > + > + lost_count = perf_bpf_filter__lost_count(evsel); > + if (lost_count) > + __record__save_lost_samples(rec, evsel, lost, 0, 0, lost_count, > + PERF_RECORD_MISC_LOST_SAMPLES_BPF); ah that's why I did not see this in kernel code, it's set by record, nice ;-) jirka