From nobody Wed Dec 17 12:19:14 2025 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B837416EBE0 for ; Thu, 11 Jul 2024 18:00:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720720827; cv=none; b=K9K8d/7mDpdFFrGhugWEAfKHMfXxLjZx9Dvlux39YHiTTMR2Q/z5oia3JNppOVm7DIHU+6TjT0xe5Ap1uYbARr6KJ1yv8WtmeROqrzfQ8Y6hpjadWmfU2Y27zm0XVcKeyLN0oPrkHJldoRA2EjXaUmaouMBKWUKGk8G19GRFkBo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720720827; c=relaxed/simple; bh=PtBRXc0c+0allU3O64DiNYmraKLIDmcwEXLGEG6EUWQ=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=jEQuIMTnJT/U/yCQxWVW0pnIVUV4mX0IeFpiuGhHTzKftJxNpvtQ/+5TyUfAx6ZBUkABGFrw8RWkK1VQ/cb1U4b6rZ41jK7+94vGEJYvvpSFGwn7ffdh+eBHBhBVstIVRCVccOmLV8Mc7BqnIaMiPRdoppq+MqfbTW6gFB1s+Yw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=YIjD2bRQ; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YIjD2bRQ" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e02a4de4f4eso1992236276.1 for ; Thu, 11 Jul 2024 11:00:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1720720825; x=1721325625; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=7irtahaUgZZ2kadtdQTAIVJwXhey7Hso05gQMGn03JQ=; b=YIjD2bRQife26ofr3m5uxiuibNXv6NUgdxztknnwRjtfcMcOmMk/l2wLXA/NPdDszT xT0UehaNSZcEoE/7M0QEIWldlOOaRlSvP8r0engcxbh79IdAiPyJ5gdPSdsDSRE9jhaC m3cei+7qJUMLzebkToILXbCItf4cTW4F8vnBEqyP7vzGDDheZv0GTcLLtmVTE3CuARNo A3R6rd6OJ3ZFL/NtbpvCY2YzmMDfG1bE8Q+KZbh1PPostzydE3qJMwTCI9y1DEfaah8A zDa2ln8GuAKMoh3LkKosgtEsru5uvLm31EkYDIFNn9XmRX0gZ9337rg4NHga8NOG+LtA 0+KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720720825; x=1721325625; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7irtahaUgZZ2kadtdQTAIVJwXhey7Hso05gQMGn03JQ=; b=EJUgaDWEbKRVvl705cKuzFxJm1uIgdFYD1Q6s1YYMl+TBkatFOsCJwJRjTaOZ3l9eH CEZx7VMyn4n24Is8YN2cCR2ojmdiJJRZZQTuGIhq4xK2dO4C6TvelcJjzvmsUk1Q6sCx 9WJqcQaq1m7Y9N2ZsE/BqtcZf5OJsJVmTWUg6+JnJnKjaJkzogpHPE/BiGs1zTYQgVCF pCxINmYnXxl19UhFJWgQEZuKOVaY4/uJJbDuLHsxd1tikY1mHIe+p/EsLiYCcgsZp5lP 4sd1zfSOZIM8rUXL8P7BMPeTQY4bRNKAw3S+ieh3t5BNte6cJCHBp2zxchFZkiiqe8uV 64uA== X-Forwarded-Encrypted: i=1; AJvYcCVxEzlJfS1RKb8vMDTzQY1GxeBLwbv/DXbCvcb393UeuYAl8hVUkKNFzI9oBb3EqgLQ3Dig1kpKYMHAIUWq2P1xqYsIsWfVCDwN3hG8 X-Gm-Message-State: AOJu0Yy7CR7500cNTEIU3xaGF7BfNP+hXNWO5wCUMOM7pl32qJxCBrS9 jNCTSznxaxhwT4zqK9H11e/AWxL7h0z5Z77jyVO+PzGl7GajsR08PDkgfuNGentWUEu4K3OSS8d 3yrSCKQ== X-Google-Smtp-Source: AGHT+IGMj2daCCdfqUIMVyxFiaBOl2uNvUMGL0sEZfXJ00x70OsfOTwTplPhBU9/aZ/vlnQv3brgWNx7JDSm X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:bd08:a1e0:c497:32db]) (user=irogers job=sendgmr) by 2002:a05:6902:248e:b0:e03:3cfa:1aa7 with SMTP id 3f1490d57ef6-e041b03709dmr19480276.1.1720720824552; Thu, 11 Jul 2024 11:00:24 -0700 (PDT) Date: Thu, 11 Jul 2024 10:59:45 -0700 In-Reply-To: <20240711180008.188906-1-irogers@google.com> Message-Id: <20240711180008.188906-6-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240711180008.188906-1-irogers@google.com> X-Mailer: git-send-email 2.45.2.993.g49e7a77208-goog Subject: [PATCH v4 05/28] perf tool: Move fill defaults into tool.c From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Suzuki K Poulose , Yicong Yang , Jonathan Cameron , Nick Terrell , Nick Desaulniers , Oliver Upton , Anshuman Khandual , Song Liu , Ilkka Koskinen , Athira Rajeev , Huacai Chen , Yanteng Si , Sun Haiyong , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The aim here is to eventually make perf_tool__fill_defaults an init function so that the tools struct is more const. Create a tool.c to go along with tool.h. Move perf_tool__fill_defaults out of session.c into tool.c along with the default stub values. Add perf_tool__compressed_is_stub for a test in perf_session__process_user_event. perf_session__process_compressed_event is only used from being default initialized so migrate into tool.c. Signed-off-by: Ian Rogers --- tools/perf/util/Build | 1 + tools/perf/util/session.c | 310 +----------------------------------- tools/perf/util/session.h | 2 - tools/perf/util/tool.c | 325 ++++++++++++++++++++++++++++++++++++++ tools/perf/util/tool.h | 4 + 5 files changed, 331 insertions(+), 311 deletions(-) create mode 100644 tools/perf/util/tool.c diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 0f18fe81ef0b..f3633342374a 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -65,6 +65,7 @@ perf-util-y +=3D map.o perf-util-y +=3D maps.o perf-util-y +=3D pstack.o perf-util-y +=3D session.o +perf-util-y +=3D tool.o perf-util-y +=3D sample-raw.o perf-util-y +=3D s390-sample-raw.o perf-util-y +=3D amd-sample-raw.o diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 7e9827e61d1b..5359ee055c85 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -38,68 +38,6 @@ #include "units.h" #include =20 -#ifdef HAVE_ZSTD_SUPPORT -static int perf_session__process_compressed_event(struct perf_session *ses= sion, - union perf_event *event, u64 file_offset, - const char *file_path) -{ - void *src; - size_t decomp_size, src_size; - u64 decomp_last_rem =3D 0; - size_t mmap_len, decomp_len =3D session->header.env.comp_mmap_len; - struct decomp *decomp, *decomp_last =3D session->active_decomp->decomp_la= st; - - if (decomp_last) { - decomp_last_rem =3D decomp_last->size - decomp_last->head; - decomp_len +=3D decomp_last_rem; - } - - mmap_len =3D sizeof(struct decomp) + decomp_len; - decomp =3D mmap(NULL, mmap_len, PROT_READ|PROT_WRITE, - MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); - if (decomp =3D=3D MAP_FAILED) { - pr_err("Couldn't allocate memory for decompression\n"); - return -1; - } - - decomp->file_pos =3D file_offset; - decomp->file_path =3D file_path; - decomp->mmap_len =3D mmap_len; - decomp->head =3D 0; - - if (decomp_last_rem) { - memcpy(decomp->data, &(decomp_last->data[decomp_last->head]), decomp_las= t_rem); - decomp->size =3D decomp_last_rem; - } - - src =3D (void *)event + sizeof(struct perf_record_compressed); - src_size =3D event->pack.header.size - sizeof(struct perf_record_compress= ed); - - decomp_size =3D zstd_decompress_stream(session->active_decomp->zstd_decom= p, src, src_size, - &(decomp->data[decomp_last_rem]), decomp_len - decomp_last_rem); - if (!decomp_size) { - munmap(decomp, mmap_len); - pr_err("Couldn't decompress data\n"); - return -1; - } - - decomp->size +=3D decomp_size; - - if (session->active_decomp->decomp =3D=3D NULL) - session->active_decomp->decomp =3D decomp; - else - session->active_decomp->decomp_last->next =3D decomp; - - session->active_decomp->decomp_last =3D decomp; - - pr_debug("decomp (B): %zd to %zd\n", src_size, decomp_size); - - return 0; -} -#else /* !HAVE_ZSTD_SUPPORT */ -#define perf_session__process_compressed_event perf_session__process_compr= essed_event_stub -#endif - static int perf_session__deliver_event(struct perf_session *session, union perf_event *event, const struct perf_tool *tool, @@ -319,251 +257,6 @@ void perf_session__delete(struct perf_session *sessio= n) free(session); } =20 -static int process_event_synth_tracing_data_stub(struct perf_session *sess= ion - __maybe_unused, - union perf_event *event - __maybe_unused) -{ - dump_printf(": unhandled!\n"); - return 0; -} - -static int process_event_synth_attr_stub(const struct perf_tool *tool __ma= ybe_unused, - union perf_event *event __maybe_unused, - struct evlist **pevlist - __maybe_unused) -{ - dump_printf(": unhandled!\n"); - return 0; -} - -static int process_event_synth_event_update_stub(const struct perf_tool *t= ool __maybe_unused, - union perf_event *event __maybe_unused, - struct evlist **pevlist - __maybe_unused) -{ - if (dump_trace) - perf_event__fprintf_event_update(event, stdout); - - dump_printf(": unhandled!\n"); - return 0; -} - -static int process_event_sample_stub(const struct perf_tool *tool __maybe_= unused, - union perf_event *event __maybe_unused, - struct perf_sample *sample __maybe_unused, - struct evsel *evsel __maybe_unused, - struct machine *machine __maybe_unused) -{ - dump_printf(": unhandled!\n"); - return 0; -} - -static int process_event_stub(const struct perf_tool *tool __maybe_unused, - union perf_event *event __maybe_unused, - struct perf_sample *sample __maybe_unused, - struct machine *machine __maybe_unused) -{ - dump_printf(": unhandled!\n"); - return 0; -} - -static int process_finished_round_stub(const struct perf_tool *tool __mayb= e_unused, - union perf_event *event __maybe_unused, - struct ordered_events *oe __maybe_unused) -{ - dump_printf(": unhandled!\n"); - return 0; -} - -static int skipn(int fd, off_t n) -{ - char buf[4096]; - ssize_t ret; - - while (n > 0) { - ret =3D read(fd, buf, min(n, (off_t)sizeof(buf))); - if (ret <=3D 0) - return ret; - n -=3D ret; - } - - return 0; -} - -static s64 process_event_auxtrace_stub(struct perf_session *session __mayb= e_unused, - union perf_event *event) -{ - dump_printf(": unhandled!\n"); - if (perf_data__is_pipe(session->data)) - skipn(perf_data__fd(session->data), event->auxtrace.size); - return event->auxtrace.size; -} - -static int process_event_op2_stub(struct perf_session *session __maybe_unu= sed, - union perf_event *event __maybe_unused) -{ - dump_printf(": unhandled!\n"); - return 0; -} - - -static -int process_event_thread_map_stub(struct perf_session *session __maybe_unu= sed, - union perf_event *event __maybe_unused) -{ - if (dump_trace) - perf_event__fprintf_thread_map(event, stdout); - - dump_printf(": unhandled!\n"); - return 0; -} - -static -int process_event_cpu_map_stub(struct perf_session *session __maybe_unused, - union perf_event *event __maybe_unused) -{ - if (dump_trace) - perf_event__fprintf_cpu_map(event, stdout); - - dump_printf(": unhandled!\n"); - return 0; -} - -static -int process_event_stat_config_stub(struct perf_session *session __maybe_un= used, - union perf_event *event __maybe_unused) -{ - if (dump_trace) - perf_event__fprintf_stat_config(event, stdout); - - dump_printf(": unhandled!\n"); - return 0; -} - -static int process_stat_stub(struct perf_session *perf_session __maybe_unu= sed, - union perf_event *event) -{ - if (dump_trace) - perf_event__fprintf_stat(event, stdout); - - dump_printf(": unhandled!\n"); - return 0; -} - -static int process_stat_round_stub(struct perf_session *perf_session __may= be_unused, - union perf_event *event) -{ - if (dump_trace) - perf_event__fprintf_stat_round(event, stdout); - - dump_printf(": unhandled!\n"); - return 0; -} - -static int process_event_time_conv_stub(struct perf_session *perf_session = __maybe_unused, - union perf_event *event) -{ - if (dump_trace) - perf_event__fprintf_time_conv(event, stdout); - - dump_printf(": unhandled!\n"); - return 0; -} - -static int perf_session__process_compressed_event_stub(struct perf_session= *session __maybe_unused, - union perf_event *event __maybe_unused, - u64 file_offset __maybe_unused, - const char *file_path __maybe_unused) -{ - dump_printf(": unhandled!\n"); - return 0; -} - -void perf_tool__fill_defaults(struct perf_tool *tool) -{ - if (tool->sample =3D=3D NULL) - tool->sample =3D process_event_sample_stub; - if (tool->mmap =3D=3D NULL) - tool->mmap =3D process_event_stub; - if (tool->mmap2 =3D=3D NULL) - tool->mmap2 =3D process_event_stub; - if (tool->comm =3D=3D NULL) - tool->comm =3D process_event_stub; - if (tool->namespaces =3D=3D NULL) - tool->namespaces =3D process_event_stub; - if (tool->cgroup =3D=3D NULL) - tool->cgroup =3D process_event_stub; - if (tool->fork =3D=3D NULL) - tool->fork =3D process_event_stub; - if (tool->exit =3D=3D NULL) - tool->exit =3D process_event_stub; - if (tool->lost =3D=3D NULL) - tool->lost =3D perf_event__process_lost; - if (tool->lost_samples =3D=3D NULL) - tool->lost_samples =3D perf_event__process_lost_samples; - if (tool->aux =3D=3D NULL) - tool->aux =3D perf_event__process_aux; - if (tool->itrace_start =3D=3D NULL) - tool->itrace_start =3D perf_event__process_itrace_start; - if (tool->context_switch =3D=3D NULL) - tool->context_switch =3D perf_event__process_switch; - if (tool->ksymbol =3D=3D NULL) - tool->ksymbol =3D perf_event__process_ksymbol; - if (tool->bpf =3D=3D NULL) - tool->bpf =3D perf_event__process_bpf; - if (tool->text_poke =3D=3D NULL) - tool->text_poke =3D perf_event__process_text_poke; - if (tool->aux_output_hw_id =3D=3D NULL) - tool->aux_output_hw_id =3D perf_event__process_aux_output_hw_id; - if (tool->read =3D=3D NULL) - tool->read =3D process_event_sample_stub; - if (tool->throttle =3D=3D NULL) - tool->throttle =3D process_event_stub; - if (tool->unthrottle =3D=3D NULL) - tool->unthrottle =3D process_event_stub; - if (tool->attr =3D=3D NULL) - tool->attr =3D process_event_synth_attr_stub; - if (tool->event_update =3D=3D NULL) - tool->event_update =3D process_event_synth_event_update_stub; - if (tool->tracing_data =3D=3D NULL) - tool->tracing_data =3D process_event_synth_tracing_data_stub; - if (tool->build_id =3D=3D NULL) - tool->build_id =3D process_event_op2_stub; - if (tool->finished_round =3D=3D NULL) { - if (tool->ordered_events) - tool->finished_round =3D perf_event__process_finished_round; - else - tool->finished_round =3D process_finished_round_stub; - } - if (tool->id_index =3D=3D NULL) - tool->id_index =3D process_event_op2_stub; - if (tool->auxtrace_info =3D=3D NULL) - tool->auxtrace_info =3D process_event_op2_stub; - if (tool->auxtrace =3D=3D NULL) - tool->auxtrace =3D process_event_auxtrace_stub; - if (tool->auxtrace_error =3D=3D NULL) - tool->auxtrace_error =3D process_event_op2_stub; - if (tool->thread_map =3D=3D NULL) - tool->thread_map =3D process_event_thread_map_stub; - if (tool->cpu_map =3D=3D NULL) - tool->cpu_map =3D process_event_cpu_map_stub; - if (tool->stat_config =3D=3D NULL) - tool->stat_config =3D process_event_stat_config_stub; - if (tool->stat =3D=3D NULL) - tool->stat =3D process_stat_stub; - if (tool->stat_round =3D=3D NULL) - tool->stat_round =3D process_stat_round_stub; - if (tool->time_conv =3D=3D NULL) - tool->time_conv =3D process_event_time_conv_stub; - if (tool->feature =3D=3D NULL) - tool->feature =3D process_event_op2_stub; - if (tool->compressed =3D=3D NULL) - tool->compressed =3D perf_session__process_compressed_event; - if (tool->finished_init =3D=3D NULL) - tool->finished_init =3D process_event_op2_stub; -} - static void swap_sample_id_all(union perf_event *event, void *data) { void *end =3D (void *) event + event->header.size; @@ -1672,8 +1365,7 @@ static s64 perf_session__process_user_event(struct pe= rf_session *session, int fd =3D perf_data__fd(session->data); int err; =20 - if (event->header.type !=3D PERF_RECORD_COMPRESSED || - tool->compressed =3D=3D perf_session__process_compressed_event_stub) + if (event->header.type !=3D PERF_RECORD_COMPRESSED || perf_tool__compress= ed_is_stub(tool)) dump_event(session->evlist, event, file_offset, &sample, file_path); =20 /* These events are processed right away */ diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index 6886cc85600f..7f69baeae7fb 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h @@ -92,8 +92,6 @@ int perf_session__process_events(struct perf_session *ses= sion); int perf_session__queue_event(struct perf_session *s, union perf_event *ev= ent, u64 timestamp, u64 file_offset, const char *file_path); =20 -void perf_tool__fill_defaults(struct perf_tool *tool); - int perf_session__resolve_callchain(struct perf_session *session, struct evsel *evsel, struct thread *thread, diff --git a/tools/perf/util/tool.c b/tools/perf/util/tool.c new file mode 100644 index 000000000000..17219ecb8fa6 --- /dev/null +++ b/tools/perf/util/tool.c @@ -0,0 +1,325 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "data.h" +#include "debug.h" +#include "header.h" +#include "session.h" +#include "stat.h" +#include "tool.h" +#include "tsc.h" +#include +#include + +#ifdef HAVE_ZSTD_SUPPORT +static int perf_session__process_compressed_event(struct perf_session *ses= sion, + union perf_event *event, u64 file_offset, + const char *file_path) +{ + void *src; + size_t decomp_size, src_size; + u64 decomp_last_rem =3D 0; + size_t mmap_len, decomp_len =3D session->header.env.comp_mmap_len; + struct decomp *decomp, *decomp_last =3D session->active_decomp->decomp_la= st; + + if (decomp_last) { + decomp_last_rem =3D decomp_last->size - decomp_last->head; + decomp_len +=3D decomp_last_rem; + } + + mmap_len =3D sizeof(struct decomp) + decomp_len; + decomp =3D mmap(NULL, mmap_len, PROT_READ|PROT_WRITE, + MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); + if (decomp =3D=3D MAP_FAILED) { + pr_err("Couldn't allocate memory for decompression\n"); + return -1; + } + + decomp->file_pos =3D file_offset; + decomp->file_path =3D file_path; + decomp->mmap_len =3D mmap_len; + decomp->head =3D 0; + + if (decomp_last_rem) { + memcpy(decomp->data, &(decomp_last->data[decomp_last->head]), decomp_las= t_rem); + decomp->size =3D decomp_last_rem; + } + + src =3D (void *)event + sizeof(struct perf_record_compressed); + src_size =3D event->pack.header.size - sizeof(struct perf_record_compress= ed); + + decomp_size =3D zstd_decompress_stream(session->active_decomp->zstd_decom= p, src, src_size, + &(decomp->data[decomp_last_rem]), decomp_len - decomp_last_rem); + if (!decomp_size) { + munmap(decomp, mmap_len); + pr_err("Couldn't decompress data\n"); + return -1; + } + + decomp->size +=3D decomp_size; + + if (session->active_decomp->decomp =3D=3D NULL) + session->active_decomp->decomp =3D decomp; + else + session->active_decomp->decomp_last->next =3D decomp; + + session->active_decomp->decomp_last =3D decomp; + + pr_debug("decomp (B): %zd to %zd\n", src_size, decomp_size); + + return 0; +} +#endif + +static int process_event_synth_tracing_data_stub(struct perf_session *sess= ion + __maybe_unused, + union perf_event *event + __maybe_unused) +{ + dump_printf(": unhandled!\n"); + return 0; +} + +static int process_event_synth_attr_stub(const struct perf_tool *tool __ma= ybe_unused, + union perf_event *event __maybe_unused, + struct evlist **pevlist + __maybe_unused) +{ + dump_printf(": unhandled!\n"); + return 0; +} + +static int process_event_synth_event_update_stub(const struct perf_tool *t= ool __maybe_unused, + union perf_event *event __maybe_unused, + struct evlist **pevlist + __maybe_unused) +{ + if (dump_trace) + perf_event__fprintf_event_update(event, stdout); + + dump_printf(": unhandled!\n"); + return 0; +} + +static int process_event_sample_stub(const struct perf_tool *tool __maybe_= unused, + union perf_event *event __maybe_unused, + struct perf_sample *sample __maybe_unused, + struct evsel *evsel __maybe_unused, + struct machine *machine __maybe_unused) +{ + dump_printf(": unhandled!\n"); + return 0; +} + +static int process_event_stub(const struct perf_tool *tool __maybe_unused, + union perf_event *event __maybe_unused, + struct perf_sample *sample __maybe_unused, + struct machine *machine __maybe_unused) +{ + dump_printf(": unhandled!\n"); + return 0; +} + +static int process_finished_round_stub(const struct perf_tool *tool __mayb= e_unused, + union perf_event *event __maybe_unused, + struct ordered_events *oe __maybe_unused) +{ + dump_printf(": unhandled!\n"); + return 0; +} + +static int skipn(int fd, off_t n) +{ + char buf[4096]; + ssize_t ret; + + while (n > 0) { + ret =3D read(fd, buf, min(n, (off_t)sizeof(buf))); + if (ret <=3D 0) + return ret; + n -=3D ret; + } + + return 0; +} + +static s64 process_event_auxtrace_stub(struct perf_session *session __mayb= e_unused, + union perf_event *event) +{ + dump_printf(": unhandled!\n"); + if (perf_data__is_pipe(session->data)) + skipn(perf_data__fd(session->data), event->auxtrace.size); + return event->auxtrace.size; +} + +static int process_event_op2_stub(struct perf_session *session __maybe_unu= sed, + union perf_event *event __maybe_unused) +{ + dump_printf(": unhandled!\n"); + return 0; +} + + +static +int process_event_thread_map_stub(struct perf_session *session __maybe_unu= sed, + union perf_event *event __maybe_unused) +{ + if (dump_trace) + perf_event__fprintf_thread_map(event, stdout); + + dump_printf(": unhandled!\n"); + return 0; +} + +static +int process_event_cpu_map_stub(struct perf_session *session __maybe_unused, + union perf_event *event __maybe_unused) +{ + if (dump_trace) + perf_event__fprintf_cpu_map(event, stdout); + + dump_printf(": unhandled!\n"); + return 0; +} + +static +int process_event_stat_config_stub(struct perf_session *session __maybe_un= used, + union perf_event *event __maybe_unused) +{ + if (dump_trace) + perf_event__fprintf_stat_config(event, stdout); + + dump_printf(": unhandled!\n"); + return 0; +} + +static int process_stat_stub(struct perf_session *perf_session __maybe_unu= sed, + union perf_event *event) +{ + if (dump_trace) + perf_event__fprintf_stat(event, stdout); + + dump_printf(": unhandled!\n"); + return 0; +} + +static int process_stat_round_stub(struct perf_session *perf_session __may= be_unused, + union perf_event *event) +{ + if (dump_trace) + perf_event__fprintf_stat_round(event, stdout); + + dump_printf(": unhandled!\n"); + return 0; +} + +static int process_event_time_conv_stub(struct perf_session *perf_session = __maybe_unused, + union perf_event *event) +{ + if (dump_trace) + perf_event__fprintf_time_conv(event, stdout); + + dump_printf(": unhandled!\n"); + return 0; +} + +static int perf_session__process_compressed_event_stub(struct perf_session= *session __maybe_unused, + union perf_event *event __maybe_unused, + u64 file_offset __maybe_unused, + const char *file_path __maybe_unused) +{ + dump_printf(": unhandled!\n"); + return 0; +} + +void perf_tool__fill_defaults(struct perf_tool *tool) +{ + if (tool->sample =3D=3D NULL) + tool->sample =3D process_event_sample_stub; + if (tool->mmap =3D=3D NULL) + tool->mmap =3D process_event_stub; + if (tool->mmap2 =3D=3D NULL) + tool->mmap2 =3D process_event_stub; + if (tool->comm =3D=3D NULL) + tool->comm =3D process_event_stub; + if (tool->namespaces =3D=3D NULL) + tool->namespaces =3D process_event_stub; + if (tool->cgroup =3D=3D NULL) + tool->cgroup =3D process_event_stub; + if (tool->fork =3D=3D NULL) + tool->fork =3D process_event_stub; + if (tool->exit =3D=3D NULL) + tool->exit =3D process_event_stub; + if (tool->lost =3D=3D NULL) + tool->lost =3D perf_event__process_lost; + if (tool->lost_samples =3D=3D NULL) + tool->lost_samples =3D perf_event__process_lost_samples; + if (tool->aux =3D=3D NULL) + tool->aux =3D perf_event__process_aux; + if (tool->itrace_start =3D=3D NULL) + tool->itrace_start =3D perf_event__process_itrace_start; + if (tool->context_switch =3D=3D NULL) + tool->context_switch =3D perf_event__process_switch; + if (tool->ksymbol =3D=3D NULL) + tool->ksymbol =3D perf_event__process_ksymbol; + if (tool->bpf =3D=3D NULL) + tool->bpf =3D perf_event__process_bpf; + if (tool->text_poke =3D=3D NULL) + tool->text_poke =3D perf_event__process_text_poke; + if (tool->aux_output_hw_id =3D=3D NULL) + tool->aux_output_hw_id =3D perf_event__process_aux_output_hw_id; + if (tool->read =3D=3D NULL) + tool->read =3D process_event_sample_stub; + if (tool->throttle =3D=3D NULL) + tool->throttle =3D process_event_stub; + if (tool->unthrottle =3D=3D NULL) + tool->unthrottle =3D process_event_stub; + if (tool->attr =3D=3D NULL) + tool->attr =3D process_event_synth_attr_stub; + if (tool->event_update =3D=3D NULL) + tool->event_update =3D process_event_synth_event_update_stub; + if (tool->tracing_data =3D=3D NULL) + tool->tracing_data =3D process_event_synth_tracing_data_stub; + if (tool->build_id =3D=3D NULL) + tool->build_id =3D process_event_op2_stub; + if (tool->finished_round =3D=3D NULL) { + if (tool->ordered_events) + tool->finished_round =3D perf_event__process_finished_round; + else + tool->finished_round =3D process_finished_round_stub; + } + if (tool->id_index =3D=3D NULL) + tool->id_index =3D process_event_op2_stub; + if (tool->auxtrace_info =3D=3D NULL) + tool->auxtrace_info =3D process_event_op2_stub; + if (tool->auxtrace =3D=3D NULL) + tool->auxtrace =3D process_event_auxtrace_stub; + if (tool->auxtrace_error =3D=3D NULL) + tool->auxtrace_error =3D process_event_op2_stub; + if (tool->thread_map =3D=3D NULL) + tool->thread_map =3D process_event_thread_map_stub; + if (tool->cpu_map =3D=3D NULL) + tool->cpu_map =3D process_event_cpu_map_stub; + if (tool->stat_config =3D=3D NULL) + tool->stat_config =3D process_event_stat_config_stub; + if (tool->stat =3D=3D NULL) + tool->stat =3D process_stat_stub; + if (tool->stat_round =3D=3D NULL) + tool->stat_round =3D process_stat_round_stub; + if (tool->time_conv =3D=3D NULL) + tool->time_conv =3D process_event_time_conv_stub; + if (tool->feature =3D=3D NULL) + tool->feature =3D process_event_op2_stub; + if (tool->compressed =3D=3D NULL) { +#ifdef HAVE_ZSTD_SUPPORT + tool->compressed =3D perf_session__process_compressed_event; +#else + tool->compressed =3D perf_session__process_compressed_event_stub; +#endif + } + if (tool->finished_init =3D=3D NULL) + tool->finished_init =3D process_event_op2_stub; +} + +bool perf_tool__compressed_is_stub(const struct perf_tool *tool) +{ + return tool->compressed =3D=3D perf_session__process_compressed_event_stu= b; +} diff --git a/tools/perf/util/tool.h b/tools/perf/util/tool.h index b192d44fe91f..7913b698033a 100644 --- a/tools/perf/util/tool.h +++ b/tools/perf/util/tool.h @@ -88,4 +88,8 @@ struct perf_tool { enum show_feature_header show_feat_hdr; }; =20 +void perf_tool__fill_defaults(struct perf_tool *tool); + +bool perf_tool__compressed_is_stub(const struct perf_tool *tool); + #endif /* __PERF_TOOL_H */ --=20 2.45.2.993.g49e7a77208-goog