From: Adrian Hunter <adrian.hunter@intel.com>
To: Namhyung Kim <namhyung@kernel.org>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
LKML <linux-kernel@vger.kernel.org>,
Ian Rogers <irogers@google.com>,
linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 3/5] perf record: Read and inject LOST_SAMPLES events
Date: Thu, 1 Sep 2022 14:22:45 +0300 [thread overview]
Message-ID: <86ca3041-3327-622c-1c23-67fc6af412f6@intel.com> (raw)
In-Reply-To: <20220831210352.145753-4-namhyung@kernel.org>
On 1/09/22 00:03, Namhyung Kim wrote:
> When there are lost samples, it can read the number of PERF_FORMAT_LOST and
> convert it to PERF_RECORD_LOST_SAMPLES and write to the data file at the end.
>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
> tools/perf/builtin-record.c | 60 +++++++++++++++++++++++++++++++++++++
> 1 file changed, 60 insertions(+)
>
> diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
> index bce8c941d558..cb9881543a07 100644
> --- a/tools/perf/builtin-record.c
> +++ b/tools/perf/builtin-record.c
> @@ -10,6 +10,7 @@
>
> #include "util/build-id.h"
> #include <subcmd/parse-options.h>
> +#include <internal/xyarray.h>
> #include "util/parse-events.h"
> #include "util/config.h"
>
> @@ -1852,6 +1853,64 @@ record__switch_output(struct record *rec, bool at_exit)
> return fd;
> }
>
> +static void __record__read_lost_samples(struct record *rec, struct evsel *evsel,
> + struct perf_record_lost_samples *lost,
> + int size, int cpu_idx, int thread_idx)
> +{
> + struct perf_counts_values count;
> + struct perf_sample_id *sid;
> + struct perf_sample sample = {};
> +
> + if (perf_evsel__read(&evsel->core, cpu_idx, thread_idx, &count) < 0) {
> + pr_err("read LOST count failed\n");
> + return;
> + }
> +
> + if (count.lost == 0)
> + return;
> +
> + lost->lost = count.lost;
> + if (evsel->core.ids) {
> + sid = xyarray__entry(evsel->core.sample_id, cpu_idx, thread_idx);
> + sample.id = sid->id;
> + }
> +
> + perf_event__synthesize_id_sample((void *)(lost + 1),
> + evsel->core.attr.sample_type, &sample);
The ID sample size can vary with sample_type and is not necessarily the same as
machine->id_hdr_size.
The following might be more robust:
id_hdr_size = perf_event__synthesize_id_sample((void *)(lost + 1), evsel->core.attr.sample_type, &sample);
lost->header.size = sizeof(*lost) + id_hdr_size;
> + record__write(rec, NULL, lost, size);
> +}
> +
> +static void record__read_lost_samples(struct record *rec)
> +{
> + struct perf_session *session = rec->session;
> + struct machine *machine = &session->machines.host;
> + struct perf_record_lost_samples *lost;
> + struct evsel *evsel;
> + int size = sizeof(*lost) + machine->id_hdr_size;
- int size = sizeof(*lost) + machine->id_hdr_size;
> +
> + lost = zalloc(size);
lost = zalloc(PERF_SAMPLE_MAX_SIZE);
> + lost->header.type = PERF_RECORD_LOST_SAMPLES;
> + lost->header.size = size;
- lost->header.size = size;
> +
> + evlist__for_each_entry(session->evlist, evsel) {
> + struct xyarray *xy = evsel->core.sample_id;
> +
> + if (xyarray__max_x(evsel->core.fd) != xyarray__max_x(xy) ||
> + xyarray__max_y(evsel->core.fd) != xyarray__max_y(xy)) {
> + pr_debug("Unmatched FD vs. sample ID: skip reading LOST count\n");
> + continue;
> + }
> +
> + 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,
> + size, x, y);
> + }
> + }
> + }
> +
> +}
> +
> static volatile int workload_exec_errno;
>
> /*
> @@ -2710,6 +2769,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
> if (rec->off_cpu)
> rec->bytes_written += off_cpu_write(rec->session);
>
> + record__read_lost_samples(rec);
> record__synthesize(rec, true);
> /* this will be recalculated during process_buildids() */
> rec->samples = 0;
next prev parent reply other threads:[~2022-09-01 11:23 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-31 21:03 [PATCHSET 0/5] perf tools: Show per-event lost sample count (v1) Namhyung Kim
2022-08-31 21:03 ` [PATCH 1/5] perf tools: Print LOST read format in the verbose mode Namhyung Kim
2022-08-31 21:03 ` [PATCH 2/5] perf record: Set PERF_FORMAT_LOST by default Namhyung Kim
2022-08-31 21:03 ` [PATCH 3/5] perf record: Read and inject LOST_SAMPLES events Namhyung Kim
2022-09-01 11:22 ` Adrian Hunter [this message]
2022-09-01 18:49 ` Namhyung Kim
2022-08-31 21:03 ` [PATCH 4/5] perf hist: Add nr_lost_samples to hist_stats Namhyung Kim
2022-08-31 21:03 ` [PATCH 5/5] perf report: Show per-event LOST SAMPLES stat Namhyung Kim
2022-09-01 19:57 [PATCHSET 0/5] perf tools: Show per-event lost sample count (v2) Namhyung Kim
2022-09-01 19:57 ` [PATCH 3/5] perf record: Read and inject LOST_SAMPLES events Namhyung Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86ca3041-3327-622c-1c23-67fc6af412f6@intel.com \
--to=adrian.hunter@intel.com \
--cc=acme@kernel.org \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®