From nobody Tue Nov 26 19:53:15 2024 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 9DBAD21E3BF for ; Wed, 16 Oct 2024 04:24:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729052679; cv=none; b=DOdGsG7bh6xE1w7rHWU2P6hhvqiBXgUS/WTyI2UIwGJRTOAxx7Vm00/Ww3EkkEBIGZRt+5KP20cag345AaRrpfEhfm6DnrcbAiosfLVT4oGz802riQiEwlcbnyGONah/WOvGttT2gYMtwmUhhBQTGr8cp6o6kuX/bsef0MkD9jU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729052679; c=relaxed/simple; bh=OImioo/hJY3HOUHy5hDrVHJMmlJ4JUsLkeB0SNT7ls4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=XaaVL9fuUiU/db8Vz+jD4e0Saksh2bO8oGpp4WCq6UKcWgJ1+kkg2k3XLtwKVG/R1TR496vUSBO+LaFF7nYRecnLUcV9vMN7CzPmjHkoWhoXAJ7EKSbdftiBPUW4wryXKXC/iodgAIuT/53dxCq0YYFG3ZDoiYKlZEPPj94JYh8= 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=EiqKYFQ9; arc=none smtp.client-ip=209.85.128.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="EiqKYFQ9" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e321d26b38so107560667b3.2 for ; Tue, 15 Oct 2024 21:24:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729052677; x=1729657477; 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=kmmW5fvjlLMhgTB5VXAqLe0L1jNULTy+R7ekdgKNNns=; b=EiqKYFQ9+8eQFsbn0VTGL9ef2UGkbFFU7mZ4I2hxpm3PrLXqa7CoykqAbS4FXxMxYF WHlSEdIs/SqBUv5/tS44emGPhmvyLAcl2U/9QPmFHyGWn4VE6Lp1CmbKuEn08aO3wauJ VL6utMP4OSZyrD+xPzZnl4CN0IeJDjf8Q3QaAB4X+QphxAa4BBvUB5v4j8Y0V4ha2Tpy ChGwUA6yHGNNkub3LWcGeWOO05JE384Gxa1Y/D9GD00tVNIzAC4JnUAoiBdwDTaiRqXC VfNhfC65vR2HQSdearFoOym1V/CpG9KyiTUtJde3Eo4IzUp8bnO6EUMAXEGKFRNBVvcE jirQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729052677; x=1729657477; 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=kmmW5fvjlLMhgTB5VXAqLe0L1jNULTy+R7ekdgKNNns=; b=j9dnBe1vJEm+1B1z2A3TdUMiuNrycLaDRIgNzSfebfQDcUZNXGVlmPheizjf0YvXxE KS/27akmCfSqalKcQttYR07oimwqx9P6XHrC+S6GM2j9JsGULtZI38bV4WShhpFWeGaB dvL7bm8q8cZ2jMj7MnuOfQFva8ENf6/S8OhWi+C6cc7XkxAJVniYxl9+xOnpHyzY9XMZ wayTd1KSmP9FYhzpE5WFkOMhhJPk8ifTPwozif/nrZxxMbbLQdwg+uCdj6t/QZC5wwms fQsUmv3V4YyXA9xjg4CIiusgK6WnsVRgSUOy7wLbrYT/bRwLre/A6J+3sdR7ZvtOwhvD fZVA== X-Forwarded-Encrypted: i=1; AJvYcCW3urvLE/SSqECZgZ6kqWKENSfV+KDQYb5LOvFRUbDszJJEeROISwAtTzXbu9wblC/kmhCgCa4FwUJmCFM=@vger.kernel.org X-Gm-Message-State: AOJu0YxW9sUR8dwHAMIBp/G4S4RkWA60GIXdTjmVr3sO7/ww5lev4Hjm L2qQM+0jYCSJp+8p/uVwT6Pbl/wHpcBGfTuWHK6f1jRirPovMv6E/AbsjVzSu8m+FoLpi4hzpZf ta1JYXg== X-Google-Smtp-Source: AGHT+IHrxQ2r0hCQPhw9EYNYegCx2S7ACEyHSwV4h2Nr0RvH+lGbCv5gi01blZB+b7YYMsiVEXuXttUD/dNi X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a05:690c:6993:b0:6e3:f32:5fc8 with SMTP id 00721157ae682-6e3d3f80022mr552507b3.1.1729052676723; Tue, 15 Oct 2024 21:24:36 -0700 (PDT) Date: Tue, 15 Oct 2024 21:24:00 -0700 In-Reply-To: <20241016042415.7552-1-irogers@google.com> Message-Id: <20241016042415.7552-2-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241016042415.7552-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Subject: [PATCH v2 01/16] perf python: Remove python 2 scripting support 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 , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Python2 was deprecated 4 years ago, remove support and workarounds. Signed-off-by: Ian Rogers --- .../scripts/python/Perf-Trace-Util/Context.c | 18 ----- tools/perf/util/python.c | 73 +++---------------- .../scripting-engines/trace-event-python.c | 63 +--------------- 3 files changed, 15 insertions(+), 139 deletions(-) diff --git a/tools/perf/scripts/python/Perf-Trace-Util/Context.c b/tools/pe= rf/scripts/python/Perf-Trace-Util/Context.c index 01f54d6724a5..d742daaa5d5a 100644 --- a/tools/perf/scripts/python/Perf-Trace-Util/Context.c +++ b/tools/perf/scripts/python/Perf-Trace-Util/Context.c @@ -24,16 +24,6 @@ #include "../../../util/srcline.h" #include "../../../util/srccode.h" =20 -#if PY_MAJOR_VERSION < 3 -#define _PyCapsule_GetPointer(arg1, arg2) \ - PyCObject_AsVoidPtr(arg1) -#define _PyBytes_FromStringAndSize(arg1, arg2) \ - PyString_FromStringAndSize((arg1), (arg2)) -#define _PyUnicode_AsUTF8(arg) \ - PyString_AsString(arg) - -PyMODINIT_FUNC initperf_trace_context(void); -#else #define _PyCapsule_GetPointer(arg1, arg2) \ PyCapsule_GetPointer((arg1), (arg2)) #define _PyBytes_FromStringAndSize(arg1, arg2) \ @@ -42,7 +32,6 @@ PyMODINIT_FUNC initperf_trace_context(void); PyUnicode_AsUTF8(arg) =20 PyMODINIT_FUNC PyInit_perf_trace_context(void); -#endif =20 static struct scripting_context *get_args(PyObject *args, const char *name= , PyObject **arg2) { @@ -213,12 +202,6 @@ static PyMethodDef ContextMethods[] =3D { { NULL, NULL, 0, NULL} }; =20 -#if PY_MAJOR_VERSION < 3 -PyMODINIT_FUNC initperf_trace_context(void) -{ - (void) Py_InitModule("perf_trace_context", ContextMethods); -} -#else PyMODINIT_FUNC PyInit_perf_trace_context(void) { static struct PyModuleDef moduledef =3D { @@ -240,4 +223,3 @@ PyMODINIT_FUNC PyInit_perf_trace_context(void) =20 return mod; } -#endif diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 31a223eaf8e6..02279ab4967c 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -25,40 +25,14 @@ #include #include "../builtin.h" =20 -#if PY_MAJOR_VERSION < 3 -#define _PyUnicode_FromString(arg) \ - PyString_FromString(arg) -#define _PyUnicode_AsString(arg) \ - PyString_AsString(arg) -#define _PyUnicode_FromFormat(...) \ - PyString_FromFormat(__VA_ARGS__) -#define _PyLong_FromLong(arg) \ - PyInt_FromLong(arg) - -#else - #define _PyUnicode_FromString(arg) \ PyUnicode_FromString(arg) #define _PyUnicode_FromFormat(...) \ PyUnicode_FromFormat(__VA_ARGS__) #define _PyLong_FromLong(arg) \ PyLong_FromLong(arg) -#endif =20 -#ifndef Py_TYPE -#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) -#endif - -/* Define PyVarObject_HEAD_INIT for python 2.5 */ -#ifndef PyVarObject_HEAD_INIT -# define PyVarObject_HEAD_INIT(type, size) PyObject_HEAD_INIT(type) size, -#endif - -#if PY_MAJOR_VERSION < 3 -PyMODINIT_FUNC initperf(void); -#else PyMODINIT_FUNC PyInit_perf(void); -#endif =20 #define member_def(type, member, ptype, help) \ { #member, ptype, \ @@ -116,7 +90,7 @@ static PyObject *pyrf_mmap_event__repr(struct pyrf_event= *pevent) pevent->event.mmap.pgoff, pevent->event.mmap.filename) < 0) { ret =3D PyErr_NoMemory(); } else { - ret =3D _PyUnicode_FromString(s); + ret =3D PyUnicode_FromString(s); free(s); } return ret; @@ -147,7 +121,7 @@ static PyMemberDef pyrf_task_event__members[] =3D { =20 static PyObject *pyrf_task_event__repr(struct pyrf_event *pevent) { - return _PyUnicode_FromFormat("{ type: %s, pid: %u, ppid: %u, tid: %u, " + return PyUnicode_FromFormat("{ type: %s, pid: %u, ppid: %u, tid: %u, " "ptid: %u, time: %" PRI_lu64 "}", pevent->event.header.type =3D=3D PERF_RECORD_FORK ? "fork" : "exit", pevent->event.fork.pid, @@ -180,7 +154,7 @@ static PyMemberDef pyrf_comm_event__members[] =3D { =20 static PyObject *pyrf_comm_event__repr(struct pyrf_event *pevent) { - return _PyUnicode_FromFormat("{ type: comm, pid: %u, tid: %u, comm: %s }", + return PyUnicode_FromFormat("{ type: comm, pid: %u, tid: %u, comm: %s }", pevent->event.comm.pid, pevent->event.comm.tid, pevent->event.comm.comm); @@ -211,7 +185,7 @@ static PyObject *pyrf_throttle_event__repr(struct pyrf_= event *pevent) { struct perf_record_throttle *te =3D (struct perf_record_throttle *)(&peve= nt->event.header + 1); =20 - return _PyUnicode_FromFormat("{ type: %sthrottle, time: %" PRI_lu64 ", id= : %" PRI_lu64 + return PyUnicode_FromFormat("{ type: %sthrottle, time: %" PRI_lu64 ", id:= %" PRI_lu64 ", stream_id: %" PRI_lu64 " }", pevent->event.header.type =3D=3D PERF_RECORD_THROTTLE ? "" : "un", te->time, te->id, te->stream_id); @@ -246,7 +220,7 @@ static PyObject *pyrf_lost_event__repr(struct pyrf_even= t *pevent) pevent->event.lost.id, pevent->event.lost.lost) < 0) { ret =3D PyErr_NoMemory(); } else { - ret =3D _PyUnicode_FromString(s); + ret =3D PyUnicode_FromString(s); free(s); } return ret; @@ -273,7 +247,7 @@ static PyMemberDef pyrf_read_event__members[] =3D { =20 static PyObject *pyrf_read_event__repr(struct pyrf_event *pevent) { - return _PyUnicode_FromFormat("{ type: read, pid: %u, tid: %u }", + return PyUnicode_FromFormat("{ type: read, pid: %u, tid: %u }", pevent->event.read.pid, pevent->event.read.tid); /* @@ -308,7 +282,7 @@ static PyObject *pyrf_sample_event__repr(struct pyrf_ev= ent *pevent) if (asprintf(&s, "{ type: sample }") < 0) { ret =3D PyErr_NoMemory(); } else { - ret =3D _PyUnicode_FromString(s); + ret =3D PyUnicode_FromString(s); free(s); } return ret; @@ -342,7 +316,7 @@ tracepoint_field(struct pyrf_event *pe, struct tep_form= at_field *field) } if (field->flags & TEP_FIELD_IS_STRING && is_printable_array(data + offset, len)) { - ret =3D _PyUnicode_FromString((char *)data + offset); + ret =3D PyUnicode_FromString((char *)data + offset); } else { ret =3D PyByteArray_FromStringAndSize((const char *) data + offset, len= ); field->flags &=3D ~TEP_FIELD_IS_STRING; @@ -431,7 +405,7 @@ static PyObject *pyrf_context_switch_event__repr(struct= pyrf_event *pevent) !!(pevent->event.header.misc & PERF_RECORD_MISC_SWITCH_OUT)) < 0) { ret =3D PyErr_NoMemory(); } else { - ret =3D _PyUnicode_FromString(s); + ret =3D PyUnicode_FromString(s); free(s); } return ret; @@ -917,17 +891,8 @@ static PyObject *pyrf_evlist__get_pollfd(struct pyrf_e= vlist *pevlist, =20 for (i =3D 0; i < evlist->core.pollfd.nr; ++i) { PyObject *file; -#if PY_MAJOR_VERSION < 3 - FILE *fp =3D fdopen(evlist->core.pollfd.entries[i].fd, "r"); - - if (fp =3D=3D NULL) - goto free_list; - - file =3D PyFile_FromFile(fp, "perf", "r", NULL); -#else file =3D PyFile_FromFd(evlist->core.pollfd.entries[i].fd, "perf", "r", -= 1, NULL, NULL, NULL, 0); -#endif if (file =3D=3D NULL) goto free_list; =20 @@ -1233,9 +1198,9 @@ static PyObject *pyrf__tracepoint(struct pyrf_evsel *= pevsel, =20 tp_format =3D trace_event__tp_format(sys, name); if (IS_ERR(tp_format)) - return _PyLong_FromLong(-1); + return PyLong_FromLong(-1); =20 - return _PyLong_FromLong(tp_format->id); + return PyLong_FromLong(tp_format->id); #endif // HAVE_LIBTRACEEVENT } =20 @@ -1249,18 +1214,11 @@ static PyMethodDef perf__methods[] =3D { { .ml_name =3D NULL, } }; =20 -#if PY_MAJOR_VERSION < 3 -PyMODINIT_FUNC initperf(void) -#else PyMODINIT_FUNC PyInit_perf(void) -#endif { PyObject *obj; int i; PyObject *dict; -#if PY_MAJOR_VERSION < 3 - PyObject *module =3D Py_InitModule("perf", perf__methods); -#else static struct PyModuleDef moduledef =3D { PyModuleDef_HEAD_INIT, "perf", /* m_name */ @@ -1273,7 +1231,6 @@ PyMODINIT_FUNC PyInit_perf(void) NULL, /* m_free */ }; PyObject *module =3D PyModule_Create(&moduledef); -#endif =20 if (module =3D=3D NULL || pyrf_event__setup_types() < 0 || @@ -1281,11 +1238,7 @@ PyMODINIT_FUNC PyInit_perf(void) pyrf_evsel__setup_types() < 0 || pyrf_thread_map__setup_types() < 0 || pyrf_cpu_map__setup_types() < 0) -#if PY_MAJOR_VERSION < 3 - return; -#else return module; -#endif =20 /* The page_size is placed in util object. */ page_size =3D sysconf(_SC_PAGE_SIZE); @@ -1334,7 +1287,7 @@ PyMODINIT_FUNC PyInit_perf(void) goto error; =20 for (i =3D 0; perf__constants[i].name !=3D NULL; i++) { - obj =3D _PyLong_FromLong(perf__constants[i].value); + obj =3D PyLong_FromLong(perf__constants[i].value); if (obj =3D=3D NULL) goto error; PyDict_SetItemString(dict, perf__constants[i].name, obj); @@ -1344,9 +1297,7 @@ PyMODINIT_FUNC PyInit_perf(void) error: if (PyErr_Occurred()) PyErr_SetString(PyExc_ImportError, "perf: Init failed!"); -#if PY_MAJOR_VERSION >=3D 3 return module; -#endif } =20 =20 diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools= /perf/util/scripting-engines/trace-event-python.c index d7183134b669..f1d461d47d73 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -58,22 +58,6 @@ #include "mem-events.h" #include "util/perf_regs.h" =20 -#if PY_MAJOR_VERSION < 3 -#define _PyUnicode_FromString(arg) \ - PyString_FromString(arg) -#define _PyUnicode_FromStringAndSize(arg1, arg2) \ - PyString_FromStringAndSize((arg1), (arg2)) -#define _PyBytes_FromStringAndSize(arg1, arg2) \ - PyString_FromStringAndSize((arg1), (arg2)) -#define _PyLong_FromLong(arg) \ - PyInt_FromLong(arg) -#define _PyLong_AsLong(arg) \ - PyInt_AsLong(arg) -#define _PyCapsule_New(arg1, arg2, arg3) \ - PyCObject_FromVoidPtr((arg1), (arg2)) - -PyMODINIT_FUNC initperf_trace_context(void); -#else #define _PyUnicode_FromString(arg) \ PyUnicode_FromString(arg) #define _PyUnicode_FromStringAndSize(arg1, arg2) \ @@ -88,7 +72,6 @@ PyMODINIT_FUNC initperf_trace_context(void); PyCapsule_New((arg1), (arg2), (arg3)) =20 PyMODINIT_FUNC PyInit_perf_trace_context(void); -#endif =20 #ifdef HAVE_LIBTRACEEVENT #define TRACE_EVENT_TYPE_MAX \ @@ -181,17 +164,7 @@ static int get_argument_count(PyObject *handler) { int arg_count =3D 0; =20 - /* - * The attribute for the code object is func_code in Python 2, - * whereas it is __code__ in Python 3.0+. - */ - PyObject *code_obj =3D PyObject_GetAttrString(handler, - "func_code"); - if (PyErr_Occurred()) { - PyErr_Clear(); - code_obj =3D PyObject_GetAttrString(handler, - "__code__"); - } + PyObject *code_obj =3D code_obj =3D PyObject_GetAttrString(handler, "__co= de__"); PyErr_Clear(); if (code_obj) { PyObject *arg_count_obj =3D PyObject_GetAttrString(code_obj, @@ -1899,12 +1872,6 @@ static void set_table_handlers(struct tables *tables) tables->synth_handler =3D get_handler("synth_data"); } =20 -#if PY_MAJOR_VERSION < 3 -static void _free_command_line(const char **command_line, int num) -{ - free(command_line); -} -#else static void _free_command_line(wchar_t **command_line, int num) { int i; @@ -1912,7 +1879,6 @@ static void _free_command_line(wchar_t **command_line= , int num) PyMem_RawFree(command_line[i]); free(command_line); } -#endif =20 =20 /* @@ -1922,30 +1888,12 @@ static int python_start_script(const char *script, = int argc, const char **argv, struct perf_session *session) { struct tables *tables =3D &tables_global; -#if PY_MAJOR_VERSION < 3 - const char **command_line; -#else wchar_t **command_line; -#endif - /* - * Use a non-const name variable to cope with python 2.6's - * PyImport_AppendInittab prototype - */ - char buf[PATH_MAX], name[19] =3D "perf_trace_context"; + char buf[PATH_MAX]; int i, err =3D 0; FILE *fp; =20 scripting_context->session =3D session; -#if PY_MAJOR_VERSION < 3 - command_line =3D malloc((argc + 1) * sizeof(const char *)); - if (!command_line) - return -1; - - command_line[0] =3D script; - for (i =3D 1; i < argc + 1; i++) - command_line[i] =3D argv[i - 1]; - PyImport_AppendInittab(name, initperf_trace_context); -#else command_line =3D malloc((argc + 1) * sizeof(wchar_t *)); if (!command_line) return -1; @@ -1953,15 +1901,10 @@ static int python_start_script(const char *script, = int argc, const char **argv, command_line[0] =3D Py_DecodeLocale(script, NULL); for (i =3D 1; i < argc + 1; i++) command_line[i] =3D Py_DecodeLocale(argv[i - 1], NULL); - PyImport_AppendInittab(name, PyInit_perf_trace_context); -#endif + PyImport_AppendInittab("perf_trace_context", PyInit_perf_trace_context); Py_Initialize(); =20 -#if PY_MAJOR_VERSION < 3 - PySys_SetArgv(argc + 1, (char **)command_line); -#else PySys_SetArgv(argc + 1, command_line); -#endif =20 fp =3D fopen(script, "r"); if (!fp) { --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Tue Nov 26 19:53:15 2024 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 1534218891F for ; Wed, 16 Oct 2024 04:24:39 +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=1729052681; cv=none; b=EJTF1z/4Kzj+YECWIL937+13V4KiieLALlkzUUlRsGsLFhiUoU6O17bZJR3QM5sDd5hfPpXrI23nllteuWsEAvVWTNVgmjuj3Deaoj9Rzx1S+6SpI0fDNPPhtDn/n0h497y05DofT6s7cLhqppfhR8tLOte+LC2f8y9IfoLXsmg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729052681; c=relaxed/simple; bh=7HLL/EuiPte+FBmbhpfQpx2M+PoIuhEyQToTclsBA9Q=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=N5jzF88XeKJ5GXgz9r3yIj74ofxu3plI1SS5IL9+3x6lApaCrt3/9a6cjzCyPkloE3ISD8tjsB3u7AYX0csDKKJDTclphTx4B4WGhbMBNKuGKINeXEbclVFF0yQVdNfCb0G6g+wwejRbUY4kfB4u3RyLgvxfaLGsaYxyzYPpAlc= 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=jxK3APKQ; 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="jxK3APKQ" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e2974759f5fso647033276.0 for ; Tue, 15 Oct 2024 21:24:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729052679; x=1729657479; 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=nufIfERJADmt3WQfqYt2dWiE1lZ61+Z8d0TsyXgm8QA=; b=jxK3APKQ0CpKf4gNqHqoTXzKfqidj5gtKdyV3qCprxGSVa57iq/8Qs/FUbTw9kh8hT X3UBD6B6T1t4w5ShkvKMG4ikE+6WkA+3EqxXMshNr9hQ6XufDFW0ZiLumO+LpStHJhWQ etadb5eF1G5fVtFxkwR5UeHf5tjabMF8Rq69U2zJESA1e5WRVlpQ89ZizZYGQ8UVYktx Pz3Dm4DmB53DBYAqFOD6dHRMVvN2ZtnRPAXc++i7vP6NjQ5pd83ea65dHHkwj36LljaZ o67QzN580p2kwJULGaOIcw4pGecay4xl9uubxMnamAm4l934qeCy42oUttJmmwsNIEhG f3+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729052679; x=1729657479; 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=nufIfERJADmt3WQfqYt2dWiE1lZ61+Z8d0TsyXgm8QA=; b=KwHAl0nUxRK7lCWR7J96gMVWNwfmO5/L3EFv+b8b4DMK17RjqdObYgIEfoQNDjBKxJ SZTO8CUycVSlhbQRVlzFlL/3s9mpEnaPA3SSskOB/byxak9KcXYyy43i30VsOakEvOVM 5c90Zv563/pZHWZ14H9y/hUVEFe3IPtYzN3ARdG6zbZ75q79IBMKBEEPffs2sJXn2wJa Hg3GEp+E1Yk8We662woUHC2osXoA3/biHQH0LRPnk8mpMwYcZvIiCMILhTli6XBgj0Mp +aTZp8BleIUO9sGA9H1powKIS+PdePQeCDfUwfakt4Mj0XuLNGcQqneYU2jRFQDZ5/kH czyw== X-Forwarded-Encrypted: i=1; AJvYcCWovcJlQqLcwE7ZfiBMGLpEKYEgcQE3L6PpiF1BZsefBomNoYO+OoiitvI+bLD6P3G9GUHbjYSu1yLxcec=@vger.kernel.org X-Gm-Message-State: AOJu0YxcizTMAvIRI6jSHwXId9K9NxwuPXiKmZeZDErsbPmEjAFSWY0r F8hEtGBZzBrWAivJrku01g0Dy6eiR9SVs85KwhJirac6EqZkYnuThNOQE1l7vphDkRU/tyj88TH Ij3gMcg== X-Google-Smtp-Source: AGHT+IFPX2vMWw8+RmSgjCEtcGdDp/ZV2Q0WFowHXgsi1nor82D1RzJMQdIEu7N1tY3siN0xWu2P77TA71+X X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a5b:f09:0:b0:e29:ad0:a326 with SMTP id 3f1490d57ef6-e2976fbb30bmr18606276.0.1729052679003; Tue, 15 Oct 2024 21:24:39 -0700 (PDT) Date: Tue, 15 Oct 2024 21:24:01 -0700 In-Reply-To: <20241016042415.7552-1-irogers@google.com> Message-Id: <20241016042415.7552-3-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241016042415.7552-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Subject: [PATCH v2 02/16] perf python: Constify variables and parameters 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 , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Opportunistically constify variables and parameters when possible. Signed-off-by: Ian Rogers --- tools/perf/util/python.c | 55 +++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 02279ab4967c..13dad27169a0 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -62,7 +62,7 @@ struct pyrf_event { sample_member_def(sample_period, period, T_ULONGLONG, "event period"), \ sample_member_def(sample_cpu, cpu, T_UINT, "event cpu"), =20 -static char pyrf_mmap_event__doc[] =3D PyDoc_STR("perf mmap event object."= ); +static const char pyrf_mmap_event__doc[] =3D PyDoc_STR("perf mmap event ob= ject."); =20 static PyMemberDef pyrf_mmap_event__members[] =3D { sample_members @@ -77,7 +77,7 @@ static PyMemberDef pyrf_mmap_event__members[] =3D { { .name =3D NULL, }, }; =20 -static PyObject *pyrf_mmap_event__repr(struct pyrf_event *pevent) +static PyObject *pyrf_mmap_event__repr(const struct pyrf_event *pevent) { PyObject *ret; char *s; @@ -106,7 +106,7 @@ static PyTypeObject pyrf_mmap_event__type =3D { .tp_repr =3D (reprfunc)pyrf_mmap_event__repr, }; =20 -static char pyrf_task_event__doc[] =3D PyDoc_STR("perf task (fork/exit) ev= ent object."); +static const char pyrf_task_event__doc[] =3D PyDoc_STR("perf task (fork/ex= it) event object."); =20 static PyMemberDef pyrf_task_event__members[] =3D { sample_members @@ -119,7 +119,7 @@ static PyMemberDef pyrf_task_event__members[] =3D { { .name =3D NULL, }, }; =20 -static PyObject *pyrf_task_event__repr(struct pyrf_event *pevent) +static PyObject *pyrf_task_event__repr(const struct pyrf_event *pevent) { return PyUnicode_FromFormat("{ type: %s, pid: %u, ppid: %u, tid: %u, " "ptid: %u, time: %" PRI_lu64 "}", @@ -141,7 +141,7 @@ static PyTypeObject pyrf_task_event__type =3D { .tp_repr =3D (reprfunc)pyrf_task_event__repr, }; =20 -static char pyrf_comm_event__doc[] =3D PyDoc_STR("perf comm event object."= ); +static const char pyrf_comm_event__doc[] =3D PyDoc_STR("perf comm event ob= ject."); =20 static PyMemberDef pyrf_comm_event__members[] =3D { sample_members @@ -152,7 +152,7 @@ static PyMemberDef pyrf_comm_event__members[] =3D { { .name =3D NULL, }, }; =20 -static PyObject *pyrf_comm_event__repr(struct pyrf_event *pevent) +static PyObject *pyrf_comm_event__repr(const struct pyrf_event *pevent) { return PyUnicode_FromFormat("{ type: comm, pid: %u, tid: %u, comm: %s }", pevent->event.comm.pid, @@ -170,7 +170,7 @@ static PyTypeObject pyrf_comm_event__type =3D { .tp_repr =3D (reprfunc)pyrf_comm_event__repr, }; =20 -static char pyrf_throttle_event__doc[] =3D PyDoc_STR("perf throttle event = object."); +static const char pyrf_throttle_event__doc[] =3D PyDoc_STR("perf throttle = event object."); =20 static PyMemberDef pyrf_throttle_event__members[] =3D { sample_members @@ -181,9 +181,10 @@ static PyMemberDef pyrf_throttle_event__members[] =3D { { .name =3D NULL, }, }; =20 -static PyObject *pyrf_throttle_event__repr(struct pyrf_event *pevent) +static PyObject *pyrf_throttle_event__repr(const struct pyrf_event *pevent) { - struct perf_record_throttle *te =3D (struct perf_record_throttle *)(&peve= nt->event.header + 1); + const struct perf_record_throttle *te =3D (const struct perf_record_throt= tle *) + (&pevent->event.header + 1); =20 return PyUnicode_FromFormat("{ type: %sthrottle, time: %" PRI_lu64 ", id:= %" PRI_lu64 ", stream_id: %" PRI_lu64 " }", @@ -201,7 +202,7 @@ static PyTypeObject pyrf_throttle_event__type =3D { .tp_repr =3D (reprfunc)pyrf_throttle_event__repr, }; =20 -static char pyrf_lost_event__doc[] =3D PyDoc_STR("perf lost event object."= ); +static const char pyrf_lost_event__doc[] =3D PyDoc_STR("perf lost event ob= ject."); =20 static PyMemberDef pyrf_lost_event__members[] =3D { sample_members @@ -210,7 +211,7 @@ static PyMemberDef pyrf_lost_event__members[] =3D { { .name =3D NULL, }, }; =20 -static PyObject *pyrf_lost_event__repr(struct pyrf_event *pevent) +static PyObject *pyrf_lost_event__repr(const struct pyrf_event *pevent) { PyObject *ret; char *s; @@ -236,7 +237,7 @@ static PyTypeObject pyrf_lost_event__type =3D { .tp_repr =3D (reprfunc)pyrf_lost_event__repr, }; =20 -static char pyrf_read_event__doc[] =3D PyDoc_STR("perf read event object."= ); +static const char pyrf_read_event__doc[] =3D PyDoc_STR("perf read event ob= ject."); =20 static PyMemberDef pyrf_read_event__members[] =3D { sample_members @@ -245,7 +246,7 @@ static PyMemberDef pyrf_read_event__members[] =3D { { .name =3D NULL, }, }; =20 -static PyObject *pyrf_read_event__repr(struct pyrf_event *pevent) +static PyObject *pyrf_read_event__repr(const struct pyrf_event *pevent) { return PyUnicode_FromFormat("{ type: read, pid: %u, tid: %u }", pevent->event.read.pid, @@ -266,7 +267,7 @@ static PyTypeObject pyrf_read_event__type =3D { .tp_repr =3D (reprfunc)pyrf_read_event__repr, }; =20 -static char pyrf_sample_event__doc[] =3D PyDoc_STR("perf sample event obje= ct."); +static const char pyrf_sample_event__doc[] =3D PyDoc_STR("perf sample even= t object."); =20 static PyMemberDef pyrf_sample_event__members[] =3D { sample_members @@ -274,7 +275,7 @@ static PyMemberDef pyrf_sample_event__members[] =3D { { .name =3D NULL, }, }; =20 -static PyObject *pyrf_sample_event__repr(struct pyrf_event *pevent) +static PyObject *pyrf_sample_event__repr(const struct pyrf_event *pevent) { PyObject *ret; char *s; @@ -289,13 +290,13 @@ static PyObject *pyrf_sample_event__repr(struct pyrf_= event *pevent) } =20 #ifdef HAVE_LIBTRACEEVENT -static bool is_tracepoint(struct pyrf_event *pevent) +static bool is_tracepoint(const struct pyrf_event *pevent) { return pevent->evsel->core.attr.type =3D=3D PERF_TYPE_TRACEPOINT; } =20 static PyObject* -tracepoint_field(struct pyrf_event *pe, struct tep_format_field *field) +tracepoint_field(const struct pyrf_event *pe, struct tep_format_field *fie= ld) { struct tep_handle *pevent =3D field->event->tep; void *data =3D pe->sample.raw_data; @@ -384,7 +385,7 @@ static PyTypeObject pyrf_sample_event__type =3D { .tp_getattro =3D (getattrofunc) pyrf_sample_event__getattro, }; =20 -static char pyrf_context_switch_event__doc[] =3D PyDoc_STR("perf context_s= witch event object."); +static const char pyrf_context_switch_event__doc[] =3D PyDoc_STR("perf con= text_switch event object."); =20 static PyMemberDef pyrf_context_switch_event__members[] =3D { sample_members @@ -394,7 +395,7 @@ static PyMemberDef pyrf_context_switch_event__members[]= =3D { { .name =3D NULL, }, }; =20 -static PyObject *pyrf_context_switch_event__repr(struct pyrf_event *pevent) +static PyObject *pyrf_context_switch_event__repr(const struct pyrf_event *= pevent) { PyObject *ret; char *s; @@ -474,7 +475,7 @@ static PyTypeObject *pyrf_event__type[] =3D { [PERF_RECORD_SWITCH_CPU_WIDE] =3D &pyrf_context_switch_event__type, }; =20 -static PyObject *pyrf_event__new(union perf_event *event) +static PyObject *pyrf_event__new(const union perf_event *event) { struct pyrf_event *pevent; PyTypeObject *ptype; @@ -542,7 +543,7 @@ static PySequenceMethods pyrf_cpu_map__sequence_methods= =3D { .sq_item =3D pyrf_cpu_map__item, }; =20 -static char pyrf_cpu_map__doc[] =3D PyDoc_STR("cpu map object."); +static const char pyrf_cpu_map__doc[] =3D PyDoc_STR("cpu map object."); =20 static PyTypeObject pyrf_cpu_map__type =3D { PyVarObject_HEAD_INIT(NULL, 0) @@ -611,7 +612,7 @@ static PySequenceMethods pyrf_thread_map__sequence_meth= ods =3D { .sq_item =3D pyrf_thread_map__item, }; =20 -static char pyrf_thread_map__doc[] =3D PyDoc_STR("thread map object."); +static const char pyrf_thread_map__doc[] =3D PyDoc_STR("thread map object.= "); =20 static PyTypeObject pyrf_thread_map__type =3D { PyVarObject_HEAD_INIT(NULL, 0) @@ -795,7 +796,7 @@ static PyMethodDef pyrf_evsel__methods[] =3D { { .ml_name =3D NULL, } }; =20 -static char pyrf_evsel__doc[] =3D PyDoc_STR("perf event selector list obje= ct."); +static const char pyrf_evsel__doc[] =3D PyDoc_STR("perf event selector lis= t object."); =20 static PyTypeObject pyrf_evsel__type =3D { PyVarObject_HEAD_INIT(NULL, 0) @@ -1078,7 +1079,7 @@ static PySequenceMethods pyrf_evlist__sequence_method= s =3D { .sq_item =3D pyrf_evlist__item, }; =20 -static char pyrf_evlist__doc[] =3D PyDoc_STR("perf event selector list obj= ect."); +static const char pyrf_evlist__doc[] =3D PyDoc_STR("perf event selector li= st object."); =20 static PyTypeObject pyrf_evlist__type =3D { PyVarObject_HEAD_INIT(NULL, 0) @@ -1100,10 +1101,12 @@ static int pyrf_evlist__setup_types(void) =20 #define PERF_CONST(name) { #name, PERF_##name } =20 -static struct { +struct perf_constant { const char *name; int value; -} perf__constants[] =3D { +}; + +static const struct perf_constant perf__constants[] =3D { PERF_CONST(TYPE_HARDWARE), PERF_CONST(TYPE_SOFTWARE), PERF_CONST(TYPE_TRACEPOINT), --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Tue Nov 26 19:53:15 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 4681418A6B8 for ; Wed, 16 Oct 2024 04:24:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729052683; cv=none; b=oKzow3adS5QLeT0pBrO/E1bbDVrfO4F5LgN/1XvdVJIjcx96PyKUGYBcLe4z1WJ269RqkfzOR2ew/CNYrVr198LdIoEL4UAdwmy1KDVplRPs+W/XRKlsT5Psmn8uSrr1raxwzEn1tE6jdMfweQuxEyL1IQDlw63nN92k1lTwiY4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729052683; c=relaxed/simple; bh=bhHQDJnTJ4bocwSVO6+nzPhKgwvVlYSgBM/QGoZ266E=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=FDEN4Wi0rRlZmK1Iglf0guHMnQL+V90uTnqKtytOKMxtGRvAPKe3JMqakw5s/ZtMKH3PiZT5KiZdlspCEv6Sa5eBShJ8Tr4YWkjuAhu9S4WHFUuy3c0UExp3wdd6iQm3MMAz0Td95AaV7bnGbI1Oh5qGsmvyaRaZ8MrVtY8F18g= 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=NvRHk3HW; arc=none smtp.client-ip=209.85.128.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="NvRHk3HW" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e3231725c9so92070477b3.1 for ; Tue, 15 Oct 2024 21:24:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729052681; x=1729657481; 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=yzM1nmvTrqtIbytQymy654+4zTDkQaKxO+Kef60mREc=; b=NvRHk3HWU3mKE3/g82sTr9qoxDJLo5p/km4krRReTHWNLSHm5GolMAVjasphZs1PkA X4OenCk0113XMBh2N1fKY/DZB1ijv8lVkFnaZ7KifSMrgwKuGv2KzyvfJozoeNPzQhnv xnXWe+UZwUGUV8SuqjXc4pCBXHc4unpXYmQJABJAUj0UPdy7yTOP8Dz0Gac7keTg7NjJ q/c2EryYcbds6qQhKs1xF+5CAL5vD3C2v/JGuPT2jv+DaGIvWeIZ5j6AI7x0rHZ2Mq2t wOv8UiqVd9VgdqX6+6GKS1PTjd+WHtk2RkIX+f7NXwcfGsW8kce6U/A2L+Av+tVQdVpP NyZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729052681; x=1729657481; 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=yzM1nmvTrqtIbytQymy654+4zTDkQaKxO+Kef60mREc=; b=Xg8CEWUShwliun16JYAZZD7ZhveseUrgDDoqRhhcNFSzF1QelE3mnVObM+z+44uWoM RTWkCtNhwBMqgGSzRABVZJWzZ4a6xLRli+k24KbK14Gc+nx7qxAQnLFCuRViOluqBGgg 02TY+g/p+78ThC9DFcH6f5ovYYiDGgHLw71zr0d7sPjXFBeam6ptLyYOtAlw05WVLi3i 9x6MbIjSKot3tHeAnhC1qjU1t13QTGBicsJQZ/0WjOrDl+rOcOyE+VWQA92/Ryu2xuoh edm7Viq2xnV8heK2J+aOENdp0fTu7QeDrt1UslTiMunn/cJ6wCnZBPsEcUDMhHOIiMwT dSeg== X-Forwarded-Encrypted: i=1; AJvYcCUBX0NW5RAHZbtUv9rhZRo8S4h6cLNFg/Iy5UMzFf0gHO3uTJT3azZ+eh52CzFyN4MZugs4qQXHebIHbE0=@vger.kernel.org X-Gm-Message-State: AOJu0YzHDt08jle0Vdxt0eJx9RSs96TbN83FinuY/VNMcpv67N962UbR ZCXn5LGMWCVSydlhRqiL7Q2SJu6n/1m3HMYEH+LoX6hd/BoNJROhHJl+jQVWC9MZdRJgQnaElPk zQ6KyvQ== X-Google-Smtp-Source: AGHT+IHj/KEQGpPTZ4ugd9O5Z+R4HSHPtTwcD6Do2ajnxTnL5lk3DXKs7OIutPqYknLJgG/exImnYAY0f88/ X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a25:acce:0:b0:e0b:958a:3344 with SMTP id 3f1490d57ef6-e297859d818mr2423276.10.1729052681221; Tue, 15 Oct 2024 21:24:41 -0700 (PDT) Date: Tue, 15 Oct 2024 21:24:02 -0700 In-Reply-To: <20241016042415.7552-1-irogers@google.com> Message-Id: <20241016042415.7552-4-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241016042415.7552-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Subject: [PATCH v2 03/16] perf python: Remove unused #include 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 , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove unused #include of bpf-filter.h. Signed-off-by: Ian Rogers --- tools/perf/util/python.c | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 13dad27169a0..974578a04099 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -16,7 +16,6 @@ #include "thread_map.h" #include "trace-event.h" #include "mmap.h" -#include "util/bpf-filter.h" #include "util/env.h" #include "util/kvm-stat.h" #include "util/kwork.h" --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Tue Nov 26 19:53:15 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 9AC2718BB90 for ; Wed, 16 Oct 2024 04:24:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729052686; cv=none; b=kKIuGdrOdBM5nVK6Ua0GrgBc2DWe13XOqm6H9QWaPRWf2WZCJHOFwAy/B1HhGzIwkhJgaYb/dj1n48QvHbl2CSiFT1jtftLgIQ6seGQRR28QpWqSGB21ymwQEJpD03ezDw6Gdap45b4pY998Zbxb0pvmmS4cInquw64nhdzSHSI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729052686; c=relaxed/simple; bh=zLV372V3NqdgZLhhP3Ug7ewTDMXX2WZU0AoI5q9l/W8=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=s1QLLXZUzT6i9vxY3MshMV3nFB1Q/hbATXBhQ0x2pedcg1iXkI/3gDzv3zM6t4fIeoVcJJ6rk8bm1WDRigoUJruRXBY6rma7UOhU56yhUNvj6HgKEixoVoJKXSkAm4WVfPr+FCOGF0HdQFvL04bAkHnryk5mfseKIaF6yvdWXnE= 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=lESikxwv; arc=none smtp.client-ip=209.85.128.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="lESikxwv" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e1fbe2a6b1so105681107b3.2 for ; Tue, 15 Oct 2024 21:24:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729052684; x=1729657484; 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=F3AUkqayHUmU4e0+n944DcuSfXi0VxOxh6mXGhbne8U=; b=lESikxwv4CDUGMvoJqrGR0bTIUaHfbjo6bGiuAGx7laFa6qfwMOZv8vy/g83iezMcv o3iDQJvRfJBIs0iQVSMueb43P+VS3gSx1+UnfEcGV/+Ng1kd/tulVibLRl6lJ0AbFFAo npDaHTiV9JGISE7XDQZ/c0hi/vrwAna9Yf86rT4Jh7cW6VMvnRt3ER9G4mEHw/vIVuMJ lSTu5PvYEY/2FYjYnLiO05OQUEA6EYrexLgmiP68PNhsKmQgcLBJVnt6ZSSKDdURgHxo NAa6m3R7ODnIcLiX15XQDDCNteRoZDdxopIyMJGb8MuuubekcI3j3fjdBacMa0QTaaLp YYfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729052684; x=1729657484; 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=F3AUkqayHUmU4e0+n944DcuSfXi0VxOxh6mXGhbne8U=; b=qqAEdhlljD1X97PY54oh3gO8inzcszntjWP45UuwZQiBPBfO+SsKlCHCZ2sDDyHqDL 7kqAoxoutMenu8hl12P6kFYugQLW3bGy45TIA+Kh3a+GetKgAaVnZAruCFnnqVtbugrQ PB+Q90lPqeOVv1F5HXC/viZBVkq8u3nHbaRlmn7NvlfO0ORmG+5dVpJCd8Z+ShW1wcTw hvFkLkm5IVkEt5TGcI6nT0Z4bmeIlKRHvoRYcKsH2HFsIuw6n0Taz/o7jKsg2bB++y2R H/Nz0ubCPXRpoOyssAwqZdYVKXvZ8LWWPlRkxxvqBNR6BFTl4F+K4fwFcWiBWDxoHHz3 ycgg== X-Forwarded-Encrypted: i=1; AJvYcCVW7yN3+S4QKUUd5TesL0ZUuple3WMzo+0x+LiPS/UZ3835u1LSAxtF+DRgHavrx9qjkTZsEnm//aK+mNQ=@vger.kernel.org X-Gm-Message-State: AOJu0YycTMguXR+2IkScOGa22leqr8vrQPtuhXJsxNYhQOzkWWboR5HU irdLr67seGkXAfVjCL1dN2P9wTvg90J67SwZfnpezsmHSHje58wESusCLgDxVmN5KToFuTOh5Jk 7eAGwAg== X-Google-Smtp-Source: AGHT+IH+B/UstQTaBPNWylRCfG5c7G6KjVDSfo/SEGNBz24zXUN6VhnJfUctTb/L68W/BCQ7jhbH+DG86Cpy X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a05:690c:2502:b0:6e2:70e:e82e with SMTP id 00721157ae682-6e3d41cb4aamr547127b3.6.1729052683538; Tue, 15 Oct 2024 21:24:43 -0700 (PDT) Date: Tue, 15 Oct 2024 21:24:03 -0700 In-Reply-To: <20241016042415.7552-1-irogers@google.com> Message-Id: <20241016042415.7552-5-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241016042415.7552-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Subject: [PATCH v2 04/16] perf script: Move scripting_max_stack out of builtin 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 , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" scripting_max_stack is used in util code which is linked into the python module. Move the variable declaration to util/trace-event-scripting.c to avoid conditional compilation. Signed-off-by: Ian Rogers --- tools/perf/builtin-script.c | 2 -- tools/perf/util/python.c | 2 -- tools/perf/util/trace-event-scripting.c | 3 +++ 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index a644787fa9e1..621c26c388c8 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -92,8 +92,6 @@ static struct dlfilter *dlfilter; static int dlargc; static char **dlargv; =20 -unsigned int scripting_max_stack =3D PERF_MAX_STACK_DEPTH; - enum perf_output_field { PERF_OUTPUT_COMM =3D 1ULL << 0, PERF_OUTPUT_TID =3D 1ULL << 1, diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 974578a04099..298f43981fc5 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1306,8 +1306,6 @@ PyMODINIT_FUNC PyInit_perf(void) /* The following are stubs to avoid dragging in builtin-* objects. */ /* TODO: move the code out of the builtin-* file into util. */ =20 -unsigned int scripting_max_stack =3D PERF_MAX_STACK_DEPTH; - bool kvm_entry_event(struct evsel *evsel __maybe_unused) { return false; diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trac= e-event-scripting.c index bd0000300c77..8abb7a7b6888 100644 --- a/tools/perf/util/trace-event-scripting.c +++ b/tools/perf/util/trace-event-scripting.c @@ -16,9 +16,12 @@ #include "debug.h" #include "trace-event.h" #include "evsel.h" +#include #include #include "util/sample.h" =20 +unsigned int scripting_max_stack =3D PERF_MAX_STACK_DEPTH; + struct scripting_context *scripting_context; =20 void scripting_context__update(struct scripting_context *c, --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Tue Nov 26 19:53:15 2024 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 64BE518BC28 for ; Wed, 16 Oct 2024 04:24:47 +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=1729052689; cv=none; b=B6RoWyp5xw7GkAPOL/QT+T/8BHZF/zasemuDyP72dnPjOsgvRIiofE+5GTF3V14w4k4+BBDUAHeHv8nZ+qPV4h9fss1YLxyzLxsgSuTf+hXTDFtCYfik1H4mPQvN1vOh3wwpYfxbSalhBfRDQPeB1vQeGPHNpncK9zA4icEjoDA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729052689; c=relaxed/simple; bh=sevNlyfEJVFmCq0ytEyhLchplPVQxoaCC3sAsSe1/f8=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=KyRfi4+/LpI7khDEK0BBKt4A9rKCP1UGsk+YiyL+Fqn2X7W2/ugb1XhiF0uoKW2lEh4AzTVRB7W751upYDWYYpqG6+mgv4+1pm/kjUPcPDNm/FaEI3cyCsi7Sg+2c4GcIu+1lvfZP/Tq1IBmlcFp/Biu56guZZebBdn7ftG7Pqc= 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=HUb4LeMs; 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="HUb4LeMs" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e293150c2c6so7795922276.1 for ; Tue, 15 Oct 2024 21:24:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729052686; x=1729657486; 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=qQyl2EObKlFstHveBm/uzMgWIzegkTZ8/5AcFUtSIFY=; b=HUb4LeMs2+Mh/5tKP4SureS+LlKFM0nW9D2y+Ox6j12Hm6z1dqVfeC8hT0SRyrE9Jz 1KvdmMRpD7M7mBY9ob0SpGK16yvwhB8wICJGQJcVNCDhqPdropIe3tfrj1tcAL1ocgJx paZhH0V+qYeSZ4ZpgUVPaeHW5m8LQOBOT2B9IykubBkQVq3RIFAppZEb3vAVRNI7T7id TgallTmxgY8xChHZ8MpIjmKgKrI+ahhWm30MHqliWgl7IhkFyaPUdd7pri40Pb3Zk6FZ OsbFX1zBl+f2zFuHQpseh93ubpnihNE32lEXc9JoM8lgzcyCwmaRIAO+nXQly3EgIs8e hrEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729052686; x=1729657486; 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=qQyl2EObKlFstHveBm/uzMgWIzegkTZ8/5AcFUtSIFY=; b=Wrq5lZiAyDHoqeD6bc0NU/mlfYiW26KfBSP+dDQSGgTeZYlm1+GvQi9va5hcRCgC3C QbWQAcOmLaK1Rq21wKuGuTRb4LmPZ4Cwzz2nzw0TyGZQSYEmFvqMlmH9W+OqVtga2C+q BKq3kbWx/cTECepsugULNk0InNRcjUtZ1ftDjkbEPOA7I7oY0FxWwu/qK+d7P2yYHqLE /lL1wtDp2q/ecjbAGGcv9FLIuVlPBsmqOvrZ8+idZe5urLFZiBESyHCmY6y35ZhDZc0l PDw/HjTcGWegC6JKV5N2VXcreT4nfJ6jJumhmsjsSXvVJKVQL/dTHCh9uEcZ12OJ93wV FkxQ== X-Forwarded-Encrypted: i=1; AJvYcCVTw1b85w3MhdB8u7QojbQtp/OCz4HjdLEauuqmC6N+PEVTXKiZG6v9VI7qvC2/xYwGxbXhN6TW8FvchLo=@vger.kernel.org X-Gm-Message-State: AOJu0YxnnUtkn9c1KAcbvppGGvvGNeXikl3C0iXLOpiHHNItVnDZiClk IkqCzcxgqZGLZGab1GurwI9Tro3Hbo/+4i81GbT/nEH/J7vsKE5qSve47FopDw56VLXi32lJs8y LZvgvjA== X-Google-Smtp-Source: AGHT+IFirg7lf86uX0MYsDX47DXOxSEArB6ExV/cuOBucvZo3ssUJELaOGG3Jw59lLKBF1qxYnQ0FIv7XUJa X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a25:aaa3:0:b0:e20:25f5:a889 with SMTP id 3f1490d57ef6-e29783030e0mr1502276.5.1729052685919; Tue, 15 Oct 2024 21:24:45 -0700 (PDT) Date: Tue, 15 Oct 2024 21:24:04 -0700 In-Reply-To: <20241016042415.7552-1-irogers@google.com> Message-Id: <20241016042415.7552-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: <20241016042415.7552-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Subject: [PATCH v2 05/16] perf kvm: Move functions used in util out of builtin 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 , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The util library code is used by the python module but doesn't have access to the builtin files. Make a util/kvm-stat.c to match the kvm-stat.h file that declares the functions and move the functions there. Signed-off-by: Ian Rogers --- tools/perf/builtin-kvm.c | 61 --------------------------------- tools/perf/util/Build | 1 + tools/perf/util/kvm-stat.c | 70 ++++++++++++++++++++++++++++++++++++++ tools/perf/util/kvm-stat.h | 3 ++ tools/perf/util/python.c | 30 ---------------- 5 files changed, 74 insertions(+), 91 deletions(-) create mode 100644 tools/perf/util/kvm-stat.c diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 55ea17c5ff02..6f34099d5fb0 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -615,67 +615,6 @@ static const char *get_filename_for_perf_kvm(void) =20 #if defined(HAVE_KVM_STAT_SUPPORT) && defined(HAVE_LIBTRACEEVENT) =20 -void exit_event_get_key(struct evsel *evsel, - struct perf_sample *sample, - struct event_key *key) -{ - key->info =3D 0; - key->key =3D evsel__intval(evsel, sample, kvm_exit_reason); -} - -bool kvm_exit_event(struct evsel *evsel) -{ - return evsel__name_is(evsel, kvm_exit_trace); -} - -bool exit_event_begin(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key) -{ - if (kvm_exit_event(evsel)) { - exit_event_get_key(evsel, sample, key); - return true; - } - - return false; -} - -bool kvm_entry_event(struct evsel *evsel) -{ - return evsel__name_is(evsel, kvm_entry_trace); -} - -bool exit_event_end(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, - struct event_key *key __maybe_unused) -{ - return kvm_entry_event(evsel); -} - -static const char *get_exit_reason(struct perf_kvm_stat *kvm, - struct exit_reasons_table *tbl, - u64 exit_code) -{ - while (tbl->reason !=3D NULL) { - if (tbl->exit_code =3D=3D exit_code) - return tbl->reason; - tbl++; - } - - pr_err("unknown kvm exit code:%lld on %s\n", - (unsigned long long)exit_code, kvm->exit_reasons_isa); - return "UNKNOWN"; -} - -void exit_event_decode_key(struct perf_kvm_stat *kvm, - struct event_key *key, - char *decode) -{ - const char *exit_reason =3D get_exit_reason(kvm, key->exit_reasons, - key->key); - - scnprintf(decode, KVM_EVENT_NAME_LEN, "%s", exit_reason); -} - static bool register_kvm_events_ops(struct perf_kvm_stat *kvm) { struct kvm_reg_events_ops *events_ops =3D kvm_reg_events_ops; diff --git a/tools/perf/util/Build b/tools/perf/util/Build index fa508e113dd0..2a2f7780e595 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -120,6 +120,7 @@ perf-util-y +=3D spark.o perf-util-y +=3D topdown.o perf-util-y +=3D iostat.o perf-util-y +=3D stream.o +perf-util-y +=3D kvm-stat.o perf-util-$(CONFIG_AUXTRACE) +=3D auxtrace.o perf-util-$(CONFIG_AUXTRACE) +=3D intel-pt-decoder/ perf-util-$(CONFIG_AUXTRACE) +=3D intel-pt.o diff --git a/tools/perf/util/kvm-stat.c b/tools/perf/util/kvm-stat.c new file mode 100644 index 000000000000..38ace736db5c --- /dev/null +++ b/tools/perf/util/kvm-stat.c @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "debug.h" +#include "evsel.h" +#include "kvm-stat.h" + +#if defined(HAVE_KVM_STAT_SUPPORT) && defined(HAVE_LIBTRACEEVENT) + +bool kvm_exit_event(struct evsel *evsel) +{ + return evsel__name_is(evsel, kvm_exit_trace); +} + +void exit_event_get_key(struct evsel *evsel, + struct perf_sample *sample, + struct event_key *key) +{ + key->info =3D 0; + key->key =3D evsel__intval(evsel, sample, kvm_exit_reason); +} + + +bool exit_event_begin(struct evsel *evsel, + struct perf_sample *sample, struct event_key *key) +{ + if (kvm_exit_event(evsel)) { + exit_event_get_key(evsel, sample, key); + return true; + } + + return false; +} + +bool kvm_entry_event(struct evsel *evsel) +{ + return evsel__name_is(evsel, kvm_entry_trace); +} + +bool exit_event_end(struct evsel *evsel, + struct perf_sample *sample __maybe_unused, + struct event_key *key __maybe_unused) +{ + return kvm_entry_event(evsel); +} + +static const char *get_exit_reason(struct perf_kvm_stat *kvm, + struct exit_reasons_table *tbl, + u64 exit_code) +{ + while (tbl->reason !=3D NULL) { + if (tbl->exit_code =3D=3D exit_code) + return tbl->reason; + tbl++; + } + + pr_err("unknown kvm exit code:%lld on %s\n", + (unsigned long long)exit_code, kvm->exit_reasons_isa); + return "UNKNOWN"; +} + +void exit_event_decode_key(struct perf_kvm_stat *kvm, + struct event_key *key, + char *decode) +{ + const char *exit_reason =3D get_exit_reason(kvm, key->exit_reasons, + key->key); + + scnprintf(decode, KVM_EVENT_NAME_LEN, "%s", exit_reason); +} + +#endif diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index 3e9ac754c3d1..4249542544bb 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -115,6 +115,8 @@ struct kvm_reg_events_ops { struct kvm_events_ops *ops; }; =20 +#if defined(HAVE_KVM_STAT_SUPPORT) && defined(HAVE_LIBTRACEEVENT) + void exit_event_get_key(struct evsel *evsel, struct perf_sample *sample, struct event_key *key); @@ -127,6 +129,7 @@ bool exit_event_end(struct evsel *evsel, void exit_event_decode_key(struct perf_kvm_stat *kvm, struct event_key *key, char *decode); +#endif =20 bool kvm_exit_event(struct evsel *evsel); bool kvm_entry_event(struct evsel *evsel); diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 298f43981fc5..ab67abf3b607 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1306,36 +1306,6 @@ PyMODINIT_FUNC PyInit_perf(void) /* The following are stubs to avoid dragging in builtin-* objects. */ /* TODO: move the code out of the builtin-* file into util. */ =20 -bool kvm_entry_event(struct evsel *evsel __maybe_unused) -{ - return false; -} - -bool kvm_exit_event(struct evsel *evsel __maybe_unused) -{ - return false; -} - -bool exit_event_begin(struct evsel *evsel __maybe_unused, - struct perf_sample *sample __maybe_unused, - struct event_key *key __maybe_unused) -{ - return false; -} - -bool exit_event_end(struct evsel *evsel __maybe_unused, - struct perf_sample *sample __maybe_unused, - struct event_key *key __maybe_unused) -{ - return false; -} - -void exit_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused, - struct event_key *key __maybe_unused, - char *decode __maybe_unused) -{ -} - int find_scripts(char **scripts_array __maybe_unused, char **scripts_path= _array __maybe_unused, int num __maybe_unused, int pathlen __maybe_unused) { --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Tue Nov 26 19:53:15 2024 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 0609518C023 for ; Wed, 16 Oct 2024 04:24:50 +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=1729052691; cv=none; b=lcuC9ID/NWRv/Uwhk+bASQIXDntWoGfkWeglmOVTdtuTPYQxOmNaYi0vzHnNsEIcBV2bk5O7jC3W0DwaWCPPr073/Gxx7V8Kp0R8OXwZihMOXlpkeGpdAVNYIRq4O/CGKkLAWE0Ppf82AFjAmCcEGbd+m+VI1lJPayoF2IOTmn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729052691; c=relaxed/simple; bh=LD8PZAXSIOgOOgpLa2IMwbrPCr39IXG4CwMRJD2bW7I=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=nzWH8xxtLn8owiRB5+cGRNx5AZhO+d5cQ4wTAlCPG42gmF/k+jvGrL53Jhjf6zIKCza8EMjpR4wvWmZ3AgFAJ2LeCj4nuq3nnMmkqdfaTxv+A7cfH/KXN3JiTN3N/VH991u28OjzUgGNoMRdErSKlfk0il4BeXejojDK9EefH7M= 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=kznWnS8Z; 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="kznWnS8Z" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e29716957d9so2049750276.1 for ; Tue, 15 Oct 2024 21:24:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729052689; x=1729657489; 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=yu0e7bexkIbucTPPPaQtVw74ZHAEcfe48qk+Nau7Kc4=; b=kznWnS8ZB2MMZUtEiMK9htn3kJZ3uvxEaxljSU4vRtSBHCPu8N1RpuzA72B1GJCIrN 7aCyuMkaPwWW2kywcUSc/7YD2VJOYOqqx+a4VzaihNpA9uHOI5QUE5710kDt49nOVMPK fjnnmf+d/b368S3LEFI4rdD8jUeYrlN05vp4lWyDeAYCrUXqzXIrB9mwK1dEUuxvsYL9 qjf8gt2XNG3T9g3mxaq/nqfNq+Hsr0Hrz/8QlHyaEWC4K5P6WZIxREBz5fYvk346WgPw DM67r5lk6+PiQIDXpaNEFxJ86pwOm4eUNY76VeXlQosQYxAYPogObba98R/JYloOsmzS wYRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729052689; x=1729657489; 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=yu0e7bexkIbucTPPPaQtVw74ZHAEcfe48qk+Nau7Kc4=; b=GU1nbqxUbUPFMDe/JIYFPvkD1buc/U+FOG8KpQemFu4Gz/niEsN91Lej5aT2gdIxDB 6ghheCj5p8kSxDh0Qt9BnBqYj3Ic3eYWjj8nmfOPMipy5TOxgJv3bPLgGbHuZb9GPyre TaftH4DEMTwKCavzpNgqg7TlHxrzSBF5m1CiYWJVwjUwycr2f17cS3M5sbifu3n2Mto+ QHXz+tTWmHNHa47BptYA7mDJRavSS9GmR7KKP43sCa+OH42wESoQeWljUqB8FX8ebcZv t2WGSl8cDMOBM/847g+yEHNK4AOQEQ+x9mLkE30H0Ccpc7kUymZ1Pyr5EtB/wHNjybWf 9Fmw== X-Forwarded-Encrypted: i=1; AJvYcCX1wPxg8XS3pLnac4lWMRA4HKCX1RHXEoP2Q7omeYt1FJJgiUkXK4oIbeYa9/PPg4tEaNKSoB9+jRFwRKo=@vger.kernel.org X-Gm-Message-State: AOJu0YxkqROoQGz9WKpxAQXq+OwBlRrkQZ0SREmaMjtmDTI34A85XnuZ CUPth1PLHuoKd7yuPbhQsLUUfzovW8Gpt+6FTR6/DD9aqo1Jtsv8tTe+M2RBfDPzpee43vllAJT YRgF8Rw== X-Google-Smtp-Source: AGHT+IHuqyd2Zr6fjIySCIeZkuJTzKAYbm9s4kP5Iv9/5E+Ys1AbGH2OeFZG26OnP3xT8ckdnKg8pVpWfQyc X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a05:6902:2d08:b0:e1d:912e:9350 with SMTP id 3f1490d57ef6-e2978559a74mr3687276.6.1729052688715; Tue, 15 Oct 2024 21:24:48 -0700 (PDT) Date: Tue, 15 Oct 2024 21:24:05 -0700 In-Reply-To: <20241016042415.7552-1-irogers@google.com> Message-Id: <20241016042415.7552-7-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241016042415.7552-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Subject: [PATCH v2 06/16] perf script: Move find_scripts to browser/scripts.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 , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The only use of find_scripts is in browser/scripts.c but the definition in builtin causes linking problems requiring a stub in python.c. Move the function to allow the stub to be removed. Rewrite the directory iteration to use openat so that large character arrays aren't needed. The arrays are warned about potential buffer overflows by GCC now that all the code exists in a single C file. Signed-off-by: Ian Rogers --- tools/perf/builtin-script.c | 138 ------------------------ tools/perf/builtin.h | 6 -- tools/perf/ui/browsers/scripts.c | 177 ++++++++++++++++++++++++++++++- tools/perf/util/python.c | 6 -- 4 files changed, 175 insertions(+), 152 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 621c26c388c8..27b2fb08ad67 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -3520,144 +3520,6 @@ static void free_dlarg(void) free(dlargv); } =20 -/* - * Some scripts specify the required events in their "xxx-record" file, - * this function will check if the events in perf.data match those - * mentioned in the "xxx-record". - * - * Fixme: All existing "xxx-record" are all in good formats "-e event ", - * which is covered well now. And new parsing code should be added to - * cover the future complex formats like event groups etc. - */ -static int check_ev_match(char *dir_name, char *scriptname, - struct perf_session *session) -{ - char filename[MAXPATHLEN], evname[128]; - char line[BUFSIZ], *p; - struct evsel *pos; - int match, len; - FILE *fp; - - scnprintf(filename, MAXPATHLEN, "%s/bin/%s-record", dir_name, scriptname); - - fp =3D fopen(filename, "r"); - if (!fp) - return -1; - - while (fgets(line, sizeof(line), fp)) { - p =3D skip_spaces(line); - if (*p =3D=3D '#') - continue; - - while (strlen(p)) { - p =3D strstr(p, "-e"); - if (!p) - break; - - p +=3D 2; - p =3D skip_spaces(p); - len =3D strcspn(p, " \t"); - if (!len) - break; - - snprintf(evname, len + 1, "%s", p); - - match =3D 0; - evlist__for_each_entry(session->evlist, pos) { - if (evsel__name_is(pos, evname)) { - match =3D 1; - break; - } - } - - if (!match) { - fclose(fp); - return -1; - } - } - } - - fclose(fp); - return 0; -} - -/* - * Return -1 if none is found, otherwise the actual scripts number. - * - * Currently the only user of this function is the script browser, which - * will list all statically runnable scripts, select one, execute it and - * show the output in a perf browser. - */ -int find_scripts(char **scripts_array, char **scripts_path_array, int num, - int pathlen) -{ - struct dirent *script_dirent, *lang_dirent; - char scripts_path[MAXPATHLEN], lang_path[MAXPATHLEN]; - DIR *scripts_dir, *lang_dir; - struct perf_session *session; - struct perf_data data =3D { - .path =3D input_name, - .mode =3D PERF_DATA_MODE_READ, - }; - char *temp; - int i =3D 0; - - session =3D perf_session__new(&data, NULL); - if (IS_ERR(session)) - return PTR_ERR(session); - - snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path()); - - scripts_dir =3D opendir(scripts_path); - if (!scripts_dir) { - perf_session__delete(session); - return -1; - } - - for_each_lang(scripts_path, scripts_dir, lang_dirent) { - scnprintf(lang_path, MAXPATHLEN, "%s/%s", scripts_path, - lang_dirent->d_name); -#ifndef HAVE_LIBPERL_SUPPORT - if (strstr(lang_path, "perl")) - continue; -#endif -#ifndef HAVE_LIBPYTHON_SUPPORT - if (strstr(lang_path, "python")) - continue; -#endif - - lang_dir =3D opendir(lang_path); - if (!lang_dir) - continue; - - for_each_script(lang_path, lang_dir, script_dirent) { - /* Skip those real time scripts: xxxtop.p[yl] */ - if (strstr(script_dirent->d_name, "top.")) - continue; - if (i >=3D num) - break; - snprintf(scripts_path_array[i], pathlen, "%s/%s", - lang_path, - script_dirent->d_name); - temp =3D strchr(script_dirent->d_name, '.'); - snprintf(scripts_array[i], - (temp - script_dirent->d_name) + 1, - "%s", script_dirent->d_name); - - if (check_ev_match(lang_path, - scripts_array[i], session)) - continue; - - i++; - } - closedir(lang_dir); - } - - closedir(scripts_dir); - perf_session__delete(session); - return i; -} - static char *get_script_path(const char *script_root, const char *suffix) { struct dirent *script_dirent, *lang_dirent; diff --git a/tools/perf/builtin.h b/tools/perf/builtin.h index 94f4b3769bf7..a07e93c53848 100644 --- a/tools/perf/builtin.h +++ b/tools/perf/builtin.h @@ -2,10 +2,6 @@ #ifndef BUILTIN_H #define BUILTIN_H =20 -#include -#include -#include - struct feature_status { const char *name; const char *macro; @@ -56,6 +52,4 @@ int cmd_ftrace(int argc, const char **argv); int cmd_daemon(int argc, const char **argv); int cmd_kwork(int argc, const char **argv); =20 -int find_scripts(char **scripts_array, char **scripts_path_array, int num, - int pathlen); #endif diff --git a/tools/perf/ui/browsers/scripts.c b/tools/perf/ui/browsers/scri= pts.c index e437d7889de6..2d04ece833aa 100644 --- a/tools/perf/ui/browsers/scripts.c +++ b/tools/perf/ui/browsers/scripts.c @@ -1,16 +1,18 @@ // SPDX-License-Identifier: GPL-2.0 -#include "../../builtin.h" -#include "../../perf.h" #include "../../util/util.h" // perf_exe() #include "../util.h" +#include "../../util/evlist.h" #include "../../util/hist.h" #include "../../util/debug.h" +#include "../../util/session.h" #include "../../util/symbol.h" #include "../browser.h" #include "../libslang.h" #include "config.h" +#include #include #include +#include #include =20 #define SCRIPT_NAMELEN 128 @@ -77,6 +79,177 @@ static int scripts_config(const char *var, const char *= value, void *data) return 0; } =20 +/* + * Some scripts specify the required events in their "xxx-record" file, + * this function will check if the events in perf.data match those + * mentioned in the "xxx-record". + * + * Fixme: All existing "xxx-record" are all in good formats "-e event ", + * which is covered well now. And new parsing code should be added to + * cover the future complex formats like event groups etc. + */ +static int check_ev_match(int dir_fd, const char *scriptname, struct perf_= session *session) +{ + char line[BUFSIZ]; + FILE *fp; + + { + char filename[FILENAME_MAX + 5]; + int fd; + + scnprintf(filename, sizeof(filename), "bin/%s-record", scriptname); + fd =3D openat(dir_fd, filename, O_RDONLY); + if (fd =3D=3D -1) + return -1; + fp =3D fdopen(fd, "r"); + if (!fp) + return -1; + } + + while (fgets(line, sizeof(line), fp)) { + char *p =3D skip_spaces(line); + + if (*p =3D=3D '#') + continue; + + while (strlen(p)) { + int match, len; + struct evsel *pos; + char evname[128]; + + p =3D strstr(p, "-e"); + if (!p) + break; + + p +=3D 2; + p =3D skip_spaces(p); + len =3D strcspn(p, " \t"); + if (!len) + break; + + snprintf(evname, len + 1, "%s", p); + + match =3D 0; + evlist__for_each_entry(session->evlist, pos) { + if (evsel__name_is(pos, evname)) { + match =3D 1; + break; + } + } + + if (!match) { + fclose(fp); + return -1; + } + } + } + + fclose(fp); + return 0; +} + +/* + * Return -1 if none is found, otherwise the actual scripts number. + * + * Currently the only user of this function is the script browser, which + * will list all statically runnable scripts, select one, execute it and + * show the output in a perf browser. + */ +static int find_scripts(char **scripts_array, char **scripts_path_array, i= nt num, + int pathlen) +{ + struct dirent *script_dirent, *lang_dirent; + int scripts_dir_fd, lang_dir_fd; + DIR *scripts_dir, *lang_dir; + struct perf_session *session; + struct perf_data data =3D { + .path =3D input_name, + .mode =3D PERF_DATA_MODE_READ, + }; + char *temp; + int i =3D 0; + const char *exec_path =3D get_argv_exec_path(); + + session =3D perf_session__new(&data, NULL); + if (IS_ERR(session)) + return PTR_ERR(session); + + { + char scripts_path[PATH_MAX]; + + snprintf(scripts_path, sizeof(scripts_path), "%s/scripts", exec_path); + scripts_dir_fd =3D open(scripts_path, O_DIRECTORY); + pr_err("Failed to open directory '%s'", scripts_path); + if (scripts_dir_fd =3D=3D -1) { + perf_session__delete(session); + return -1; + } + } + scripts_dir =3D fdopendir(scripts_dir_fd); + if (!scripts_dir) { + close(scripts_dir_fd); + perf_session__delete(session); + return -1; + } + + while ((lang_dirent =3D readdir(scripts_dir)) !=3D NULL) { + if (lang_dirent->d_type !=3D DT_DIR && + (lang_dirent->d_type =3D=3D DT_UNKNOWN && + !is_directory_at(scripts_dir_fd, lang_dirent->d_name))) + continue; + if (!strcmp(lang_dirent->d_name, ".") || !strcmp(lang_dirent->d_name, ".= .")) + continue; + +#ifndef HAVE_LIBPERL_SUPPORT + if (strstr(lang_dirent->d_name, "perl")) + continue; +#endif +#ifndef HAVE_LIBPYTHON_SUPPORT + if (strstr(lang_dirent->d_name, "python")) + continue; +#endif + + lang_dir_fd =3D openat(scripts_dir_fd, lang_dirent->d_name, O_DIRECTORY); + if (lang_dir_fd =3D=3D -1) + continue; + lang_dir =3D fdopendir(lang_dir_fd); + if (!lang_dir) { + close(lang_dir_fd); + continue; + } + while ((script_dirent =3D readdir(lang_dir)) !=3D NULL) { + if (script_dirent->d_type =3D=3D DT_DIR) + continue; + if (script_dirent->d_type =3D=3D DT_UNKNOWN && + is_directory_at(lang_dir_fd, script_dirent->d_name)) + continue; + /* Skip those real time scripts: xxxtop.p[yl] */ + if (strstr(script_dirent->d_name, "top.")) + continue; + if (i >=3D num) + break; + scnprintf(scripts_path_array[i], pathlen, "%s/scripts/%s/%s", + exec_path, + lang_dirent->d_name, + script_dirent->d_name); + temp =3D strchr(script_dirent->d_name, '.'); + snprintf(scripts_array[i], + (temp - script_dirent->d_name) + 1, + "%s", script_dirent->d_name); + + if (check_ev_match(lang_dir_fd, scripts_array[i], session)) + continue; + + i++; + } + closedir(lang_dir); + } + + closedir(scripts_dir); + perf_session__delete(session); + return i; +} + /* * When success, will copy the full path of the selected script * into the buffer pointed by script_name, and return 0. diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index ab67abf3b607..5f11ae88943d 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1306,12 +1306,6 @@ PyMODINIT_FUNC PyInit_perf(void) /* The following are stubs to avoid dragging in builtin-* objects. */ /* TODO: move the code out of the builtin-* file into util. */ =20 -int find_scripts(char **scripts_array __maybe_unused, char **scripts_path= _array __maybe_unused, - int num __maybe_unused, int pathlen __maybe_unused) -{ - return -1; -} - void perf_stat__set_no_csv_summary(int set __maybe_unused) { } --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Tue Nov 26 19:53:15 2024 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 3F70E18C320 for ; Wed, 16 Oct 2024 04:24:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729052693; cv=none; b=LOCfmV3c86/RPWJTWeqiuOfZTr9e/09UDOOtbTjVqWBkbCDk+UaMSetbu+6a7nJHWneWkHiCVAucNl9jYd0165nlQVp2GYfkHl50uqNXwE6FWBzsG2RiAXuNMBKYJWuJyyWllonrZCpdhd5Qw9K3eyHI4RzOOex9dM7QhUaSQU8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729052693; c=relaxed/simple; bh=FPFuPmBPt7VWVVl60u3bBX6B7xsgFnLZgU82y4W7MNU=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=qCHlFYq+B1nRaGYNIARlt4ekPe9Kmk8oAzphaw9iq+zJym45mAXCTS3sJiRQlhDw9wThcHp/c3tI2BZuwHM26TurWGLynAD/30TV2uU0IJ8UmyhM5yK4FAjtwPbTEnO3+ZOv0dhCIKrWe8TX3ZVb18X2nfj3YdEXV9K6Y04umuE= 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=dWx304M6; arc=none smtp.client-ip=209.85.128.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="dWx304M6" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e3497c8eb0so9639887b3.0 for ; Tue, 15 Oct 2024 21:24:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729052691; x=1729657491; 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=ap+FrbJxp8E8bGWyP9N2suLQLG9YzOCt0lYTcOUnQbY=; b=dWx304M6qP6Fh67Ggr60WI3+Vku4szSlCoTqtQF0PRbWM48iDrwQnz/9clHlwHF3NS yTlNu/WjYZFpJ/ya8x9s2VxfDKXdiekoyN9wsZpfhYR5pzS6fPCILdrYmVMEsBG/2XoW JF6hMq0wAx8QFp5U9+LcIFt8yn/7Ff+UrQ1g6K7cLEb77TOur2E5kBuPjPGbGEXZh3De REwY2T6h+NEjOhoa4p5tmQbUvbZGxK6E6WhaYfZ6P+KhiFn9Z8L3TcgZ8TqldEXikiKq H8fOpmTvrpZC7SIMLta/kku5N1pIQ6E+ShP5+QLAFqvnF9lfTwDUawkodB8S57bB6LUL OqMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729052691; x=1729657491; 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=ap+FrbJxp8E8bGWyP9N2suLQLG9YzOCt0lYTcOUnQbY=; b=Xlk4A8fJvQ9VPmM4wPtg8K0xGD6ZU35w76EaXFryXi2my+k2N6Y5iJRoKMb/KdB8FF 6hFKSI5ayK1a0bm1lg+G7LpzIFTcIUvEpUfeIk50DSEa0aNcGyvpGIus0GB+wduSHhu9 5OrNJ4t23qFh+96Q8JZO/u/DWrMZBCHRcmfgjZ2VAzsgb/OAdBOyn7kTKebYF2V0ys0r YtcjISoPKzeY572tY4eaGQ7rxgcMVvnOg1fjvYiMa+IqZT8+3CHAfACxj80NfZ/tbvyS JQK9SvKCRrFjRMEkmAHRD/SZb+ZgrPt7utrCWVILvh7zHGgCQsjBSymdI5Yvwu9BAWu4 namA== X-Forwarded-Encrypted: i=1; AJvYcCW8nP25uma4JxQjd45nXwIf3b1dBPXu1QUj2CCevTwoPNOMz64papTJa/DNLW7XIfT3uc7orjWfacFz2U8=@vger.kernel.org X-Gm-Message-State: AOJu0YxD8XVsTC59eXvR30WFG7RRnRL/yq3x57I4DUJMC16S8ifyrbOh 604gz4fWO3R1ABCDhO1Joycu4CNLOimEhvXMJSrdT+47y9rmMRmk9Jy25vcV25kJMq6ePjX5gGz VIC8FNQ== X-Google-Smtp-Source: AGHT+IGs4ztI6fTPgYyABepF0hX41H2FNYql9czfyrZlR8K7I1g7IzUnZUlotwZvFjU/QF8Xw/xXIijtHH5z X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a05:690c:6a13:b0:6db:e464:addc with SMTP id 00721157ae682-6e3d3a5c75bmr544237b3.4.1729052691394; Tue, 15 Oct 2024 21:24:51 -0700 (PDT) Date: Tue, 15 Oct 2024 21:24:06 -0700 In-Reply-To: <20241016042415.7552-1-irogers@google.com> Message-Id: <20241016042415.7552-8-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241016042415.7552-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Subject: [PATCH v2 07/16] perf stat: Move stat_config into config.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 , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" stat_config is accessed by config.c via helper functions, but declared in builtin-stat. Move to util/config.c so that stub functions aren't needed in python.c which doesn't link against the builtin files. To avoid name conflicts change builtin-script to use the same stat_config as builtin-stat. Rename local variables in tests to avoid shadow declaration warnings. Signed-off-by: Ian Rogers --- tools/perf/builtin-script.c | 1 - tools/perf/builtin-stat.c | 27 --------------------------- tools/perf/tests/stat.c | 16 +++++++++------- tools/perf/util/config.c | 27 +++++++++++++++++++++++++++ tools/perf/util/path.c | 10 ++++++++++ tools/perf/util/path.h | 1 + tools/perf/util/python.c | 9 --------- tools/perf/util/stat.h | 3 ++- 8 files changed, 49 insertions(+), 45 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 27b2fb08ad67..1ce7b71f1f46 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -85,7 +85,6 @@ static bool system_wide; static bool print_flags; static const char *cpu_list; static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); -static struct perf_stat_config stat_config; static int max_blocks; static bool native_arch; static struct dlfilter *dlfilter; diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index b5e18853982c..7c7424824b0e 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -112,8 +112,6 @@ static struct target target =3D { .uid =3D UINT_MAX, }; =20 -#define METRIC_ONLY_LEN 20 - static volatile sig_atomic_t child_pid =3D -1; static int detailed_run =3D 0; static bool transaction_run; @@ -151,21 +149,6 @@ static struct perf_stat perf_stat; =20 static volatile sig_atomic_t done =3D 0; =20 -static struct perf_stat_config stat_config =3D { - .aggr_mode =3D AGGR_GLOBAL, - .aggr_level =3D MAX_CACHE_LVL + 1, - .scale =3D true, - .unit_width =3D 4, /* strlen("unit") */ - .run_count =3D 1, - .metric_only_len =3D METRIC_ONLY_LEN, - .walltime_nsecs_stats =3D &walltime_nsecs_stats, - .ru_stats =3D &ru_stats, - .big_num =3D true, - .ctl_fd =3D -1, - .ctl_fd_ack =3D -1, - .iostat_run =3D false, -}; - /* Options set from the command line. */ struct opt_aggr_mode { bool node, socket, die, cluster, cache, core, thread, no_aggr; @@ -1059,16 +1042,6 @@ static void sig_atexit(void) kill(getpid(), signr); } =20 -void perf_stat__set_big_num(int set) -{ - stat_config.big_num =3D (set !=3D 0); -} - -void perf_stat__set_no_csv_summary(int set) -{ - stat_config.no_csv_summary =3D (set !=3D 0); -} - static int stat__set_big_num(const struct option *opt __maybe_unused, const char *s __maybe_unused, int unset) { diff --git a/tools/perf/tests/stat.c b/tools/perf/tests/stat.c index 6468cc0d0204..d60983657bad 100644 --- a/tools/perf/tests/stat.c +++ b/tools/perf/tests/stat.c @@ -27,7 +27,7 @@ static int process_stat_config_event(const struct perf_to= ol *tool __maybe_unused struct machine *machine __maybe_unused) { struct perf_record_stat_config *config =3D &event->stat_config; - struct perf_stat_config stat_config =3D {}; + struct perf_stat_config test_stat_config =3D {}; =20 #define HAS(term, val) \ has_term(config, PERF_STAT_CONFIG_TERM__##term, val) @@ -39,25 +39,27 @@ static int process_stat_config_event(const struct perf_= tool *tool __maybe_unused =20 #undef HAS =20 - perf_event__read_stat_config(&stat_config, config); + perf_event__read_stat_config(&test_stat_config, config); =20 - TEST_ASSERT_VAL("wrong aggr_mode", stat_config.aggr_mode =3D=3D AGGR_CORE= ); - TEST_ASSERT_VAL("wrong scale", stat_config.scale =3D=3D 1); - TEST_ASSERT_VAL("wrong interval", stat_config.interval =3D=3D 1); + TEST_ASSERT_VAL("wrong aggr_mode", test_stat_config.aggr_mode =3D=3D AGGR= _CORE); + TEST_ASSERT_VAL("wrong scale", test_stat_config.scale =3D=3D 1); + TEST_ASSERT_VAL("wrong interval", test_stat_config.interval =3D=3D 1); return 0; } =20 static int test__synthesize_stat_config(struct test_suite *test __maybe_un= used, int subtest __maybe_unused) { - struct perf_stat_config stat_config =3D { + struct perf_stat_config test_stat_config =3D { .aggr_mode =3D AGGR_CORE, .scale =3D 1, .interval =3D 1, }; =20 TEST_ASSERT_VAL("failed to synthesize stat_config", - !perf_event__synthesize_stat_config(NULL, &stat_config, process_stat_con= fig_event, NULL)); + !perf_event__synthesize_stat_config(NULL, &test_stat_config, + process_stat_config_event, + NULL)); =20 return 0; } diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c index 68f9407ca74b..2d07c9257a1a 100644 --- a/tools/perf/util/config.c +++ b/tools/perf/util/config.c @@ -13,6 +13,7 @@ #include #include "cache.h" #include "callchain.h" +#include "header.h" #include #include "util/event.h" /* proc_map_timeout */ #include "util/hist.h" /* perf_hist_config */ @@ -34,6 +35,22 @@ =20 #define DEBUG_CACHE_DIR ".debug" =20 +#define METRIC_ONLY_LEN 20 + +struct perf_stat_config stat_config =3D { + .aggr_mode =3D AGGR_GLOBAL, + .aggr_level =3D MAX_CACHE_LVL + 1, + .scale =3D true, + .unit_width =3D 4, /* strlen("unit") */ + .run_count =3D 1, + .metric_only_len =3D METRIC_ONLY_LEN, + .walltime_nsecs_stats =3D &walltime_nsecs_stats, + .ru_stats =3D &ru_stats, + .big_num =3D true, + .ctl_fd =3D -1, + .ctl_fd_ack =3D -1, + .iostat_run =3D false, +}; =20 char buildid_dir[MAXPATHLEN]; /* root dir for buildid, binary cache */ =20 @@ -455,6 +472,16 @@ static int perf_ui_config(const char *var, const char = *value) return 0; } =20 +void perf_stat__set_big_num(int set) +{ + stat_config.big_num =3D (set !=3D 0); +} + +static void perf_stat__set_no_csv_summary(int set) +{ + stat_config.no_csv_summary =3D (set !=3D 0); +} + static int perf_stat_config(const char *var, const char *value) { if (!strcmp(var, "stat.big-num")) diff --git a/tools/perf/util/path.c b/tools/perf/util/path.c index 00adf872bf00..9712466c51e2 100644 --- a/tools/perf/util/path.c +++ b/tools/perf/util/path.c @@ -68,6 +68,16 @@ bool is_directory(const char *base_path, const struct di= rent *dent) return S_ISDIR(st.st_mode); } =20 +bool is_directory_at(int dir_fd, const char *path) +{ + struct stat st; + + if (fstatat(dir_fd, path, &st, /*flags=3D*/0)) + return false; + + return S_ISDIR(st.st_mode); +} + bool is_executable_file(const char *base_path, const struct dirent *dent) { char path[PATH_MAX]; diff --git a/tools/perf/util/path.h b/tools/perf/util/path.h index d94902c22222..fbafbe7015dd 100644 --- a/tools/perf/util/path.h +++ b/tools/perf/util/path.h @@ -12,6 +12,7 @@ int path__join3(char *bf, size_t size, const char *path1,= const char *path2, con =20 bool is_regular_file(const char *file); bool is_directory(const char *base_path, const struct dirent *dent); +bool is_directory_at(int dir_fd, const char *path); bool is_executable_file(const char *base_path, const struct dirent *dent); =20 #endif /* _PERF_PATH_H */ diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 5f11ae88943d..0fa8e27769be 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -17,7 +17,6 @@ #include "trace-event.h" #include "mmap.h" #include "util/env.h" -#include "util/kvm-stat.h" #include "util/kwork.h" #include "util/sample.h" #include "util/lock-contention.h" @@ -1306,14 +1305,6 @@ PyMODINIT_FUNC PyInit_perf(void) /* The following are stubs to avoid dragging in builtin-* objects. */ /* TODO: move the code out of the builtin-* file into util. */ =20 -void perf_stat__set_no_csv_summary(int set __maybe_unused) -{ -} - -void perf_stat__set_big_num(int set __maybe_unused) -{ -} - int script_spec_register(const char *spec __maybe_unused, struct scripting= _ops *ops __maybe_unused) { return -1; diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index fd7a187551bd..78ddc14507b7 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -117,8 +117,9 @@ struct perf_stat_config { unsigned int topdown_level; }; =20 +extern struct perf_stat_config stat_config; + void perf_stat__set_big_num(int set); -void perf_stat__set_no_csv_summary(int set); =20 void update_stats(struct stats *stats, u64 val); double avg_stats(struct stats *stats); --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Tue Nov 26 19:53:15 2024 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 7BFE418C356 for ; Wed, 16 Oct 2024 04:24:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729052696; cv=none; b=HVAO2cM6oD07PPoEc8DOi9i/xbqK7Lo6LPhK7yowqJHw3snjbPlzYx3hg/PXHxV3EsxDwmjBCaljqHI3aurqpYmgb4ta2CaCfiL76xFJV16mqGqP+ATEwd5WzOUu92rBjjY0sexvgMX6vzRgOMVRcF9rJOD7ObqQ23FehbITWGc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729052696; c=relaxed/simple; bh=tzlKt/xEu5otGWCZvc+6lY/D07Nniiv63xyh7KE0+EE=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=E0EROqO6eITYIYoFf6Rn1zixAFQT559J9rt/z+olVWQ06SCOfmZY2fgkb5BkuC4zKB6jEVBuvekIYgW+W1K3revmgzU2+D8bYNFApZ+G6wk2qykaTPelFDIrENrhqbg1Tkn5P05VIAeTzaX+IWRarx+1QmkkBtXteamxJeErJfo= 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=jU+h/4Wa; arc=none smtp.client-ip=209.85.128.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="jU+h/4Wa" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e32f43c797so5136157b3.1 for ; Tue, 15 Oct 2024 21:24:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729052693; x=1729657493; 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=wUCgc+yh1v+6ab10mK41hwbEx+6NETQ8lxM12doIl4U=; b=jU+h/4WahAkNcpyuMp0CdWxIzbMD64qJ4/B8bXBEgw1TU56X+Ler42EdoIxwbebtIv LQM3uK0Lik8cp7jnpyZwdBpGbiNzQh7FrDjgwaD0zwWNN2Qc52ZOHG+vNWwHaBn0wrx3 FSTfnevUjd5hjejf33Da4KTgiSSSWje54Um6iAQhzVV9BW+WdgenHW10S6DRFsq4BKI3 CQC0C5uHxJpo1jRj4dcXiPd1Z38m2XYG5qzDUAxVTVqVeqQRFFWPJfeNz4lYmI7IMYEw i7vgmvituxriQNSbxZS4uLytR/2sEQ2HXjQo34e/Dw5QLFoOvTbMQD66i5tw2/5Lfn3V VpfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729052693; x=1729657493; 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=wUCgc+yh1v+6ab10mK41hwbEx+6NETQ8lxM12doIl4U=; b=FoR9fq4i1bfqFXw/7nVtSikjOf6OvVqNtvz0fs9hW9kg2qeefsyN+rmNYngeunb8vB TCMAkETlh8EDR0IV436PGhPGTHX0jIOHBvy+97DTHtcobNvRc24lXa0+EX3cAu7Rv1Ff EhSOQ6DOjfbyFy2sNVuwmiGM9YEbvEfY8sfvMpUD9MGfKnAEaORrzTAExdt3xn8uAzbX vZuAILy5CZdo0i4/4shOMYEmr66bzZp1YPvxU2PrSRXJmWFXNoJ1R5+E8wuEP+sITJUy KzRgF+rVdrFiXgAEuUmN4w+o4fveR/C39dmbLOQylN4pM75ic4pzMQhblx6hWYTHp+XX Y53A== X-Forwarded-Encrypted: i=1; AJvYcCVkPZwFyObu5s5d1qQDRPAMWxOxxm2q/JOCrt20umWixyTkvMaQeHiD4z/UlnWeTQjj2L5rBHvni99sZaQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzYayLP9E6GQi3FHgq9ouSC2Bf1nOCQJ15JoUHwEbqO9XKlVHXb Y+FAm9oI4a9cK8Z1puzmwM75cc+wYALnd7f3NZ7A+m2GrB8DbUSqDi2dUbL18Uyj5YYJ2QAYI3y 9SsucfA== X-Google-Smtp-Source: AGHT+IHxlINltYDsw7498D30y2bJcc3xb1Of/WNilHeA1HO9MrBoD+DTz+ppZUt5pIoJcfRZuyDwf6Pgr/OD X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a05:690c:3587:b0:68e:8de6:617c with SMTP id 00721157ae682-6e3d3aacfc0mr526637b3.5.1729052693654; Tue, 15 Oct 2024 21:24:53 -0700 (PDT) Date: Tue, 15 Oct 2024 21:24:07 -0700 In-Reply-To: <20241016042415.7552-1-irogers@google.com> Message-Id: <20241016042415.7552-9-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241016042415.7552-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Subject: [PATCH v2 08/16] perf script: Move script_spec code 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 , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The script_spec code is referenced in util/trace-event-scripting but the list was in builtin-script, accessed via a function that required a stub function in python.c. Move all the logic to trace-event-scripting, with lookup and foreach functions exposed for builtin-script's benefit. Signed-off-by: Ian Rogers --- tools/perf/builtin-script.c | 67 +--------------------- tools/perf/util/python.c | 5 -- tools/perf/util/trace-event-scripting.c | 75 +++++++++++++++++++++++++ tools/perf/util/trace-event.h | 3 +- 4 files changed, 80 insertions(+), 70 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 1ce7b71f1f46..b838470657d4 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2955,79 +2955,18 @@ static int __cmd_script(struct perf_script *script) return ret; } =20 -struct script_spec { - struct list_head node; - struct scripting_ops *ops; - char spec[]; -}; - -static LIST_HEAD(script_specs); - -static struct script_spec *script_spec__new(const char *spec, - struct scripting_ops *ops) +static int list_available_languages_cb(struct scripting_ops *ops, const ch= ar *spec) { - struct script_spec *s =3D malloc(sizeof(*s) + strlen(spec) + 1); - - if (s !=3D NULL) { - strcpy(s->spec, spec); - s->ops =3D ops; - } - - return s; -} - -static void script_spec__add(struct script_spec *s) -{ - list_add_tail(&s->node, &script_specs); -} - -static struct script_spec *script_spec__find(const char *spec) -{ - struct script_spec *s; - - list_for_each_entry(s, &script_specs, node) - if (strcasecmp(s->spec, spec) =3D=3D 0) - return s; - return NULL; -} - -int script_spec_register(const char *spec, struct scripting_ops *ops) -{ - struct script_spec *s; - - s =3D script_spec__find(spec); - if (s) - return -1; - - s =3D script_spec__new(spec, ops); - if (!s) - return -1; - else - script_spec__add(s); - + fprintf(stderr, " %-42s [%s]\n", spec, ops->name); return 0; } =20 -static struct scripting_ops *script_spec__lookup(const char *spec) -{ - struct script_spec *s =3D script_spec__find(spec); - if (!s) - return NULL; - - return s->ops; -} - static void list_available_languages(void) { - struct script_spec *s; - fprintf(stderr, "\n"); fprintf(stderr, "Scripting language extensions (used in " "perf script -s [spec:]script.[spec]):\n\n"); - - list_for_each_entry(s, &script_specs, node) - fprintf(stderr, " %-42s [%s]\n", s->spec, s->ops->name); - + script_spec__for_each(&list_available_languages_cb); fprintf(stderr, "\n"); } =20 diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 0fa8e27769be..3d938fe2de6a 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1305,11 +1305,6 @@ PyMODINIT_FUNC PyInit_perf(void) /* The following are stubs to avoid dragging in builtin-* objects. */ /* TODO: move the code out of the builtin-* file into util. */ =20 -int script_spec_register(const char *spec __maybe_unused, struct scripting= _ops *ops __maybe_unused) -{ - return -1; -} - arch_syscalls__strerrno_t *arch_syscalls__strerrno_function(const char *ar= ch __maybe_unused) { return NULL; diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trac= e-event-scripting.c index 8abb7a7b6888..ad62d8e5a368 100644 --- a/tools/perf/util/trace-event-scripting.c +++ b/tools/perf/util/trace-event-scripting.c @@ -24,6 +24,81 @@ unsigned int scripting_max_stack =3D PERF_MAX_STACK_DEPT= H; =20 struct scripting_context *scripting_context; =20 +struct script_spec { + struct list_head node; + struct scripting_ops *ops; + char spec[]; +}; + +static LIST_HEAD(script_specs); + +static struct script_spec *script_spec__new(const char *spec, + struct scripting_ops *ops) +{ + struct script_spec *s =3D malloc(sizeof(*s) + strlen(spec) + 1); + + if (s !=3D NULL) { + strcpy(s->spec, spec); + s->ops =3D ops; + } + + return s; +} + +static void script_spec__add(struct script_spec *s) +{ + list_add_tail(&s->node, &script_specs); +} + +static struct script_spec *script_spec__find(const char *spec) +{ + struct script_spec *s; + + list_for_each_entry(s, &script_specs, node) + if (strcasecmp(s->spec, spec) =3D=3D 0) + return s; + return NULL; +} + +static int script_spec_register(const char *spec, struct scripting_ops *op= s) +{ + struct script_spec *s; + + s =3D script_spec__find(spec); + if (s) + return -1; + + s =3D script_spec__new(spec, ops); + if (!s) + return -1; + + script_spec__add(s); + return 0; +} + +struct scripting_ops *script_spec__lookup(const char *spec) +{ + struct script_spec *s =3D script_spec__find(spec); + + if (!s) + return NULL; + + return s->ops; +} + +int script_spec__for_each(int (*cb)(struct scripting_ops *ops, const char = *spec)) +{ + struct script_spec *s; + int ret =3D 0; + + list_for_each_entry(s, &script_specs, node) { + ret =3D cb(s->ops, s->spec); + if (ret) + break; + } + return ret; +} + void scripting_context__update(struct scripting_context *c, union perf_event *event, struct perf_sample *sample, diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h index bbf8b26bc8da..81fceaf297ba 100644 --- a/tools/perf/util/trace-event.h +++ b/tools/perf/util/trace-event.h @@ -116,7 +116,8 @@ struct scripting_ops { =20 extern unsigned int scripting_max_stack; =20 -int script_spec_register(const char *spec, struct scripting_ops *ops); +struct scripting_ops *script_spec__lookup(const char *spec); +int script_spec__for_each(int (*cb)(struct scripting_ops *ops, const char = *spec)); =20 void script_fetch_insn(struct perf_sample *sample, struct thread *thread, struct machine *machine); --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Tue Nov 26 19:53:15 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 AD47918CC01 for ; Wed, 16 Oct 2024 04:24:56 +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=1729052698; cv=none; b=p8uGBmns8BEdIthkJh7jEQ4g/LWFI/ImIR1Nux7NvEd8uKeHptEqtmB4ml+9g8y+cMNwO0mnmQWZFD6wfCbKH0xDiw+Ti4wKvNDl5js50bvlJg4HANb9DYy5yhwfkO7qgKNYeIo5Hmcr3wBirYRukgcRIq1yuvnphjZs0a2/IP8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729052698; c=relaxed/simple; bh=cZb5xvuzqqa8/zADFxb6PqvGhOFZ4T95f/Rcci8bRQI=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=RbKK/LMesvqIXYlsPsnJNbmGLabNThfriOI1rLdh7Rgkkdeo5FzVN4FXNLIb1sFJf45rm+CL/5z2t9gWaGJUexePaukBg097J0kuW9XGSFBpUS4KOeTr1oBsBbZEVjTPtbNRfUf+sl/6TwxVp6j2ixst7Hy40Jp/xFlpxh85Ps4= 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=k21fa+Qr; 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="k21fa+Qr" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e28ef71f0d8so9894988276.0 for ; Tue, 15 Oct 2024 21:24:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729052696; x=1729657496; 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=aUanJd9R6GPljwzcW3pIhRSAGsTkrn8IEGI+GvcCVuc=; b=k21fa+QroCXwTxf+J0PR1Z1Z2A9elPgdUb894ffPo+gd8tyeq+ZiUY0lTl9oiBKdxJ ElaWMymQZdKrtZFzgMqOQ/2v3B4SC7WbXG0z17uxuSuKQffh+I7yd26zg5qYbMeBmIju KH9G5mRRT1CWspjsaL6DB5cBewQH3rP18c82JvSZ8Nw7TwiExsKmoEnruixxwhhcL/7d KCnie3h4akIUgVkzZaETGMOEQaT2xEK9X2s0J54IsXNvQ5R+HI6G4bPC06644awfVfvg ERVrWqMIQ4Jn1A4qvgYutyy9w4fxvrQeHUh3UiFkIBORN6VtbH/khlZCvpTvQgea4kIb NTug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729052696; x=1729657496; 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=aUanJd9R6GPljwzcW3pIhRSAGsTkrn8IEGI+GvcCVuc=; b=IORNFiKxjAcUgn6jKqvnV/1L5FIM7Ncaw17DdsGwrjvNcfKV+52Xb1wCaobTAUX2m+ P3TwJKaEqZEVB3Ef0nPW0hHKaHK7QrF2g1MxWduHRzRQixpd68mmta2emcEWnHWLMtE+ BRj+TXKXqRkSlI7o3pln+kBC7hyLrXJPdHZS/rGbyBSIaPrYr+Bp1iPf+2A3PwgsfD/v Oqzbk8vDskYvjS4te/Ubnf2jxrbZnNmGpQJC7G4TyOs+bXFhcXJ6ZtTHIhUplQpyL3Sq T0vrzFYYS9tafbJc+iaqbL4wQpkDrqG8TXDuShdh2TR+NN3Gr4X9tYETTcMgW6ikrDle PAxg== X-Forwarded-Encrypted: i=1; AJvYcCUVXCGZtT9LhLvi5iApIJvIivEZ/kyDxGScjPPsi+7ytzsI+Wm7K3uw2WTcjseG58zr4P4/jEq0MUKDrJc=@vger.kernel.org X-Gm-Message-State: AOJu0YxleWV0NrIz2GV8lLCa4POj7P9q7ts89TxP0k117NjCsvTTBEHI j7L0jn3Zu4yseIvU3J87qk40hISK1/55R4n1jkTWkS5kxoAfeg6r7nlut+WsFi4SZpJ+a6loCK4 alo/uzA== X-Google-Smtp-Source: AGHT+IE92oRUPfuRbjJX6fYqcZzWlqLUcLAT0RFlIRttpeNClwYVe3iHPPYhGgfCJxJOyvIG3xK8nBaMc8sV X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a25:ad64:0:b0:e16:68fb:f261 with SMTP id 3f1490d57ef6-e297830baadmr1307276.5.1729052695722; Tue, 15 Oct 2024 21:24:55 -0700 (PDT) Date: Tue, 15 Oct 2024 21:24:08 -0700 In-Reply-To: <20241016042415.7552-1-irogers@google.com> Message-Id: <20241016042415.7552-10-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241016042415.7552-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Subject: [PATCH v2 09/16] perf script: Move script_fetch_insn 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 , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add native_arch as a parameter to script_fetch_insn rather than relying on the builtin-script value that won't be initialized for the dlfilter and python Context use cases. Assume both of those cases are running natively. Switch the weak arch_fetch_insn to being guarded by ifdefs as weak functions are outside of the C specification. Signed-off-by: Ian Rogers --- tools/perf/builtin-script.c | 15 +-------------- .../scripts/python/Perf-Trace-Util/Context.c | 2 +- tools/perf/util/dlfilter.c | 3 ++- tools/perf/util/python.c | 6 ------ tools/perf/util/trace-event-scripting.c | 16 ++++++++++++++++ tools/perf/util/trace-event.h | 2 +- 6 files changed, 21 insertions(+), 23 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index b838470657d4..63a00dad02c6 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -1586,19 +1586,6 @@ static int perf_sample__fprintf_callindent(struct pe= rf_sample *sample, return len + dlen; } =20 -__weak void arch_fetch_insn(struct perf_sample *sample __maybe_unused, - struct thread *thread __maybe_unused, - struct machine *machine __maybe_unused) -{ -} - -void script_fetch_insn(struct perf_sample *sample, struct thread *thread, - struct machine *machine) -{ - if (sample->insn_len =3D=3D 0 && native_arch) - arch_fetch_insn(sample, thread, machine); -} - static int perf_sample__fprintf_insn(struct perf_sample *sample, struct evsel *evsel, struct perf_event_attr *attr, @@ -1608,7 +1595,7 @@ static int perf_sample__fprintf_insn(struct perf_samp= le *sample, { int printed =3D 0; =20 - script_fetch_insn(sample, thread, machine); + script_fetch_insn(sample, thread, machine, native_arch); =20 if (PRINT_FIELD(INSNLEN)) printed +=3D fprintf(fp, " ilen: %d", sample->insn_len); diff --git a/tools/perf/scripts/python/Perf-Trace-Util/Context.c b/tools/pe= rf/scripts/python/Perf-Trace-Util/Context.c index d742daaa5d5a..60dcfe56d4d9 100644 --- a/tools/perf/scripts/python/Perf-Trace-Util/Context.c +++ b/tools/perf/scripts/python/Perf-Trace-Util/Context.c @@ -93,7 +93,7 @@ static PyObject *perf_sample_insn(PyObject *obj, PyObject= *args) if (c->sample->ip && !c->sample->insn_len && thread__maps(c->al->thread))= { struct machine *machine =3D maps__machine(thread__maps(c->al->thread)); =20 - script_fetch_insn(c->sample, c->al->thread, machine); + script_fetch_insn(c->sample, c->al->thread, machine, /*native_arch=3D*/t= rue); } if (!c->sample->insn_len) Py_RETURN_NONE; /* N.B. This is a return statement */ diff --git a/tools/perf/util/dlfilter.c b/tools/perf/util/dlfilter.c index 7d180bdaedbc..ddacef881af2 100644 --- a/tools/perf/util/dlfilter.c +++ b/tools/perf/util/dlfilter.c @@ -234,7 +234,8 @@ static const __u8 *dlfilter__insn(void *ctx, __u32 *len) struct machine *machine =3D maps__machine(thread__maps(al->thread)); =20 if (machine) - script_fetch_insn(d->sample, al->thread, machine); + script_fetch_insn(d->sample, al->thread, machine, + /*native_arch=3D*/true); } } =20 diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 3d938fe2de6a..22edadd64e5f 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 -void script_fetch_insn(struct perf_sample *sample __maybe_unused, - struct thread *thread __maybe_unused, - struct machine *machine __maybe_unused) -{ -} - int perf_sample__sprintf_flags(u32 flags __maybe_unused, char *str __maybe= _unused, size_t sz __maybe_unused) { diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trac= e-event-scripting.c index ad62d8e5a368..543e78b17e5f 100644 --- a/tools/perf/util/trace-event-scripting.c +++ b/tools/perf/util/trace-event-scripting.c @@ -13,6 +13,7 @@ #include #endif =20 +#include "archinsn.h" #include "debug.h" #include "trace-event.h" #include "evsel.h" @@ -269,3 +270,18 @@ void setup_perl_scripting(void) } #endif #endif + +#if !defined(__i386__) && !defined(__x86_64__) +void arch_fetch_insn(struct perf_sample *sample __maybe_unused, + struct thread *thread __maybe_unused, + struct machine *machine __maybe_unused) +{ +} +#endif + +void script_fetch_insn(struct perf_sample *sample, struct thread *thread, + struct machine *machine, bool native_arch) +{ + if (sample->insn_len =3D=3D 0 && native_arch) + arch_fetch_insn(sample, thread, machine); +} diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h index 81fceaf297ba..e0bb42e6509e 100644 --- a/tools/perf/util/trace-event.h +++ b/tools/perf/util/trace-event.h @@ -120,7 +120,7 @@ struct scripting_ops *script_spec__lookup(const char *s= pec); int script_spec__for_each(int (*cb)(struct scripting_ops *ops, const char = *spec)); =20 void script_fetch_insn(struct perf_sample *sample, struct thread *thread, - struct machine *machine); + struct machine *machine, bool native_arch); =20 void setup_perl_scripting(void); void setup_python_scripting(void); --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Tue Nov 26 19:53:15 2024 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 02F9518D655 for ; Wed, 16 Oct 2024 04:24:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729052700; cv=none; b=hkedQai6kI/Z+EXPuhkt0B18PdQw6B9so2kjbP5E6pxDNEiq5bz7oHksKOZTnFbt+2rwxevRXFMoh5GbtB5fRAM8REkbUbaEE3OKfc19sllXXT/0P4/v9SCDN1vJYWJ019bIuNhL5dKwTfOums7+DBeDQfRAwL809jvKIE8RfR8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729052700; c=relaxed/simple; bh=epKVJe3RCWYyjZNsPJZUgS3AsJWoqZo4b5ZWJnDvWVE=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=JjmJNkZMfWqjNq+hR7fp5yKvvUyIX2g+ynXe0Nwh21diVd1O4zj3TSo61rr4CPAqrWTCubql/TASYjYAB61dTq203f3gby/yAxaRwIjRSELk44SWnQ8/44OvguK7oxPRDoXIo12SX1nXHncatAhM92TUE6dG8LyqHmNhnYvRRlE= 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=y+BiNhPZ; arc=none smtp.client-ip=209.85.128.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="y+BiNhPZ" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e32e8436adso75824777b3.0 for ; Tue, 15 Oct 2024 21:24:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729052698; x=1729657498; 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=lK9SNOIgTuh2oYu8HhqBxPR4MfR5jmGAMzuSS+m3nhg=; b=y+BiNhPZPAkEMATH9wWe1YvsQyycF0yLVarQR2wbgtB4LSMAa2OKXqDoR1Zj5rV2Ze XE4FuHa+9TVRDy7EVZsdP1ieWw32lZdJQ1pLlUsA02iCOBmUStS98ijbo3QxDEwltkqY iGZKkgwcRyDLE6p/ta6pT0TOuSqCQrkaLWfv23B3j/z0YQUxYKvbF7xJG4BKj8Th9kkz 0c1Z5HzZUsJUZkjWxK7nklcKAv+L2il34kWo/hzPiIzEksnnEpa/hV0spIvANLA8bMo2 pJXI6PN/g9sLnJoG6hR6lk1LuSyoEKhk3nju018UuxirlhHscw1QPKeF23eTSx8gTZVg 4JnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729052698; x=1729657498; 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=lK9SNOIgTuh2oYu8HhqBxPR4MfR5jmGAMzuSS+m3nhg=; b=vTc9wrEVdRHMbyoauOTo8QeCsoc6FXGXlcyY9CoLGOIogzKfufru72fuTSkRSapw0y Wsa1UWX+NKNsJuSKnzFNL/WjneYJQhTddnXbyqhYcJ+r3J0rbE1CaBQRM8yMDzFveFsx 6J0wJgZl9/QiA9t5PvT/OzDgDXImGcg4bj8MDjPg2R+rGd5giUNYIkGNFSdE916oh9ao /WxekQ0aG113USSUNBlAemwJUeeduqn+dwCxqOUMh3+iy4jf5txCvhRfoNxfDicLJ6nD WwIDMOORG+Gjt8KmY1juL2qyU+fPFsl4PskHcceC5jTq3+Y4yP55GxzqgpQb1tk8YXjj 3TVg== X-Forwarded-Encrypted: i=1; AJvYcCXOpSYf5gzo8sSISurmiWCluukSr3+yqmr9g3VwMGkXjZfLT8+oT7YCYHwuWxDmYeBakuci8RvAR/RAXdw=@vger.kernel.org X-Gm-Message-State: AOJu0Yz0vzIQWiIDg0M6MGD/HBSWmY3u30eyEgqhdoRSLdIRB29Bmqwz I8O2Cp3Ic4LQHb4n7XXgg3uEXHVydbES0hxFZEKH+zgCkmLiQCRNuQMCM4DQ0Mw5rcBhCivgZ70 DR+dLxA== X-Google-Smtp-Source: AGHT+IEuWNkaP5l8NR2ftX8OExHxtrWqnWB9d4b5/+fsXNg6F4svjb/qo6bbUXwX/H7RKl/E3j6U49o2TWBe X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a25:ad64:0:b0:e29:67f4:8033 with SMTP id 3f1490d57ef6-e297830fafdmr2506276.5.1729052698166; Tue, 15 Oct 2024 21:24:58 -0700 (PDT) Date: Tue, 15 Oct 2024 21:24:09 -0700 In-Reply-To: <20241016042415.7552-1-irogers@google.com> Message-Id: <20241016042415.7552-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: <20241016042415.7552-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Subject: [PATCH v2 10/16] 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 , 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 | 80 ------------------------ tools/perf/util/python.c | 6 -- tools/perf/util/trace-event-scripting.c | 82 +++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 86 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 63a00dad02c6..b5329f4b0602 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -1693,86 +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"}, - {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 543e78b17e5f..1734967d7f70 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 @@ -285,3 +286,84 @@ 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"}, + {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.rc1.288.g06298d1525-goog From nobody Tue Nov 26 19:53:15 2024 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 53CB918E05E for ; Wed, 16 Oct 2024 04:25:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729052702; cv=none; b=NJCry8GZvUaajFcugqhq4Q1hYXE3SdblA+SJi8Zoy2gctUJRjblzn+Y5z3uz5zyLO+sa1O45roVTeNvHS0uKu8+c0IbuEo2jf4MVETC2/3s3tF19csy6ni14TUy1PweqNjrTwa9PoQjmqoEDyOTdrRl7FOGc+TGNh6/aMczdpCM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729052702; c=relaxed/simple; bh=csnU2nMbZf5Pe92hJAmSHVFhIlfl3DEzLXbD5ATPQLs=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=kSaQk0a/jNUy0cTx+SvRcMx9Jq4WHKOqU711cTftlR/Eq3kf0OpN76/Kz/t8i0u3Iwo8BH7foNyNaOqYBEMmefc20nfILWMAWIKpGt0KmuvXDmVXrp8PjrGOe8Rym3eQV9wnZmaXXXpjGtNLD5OP6JVzuCfekq9kzZarlkWT8Nw= 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=NvDzyGdq; arc=none smtp.client-ip=209.85.128.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="NvDzyGdq" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e370d76c15so54665777b3.2 for ; Tue, 15 Oct 2024 21:25:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729052700; x=1729657500; 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=NFPRD+Qjr10yjyax0Sdihwuno8XGcCJ8rIRuK3Rp//c=; b=NvDzyGdqNflZzzodaxQStqZIirL071z0lzlD/gXiUkW+prgQh7YyytjFdY0wfPUKBo L7zLvxlgjy+ZtuAGJE8qe6PdU09HXyzHR9qlwB05LfDACEwNoXC6jdFzzYZSHt9iSOHy QNNt4CHepmlOI327Ct0BMKJKwLZwM22KKMiwiHpRSDoLm7UoT+L845tQCXynR0eJmaG3 KHQxxoA66B5ZutLhHueYFK/Ot4+U18w/HJtLLDDMFp4L38pJL6hbmsqHGiaMBSLYryop 4/0cUcHu6FUN8Ev/GMbYuPsuAXIDpvcu+R+rNvrC79rSb4RUGWyXQags4d9c3aB64kb3 AgWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729052700; x=1729657500; 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=NFPRD+Qjr10yjyax0Sdihwuno8XGcCJ8rIRuK3Rp//c=; b=rNTu16CTPJllnatF7xkTuvFkB8l7qSK2es7kmgOZcUKDpHpeewcvoGD15dLn1qeN0k RRuWj1baVAjeUYj+Bfy2qxIHEm54+qJ6OPvKmtivCciCuga/iHVIivJaI60Ru/yYzpam iC6Wu/JJGs43ril5OTaRzaB3seJC9IHvDR9tCT1qLjtYOL31JGr1g8tVA8eVuwUxYUhl tQfsnttVNJIHhzf55Pr/85V1eLlNRW7WOdAFYR7eoMQx6ROcUyffjG+nDJYD2jkWQo+A cjd89XKgTyxxFpbq2/dZE0HboSYtae+86OrIVL7ysCF/wpB0VNoGe57OaV2ucle8flE3 zsKg== X-Forwarded-Encrypted: i=1; AJvYcCXQIcSDMIGcIudGLjHFuzdG/WjXVGCE5grwOCDcJrwyBi+t5eq617C22JtXoQJ5HhXoo3sgxhkPMBGro50=@vger.kernel.org X-Gm-Message-State: AOJu0YyqYEXdR+EsUlaun3vLOcT5QAk1eD1rba62OSYDDQcwPd0A8Oyr 7OJvKP2/5vw9eRJ2E94m8dfzjuZ8ePG9xZAS0H34+ijuO6JsaorhtYwV7U+BEJZcdTX2vwnxuzf DZ+Sg7Q== X-Google-Smtp-Source: AGHT+IHy9VhwEOlQQZCPiCmNMOLjfo0Pg6kbmWFmia3Btzn9BB2PiEzR8ZQYj+cKn0L1Hy3IxY51u3+e8H1l X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a05:690c:6204:b0:6dd:bf69:7e23 with SMTP id 00721157ae682-6e3d41dfebbmr777617b3.7.1729052700409; Tue, 15 Oct 2024 21:25:00 -0700 (PDT) Date: Tue, 15 Oct 2024 21:24:10 -0700 In-Reply-To: <20241016042415.7552-1-irogers@google.com> Message-Id: <20241016042415.7552-12-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241016042415.7552-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Subject: [PATCH v2 11/16] perf env: Move arch errno function to only use in env 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 , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move arch_syscalls__strerrno_function out of builtin-trace.c to env.c so that there isn't a util to builtin function call. This allows the python.c stub to be removed. Also, remove declaration/prototype from env.h and make static to reduce scope. Signed-off-by: Ian Rogers --- tools/perf/builtin-trace.c | 1 - tools/perf/trace/beauty/arch_errno_names.sh | 3 ++- tools/perf/util/env.c | 2 ++ tools/perf/util/env.h | 2 -- tools/perf/util/python.c | 6 ------ 5 files changed, 4 insertions(+), 10 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 0b30297b4ecb..dbcf74a9e047 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -1108,7 +1108,6 @@ static bool syscall_arg__strtoul_btf_type(char *bf __= maybe_unused, size_t size _ .strtoul =3D STUL_STRARRAY_FLAGS, \ .parm =3D &strarray__##array, } =20 -#include "trace/beauty/arch_errno_names.c" #include "trace/beauty/eventfd.c" #include "trace/beauty/futex_op.c" #include "trace/beauty/futex_val3.c" diff --git a/tools/perf/trace/beauty/arch_errno_names.sh b/tools/perf/trace= /beauty/arch_errno_names.sh index 30d3889b2957..b22890b8d272 100755 --- a/tools/perf/trace/beauty/arch_errno_names.sh +++ b/tools/perf/trace/beauty/arch_errno_names.sh @@ -57,7 +57,8 @@ create_arch_errno_table_func() archlist=3D"$1" default=3D"$2" =20 - printf 'arch_syscalls__strerrno_t *arch_syscalls__strerrno_function(const= char *arch)\n' + printf 'static arch_syscalls__strerrno_t *\n' + printf 'arch_syscalls__strerrno_function(const char *arch)\n' printf '{\n' for arch in $archlist; do arch_str=3D$(arch_string "$arch") diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index 1edbccfc3281..a903917a09a4 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -22,6 +22,8 @@ struct perf_env perf_env; #include "bpf-utils.h" #include =20 +#include "trace/beauty/arch_errno_names.c" + void perf_env__insert_bpf_prog_info(struct perf_env *env, struct bpf_prog_info_node *info_node) { diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h index 51b36c36019b..6a61ceff10bc 100644 --- a/tools/perf/util/env.h +++ b/tools/perf/util/env.h @@ -56,8 +56,6 @@ struct pmu_caps { =20 typedef const char *(arch_syscalls__strerrno_t)(int err); =20 -arch_syscalls__strerrno_t *arch_syscalls__strerrno_function(const char *ar= ch); - struct perf_env { char *hostname; char *os_release; diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 77e02fcc51dd..35d84a96dbec 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -16,7 +16,6 @@ #include "thread_map.h" #include "trace-event.h" #include "mmap.h" -#include "util/env.h" #include "util/kwork.h" #include "util/sample.h" #include "util/lock-contention.h" @@ -1305,11 +1304,6 @@ PyMODINIT_FUNC PyInit_perf(void) /* The following are stubs to avoid dragging in builtin-* objects. */ /* TODO: move the code out of the builtin-* file into util. */ =20 -arch_syscalls__strerrno_t *arch_syscalls__strerrno_function(const char *ar= ch __maybe_unused) -{ - return NULL; -} - struct kwork_work *perf_kwork_add_work(struct perf_kwork *kwork __maybe_un= used, struct kwork_class *class __maybe_unused, struct kwork_work *key __maybe_unused) --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Tue Nov 26 19:53:15 2024 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 A670C191466 for ; Wed, 16 Oct 2024 04:25:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729052705; cv=none; b=A5Q+5I65LMd1APZ4PYOE9hHhzSVSZJOFRz7rJjC+1pzW/1a9FdFD0wNSOC+hw8CJmOHcwbousdtZphkkYOHDgDKRjd3kP+JXaST6xY4QHY1h2DdiSCTMfNmnARTMFuz+nC6igZGEXVegKbwyG0trVBryXNVqwrmgbGqjEqc9LZI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729052705; c=relaxed/simple; bh=xDMRh+ZHjcHEujt5lqJBKx4q8NwRF+UlbwZuGNd20L4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=o2mPvmiuRQlxCiiXb3N7BMpXhms3+piHHbAeY9VOAlorUC0qLFWKScxNJl/zRduaw/GFMSWshl7acpEUX0y8/wBQxqpW65RCLB/koiLuKuhq7IJawJN7+PY1n4eVels+LQO2cW6cHyBvF58dbCjahwZXLQl9V0hwJlE0s2ox3oA= 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=4EqRmEGn; arc=none smtp.client-ip=209.85.128.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="4EqRmEGn" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e390b164c7so46389867b3.1 for ; Tue, 15 Oct 2024 21:25:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729052703; x=1729657503; 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=Lur4ZrKvhJv2/owFCIZd4RUVflpVqjCFqvJ7X+ZkMro=; b=4EqRmEGnqCNODmo/fmb0E0ahmJmN1ibFPY7CByFvo8r7WHNqzRL5624gqCvzmICPpB zpfzgNzeylJU+7da6Qrb+bJce6X6JAYE9cUHqXG2Hhiu0LbHScjc2CBkOZCTIah4gJiN iV63PeKcRGcw1TV8fQtTertFlPnp+WKXogsEHuhahUYd8GL+nfPv4kSLgckN93mbZGom wqK5tmECtqJlfxvVqrufqmR8rETpTGQN5YnV/3ou+txdiYoGVsbFc4yqElmO9uqmlU7k wM3T7k1Y0YElbh0x2oXMzJpP2g2iTxxJd29gA8JH7tEhCkDCMgv+4VExb45y7zHuuMep 1JmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729052703; x=1729657503; 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=Lur4ZrKvhJv2/owFCIZd4RUVflpVqjCFqvJ7X+ZkMro=; b=X8NtxtR4eYfvvip89Jw2YuOq0aKXSo6DtFxXt5QOYIDgVf0tKxycHtcRARcUgZhymw E9LEJMXFCvtZJJexLutMo39PoUGS32L45DlnEil2il+Xd4oVTg3Z+tPNuY7vFwTzVyfm 8QmxxXbYcWs7O319zy2QKNVFpOIMa05Gvp7DxKnz2T6S+MBObxnPMqwF/QfwGFuMsWUp xW89D/gPkCv706777FrMa+CIm86P8xwand4+NVhywNT30lkH/seT1jWgRvE3O6bHjB4J Df/JKsk2fU+yZC1ToiffE9ek6fzoFIVgHj0+GFyIh4P6JAdfDZWyqc3T6waRl3km6pIy Rg6w== X-Forwarded-Encrypted: i=1; AJvYcCWxyEHVxyvFne8uHOT1hZ15x/1FtJ1LtxQDEhfvwJXtUzHRQANr5aeRRS8uIls6WbjpbNB4oysEXCPawWo=@vger.kernel.org X-Gm-Message-State: AOJu0Ywy9lf1RfgKvrPxQz5VNa6kivHTWHeZFksOIodXXukLNIXQ2ZbO S3jWECUEJ9BNHsJAm09coxrEPqNmunuR7Gk8eUxGgI/LtiVu76tPKMneOoD3+EhL6bGXM+mtLKQ 5/VbEqg== X-Google-Smtp-Source: AGHT+IFqya7Vh9N5Q+SuC9i+bx9LncN7JqSRoQU+b6lU0Ehk5ym9Mk26PRby/4dos/VDRJoJDFig1hkP6Dmg X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a05:690c:4b12:b0:62c:f6fd:5401 with SMTP id 00721157ae682-6e3d41ca698mr483037b3.6.1729052702780; Tue, 15 Oct 2024 21:25:02 -0700 (PDT) Date: Tue, 15 Oct 2024 21:24:11 -0700 In-Reply-To: <20241016042415.7552-1-irogers@google.com> Message-Id: <20241016042415.7552-13-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241016042415.7552-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Subject: [PATCH v2 12/16] perf lock: Move common lock contention code to new file 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 , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Avoid references from util code to builtin-lock that require python stubs. Move the functions and related variables to util/lock-contention.c. Add max_stack_depth parameter to match_callstack_filter to avoid sharing a global variable. Signed-off-by: Ian Rogers --- tools/perf/builtin-lock.c | 137 +-------------------- tools/perf/util/Build | 1 + tools/perf/util/bpf_lock_contention.c | 2 +- tools/perf/util/lock-contention.c | 170 ++++++++++++++++++++++++++ tools/perf/util/lock-contention.h | 37 ++---- tools/perf/util/python.c | 17 --- 6 files changed, 185 insertions(+), 179 deletions(-) create mode 100644 tools/perf/util/lock-contention.c diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index 062e2b56a2ab..f66948b1fbed 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -46,15 +46,6 @@ static struct perf_session *session; static struct target target; =20 -/* based on kernel/lockdep.c */ -#define LOCKHASH_BITS 12 -#define LOCKHASH_SIZE (1UL << LOCKHASH_BITS) - -static struct hlist_head *lockhash_table; - -#define __lockhashfn(key) hash_long((unsigned long)key, LOCKHASH_BITS) -#define lockhashentry(key) (lockhash_table + __lockhashfn((key))) - static struct rb_root thread_stats; =20 static bool combine_locks; @@ -67,24 +58,13 @@ static unsigned long bpf_map_entries =3D MAX_ENTRIES; static int max_stack_depth =3D CONTENTION_STACK_DEPTH; static int stack_skip =3D CONTENTION_STACK_SKIP; static int print_nr_entries =3D INT_MAX / 2; -static LIST_HEAD(callstack_filters); static const char *output_name =3D NULL; static FILE *lock_output; =20 -struct callstack_filter { - struct list_head list; - char name[]; -}; - static struct lock_filter filters; =20 static enum lock_aggr_mode aggr_mode =3D LOCK_AGGR_ADDR; =20 -static bool needs_callstack(void) -{ - return !list_empty(&callstack_filters); -} - static struct thread_stat *thread_stat_find(u32 tid) { struct rb_node *node; @@ -477,93 +457,6 @@ static struct lock_stat *pop_from_result(void) return container_of(node, struct lock_stat, rb); } =20 -struct lock_stat *lock_stat_find(u64 addr) -{ - struct hlist_head *entry =3D lockhashentry(addr); - struct lock_stat *ret; - - hlist_for_each_entry(ret, entry, hash_entry) { - if (ret->addr =3D=3D addr) - return ret; - } - return NULL; -} - -struct lock_stat *lock_stat_findnew(u64 addr, const char *name, int flags) -{ - struct hlist_head *entry =3D lockhashentry(addr); - struct lock_stat *ret, *new; - - hlist_for_each_entry(ret, entry, hash_entry) { - if (ret->addr =3D=3D addr) - return ret; - } - - new =3D zalloc(sizeof(struct lock_stat)); - if (!new) - goto alloc_failed; - - new->addr =3D addr; - new->name =3D strdup(name); - if (!new->name) { - free(new); - goto alloc_failed; - } - - new->flags =3D flags; - new->wait_time_min =3D ULLONG_MAX; - - hlist_add_head(&new->hash_entry, entry); - return new; - -alloc_failed: - pr_err("memory allocation failed\n"); - return NULL; -} - -bool match_callstack_filter(struct machine *machine, u64 *callstack) -{ - struct map *kmap; - struct symbol *sym; - u64 ip; - const char *arch =3D perf_env__arch(machine->env); - - if (list_empty(&callstack_filters)) - return true; - - for (int i =3D 0; i < max_stack_depth; i++) { - struct callstack_filter *filter; - - /* - * In powerpc, the callchain saved by kernel always includes - * first three entries as the NIP (next instruction pointer), - * LR (link register), and the contents of LR save area in the - * second stack frame. In certain scenarios its possible to have - * invalid kernel instruction addresses in either LR or the second - * stack frame's LR. In that case, kernel will store that address as - * zero. - * - * The below check will continue to look into callstack, - * incase first or second callstack index entry has 0 - * address for powerpc. - */ - if (!callstack || (!callstack[i] && (strcmp(arch, "powerpc") || - (i !=3D 1 && i !=3D 2)))) - break; - - ip =3D callstack[i]; - sym =3D machine__find_kernel_symbol(machine, ip, &kmap); - if (sym =3D=3D NULL) - continue; - - list_for_each_entry(filter, &callstack_filters, list) { - if (strstr(sym->name, filter->name)) - return true; - } - } - return false; -} - struct trace_lock_handler { /* it's used on CONFIG_LOCKDEP */ int (*acquire_event)(struct evsel *evsel, @@ -1165,7 +1058,7 @@ static int report_lock_contention_begin_event(struct = evsel *evsel, if (callstack =3D=3D NULL) return -ENOMEM; =20 - if (!match_callstack_filter(machine, callstack)) { + if (!match_callstack_filter(machine, callstack, max_stack_depth)) { free(callstack); return 0; } @@ -2449,34 +2342,6 @@ static int parse_lock_addr(const struct option *opt = __maybe_unused, const char * return ret; } =20 -static int parse_call_stack(const struct option *opt __maybe_unused, const= char *str, - int unset __maybe_unused) -{ - char *s, *tmp, *tok; - int ret =3D 0; - - s =3D strdup(str); - if (s =3D=3D NULL) - return -1; - - for (tok =3D strtok_r(s, ", ", &tmp); tok; tok =3D strtok_r(NULL, ", ", &= tmp)) { - struct callstack_filter *entry; - - entry =3D malloc(sizeof(*entry) + strlen(tok) + 1); - if (entry =3D=3D NULL) { - pr_err("Memory allocation failure\n"); - free(s); - return -1; - } - - strcpy(entry->name, tok); - list_add_tail(&entry->list, &callstack_filters); - } - - free(s); - return ret; -} - static int parse_output(const struct option *opt __maybe_unused, const cha= r *str, int unset __maybe_unused) { diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 2a2f7780e595..ea2d9eced92e 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -121,6 +121,7 @@ perf-util-y +=3D topdown.o perf-util-y +=3D iostat.o perf-util-y +=3D stream.o perf-util-y +=3D kvm-stat.o +perf-util-y +=3D lock-contention.o perf-util-$(CONFIG_AUXTRACE) +=3D auxtrace.o perf-util-$(CONFIG_AUXTRACE) +=3D intel-pt-decoder/ perf-util-$(CONFIG_AUXTRACE) +=3D intel-pt.o diff --git a/tools/perf/util/bpf_lock_contention.c b/tools/perf/util/bpf_lo= ck_contention.c index 41a1ad087895..37e17c56f106 100644 --- a/tools/perf/util/bpf_lock_contention.c +++ b/tools/perf/util/bpf_lock_contention.c @@ -458,7 +458,7 @@ int lock_contention_read(struct lock_contention *con) if (con->save_callstack) { bpf_map_lookup_elem(stack, &key.stack_id, stack_trace); =20 - if (!match_callstack_filter(machine, stack_trace)) { + if (!match_callstack_filter(machine, stack_trace, con->max_stack)) { con->nr_filtered +=3D data.count; goto next; } diff --git a/tools/perf/util/lock-contention.c b/tools/perf/util/lock-conte= ntion.c new file mode 100644 index 000000000000..841bb18b1f06 --- /dev/null +++ b/tools/perf/util/lock-contention.c @@ -0,0 +1,170 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "debug.h" +#include "env.h" +#include "lock-contention.h" +#include "machine.h" +#include "symbol.h" + +#include +#include + +#include +#include + +#define __lockhashfn(key) hash_long((unsigned long)key, LOCKHASH_BITS) +#define lockhashentry(key) (lockhash_table + __lockhashfn((key))) + +struct callstack_filter { + struct list_head list; + char name[]; +}; + +static LIST_HEAD(callstack_filters); +struct hlist_head *lockhash_table; + +int parse_call_stack(const struct option *opt __maybe_unused, const char *= str, + int unset __maybe_unused) +{ + char *s, *tmp, *tok; + int ret =3D 0; + + s =3D strdup(str); + if (s =3D=3D NULL) + return -1; + + for (tok =3D strtok_r(s, ", ", &tmp); tok; tok =3D strtok_r(NULL, ", ", &= tmp)) { + struct callstack_filter *entry; + + entry =3D malloc(sizeof(*entry) + strlen(tok) + 1); + if (entry =3D=3D NULL) { + pr_err("Memory allocation failure\n"); + free(s); + return -1; + } + + strcpy(entry->name, tok); + list_add_tail(&entry->list, &callstack_filters); + } + + free(s); + return ret; +} + +bool needs_callstack(void) +{ + return !list_empty(&callstack_filters); +} + +struct lock_stat *lock_stat_find(u64 addr) +{ + struct hlist_head *entry =3D lockhashentry(addr); + struct lock_stat *ret; + + hlist_for_each_entry(ret, entry, hash_entry) { + if (ret->addr =3D=3D addr) + return ret; + } + return NULL; +} + +struct lock_stat *lock_stat_findnew(u64 addr, const char *name, int flags) +{ + struct hlist_head *entry =3D lockhashentry(addr); + struct lock_stat *ret, *new; + + hlist_for_each_entry(ret, entry, hash_entry) { + if (ret->addr =3D=3D addr) + return ret; + } + + new =3D zalloc(sizeof(struct lock_stat)); + if (!new) + goto alloc_failed; + + new->addr =3D addr; + new->name =3D strdup(name); + if (!new->name) { + free(new); + goto alloc_failed; + } + + new->flags =3D flags; + new->wait_time_min =3D ULLONG_MAX; + + hlist_add_head(&new->hash_entry, entry); + return new; + +alloc_failed: + pr_err("memory allocation failed\n"); + return NULL; +} + +bool match_callstack_filter(struct machine *machine, u64 *callstack, int m= ax_stack_depth) +{ + struct map *kmap; + struct symbol *sym; + u64 ip; + const char *arch =3D perf_env__arch(machine->env); + + if (list_empty(&callstack_filters)) + return true; + + for (int i =3D 0; i < max_stack_depth; i++) { + struct callstack_filter *filter; + + /* + * In powerpc, the callchain saved by kernel always includes + * first three entries as the NIP (next instruction pointer), + * LR (link register), and the contents of LR save area in the + * second stack frame. In certain scenarios its possible to have + * invalid kernel instruction addresses in either LR or the second + * stack frame's LR. In that case, kernel will store that address as + * zero. + * + * The below check will continue to look into callstack, + * incase first or second callstack index entry has 0 + * address for powerpc. + */ + if (!callstack || (!callstack[i] && (strcmp(arch, "powerpc") || + (i !=3D 1 && i !=3D 2)))) + break; + + ip =3D callstack[i]; + sym =3D machine__find_kernel_symbol(machine, ip, &kmap); + if (sym =3D=3D NULL) + continue; + + list_for_each_entry(filter, &callstack_filters, list) { + if (strstr(sym->name, filter->name)) + return true; + } + } + return false; +} + +#ifndef HAVE_BPF_SKEL +int lock_contention_prepare(struct lock_contention *con __maybe_unused) +{ + return 0; +} + +int lock_contention_start(void) +{ + return 0; +} + +int lock_contention_stop(void) +{ + return 0; +} + +int lock_contention_finish(struct lock_contention *con __maybe_unused) +{ + return 0; +} + +int lock_contention_read(struct lock_contention *con __maybe_unused) +{ + return 0; +} +#endif /* !HAVE_BPF_SKEL */ diff --git a/tools/perf/util/lock-contention.h b/tools/perf/util/lock-conte= ntion.h index 1a7248ff3889..bfa5c7db0a5d 100644 --- a/tools/perf/util/lock-contention.h +++ b/tools/perf/util/lock-contention.h @@ -67,10 +67,11 @@ struct lock_stat { */ #define MAX_LOCK_DEPTH 48 =20 -struct lock_stat *lock_stat_find(u64 addr); -struct lock_stat *lock_stat_findnew(u64 addr, const char *name, int flags); +/* based on kernel/lockdep.c */ +#define LOCKHASH_BITS 12 +#define LOCKHASH_SIZE (1UL << LOCKHASH_BITS) =20 -bool match_callstack_filter(struct machine *machine, u64 *callstack); +extern struct hlist_head *lockhash_table; =20 /* * struct lock_seq_stat: @@ -148,7 +149,14 @@ struct lock_contention { bool save_callstack; }; =20 -#ifdef HAVE_BPF_SKEL +struct option; +int parse_call_stack(const struct option *opt, const char *str, int unset); +bool needs_callstack(void); + +struct lock_stat *lock_stat_find(u64 addr); +struct lock_stat *lock_stat_findnew(u64 addr, const char *name, int flags); + +bool match_callstack_filter(struct machine *machine, u64 *callstack, int m= ax_stack_depth); =20 int lock_contention_prepare(struct lock_contention *con); int lock_contention_start(void); @@ -156,25 +164,4 @@ int lock_contention_stop(void); int lock_contention_read(struct lock_contention *con); int lock_contention_finish(struct lock_contention *con); =20 -#else /* !HAVE_BPF_SKEL */ - -static inline int lock_contention_prepare(struct lock_contention *con __ma= ybe_unused) -{ - return 0; -} - -static inline int lock_contention_start(void) { return 0; } -static inline int lock_contention_stop(void) { return 0; } -static inline int lock_contention_finish(struct lock_contention *con __may= be_unused) -{ - return 0; -} - -static inline int lock_contention_read(struct lock_contention *con __maybe= _unused) -{ - return 0; -} - -#endif /* HAVE_BPF_SKEL */ - #endif /* PERF_LOCK_CONTENTION_H */ diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 35d84a96dbec..91fd444615cd 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -18,7 +18,6 @@ #include "mmap.h" #include "util/kwork.h" #include "util/sample.h" -#include "util/lock-contention.h" #include #include "../builtin.h" =20 @@ -1311,22 +1310,6 @@ struct kwork_work *perf_kwork_add_work(struct perf_k= work *kwork __maybe_unused, return NULL; } =20 -bool match_callstack_filter(struct machine *machine __maybe_unused, u64 *c= allstack __maybe_unused) -{ - return false; -} - -struct lock_stat *lock_stat_find(u64 addr __maybe_unused) -{ - return NULL; -} - -struct lock_stat *lock_stat_findnew(u64 addr __maybe_unused, const char *n= ame __maybe_unused, - int flags __maybe_unused) -{ - return NULL; -} - int cmd_inject(int argc __maybe_unused, const char *argv[] __maybe_unused) { return -1; --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Tue Nov 26 19:53:15 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 A74CB193072 for ; Wed, 16 Oct 2024 04:25:05 +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=1729052707; cv=none; b=dtQq9nFiLr760L5GRYczgVIQvgs3Qwqr8sTa3vawuUVUhe4P1kK1+EEh0m3aBHZg+h8+5dkZ+RJND4cz844SlPrYG8Rhd0dJjUcD2ps7NqcJFM130P1c1xZ3SBs90gzFUSXUehE1h6am4U0Qz5PYX2bvVcGRo1EmmmSKI6bsEm0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729052707; c=relaxed/simple; bh=Lxd44HNIIUMBFIsdkVzpn2nUHSToU/AOD0h6f9vtF1I=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=ROm3zDCPLIKdOD5Y4qDb9DeGGEqaTsJjOYrHfLbIgI3pdqvUz9Edj4Rlsu+gq5kn5nmSCytAnLKfCYmjKrFoiBnb4E/n7ZquOLXiJ1Y8uHG2rSuJWc2cJV0AIK60mBqThLBdQ6HOUvMIc/jtq/pTELj7dDkSe30ELBcFiVKhIeE= 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=fOb3SRGh; 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="fOb3SRGh" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e28fc8902e6so8708643276.0 for ; Tue, 15 Oct 2024 21:25:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729052705; x=1729657505; 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=wEJZm+zO7NJ5VjFkt41/KKWQvQrLbI4UzfjSvW39ruY=; b=fOb3SRGhuDmWpADCTJL9bQtzjLtJ9wlFhmg6g4XBTDPj5Xk+grP0ZpaaXegrGNe/kY kpMvwzCqfnry4DgFsMh3fKKrIlJxReMJeqdW/YTUpWmw7M/bwaMvX29OhgjzT9W4RGk0 +wYLqSQ21kyF7w6uMn543kFGNiERCZSfCgkUcFFavUX8BxTw3RnKXqskHV1/JdWiy1hU KMIFK4tvpiGL1X6nbbpcNf4Cfaylzvaek79qBse8S2fE2Vzfv6gSbquIxOzO4kGJpzGu IUs+MeJ0DAq5qmn1ZRTfzUGQLnWySjG9XtWf2GSor1kAt1XEFoD87Ifr00VbW3l+Jh+p jhKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729052705; x=1729657505; 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=wEJZm+zO7NJ5VjFkt41/KKWQvQrLbI4UzfjSvW39ruY=; b=FP2/aX8nU06DbYMF+rvCTgT5fh1uRTsRtpd0vz42KcjNPXj1g5AtcntA84chOuoLuS iDeEx88stcl8oqzHI6tin76SqF0b+IgE4VUWM/mPVR4nTnXDLX5r938SIJr0yXS8qLOh jMAnq3+B7slh6RBBO/F08jnItSuV8eZfNcav5fge/jKt9nCv3gTKCJ3gILHGE9vv8eje 15mDOEYYg9m3BxW9prWIAmb/vckb3T2uSIAih1IdtxCxw5x8ZTyjjnD3FsGqxHxbsxpO ff3fhD4zlVCR750kw+qxkt8S8QMPFAFtm2Pf71mNQbubRe5RDtSif1m8PK4oYyskqS8C 3TnA== X-Forwarded-Encrypted: i=1; AJvYcCVykWX5upU4ZTk77cQLKUdHFh8CC+CJIq+F910NNkAZSTeYlHdnsf11Kau8pcQdwQtNt8pkdvo4yHzWtxo=@vger.kernel.org X-Gm-Message-State: AOJu0YyQX5P0DlTearKunU2lkphoCsClpSRwDW5+64iOOijIzumVlb0W Uf3f5jP4PbJQl56V1SzEX1QtgnGPl4XWHf9BGZ4GnU3b+p+ZG6FuvHcHUCE+L8Jrj2RV2bqXhDp mM3XUUw== X-Google-Smtp-Source: AGHT+IEN9tRbNqWXI3cWGhRxH41kFQoOZdjSIJ+Slt9AQ5secKvbfHsMFkGkNd2I3hJ4+wwqJgXxiRybI3G3 X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a25:e910:0:b0:e1f:eaf1:2254 with SMTP id 3f1490d57ef6-e2978573afemr2136276.8.1729052704783; Tue, 15 Oct 2024 21:25:04 -0700 (PDT) Date: Tue, 15 Oct 2024 21:24:12 -0700 In-Reply-To: <20241016042415.7552-1-irogers@google.com> Message-Id: <20241016042415.7552-14-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241016042415.7552-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Subject: [PATCH v2 13/16] perf bench: Remove reference to cmd_inject 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 , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Avoid `perf bench internals inject-build-id` referencing the cmd_inject sub-command that requires perf-bench to backward reference internals of builtins. Replace the reference to cmd_inject with a call to main. To avoid python.c needing to link with something providing main, drop the libperf-bench library from the python shared object. Signed-off-by: Ian Rogers --- tools/perf/Makefile.perf | 7 +++++-- tools/perf/bench/inject-buildid.c | 13 +++++++------ tools/perf/util/python.c | 6 ------ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index 105f734b6820..e54c6953cf02 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -487,6 +487,9 @@ endif EXTLIBS :=3D $(call filter-out,$(EXCLUDE_EXTLIBS),$(EXTLIBS)) LIBS =3D -Wl,--whole-archive $(PERFLIBS) $(EXTRA_PERFLIBS) -Wl,--no-whole-= archive -Wl,--start-group $(EXTLIBS) -Wl,--end-group =20 +PERFLIBS_PY :=3D $(call filter-out,$(LIBPERF_BENCH),$(PERFLIBS)) +LIBS_PY =3D -Wl,--whole-archive $(PERFLIBS_PY) $(EXTRA_PERFLIBS) -Wl,--no-= whole-archive -Wl,--start-group $(EXTLIBS) -Wl,--end-group + export INSTALL SHELL_PATH =20 ### Build rules @@ -735,9 +738,9 @@ all: shell_compatibility_test $(ALL_PROGRAMS) $(LANG_BI= NDINGS) $(OTHER_PROGRAMS) # Create python binding output directory if not already present $(shell [ -d '$(OUTPUT)python' ] || mkdir -p '$(OUTPUT)python') =20 -$(OUTPUT)python/perf$(PYTHON_EXTENSION_SUFFIX): util/python.c util/setup.p= y $(PERFLIBS) +$(OUTPUT)python/perf$(PYTHON_EXTENSION_SUFFIX): util/python.c util/setup.p= y $(PERFLIBS_PY) $(QUIET_GEN)LDSHARED=3D"$(CC) -pthread -shared" \ - CFLAGS=3D'$(CFLAGS)' LDFLAGS=3D'$(LDFLAGS) $(LIBS)' \ + CFLAGS=3D'$(CFLAGS)' LDFLAGS=3D'$(LDFLAGS) $(LIBS_PY)' \ $(PYTHON_WORD) util/setup.py \ --quiet build_ext; \ cp $(PYTHON_EXTBUILD_LIB)perf*.so $(OUTPUT)python/ diff --git a/tools/perf/bench/inject-buildid.c b/tools/perf/bench/inject-bu= ildid.c index a759eb2328be..f55c07e4be94 100644 --- a/tools/perf/bench/inject-buildid.c +++ b/tools/perf/bench/inject-buildid.c @@ -52,7 +52,7 @@ struct bench_dso { static int nr_dsos; static struct bench_dso *dsos; =20 -extern int cmd_inject(int argc, const char *argv[]); +extern int main(int argc, const char **argv); =20 static const struct option options[] =3D { OPT_UINTEGER('i', "iterations", &iterations, @@ -294,7 +294,7 @@ static int setup_injection(struct bench_data *data, boo= l build_id_all) =20 if (data->pid =3D=3D 0) { const char **inject_argv; - int inject_argc =3D 2; + int inject_argc =3D 3; =20 close(data->input_pipe[1]); close(data->output_pipe[0]); @@ -318,15 +318,16 @@ static int setup_injection(struct bench_data *data, b= ool build_id_all) if (inject_argv =3D=3D NULL) exit(1); =20 - inject_argv[0] =3D strdup("inject"); - inject_argv[1] =3D strdup("-b"); + inject_argv[0] =3D strdup("perf"); + inject_argv[1] =3D strdup("inject"); + inject_argv[2] =3D strdup("-b"); if (build_id_all) - inject_argv[2] =3D strdup("--buildid-all"); + inject_argv[3] =3D strdup("--buildid-all"); =20 /* signal that we're ready to go */ close(ready_pipe[1]); =20 - cmd_inject(inject_argc, inject_argv); + main(inject_argc, inject_argv); =20 exit(0); } diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 91fd444615cd..c52da509ae58 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -19,7 +19,6 @@ #include "util/kwork.h" #include "util/sample.h" #include -#include "../builtin.h" =20 #define _PyUnicode_FromString(arg) \ PyUnicode_FromString(arg) @@ -1309,8 +1308,3 @@ struct kwork_work *perf_kwork_add_work(struct perf_kw= ork *kwork __maybe_unused, { return NULL; } - -int cmd_inject(int argc __maybe_unused, const char *argv[] __maybe_unused) -{ - return -1; -} --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Tue Nov 26 19:53:15 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 1599A19AA58 for ; Wed, 16 Oct 2024 04:25:07 +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=1729052709; cv=none; b=so0np7+y4NlPj1ReJszVK4iuSrXAfvYhiBn1kC9ZQQw9QJy6XRxDgK6Z2BAGlhXU+gmaSLRZLbFj1c2XPJVA1A/IeoD4OhC+MJ7k1SEmbyNZ2xDB3ANrhu+ZPfmPg0KRyar3JDCYHxbMm+ZCRrmXLGl0oX0XE8KbAjbNjjw1Les= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729052709; c=relaxed/simple; bh=s5yyLidwQ40d4OogKqHnOvqWwc/N1AglqDKRBjOI2yk=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Ldygx/5ydIQdKc/5PaigtDfGu63RyH2u+6MEyerGls9XOl9uxmGCy9eoqP6zFEcrA9I4JwrTW9zteSBQNQ9pnmUKPeSnm+pHSavpgd6FDTN+OjUr2mX0T7N9ldfnkxs8tU8K8+v6MKld2dpvw/mz5ny6U9a4NN27M8K62lRwsUI= 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=S/D3wXsg; 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="S/D3wXsg" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e293b3e014aso4976616276.3 for ; Tue, 15 Oct 2024 21:25:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729052707; x=1729657507; 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=TSfb1a/n/0uhtJ4YqpAgkjD+74Vwwf3V49tKPgTATBU=; b=S/D3wXsgD5rY3sQXZYqKtwCjBhFHFvZD84AhOuTPrVhsx2iP4Qut/K4Rox/MP/GUD8 TVpMEhz8+5fM29GMhUTqo4fTgeSGEOvHl/sNE2qNlxTd4+evmNh4PcX0YflrhDgCZuUx KkH341qU8U1h4j3zMbo3d6XXdjx9igXz83Bn07GOZgsQonJhnN2iS7O74P6TCCBu2PhQ 8Nl88rKwh6t7838RmQkzMID0dHHpCiEVhgM9WSGm0lSeP2bn7/X5VAOoskSS4in7ABvD Co/CwD/xXOqiy8acFYGo3guKQVqc7z6LOwsalrc6HlsiXy5dTJptY0N1UgKBUbx6R26Y GJ0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729052707; x=1729657507; 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=TSfb1a/n/0uhtJ4YqpAgkjD+74Vwwf3V49tKPgTATBU=; b=UTANPnbZVNS9GR39bUbRJY27NlsqCOP3s51u7JXjDFo6hxp7hXo5W/EgciB7eNKAys XruJfRoTPLwYlrMiKjRsQ2RGG4nt5t0DeMjoFrS7W1pmtUPM66PkXJ9A2yfmCTzhU+md D3ad3EkgAn9L3/G8UOEnh/l3qBXr9S78nCpBqbjL9jHrGGpFRyAnxqL0PCCo29zlp9lt kLMFhVGKdu+JlhurDnmdMIAgYiHNViwgFb6E+rGVzpzeN/Hqfj15yxEQdVZkRdNFMxqJ /HGnjjSu4XR6gyKb1WxsfUMD8vghAnwPQAb5ECL1dRws5PSthfx3pX65deBOO6AnANbl bgwg== X-Forwarded-Encrypted: i=1; AJvYcCUXLZRmEgwkfSQF1l7Cr5tiEbtrRtSfx56wYWA1tV5hPSz3j6eLeuYlp8EFZlLDIG5jTZDFeOXZ9QjMN0c=@vger.kernel.org X-Gm-Message-State: AOJu0Yw4M2NrmpFb5WUMqN28cOutTfmJAfzQgRiNNpvAXRNXBi2Du+xd 6MGaUDnvGZzqeoV7Jb9eb0KOvJvidCZZH7bNDvd2iyx9GLjzuHKQGRqIgXle5Y5MBi77PJyor3U /YrPcZg== X-Google-Smtp-Source: AGHT+IF7iU/lbO7eXiz62Z6cqJvELGnqBvwlKfToxBCxdccEfMP6WMhQ7/Sl3phnoOJD2uCh5sht0jY1WzGJ X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a05:6902:2d08:b0:e28:f6b3:3666 with SMTP id 3f1490d57ef6-e2978567367mr2282276.7.1729052706878; Tue, 15 Oct 2024 21:25:06 -0700 (PDT) Date: Tue, 15 Oct 2024 21:24:13 -0700 In-Reply-To: <20241016042415.7552-1-irogers@google.com> Message-Id: <20241016042415.7552-15-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241016042415.7552-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Subject: [PATCH v2 14/16] perf kwork: Make perf_kwork_add_work a callback 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 , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" perf_kwork_add_work is declared in builtin-kwork, whereas much kwork code is in util. To avoid needing to stub perf_kwork_add_work in python.c, add a callback to struct perf_kwork and initialize it in builtin-kwork to perf_kwork_add_work - this is the only struct perf_kwork. This removes the need for the stub in python.c. Signed-off-by: Ian Rogers --- tools/perf/builtin-kwork.c | 3 ++- tools/perf/util/bpf_kwork.c | 2 +- tools/perf/util/bpf_kwork_top.c | 2 +- tools/perf/util/kwork.h | 6 ++++-- tools/perf/util/python.c | 12 ------------ 5 files changed, 8 insertions(+), 17 deletions(-) diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c index c1daf82c9b92..fabfcb74800b 100644 --- a/tools/perf/builtin-kwork.c +++ b/tools/perf/builtin-kwork.c @@ -1846,7 +1846,7 @@ static void process_skipped_events(struct perf_kwork = *kwork, } } =20 -struct kwork_work *perf_kwork_add_work(struct perf_kwork *kwork, +static struct kwork_work *perf_kwork_add_work(struct perf_kwork *kwork, struct kwork_class *class, struct kwork_work *key) { @@ -2344,6 +2344,7 @@ int cmd_kwork(int argc, const char **argv) .all_runtime =3D 0, .all_count =3D 0, .nr_skipped_events =3D { 0 }, + .add_work =3D perf_kwork_add_work, }; static const char default_report_sort_order[] =3D "runtime, max, count"; static const char default_latency_sort_order[] =3D "avg, max, count"; diff --git a/tools/perf/util/bpf_kwork.c b/tools/perf/util/bpf_kwork.c index 6c7126b7670d..5cff755c71fa 100644 --- a/tools/perf/util/bpf_kwork.c +++ b/tools/perf/util/bpf_kwork.c @@ -285,7 +285,7 @@ static int add_work(struct perf_kwork *kwork, (bpf_trace->get_work_name(key, &tmp.name))) return -1; =20 - work =3D perf_kwork_add_work(kwork, tmp.class, &tmp); + work =3D kwork->add_work(kwork, tmp.class, &tmp); if (work =3D=3D NULL) return -1; =20 diff --git a/tools/perf/util/bpf_kwork_top.c b/tools/perf/util/bpf_kwork_to= p.c index 7261cad43468..b6f187dd9136 100644 --- a/tools/perf/util/bpf_kwork_top.c +++ b/tools/perf/util/bpf_kwork_top.c @@ -255,7 +255,7 @@ static int add_work(struct perf_kwork *kwork, struct wo= rk_key *key, bpf_trace =3D kwork_class_bpf_supported_list[type]; tmp.class =3D bpf_trace->class; =20 - work =3D perf_kwork_add_work(kwork, tmp.class, &tmp); + work =3D kwork->add_work(kwork, tmp.class, &tmp); if (!work) return -1; =20 diff --git a/tools/perf/util/kwork.h b/tools/perf/util/kwork.h index 76fe2a821bcf..29352ca1d497 100644 --- a/tools/perf/util/kwork.h +++ b/tools/perf/util/kwork.h @@ -251,12 +251,14 @@ struct perf_kwork { * perf kwork top data */ struct kwork_top_stat top_stat; -}; =20 -struct kwork_work *perf_kwork_add_work(struct perf_kwork *kwork, + /* Add work callback. */ + struct kwork_work *(*add_work)(struct perf_kwork *kwork, struct kwork_class *class, struct kwork_work *key); =20 +}; + #ifdef HAVE_BPF_SKEL =20 int perf_kwork__trace_prepare_bpf(struct perf_kwork *kwork); diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index c52da509ae58..6e2ff0076daa 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -16,7 +16,6 @@ #include "thread_map.h" #include "trace-event.h" #include "mmap.h" -#include "util/kwork.h" #include "util/sample.h" #include =20 @@ -1297,14 +1296,3 @@ PyMODINIT_FUNC PyInit_perf(void) PyErr_SetString(PyExc_ImportError, "perf: Init failed!"); return module; } - - -/* The following are stubs to avoid dragging in builtin-* objects. */ -/* TODO: move the code out of the builtin-* file into util. */ - -struct kwork_work *perf_kwork_add_work(struct perf_kwork *kwork __maybe_un= used, - struct kwork_class *class __maybe_unused, - struct kwork_work *key __maybe_unused) -{ - return NULL; -} --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Tue Nov 26 19:53:15 2024 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 199E91AF0C5 for ; Wed, 16 Oct 2024 04:25:10 +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=1729052712; cv=none; b=rOcHUs3s5chSXGtvPGn0ZxepOT8+mvniNQepY/dOSRMO7IReo1c7hjq4QewF5pUhWn0SY8OYpmjFziIxhf3mjrjsglE5WQR4toxfUmiwqpDAO/Go3rQfbe/KwshZSxc1+6OIzoWQ4FStfZ2nmX/XwD3jNeIaW2e500kRDm/M48U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729052712; c=relaxed/simple; bh=atNphtq2muvnpNjRyq+CfSdLflI1yp8tf59eJGJ5FKY=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=qUxkialsOqat0Thq8PBQ1HSmlUwbT/GBs/VLeo35XcI8QgWYHKQKPlk/khMActeMR3s44M6G+roSB/eR8jKUrunpVPtGaVrCLpoGGWYZMe7hBQdwVKJQwZi9+RMwyxYnjWzkNmv1cxQgUpRLsPMhq4Ltd96gZvTw8bKemoHPOww= 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=GfhSnokz; 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="GfhSnokz" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e2939e25402so5335212276.2 for ; Tue, 15 Oct 2024 21:25:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729052709; x=1729657509; 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=B9FBvcyPFVemeh0oNlvVwr42rd3aNqdBh2Zt6Y7kv3s=; b=GfhSnokzPlTdThNa+NEMJ5l9YQcMB62EJc1mOKCi01/q67Jr+JqHy3WH/UtmNwbh/m kku9tcPZ3NT6Fq+7shTyB1I2nMmIvhNaZcoHZql7aBec5Rlg2jQ4SfjKSXfrGXuGUzU8 sNcc3vU8E+VLNg8nxmTH3fgT5a1oWNFcjkra2jdz7JNQKFWGaqLSTWZKdHPH3jYS17fY H6W9e0lvfiJFj/t6a63+uHYsQU6l56TVyaHL5ELo3KZDjr6w84r8bUiVw+M/iiXLerFD PdYNNrFLeNpf+XoDIO3FaPAi42jEC6B9HwGIkG2+RdfhdOErMQ4M/RiBfhOiu1yG5BKk ZKgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729052709; x=1729657509; 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=B9FBvcyPFVemeh0oNlvVwr42rd3aNqdBh2Zt6Y7kv3s=; b=nV3GCOib0iREbQ//FbIBs8j2mxdbjKR/zj/5IS2yRVD7F1sgEOa04Wp7s+RmWaxUv6 nzXaaUj9nGRQzDYlQamzIX1Bq+EgDW2WxhVDKedoQzsGBy0Jrn8VQ84KCV3dzbl7uh8m 0h1kMzz7esjfTtj+vOe4ieG4N0tJVvbS9qY8JW+nGARFXoofqJHkefcoLpuLgUpXOCgC FRxrqxJNtQz8uvjSFQf7xyOopzzyo6quzIZ7weW6WZkX5aC0shZ2ESvoEyWL1q8ee13v 6o4T5qIr4VogrsyPTsnZhQlk1uGNXOHCDRnKm+VAs8wkzAvxyMXHzOEisqY/9OgRoekH FIRw== X-Forwarded-Encrypted: i=1; AJvYcCUSk9ubcO9xTFZZmUPSerulxlvNvA9RWDwwZWAZw3t8wLLtj15gUQfmZZcafQ8MN0P9BUqqPsuzR4p88Ng=@vger.kernel.org X-Gm-Message-State: AOJu0YzYQ5ISttHVMBZxMqyMrxDVucjMj/4M2v4rjSOY0C34thv1uSxq MOBJmAVOw3RPuUGZhU1UdBIbNpe9lnQYVw5q2z9CxBgOnX/G6y4Cw88Zo84w/z0YTS2l1KtTQgq Is7LU1g== X-Google-Smtp-Source: AGHT+IG0WlG2n418T7PMxezvNke9lFkjjek058CnnTXKNxeKbgILUTZrua9v/4XFvBZYiE3o8pXnS/9hYV2Y X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a25:d614:0:b0:e03:53a4:1a7 with SMTP id 3f1490d57ef6-e29785a421amr2168276.10.1729052709171; Tue, 15 Oct 2024 21:25:09 -0700 (PDT) Date: Tue, 15 Oct 2024 21:24:14 -0700 In-Reply-To: <20241016042415.7552-1-irogers@google.com> Message-Id: <20241016042415.7552-16-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241016042415.7552-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Subject: [PATCH v2 15/16] perf build: Remove test library from python shared object 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 , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" With the attr.c code moved to a shell test, there is no need to link the test code into the python dso to avoid a missing reference to test_attr__open. Drop the test code from the python library. With the bench and test code removed from the python library on my x86 debian derived laptop the python library is reduced in size by 508,712 bytes or nearly 5%. Signed-off-by: Ian Rogers --- tools/perf/Makefile.perf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index e54c6953cf02..957b25322786 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -487,7 +487,7 @@ endif EXTLIBS :=3D $(call filter-out,$(EXCLUDE_EXTLIBS),$(EXTLIBS)) LIBS =3D -Wl,--whole-archive $(PERFLIBS) $(EXTRA_PERFLIBS) -Wl,--no-whole-= archive -Wl,--start-group $(EXTLIBS) -Wl,--end-group =20 -PERFLIBS_PY :=3D $(call filter-out,$(LIBPERF_BENCH),$(PERFLIBS)) +PERFLIBS_PY :=3D $(call filter-out,$(LIBPERF_BENCH) $(LIBPERF_TEST),$(PERF= LIBS)) LIBS_PY =3D -Wl,--whole-archive $(PERFLIBS_PY) $(EXTRA_PERFLIBS) -Wl,--no-= whole-archive -Wl,--start-group $(EXTLIBS) -Wl,--end-group =20 export INSTALL SHELL_PATH --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Tue Nov 26 19:53:15 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 8D5381B393A for ; Wed, 16 Oct 2024 04:25:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729052714; cv=none; b=F2PjbpaFW92AtvexZxoZ4fQQ4drMO5wVUR2Kxneak9GIORmlS9UjtxJZD68bZ6yIbZ3JHHpe4d1J5sKr8SEoB8BvNeI7dwoEpczRG6wn1U2l19GvzD+mutieGhF0BXD2h0q1ZtlPyi9VZXxSNCIjWiVgBVseV6iTydM+b4cYXXM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729052714; c=relaxed/simple; bh=YTJsvsOE8a25R1DD/RA8PVQLNC4Uq1qBnyneB6eRW0g=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=QrABTsx0qJbYxSpfIJiD0zsqYiR21irPdS31Nlu2dGqJuYX5GMkBsanqTUjOaFYWxNwcRhg+reeCdIrhwpJG/xkTL/VWdDN/obWIC151Bb9loh+1SYGDceGpOh7IKk6klKfxq+JW0DYa+zOh4Ma+RTRTfeOKsmdzJA4H85CD8FU= 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=2QOvH27j; arc=none smtp.client-ip=209.85.128.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="2QOvH27j" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e376aa4586so58379987b3.1 for ; Tue, 15 Oct 2024 21:25:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729052711; x=1729657511; 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=hqYrLnfi6pZq/dyjCorwIaw7kfTRCdabnWEBnJH4emk=; b=2QOvH27juX3O1CUWCYYRMXX63kUlQW+wG/6I08/H4Qnu1YZxB5TgWDHdNKPemN4//I 9iAMI4pQdbrIGDvUHxHkuz3spcdON6iQNtU2ch4Wgrrg8eTn0p92vZHa67g7Ch83JrUP SSbAP9DHR/0vFD6ShuIoWZYinJw5yTUW639WYUYT4mB5ZIhUYgGGHcRF9p6U9ckxYSqE SXhzNn8snQJOFt3ogz/5jNpH0CeGwfdPRQQLnQ35RLXSR1phAS9MT7rxD7E8+q+pEK9q a1d+UWXwfATn7Mfm39dFHXnjxsIrNx/FvaAmODOkl1dq4sruJ2AzW/AkDiN9RzsP2erR V5bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729052711; x=1729657511; 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=hqYrLnfi6pZq/dyjCorwIaw7kfTRCdabnWEBnJH4emk=; b=tU5S5RvwISUHUDr1s3GdaWK1J1Y5ELUvXGMi5AvSa9wDf3FNBlX3lSsLbXZcR6mA/t VEaidKQKCm2qbM6rnC/DGdpm4fqvHKhLmV+rpAZ8+pIleyCqUBrEA/wAokxxXyIgEjGT og2CvRQsyyPP5Ss8now1divJ3S52z6mCqnLLO/Jl5ug8Ro/Qkf6G5+QBapbm3Kpxlg1c gQsbDS9V50tYa+dxzNKg0tX+WBkoOJyc1a+iMbG2fwHW9xwxBGcjbFUJ+QdIIFUpBWLs b8O7/D9FFoXY/w4k4zUIeGcfzXm+xi3HiMsWim9ojkdg5UsQ0tTBHUD6U2BsD9ey5M51 U/Vg== X-Forwarded-Encrypted: i=1; AJvYcCUA2P0D3q3CsJfpwpbnxA3NQtvx/T+NqFsrMNXQLH/UiCqzKciOMR6dzfYlfN/zQhVfAG03Wh6EpNRsNtg=@vger.kernel.org X-Gm-Message-State: AOJu0YwHK6tUMBkoGRa91Mh2i75OX2rghhJDHRis3rRbcLLFNKztwYsW zEhAZvcCMlW0J+Ppuo+4hemeOxsbZwdvenI7bu1IZBw6yesjSYLEagOsO6AaK3Q9qJWZWm/R4G9 PK0J72Q== X-Google-Smtp-Source: AGHT+IGPhS0PoOQUoVyeqB2Lwq/bFZXE1TdnwJnJCsevOVA+4Nsjgul44oYsbPNu44WV2uFZF8Ik9X8Hed4D X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a05:690c:3610:b0:6e3:3407:8575 with SMTP id 00721157ae682-6e3d41e809bmr691907b3.8.1729052711513; Tue, 15 Oct 2024 21:25:11 -0700 (PDT) Date: Tue, 15 Oct 2024 21:24:15 -0700 In-Reply-To: <20241016042415.7552-1-irogers@google.com> Message-Id: <20241016042415.7552-17-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241016042415.7552-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Subject: [PATCH v2 16/16] perf python: Add parse_events function 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 , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add basic parse_events function that takes a string and returns an evlist. Signed-off-by: Ian Rogers --- tools/perf/util/python.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 6e2ff0076daa..ec37f887db43 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1201,6 +1201,30 @@ static PyObject *pyrf__tracepoint(struct pyrf_evsel = *pevsel, #endif // HAVE_LIBTRACEEVENT } =20 +static PyObject *pyrf__parse_events(PyObject *self, PyObject *args) +{ + const char *input; + struct pyrf_evlist *pevlist; + struct parse_events_error err; + + if (!PyArg_ParseTuple(args, "s", &input)) + return NULL; + + pevlist =3D PyObject_New(struct pyrf_evlist, &pyrf_evlist__type); + if (!pevlist) + return NULL; + + parse_events_error__init(&err); + memset(&pevlist->evlist, 0, sizeof(pevlist->evlist)); + evlist__init(&pevlist->evlist, NULL, NULL); + if (parse_events(&pevlist->evlist, input, &err)) { + parse_events_error__print(&err, input); + PyErr_SetFromErrno(PyExc_OSError); + return NULL; + } + return (PyObject *)pevlist; +} + static PyMethodDef perf__methods[] =3D { { .ml_name =3D "tracepoint", @@ -1208,6 +1232,12 @@ static PyMethodDef perf__methods[] =3D { .ml_flags =3D METH_VARARGS | METH_KEYWORDS, .ml_doc =3D PyDoc_STR("Get tracepoint config.") }, + { + .ml_name =3D "parse_events", + .ml_meth =3D (PyCFunction) pyrf__parse_events, + .ml_flags =3D METH_VARARGS, + .ml_doc =3D PyDoc_STR("Parse a string of events and return an evlist.") + }, { .ml_name =3D NULL, } }; =20 --=20 2.47.0.rc1.288.g06298d1525-goog