From nobody Mon Nov 25 03:22:50 2024 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 0B18813D245 for ; Thu, 31 Oct 2024 01:43:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339023; cv=none; b=gSW0v9sPmnXqv3EgmH6Llq1Qx0c1UDqsSm6oDfLmU8MRdmpURJRP4U2hUD5foXm05qU+CaiZw0G5z93uD/PudAd3BqtPZ3f4lgyPyq3Dx/F9XJnU5fILV/RXyvrUOeBbyg8hpU25kXrrCzCW1GtTIrxHJVS2RwraksCcOMtkuCA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339023; c=relaxed/simple; bh=zMeecy7/smWWbX5JVxugJXTBkHPzGUQGmIH9BZfWEU8=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=J9l5uH1hKNZ8dDN+uAlbrlrjxU4uqool6+6ycoW27/xkYcqZ0i65zfdxLV9kTGc4TOpt4HB0B5V+GKuLRbCOhGwbpASjDe3+JtoiT1oSbvFzUoEpIagO8itkiiYbepGnOuNGQ8Uqn44ynTyFzJ8hBvLGgLgkP8hYsPfBfm5Bnc0= 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=NQtgxhYr; arc=none smtp.client-ip=209.85.219.201 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="NQtgxhYr" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e30cd709b40so807362276.1 for ; Wed, 30 Oct 2024 18:43:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730339020; x=1730943820; 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=aIG2rq27RxuU3SrtyLvz5J2CM3te2VzhilM3WPSQ4As=; b=NQtgxhYr55hiXMyx+CSdDiD4nBa+y4ersLtGDxd25pgIfl2Zw3g556kgrKwv2JuTu6 dl4RZ9OQXDgXwmQJ8MQs9Y7oRlJ0wZMWF/FU6h+wG7VBhYH9SbDyTEunXXh5ANNcrK0T RHrWjNaTN1Qq5ftcyEsXl9nZqiIYD0GJYILtJdEtry9miPrl+5gdXB/FAks6sukIgjsA TfRPf8drh5RT8SeJN0IlKOZ2Y3aAlBQxZAzpvh5J1SPyNkCkesR3cOh4bK2VGwSRO5Mw wRUkM2jXnaahGiEVef7DT8RR8rlmGEiV8zdaofKL5FXLS5TY0AmlIvvSRJ0NCzukpvcu LiyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730339020; x=1730943820; 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=aIG2rq27RxuU3SrtyLvz5J2CM3te2VzhilM3WPSQ4As=; b=iKw3Hmnc0Xb3GzcScY/r9gpYPkd+JyqcY6IbqfR7vfH+UiXIXrwVR4vY9Jkk3xHwmq OCAbb4WM6l5Ychbacx+pGlCfE3akP8zN9Ei74YUzChqm5Yp/wBvVZv1SRBbX5bzalorb BjVMODGM/v/Ya6TX91of0aLG0TelImvd2ujY9Wl1Cu0wY9T3mYS6k9C/RMdU7K3311NZ KsueGLFMcF5s/QEOE56g1k17UxcAFkLtRWp6dPn6UWT5xG1+F+90jOg/Wbcc4GRkhFJY g/lh6iiefg9zTpb8sbaGdP/5I1A0wx3b1S5hHxkVEtXgtAE6RPORynlgoSQ0Dj6o4t3e zNQQ== X-Forwarded-Encrypted: i=1; AJvYcCWCse5Fph9cm1V1u+s45aG9wMVu0BoR9JsZOb7BC0TxDtDomYtho0O+UDbEgfUStp0bpFscdX8+xRvar34=@vger.kernel.org X-Gm-Message-State: AOJu0Yw4Mp8sL3aL94lIKr2cjZa2vV1R/ehu7P15YUhkTm3BJ3KrTMz5 elBF0dWmi/pAG/EAR9BsoighRRBrIWp2urIU9aX+bKdf4z9W4gp8WEXTyd+tCMjfdhbctXjojrN wEi25cQ== X-Google-Smtp-Source: AGHT+IHzA+wOxNKEWWHOYzf5aDHV9IRu8jnhkG9ujTbzcDUuPo4sTsvFQ39Gyr+/Aekz2wO12kQ1Bx6+U4P+ X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:ad0f:67e7:f1a6:84c4]) (user=irogers job=sendgmr) by 2002:a25:aace:0:b0:e28:f35b:c719 with SMTP id 3f1490d57ef6-e3087bd6066mr51467276.6.1730339019914; Wed, 30 Oct 2024 18:43:39 -0700 (PDT) Date: Wed, 30 Oct 2024 18:42:41 -0700 In-Reply-To: <20241031014252.753588-1-irogers@google.com> Message-Id: <20241031014252.753588-11-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241031014252.753588-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v5 10/21] perf script: Move perf_sample__sprintf_flags to trace-event-scripting.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 , James Clark , Howard Chu , Athira Jajeev , Michael Petlan , Veronika Molnarova , Dapeng Mi , Thomas Richter , Ilya Leoshkevich , Colin Ian King , Weilin Wang , Andi Kleen , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" perf_sample__sprintf_flags is used in the python C code and so needs to be in the util library rather than a builtin. Signed-off-by: Ian Rogers --- tools/perf/builtin-script.c | 81 ------------------------ tools/perf/util/python.c | 6 -- tools/perf/util/trace-event-scripting.c | 83 +++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 87 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 22d78a9d8f27..1eda065dcb2b 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -1693,87 +1693,6 @@ static int perf_sample__fprintf_bts(struct perf_samp= le *sample, return printed; } =20 -static struct { - u32 flags; - const char *name; -} sample_flags[] =3D { - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL, "call"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_RETURN, "return"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CONDITIONAL, "jcc"}, - {PERF_IP_FLAG_BRANCH, "jmp"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_INTERRUPT, "int"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_RETURN | PERF_IP_FLAG_INTERRUPT, "ire= t"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_SYSCALLRET, "sysc= all"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_RETURN | PERF_IP_FLAG_SYSCALLRET, "sy= sret"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_ASYNC, "async"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_ASYNC | PERF_IP_F= LAG_INTERRUPT, "hw int"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TX_ABORT, "tx abrt"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TRACE_BEGIN, "tr strt"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TRACE_END, "tr end"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_VMENTRY, "vmentry= "}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_VMEXIT, "vmexit"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_BRANCH_MISS, "br miss"}, - {0, NULL} -}; - -static const char *sample_flags_to_name(u32 flags) -{ - int i; - - for (i =3D 0; sample_flags[i].name ; i++) { - if (sample_flags[i].flags =3D=3D flags) - return sample_flags[i].name; - } - - return NULL; -} - -int perf_sample__sprintf_flags(u32 flags, char *str, size_t sz) -{ - u32 xf =3D PERF_IP_FLAG_IN_TX | PERF_IP_FLAG_INTR_DISABLE | - PERF_IP_FLAG_INTR_TOGGLE; - const char *chars =3D PERF_IP_FLAG_CHARS; - const size_t n =3D strlen(PERF_IP_FLAG_CHARS); - const char *name =3D NULL; - size_t i, pos =3D 0; - char xs[16] =3D {0}; - - if (flags & xf) - snprintf(xs, sizeof(xs), "(%s%s%s)", - flags & PERF_IP_FLAG_IN_TX ? "x" : "", - flags & PERF_IP_FLAG_INTR_DISABLE ? "D" : "", - flags & PERF_IP_FLAG_INTR_TOGGLE ? "t" : ""); - - name =3D sample_flags_to_name(flags & ~xf); - if (name) - return snprintf(str, sz, "%-15s%6s", name, xs); - - if (flags & PERF_IP_FLAG_TRACE_BEGIN) { - name =3D sample_flags_to_name(flags & ~(xf | PERF_IP_FLAG_TRACE_BEGIN)); - if (name) - return snprintf(str, sz, "tr strt %-7s%6s", name, xs); - } - - if (flags & PERF_IP_FLAG_TRACE_END) { - name =3D sample_flags_to_name(flags & ~(xf | PERF_IP_FLAG_TRACE_END)); - if (name) - return snprintf(str, sz, "tr end %-7s%6s", name, xs); - } - - for (i =3D 0; i < n; i++, flags >>=3D 1) { - if ((flags & 1) && pos < sz) - str[pos++] =3D chars[i]; - } - for (; i < 32; i++, flags >>=3D 1) { - if ((flags & 1) && pos < sz) - str[pos++] =3D '?'; - } - if (pos < sz) - str[pos] =3D 0; - - return pos; -} - static int perf_sample__fprintf_flags(u32 flags, FILE *fp) { char str[SAMPLE_FLAGS_BUF_SIZE]; diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 22edadd64e5f..77e02fcc51dd 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1317,12 +1317,6 @@ struct kwork_work *perf_kwork_add_work(struct perf_k= work *kwork __maybe_unused, return NULL; } =20 -int perf_sample__sprintf_flags(u32 flags __maybe_unused, char *str __maybe= _unused, - size_t sz __maybe_unused) -{ - return -1; -} - bool match_callstack_filter(struct machine *machine __maybe_unused, u64 *c= allstack __maybe_unused) { return false; diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trac= e-event-scripting.c index beac456260ae..2e9da0b089ef 100644 --- a/tools/perf/util/trace-event-scripting.c +++ b/tools/perf/util/trace-event-scripting.c @@ -15,6 +15,7 @@ =20 #include "archinsn.h" #include "debug.h" +#include "event.h" #include "trace-event.h" #include "evsel.h" #include @@ -283,3 +284,85 @@ void script_fetch_insn(struct perf_sample *sample, str= uct thread *thread, if (sample->insn_len =3D=3D 0 && native_arch) arch_fetch_insn(sample, thread, machine); } + +static const struct { + u32 flags; + const char *name; +} sample_flags[] =3D { + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL, "call"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_RETURN, "return"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CONDITIONAL, "jcc"}, + {PERF_IP_FLAG_BRANCH, "jmp"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_INTERRUPT, "int"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_RETURN | PERF_IP_FLAG_INTERRUPT, "ire= t"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_SYSCALLRET, "sysc= all"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_RETURN | PERF_IP_FLAG_SYSCALLRET, "sy= sret"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_ASYNC, "async"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_ASYNC | PERF_IP_F= LAG_INTERRUPT, + "hw int"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TX_ABORT, "tx abrt"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TRACE_BEGIN, "tr strt"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TRACE_END, "tr end"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_VMENTRY, "vmentry= "}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_VMEXIT, "vmexit"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_BRANCH_MISS, "br miss"}, + {0, NULL} +}; + +static const char *sample_flags_to_name(u32 flags) +{ + int i; + + for (i =3D 0; sample_flags[i].name ; i++) { + if (sample_flags[i].flags =3D=3D flags) + return sample_flags[i].name; + } + + return NULL; +} + +int perf_sample__sprintf_flags(u32 flags, char *str, size_t sz) +{ + u32 xf =3D PERF_IP_FLAG_IN_TX | PERF_IP_FLAG_INTR_DISABLE | + PERF_IP_FLAG_INTR_TOGGLE; + const char *chars =3D PERF_IP_FLAG_CHARS; + const size_t n =3D strlen(PERF_IP_FLAG_CHARS); + const char *name =3D NULL; + size_t i, pos =3D 0; + char xs[16] =3D {0}; + + if (flags & xf) + snprintf(xs, sizeof(xs), "(%s%s%s)", + flags & PERF_IP_FLAG_IN_TX ? "x" : "", + flags & PERF_IP_FLAG_INTR_DISABLE ? "D" : "", + flags & PERF_IP_FLAG_INTR_TOGGLE ? "t" : ""); + + name =3D sample_flags_to_name(flags & ~xf); + if (name) + return snprintf(str, sz, "%-15s%6s", name, xs); + + if (flags & PERF_IP_FLAG_TRACE_BEGIN) { + name =3D sample_flags_to_name(flags & ~(xf | PERF_IP_FLAG_TRACE_BEGIN)); + if (name) + return snprintf(str, sz, "tr strt %-7s%6s", name, xs); + } + + if (flags & PERF_IP_FLAG_TRACE_END) { + name =3D sample_flags_to_name(flags & ~(xf | PERF_IP_FLAG_TRACE_END)); + if (name) + return snprintf(str, sz, "tr end %-7s%6s", name, xs); + } + + for (i =3D 0; i < n; i++, flags >>=3D 1) { + if ((flags & 1) && pos < sz) + str[pos++] =3D chars[i]; + } + for (; i < 32; i++, flags >>=3D 1) { + if ((flags & 1) && pos < sz) + str[pos++] =3D '?'; + } + if (pos < sz) + str[pos] =3D 0; + + return pos; +} --=20 2.47.0.163.g1226f6d8fa-goog