From nobody Mon Nov 25 05:34:01 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 8563220A5F7 for ; Tue, 29 Oct 2024 22:44:39 +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=1730241882; cv=none; b=qWurSq9sV1OcwPrBQY3hz4qBEcmcCRJDxRrE0WUJFgfRPtUxCJk4gnlCO3pZnubiJQyJzXFSXuA7jWWAXlvRMEXfbadzIlNajvfErw0BQa2OENupwsfcQayRP5DohNUD9IYmpBfYaZe+0X7alTOETsF/CBNSY10faRJJ127IKlw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730241882; c=relaxed/simple; bh=06rUym8mEKwnrNebRhLzrvBcLI6yg+52u2nqnHXOz4k=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=lJd/x2QhcoAYylnnwYw4IAwyrSiu68n4tDQmcajcUCwl8E6UKhdBPcCOl3JDTovAeHAf6wT56NsoSaMWDA88P/CIWkPrmy+PpR7TXquVJk7zeHa5APLsCSe+rknl2tfaLnopVxL+/xTEy5OvaNbvU9orGQNcLQS6J5G2NLvMLVk= 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=QE3S9XkO; 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="QE3S9XkO" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e3497c8eb0so4666417b3.0 for ; Tue, 29 Oct 2024 15:44:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730241878; x=1730846678; 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=xl5YYT6/j2snqAzcSfRTiY37ktA1YE2VwqMAMMgNcVo=; b=QE3S9XkOQrIif+IZlNwqwW2pSYYY3GvW5ewmFTMhu9o1VhMKCViyDe8uN20MKzC1GH Ze+RFATnVJfICTEMJB052Du1exAirwKWO5PjysaehtgyoJDk33/Ps55AyXb3qbtdMkFC KETOM0dPKGkEM5g5QaIAr/4WInKE3GUOcn2D2L7axOZPq89kEtmVQbtMhxPe8MA243oP dJ8e+p6Anu8tz7leeSgHSyFL3LVWKp3/xlcbOzXxaE6K3kwegL+avimCqWI0AkJgY8aG 7CMw6UUB2naWEEZFwRI2OQ2ZeXqJXja8GrOF45afMkzSJ71dIrh/oXYjUD7xO+Z87Cc9 NUbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730241878; x=1730846678; 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=xl5YYT6/j2snqAzcSfRTiY37ktA1YE2VwqMAMMgNcVo=; b=dmIA95mDk56/JZSOvLzQ6z/ZxqgvNHoLHALeP/Ux99EDidm/wtBBvT+SzjRMMyYunF JESJ4/xMJHUKBR4KvPfLiHYDBOKK1KrQW65AvLVoebPulNQuktgti7gxPmPgR4eGPyQQ Z8aPhEzBr15p/RSsOILw20NCGY20Xttfpy1cKB3Vi+XXsYbSI+5cDa9jDm645rwIgRBK nJ8R9IS3OtS3EhewN4XBIemnhD9BLFvr1xrmKP5hS2UCum1AvrDeH7bVgyTAev0NuvWt JagfMnrOz2G3XxjPzlA9w747qPKMxAwfftY2ghGcPevxn/BfaflwOIeGT24dpr15F20f AEGw== X-Forwarded-Encrypted: i=1; AJvYcCXikzQscNjFmxWNCJ4zQY4LJ3Bc3ksSRiBAqR2nRehHuklrIb4R4oIMEWQrUjILn8aox57uBBZaQCR36b4=@vger.kernel.org X-Gm-Message-State: AOJu0YySL332EjJPILW1YP7RzrqzrS/icfXfrRte6e7ReJki7tricvVt WvjS+U7cj2991HDyKRf5n089kAE3ad6TyBXU5NE9eLTz+qYLE6YM3dmBqRALf87pxCEOsWoF2Bh aTdZDNw== X-Google-Smtp-Source: AGHT+IEUIWLmAbEaJu9VyQ/qtIg72JVQfqJlTeZ6UmYRgXfhi7tFEmj2/+5C0NEM08mDDPHO84A9NPr9gcPS X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8991:d3fd:38a7:c282]) (user=irogers job=sendgmr) by 2002:a05:690c:4d45:b0:6e2:ac0a:8982 with SMTP id 00721157ae682-6ea3e59140amr229807b3.0.1730241878507; Tue, 29 Oct 2024 15:44:38 -0700 (PDT) Date: Tue, 29 Oct 2024 15:44:13 -0700 In-Reply-To: <20241029224431.167623-1-irogers@google.com> Message-Id: <20241029224431.167623-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: <20241029224431.167623-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v4 01/19] 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.163.g1226f6d8fa-goog From nobody Mon Nov 25 05:34:01 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 089F020B1EF for ; Tue, 29 Oct 2024 22:44:41 +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=1730241884; cv=none; b=oS9kVbbFMmNpPw35p9yO7GF+igS+OdAz4SSqMHnrP2XfCopQ8T9GCLAXcjlPM0me8hdee2weZg4DVLhqrpIH6A2L2pfrk95MOnQbQu0G3GXjAzBo5mprjmsxgvkHIIEQHnRh3mgZ7KKLwud6NyIZXyJmwsef1wyG1vc5xKEB7Ok= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730241884; c=relaxed/simple; bh=CiUzxYw0RBvkytit97TqdNjM6aeeFRoA/HnhpHqF9To=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=D4eQzq8s6OoS/ErDPdPBVy4aMF0EWob9UANRGqzOqXplu2SJFPX+58/ZRccQHOTRSaYWwHixYucF8DD8kPeVJPEgqB7y7jTdXu614fmBH48nmDxJJ4fgMmwGgIJm8v75Bmr2rJucT2scmiZOEcr6uKXbmcZRaARXacqlpMqFKjQ= 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=OVLOqlsx; 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="OVLOqlsx" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e2954ada861so10216186276.3 for ; Tue, 29 Oct 2024 15:44:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730241881; x=1730846681; 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=H603DVgWa6efETS0jocUXZJdUuhFvKOBL+70ertaUeY=; b=OVLOqlsxmegL6Vee/qEZnVPws2Ov9yW7065ekqMGCnhBotHnq5IhQhkjQcVEuBLRfZ BXqHu8qQjcrK+D42Zk1uZTMQ3uVYZY+pu6aQBw/o6LYAnemXtJp3GZdwTIi9QQYZMjnO mw2DAS8HnKCUx1SZuJ2KdqiSk73WgUYf1b5Ztvw0PdXzFbZojgMp00xYRRUD/tKxctd/ UxqanWcdBGTSTkxt6Q9cjQQuILsklEro8pyW5iftEpXf0PLUnpxWCBNhGcA7aLGJV1PQ I3u9PlTN7FGFWSwLRcyddt/rnMQr9H71MdE6lz/bbQBKnBBEdj3siiAXJSu0WpC2afOy 7QjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730241881; x=1730846681; 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=H603DVgWa6efETS0jocUXZJdUuhFvKOBL+70ertaUeY=; b=aeD6MKvtsH8O4Dn8Z1Jr/WeqbcsFvx+dUkhlSYid+XOi6aQDYHZp1y0ifKSr0ULZE7 Vl+VFSQsAbMObeiT48KP8+IMleQZoAmwM8+VyXTtb1E21M5DwdGjkAJc8sISrqwU3ul5 SaZEu4d53YwT5jGKsFjRJPB4CHB9kCjy+FOQP9c16S269cUUYG/R6crrOLzzJVYSwS+g 0hwryTmCIEqncSt5PneMx7VE+skZJj7KVEkd3134npO6Z20HCTg6AIzhlgS1zcxHpunl 5QlP/DO1d+d9EnH90Z7KPxlp32gIvbVWGM6rz0rvVaGvdHJV9uE0N0+xDv/k7ok4D32E 06eg== X-Forwarded-Encrypted: i=1; AJvYcCVzFSqfDQNpbV2cht/lPe7NnroL9eu7dlNo237GpTgr+N9Mc4QsmjFEhOCizoHI9ycYobk2PgkJOvBzdDQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwXhjS9pKcCaznwhJnu8+RBG2sQ8l/L45Vib8MV4PNjvZBFCDGu AK1sNf6bGXJYoNCPwfEPv0gL7mpNGNf0OLd/A6a5xpNbKHKujqgs4TBGl9iuicsMB+ryJVK227p VIQKh+w== X-Google-Smtp-Source: AGHT+IHagm+13IWW2EE3LQN6Gh3ePoggnEOFKoBcoJfbPY7ELsZApNJgOj+3zTWFaULAb7Et6fdw9xd/KVPS X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8991:d3fd:38a7:c282]) (user=irogers job=sendgmr) by 2002:a25:a42a:0:b0:e2e:2b0f:19fc with SMTP id 3f1490d57ef6-e3087a6b354mr46270276.4.1730241880828; Tue, 29 Oct 2024 15:44:40 -0700 (PDT) Date: Tue, 29 Oct 2024 15:44:14 -0700 In-Reply-To: <20241029224431.167623-1-irogers@google.com> Message-Id: <20241029224431.167623-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: <20241029224431.167623-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v4 02/19] 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.163.g1226f6d8fa-goog From nobody Mon Nov 25 05:34:01 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 669D020B21E for ; Tue, 29 Oct 2024 22:44: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=1730241886; cv=none; b=Dc72AdzhlywWCTzAp1t189fuKuQarN049FWERAYNTt4cr28y/jXCR/yV9u2RqWAVgRv590iMatXW/rgU+toEQFfipPbUHw5DXbXYTRC4c3n6+FGS2gIngAD4KPopFXFX/OzUB6t7Bro5wsyreVjTmo8xiU3dxVkFzvDCnrbHceE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730241886; c=relaxed/simple; bh=GYxmpcXArXMONJWsRe5WPl7DZqsyI1iL6F7x/lVFYsI=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=AWXSsfMMY7wTnyOcJay6SyumnijLTRHdzB2spo1xnKvoZMkJGE8TGBOnzADJfUZzXb4No3EMtjqsHRIeBWZHoqITAmaerPElgF55oL4xndHxktAABx03587dpUOidZcpZddCKGkhLLXmYZbQLdvBlBhFJP9qywPNJStmUIPADtA= 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=kPBhBlF0; 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="kPBhBlF0" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e31d9c8efcso116497037b3.0 for ; Tue, 29 Oct 2024 15:44:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730241883; x=1730846683; 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=HNJdU7+o4d1QH5mPoNKTab3DA0/sS4GdEQIezl8TuMU=; b=kPBhBlF0DgUiCLowoYKdoq6OJJWUSE5CI2Nt+RoWQReK5+Rk7HVusHPJ/QJBU3M1i3 3y+2wtK60zr7UB/vIqtkPTev1eLYr1mXIdpYWZfrBNFEeHeJ8F67ES6h81S1rzAOTsbY rQ3gHzygOkVZWCZ/b0GWaKAUnkMQvMw94akup0GZiUBav4NX/8gk6OLxmOPQBry10moN dTXGfe7S27HT+aTpmgYLW7dVyV8fSg95ICdIzckz7JjsmR1z0xWhHRPJmSY1hUiOkMhx yTKUiyDPU4nGTn3Qzcm7YCk8s6svROwrf3N8xwqRV+7u+MDbvitscwErlZbk+Y4rF1hB DKmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730241883; x=1730846683; 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=HNJdU7+o4d1QH5mPoNKTab3DA0/sS4GdEQIezl8TuMU=; b=b0FJtqSkcjyhQyerVPTwzQrexicEWUzZs0q1FYopVlXHpKlSSRnRKGDu5z7jZ+gj9b wW9/YypUeisZ9QjEl2q1C48SRT/I3Namf7cl3YWE+acQeR5IESV25dexuZ3Quq744GYg PlHan1S9/JO+KuaZLFJ57m+0faDoRmjCEoCjKB1GJ1gsMA5V4kDFvOFH5LTFV6pO7hka mzTKtyTNkO/PDanMrd32D9o27O1Xd8X+vjh1r4mXGM7IbV2Mb4euGF70T4p6RVKRf9AI jAAF8T+fx9evp+VZjSSRRxweeEBVpnMcRgyaZfHNBIqF0cmO98Pb+ndHlJLhv0GjSq+s 2R4A== X-Forwarded-Encrypted: i=1; AJvYcCVvDldciasuwvL5PBBkSDHfNux58WEplKk1dSlBxrhm/YDIFZ0xtWXYuumxlwT3C9PRRaduqW3cP7oWJ5k=@vger.kernel.org X-Gm-Message-State: AOJu0YwHlYW71WFidj/HpqochjGWmHYd/CK1kwN9W2RIXis0Ib5XvzFL Xl1kqtO12s/wtJlMXoEKr/8aCr/vAS3TZl/DB18pYtZP1pWrEq0aPUN64H7lIKxqxqvMC2gDMdg y98MJQw== X-Google-Smtp-Source: AGHT+IHlAm3tLezbzVt8GbVuqDvnkCdiAAUbGwwokxk31Ep1SZRLobw2hi3jMVj1TyxSH6r16iitdVAfC4fJ X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8991:d3fd:38a7:c282]) (user=irogers job=sendgmr) by 2002:a05:690c:4c09:b0:6e7:e493:2db6 with SMTP id 00721157ae682-6ea3b951361mr508657b3.3.1730241883136; Tue, 29 Oct 2024 15:44:43 -0700 (PDT) Date: Tue, 29 Oct 2024 15:44:15 -0700 In-Reply-To: <20241029224431.167623-1-irogers@google.com> Message-Id: <20241029224431.167623-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: <20241029224431.167623-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v4 03/19] 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.163.g1226f6d8fa-goog From nobody Mon Nov 25 05:34:01 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 0055620C025 for ; Tue, 29 Oct 2024 22:44:46 +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=1730241889; cv=none; b=ZMV2dIb/TQcDQ/6m2SGclUz/kTaSowW7urTeJnwJFaryxOYbGoFL2wbAlMrWEpwVVStJRWkJOLXqyLGb03y+9LVdb1Yw/1VfEmbp5nGq5rSj05WjdNScMfhPuiKF1WbDu8BuVVCaZVzX6ssDEgAWzbOviGxjJNcguwjPMQ0E0dQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730241889; c=relaxed/simple; bh=bgAMnten7yUv77lry4kHbLHEtlNNVxnv2bZhCLDu2bk=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=RAFONoEEi0M5h8YdBrPomvdDoqy36BO9m6CripchI0wqQTN6aEY5rTdJOEUf/rZJUkCxqABqgnx7aHFDxEkWujLMKA3GKg1G1kBaEdx/QWuLZs4iZDJm+kAspQRNX5Qb5xDmUJW/BlnUVdLlJPAVcJz9aDIktOp32VnHbjboMQ0= 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=HGft9Nfd; 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="HGft9Nfd" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e291ac8dcf3so10425387276.3 for ; Tue, 29 Oct 2024 15:44:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730241886; x=1730846686; 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=Dn03tO6yjk+hHI/uxx4ev1BNOlrfTOa71VTpKPW70Iw=; b=HGft9Nfd98oTkw4ke7KdjOGf1sLw+WmzDf5miRr4m87aOHnpLqh/4u7td+cC+CvbmZ rT33+nMOMu85KXB/8N594wZnhSnWIuaVpP9GoWRjTeHYVFa6I9RXa1DBQLZNzIqdmfhd mKZdethPBF/flhPSFJB533G/ZPaLlxKZfsG22vKOll4TQOihStPl1ewa9waTALUXfps8 OhsIA7IZTM0CjbWfdKTqkB9alC1nIoWaMvQpsCaPWsMOqrQ6WZVELIMjXqMCAKfuDsbW rXTboAtoXzYQxxoWuDbB5jkmO8WW4apCi1SSX980la/PCSsxMFnq2TWJCsBD49K2l6Ki mNRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730241886; x=1730846686; 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=Dn03tO6yjk+hHI/uxx4ev1BNOlrfTOa71VTpKPW70Iw=; b=NF3sagp0QfPYCc1qqTQDkGXOt3wqU5F8R+UYun/JdSYG0llH4KxMfsLGkIxZCqgAsR Il6chdZM9HQrjwtV/VxLKyhAOpIWOSGpm56zDs9dtiK5nseBx2K4ukK9vT4GbXxJ8e3x 1KdH2n26rASC/V2Q8BaToIzkFTg/OC7EBaUAxWksLRjMNF04sWb07uWmEN61ql+M0oqk 6noWpRcxkFvbmhjm6pRjiDzw4naurI6qUoCGqFYWAmw6m4GFhI12xt5gmuK/+nurQV7Y 7W2wLaKttYOcrwhH2x/PakZbGr4VLoRoqLdwArEWGSWxPItsI/Qq8P3gXtjm2Ku8v+W0 u0pw== X-Forwarded-Encrypted: i=1; AJvYcCUTmqcCP4QshHCC4rJsHqC2QlbABJHfZk4icFgmJvdPWu8dZCXjjh9H5KRpyD8wcmC32MovZoMZIId5OSU=@vger.kernel.org X-Gm-Message-State: AOJu0YxEV6dkbfKlArnSu+DuY/9BYAkMdHIM/D9BclQNrxetng1cvtLv NcKvM6mDUqXl4mKECMnQqEmqAXZdgkPEq9zwFcyoQp0JIy4RM2lAJar+VbcrEbe8hVgVwgVmnyW gAKB3mw== X-Google-Smtp-Source: AGHT+IExA3JFVO57o5s1aC/oywbSW2IzrWYHiZ5NZUiXTsoJ3RexOTnxGKyv3IbKPCltwR6LNnBfyO+G729l X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8991:d3fd:38a7:c282]) (user=irogers job=sendgmr) by 2002:a25:d80e:0:b0:e2e:3328:7a00 with SMTP id 3f1490d57ef6-e3087a548eemr49327276.3.1730241885935; Tue, 29 Oct 2024 15:44:45 -0700 (PDT) Date: Tue, 29 Oct 2024 15:44:16 -0700 In-Reply-To: <20241029224431.167623-1-irogers@google.com> Message-Id: <20241029224431.167623-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: <20241029224431.167623-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v4 04/19] 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 8c5d5cecfba4..ff30fe466189 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.163.g1226f6d8fa-goog From nobody Mon Nov 25 05:34:01 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 0ADA820C464 for ; Tue, 29 Oct 2024 22:44:49 +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=1730241891; cv=none; b=I/feIcv7rbKx3DyAIk6iNu5cKqQXJsr5jM+rzN0zG5ORbTywWgkVQk40yExdygWIJ1NQLcIPBBoyqhwmRZqTbf4AwM/GNiBGFTw0WI1mRVgl5iuh3JoXU9J6hHBYm7+tWVV8ZcHXzyIlnzXLa6oj5AASocM4WtQCOu+5bEuWH40= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730241891; c=relaxed/simple; bh=aVce+4MfNDpZ0CbKS/Y3lxpj+YoiC94qhm+g5EWIpQE=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=q04xCYpYLpJTOURD2LvG5JofjKfAgaG60fVQXLOHQHJh8swr+SBNR1FCDVbfGGpPa1WfOQ1brW3w2MjuxmmwEBA06yoUbwL/j0qOMnDiQlxWhgsq29ngAUYTomyNfMfSfBnfxEyQL1rkpC7n1dTUYbIeKF1cqrVmR6xx+4gQGng= 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=UAfvi8Fb; 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="UAfvi8Fb" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e59dc7df64so5020997b3.1 for ; Tue, 29 Oct 2024 15:44:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730241888; x=1730846688; 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=PeOJZ1eHy/s5KnsoiJfHZk8rV3gYmSD8emrvfidGiQI=; b=UAfvi8FbNsNUqlOBn0/6PIaz7N94puNuFSKGr1rv6tZ7ACTpvlIlMP4Nzmf25BI17Q h09loR7O8VMNWWJ6FSps8xqQmHymfgM0lKWDlKAz8z1+0pLUkhBmtadygJrFz2tv3nqG zUMOg6pARr3D+WZrq4l4WEKLzvS3CpPe6r291jn48f8jHWkkoFE2EJ04TEBvLP6G5+4o cX4txgBOMxe+XuuiB5rLasTxD8N3urEZb4zmjJRd0Kvh+Y0LqB25RKUVzSwGoQeE47yH JZyKZyl89DOF/e9Vd/0r6aWaIUwICaB0tfG3YL7XnTz3tsnoy1KNkzZLJ7JWErvzqXIK 5FVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730241888; x=1730846688; 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=PeOJZ1eHy/s5KnsoiJfHZk8rV3gYmSD8emrvfidGiQI=; b=Q5d6BrQRg+0RclfxAcZVGuFyc2ECGGvD1uFECYOGqUEl3mKltF5Suap2Ql1Gdc3QpA 7sbVET/SSdQvLQ3mdwFNPYNVybp2+RpSUU3cDOcycEqnzRFDqehlg2gMvoggmFi6oP6Z K1p9wh9PbWSg2BvcjJkZRJ4xKBNEd4OORlUB0Kqck3jN2ikku5pJcxw9dlndAViDdRp9 TW9c1pfY5swd0VUjeRqjnV8OR+q+p79M9Yfs+8D3mreVnqh8VVXCe4l5rHQUMvXcy74X BiSev/t6ITq+PFufTkBCOVLDArd6YirwooEubkO+UMG/TdAF+TShubEjfH0uJqsGuWgW vCaA== X-Forwarded-Encrypted: i=1; AJvYcCW9jVjYO9Qz0DGpGlRPrWFdsrKqOa0l+D25ibxt1By/EcLyTOF0vf/2h4GhbkvJWWWjRWTOL1ePOBi+Tfc=@vger.kernel.org X-Gm-Message-State: AOJu0YxRXVVJfosDTpbg8jiiUQ860Raubz8ZMQeImi7E6m22YJgBmNHz /xunljvAvzQRfq8aMd+GADWtDb7dn3X939v+zBIAymYQlExi1qYuQlyyzjyeOPeNODF3TNpgOi6 xYUp/Pw== X-Google-Smtp-Source: AGHT+IGlvP8FFw7+T2DH8tL6rqXdLZ2mFDUr5Ad/ueP6ieFkuEIhAcsNxGqRKPPLXh698+xGdiTQxQ9GI5CA X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8991:d3fd:38a7:c282]) (user=irogers job=sendgmr) by 2002:a05:690c:61c5:b0:68e:8de6:617c with SMTP id 00721157ae682-6ea2c2539f2mr3326917b3.5.1730241888274; Tue, 29 Oct 2024 15:44:48 -0700 (PDT) Date: Tue, 29 Oct 2024 15:44:17 -0700 In-Reply-To: <20241029224431.167623-1-irogers@google.com> Message-Id: <20241029224431.167623-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: <20241029224431.167623-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v4 05/19] 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 099ce3ebf67c..e50cd04e3725 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 1eedead5f2f2..650974413849 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.163.g1226f6d8fa-goog From nobody Mon Nov 25 05:34:01 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 A41B020C47F for ; Tue, 29 Oct 2024 22:44:51 +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=1730241894; cv=none; b=hRJmE54Eu5NzD8WAUkopIJf2dgnwQeGg60yg2Pp75RCxGU0eV0tESf9vOuORRm9BNZW/PhWJUcqEcic5tijrKxTb0y3nNRg72kEpGmwTg7BBvYKl3GjvFNjOfMymN2qR6g/B+e11s9HG5d2yb0z3cW6yXTq0foRcKDzOI6JixFQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730241894; c=relaxed/simple; bh=eOhqswzbqiD/mQewQTcc7e297f5ySC3T7Rd4vlXk+CE=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=gEio1wzfikYrjU+77coDlYlHGpY9S3ucTnQ/J1+iNsaknMWDDBI5PnlEJKKTEkf/JIsyylDA5iVXtoGWSo2EwrboNWdrhmRSfMrspaZnNUq2qXLlKoJKW79IYvypw8OY57rtZI8SpDevQ5BlgYA33gF9Ibtf3bKIXeMweM0Zzw0= 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=GLTyWU8B; 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="GLTyWU8B" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e0082c1dd0so126342347b3.3 for ; Tue, 29 Oct 2024 15:44:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730241890; x=1730846690; 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=WZniLOY6zt4yEfnCphzbGvx8nNysYFG4WnDu6HN1+kY=; b=GLTyWU8B716c3oURrAOhJeTe4LumrTn9HyYwy8iRACodLETeCyl6olbDcjS6iBf1EV dcOg1HJMwrZ+nlOKc76uN07t1EOrSg9pCfQ+1DcVvDCy2lJ4Noz84AQkeB+atjKIRGJ6 lVs47SELFhy4wZYWSE7JUOyoqnENxUVjJpxZ6c5WUd6ckV4is5tYp9597jn9iurIZA5U ofmv84eajsV+RvygMKTCsmatdicgiv0cdTcEW31eE+lhb9QINQH5QM5kGjmuTDfYuh+/ LrzFI4u2rfxwdcP0AVXTRKicFt0JvuF2cwuvt9OGdVLTHexxvn1bwmsx6eCjx+9Z4HN+ taGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730241890; x=1730846690; 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=WZniLOY6zt4yEfnCphzbGvx8nNysYFG4WnDu6HN1+kY=; b=uSzAjnBO45jQiK82+vw1ro3l/gOoMAZPIdXayDbqo0X9YYz1YNL6pbjq5bU3HWAgXg nmkNY7qUbBhucfVqgfZiCCwLeaiqbTW6FS4i/8J4R1Zef6R+ORB50CQ2iwFA+FtxGSUT yLovHP5J+sK8FzNy14jm80KVKMhAzTkX4ch8T5XEEFWJL6D2hzIM5FyjYzghnxWYRtOA MEruor6ZAZpDjzPBSqcBAZMr2qJwRHhfk+D6QTVsnwB0+PgIMYuD/82b8H5ldjWSrWJm VLcutsrQah76splo8SOqwNUICcEMxNNfTLG+jwGTjeLbZwrPG3F6+WjHSjpvPdX+BAcP j9rw== X-Forwarded-Encrypted: i=1; AJvYcCW5I5uDob80XcLGeoCpOaRKGJ61PPRfPjrDWeDQEjviz943+BL0jDlPIUIsqpGjy33ph6Fc3/wNNcm1ogg=@vger.kernel.org X-Gm-Message-State: AOJu0YyGBj8yQJmCgUUTlJqQOzEAVn6OyT1jdf93nUIwddBS6m5QXL7t p35TCxLx3hZRvf4Em66zSPVEquVqkYM45QJ1UxuIjlmWxBGiXdQix7XRVmNqQynbCSCYP9eyDUC RYjdBzw== X-Google-Smtp-Source: AGHT+IEHDW2f3XuycHFjPJqpz19RLyv5WtfYT95xhi1ztu4O7jYG7CzQUp81DfTvzq7RGFvKwkZ/fH3xQdBn X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8991:d3fd:38a7:c282]) (user=irogers job=sendgmr) by 2002:a05:690c:288e:b0:6e2:4b3:ee22 with SMTP id 00721157ae682-6ea3b96d91emr238607b3.6.1730241890576; Tue, 29 Oct 2024 15:44:50 -0700 (PDT) Date: Tue, 29 Oct 2024 15:44:18 -0700 In-Reply-To: <20241029224431.167623-1-irogers@google.com> Message-Id: <20241029224431.167623-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: <20241029224431.167623-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v4 06/19] 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/path.c | 10 ++ tools/perf/util/path.h | 1 + tools/perf/util/python.c | 6 -- 6 files changed, 186 insertions(+), 152 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index ff30fe466189..bbcba999c46a 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/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 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.163.g1226f6d8fa-goog From nobody Mon Nov 25 05:34:01 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 E438C20C492 for ; Tue, 29 Oct 2024 22:44:53 +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=1730241896; cv=none; b=ERdY9yqZiW7K3N3W1GIOeFTRWy1cy0Z8lSl6SxX1xEMMAjPzboeZ//i9UW/X+2jmEKYKpwfcEpA9XOUKy6B8uI67/EefBboAbvSQEzA2PVbpTvLPjDhGVDuPamOnlnM+PJ0azvrPd9FUxUWpp4W5Tj7i/7bU48h2F9XoG2kSIYE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730241896; c=relaxed/simple; bh=XaOvMMky+W4tQZ0auY5DPd3c5z1zzV7JnI//OOBTH+A=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=kAp/sKZq5jQPpPsBlxWjm+U6bMUyb4Rlaluov0ePaA0OsN0dMUfzbZsBu97tntsF1DBPhx9ytP4PGHQO5vMIPLi5avvVyA1p6BGTphdKhfcuqubGgWhN2nPeAQy8iJq1FQPBn8IOLS6Mwxa9PHaLAw1Kt74i7z8oJ8SgJOKm6P0= 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=lv+gb6xu; 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="lv+gb6xu" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e291ac8dcf3so10425527276.3 for ; Tue, 29 Oct 2024 15:44:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730241893; x=1730846693; 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=gKw0V2lpE5vC7td6dRkvoyg5c/z2+Yaq5BpAB3ZHY5g=; b=lv+gb6xuJVe5qN95a9I6Lh6UayZGbDgRJHGh/NIw6fe59hz3Vb0/kyqu09jV5FPADK 6UytlImTF7MvyhxnH3zzn21VXC2mUOgdQyWRpEnrImCA+hYQTGT1D2wYm0JX1OVdST+8 UaCcR4DkjD42/dxoNGPcPAVlaEnqxr/gqu4C8ay60/JRi3VRWLzQfx9VBlbBOEPaKxZM f3TkGNw8+MH/5kVHr278sXqjzLFVvj/x4jD5FJ+RD2zKd97EXxxIKvaZBcZiiZwz0DpJ p4hKT/eeMLgvLWk56dYhCc1Eyc8+beuMaQC9rf7xXxZoj8YLJElH8LS/Qoix13CzzRvk a/sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730241893; x=1730846693; 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=gKw0V2lpE5vC7td6dRkvoyg5c/z2+Yaq5BpAB3ZHY5g=; b=W4FwRd3zTwsi9x+q+5jbPi4r+CBrnFy1kTfOlaEGd9GTITDg8O7+bDbcbWc5zW5r1W FgwjMhE5E/JRtZb/rCLRznc4HKqFo/XWmu4t2OMY1+HI1l7TXwGXEsHmkbu5RFEqkEza M2D/sWituV7pTHGZLHrda+Lt0FHO+uuxkFX+ORVCkyiJM9vIfF2QaC5T2dYpopF8PUNb DArDKx2pRpsJPVveUAB4uuLsKVD0/+Qprw4IuRTf6lcP/zPFBqOnx/HzMfAg6qcTfb90 SedeEAg+j1xX3A+xabl3X+FPtl7KDRjZwoO4hi5lADbbjjbb60jE87J98Hiax4EbEy1Q V85Q== X-Forwarded-Encrypted: i=1; AJvYcCWOsfF9XDJ3m0pi4s+zUMmH0eTyh2TItEtvuKQIE2I8aniXoG9L8+B/iRPUckNQC8N6R1Gy7MLm9J/qi+E=@vger.kernel.org X-Gm-Message-State: AOJu0Ywv3EVG7gqSo5zyjaE3c+gQbxDGGUKYlgaHxQPSegDJFUru0jZK w6yPYKexiHB1RHffDEWSIrN69ihmQfdEKHlKPcYbkBEjHYxYcJ4oENqOhcqxXsmfehg04gYyQMv z4WZqlw== X-Google-Smtp-Source: AGHT+IEcwtNsOiDHD85HS5e0/+Kx3IkR/Sef/a1FOLmC0RogqOt7ZrxzXiE1LT70id2av5f4+J6LdD9J/F3U X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8991:d3fd:38a7:c282]) (user=irogers job=sendgmr) by 2002:a25:d648:0:b0:e24:a00a:518e with SMTP id 3f1490d57ef6-e3087be931bmr46073276.7.1730241893012; Tue, 29 Oct 2024 15:44:53 -0700 (PDT) Date: Tue, 29 Oct 2024 15:44:19 -0700 In-Reply-To: <20241029224431.167623-1-irogers@google.com> Message-Id: <20241029224431.167623-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: <20241029224431.167623-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v4 07/19] 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/python.c | 9 --------- tools/perf/util/stat.h | 3 ++- 6 files changed, 38 insertions(+), 45 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index bbcba999c46a..8a510d6412cc 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 c12158d99353..a1625443e5a5 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; @@ -1071,16 +1054,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/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 6f8cff3cd39a..2fda9acd7374 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.163.g1226f6d8fa-goog From nobody Mon Nov 25 05:34:01 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 1434520CCC9 for ; Tue, 29 Oct 2024 22:44:56 +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=1730241898; cv=none; b=YTDsd6ZgV80SDK+cigkP/0daocYQJ3P40AEk8toHeLogFV1OPJdecVpAuOSbUY4AOFw3hl/B0iGzlAdwGoqLRKSR1NKOcRsFyAaQ8q2O9XkonoD1s+3v52uk8hZVHu811JLknZ0qbrh7Z0kqcAgbgvzpGt8VVFXPcIeb8UiFo2I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730241898; c=relaxed/simple; bh=7MX0JfCi6kfdsDcBX+OpEjk+nsi28Hr9lMOG3fkqXVQ=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Tly5LC7q7v814VQNtP/8fCDboGgB8UKIxMybmYhvZ2/rurLTKPCqrd2N4YD13Wc1dkf0k+YoyunIbgkcwdVmJwWypSmTutqAR76kjHPeBodS7QN7kVAhjn4UyA66sQ2Pzaoj/kBj/ZW8K1yMzhd1PCr6TF7pQ+E7BdO8TghaOFw= 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=Sfz5yGbm; 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="Sfz5yGbm" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e7e7568ed3so5233257b3.1 for ; Tue, 29 Oct 2024 15:44:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730241895; x=1730846695; 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=eC8ob0xZGEdP+WjhTSNLt8FUry/vYoIKckpm7VVq6as=; b=Sfz5yGbmHY3L/tcLfkQIdX4NKZOJkIPTurccgMpREx1CDl5BCzU9FkrqIFfZUBYEcI U50bwTwYOoPn56e0v4/8XISoz2D3pSf9hTYPW2F3sGXk7kvHvGIqplMYVCTljf+oWnXl qgXwMc2YOz2CfNfXYFS9e2V0+t7V6iYYNFiKUN9mLa81JkZujV2SrB8FiDCIT7PhUcYC aVk2kTjLsK9jESHIJgB6z8hCD3LhEHqdCtxH/Yy7JCWdFAbYDOck/A5K6MYcxiBFnJBu 3GYX65DhCWL88DVQLHzWYqPR8dqubHXKGPjmI53+pJheDZkRz/yCvg5RMS6fTUIvMkOt AFKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730241895; x=1730846695; 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=eC8ob0xZGEdP+WjhTSNLt8FUry/vYoIKckpm7VVq6as=; b=ggP96CXJ9xz/5kRqZBIP3rFJzXYDMqDCTmHHOsmKWlToVar8RtPJwbf6MspLkVYTwf fnhufBj+m1euDJ1mj4rhbUJ04Hqmdfp2O52u/e9ffF+68g+9FQAK1eftQ1+8GiEaLdGl Rdmn5d6Wco65F7vDf23+qbEh07Xm71KqlF28yE0OrIXkRUycArrxZvKTIAD52WKCX/qv CReM/6Ovkmg/SY2FSXnHID/CjbhBo/p8IufNbuniXzjB7yDijsV3IcK52CWx9kVQaAw2 vaRCmprZLho/TY9TmP8QNGKfmlR4qRUvU6Z2ej/6fDp7K+ZOHKcKCKwolNZlVflyxx+H KHkQ== X-Forwarded-Encrypted: i=1; AJvYcCUU2H2xAM0wG6fq1my5FGVbDYQWwXn462I/iR95aWaQiytq2KPqQLa3FnZSjpOPW1CMyl96kSECCF7NJrk=@vger.kernel.org X-Gm-Message-State: AOJu0YwW+NzFseUUYUCUWm1iPeFW38NU0bVz3J51OL9zqCJK5l32gwFa 3Ibv8PTqp42WfNN6QDsEHE5n54ChZN8/pj5zAv8HbUqLuQe2QbWy8Shk1QZrU5kHv+QtOn1xYI6 Uu19bkg== X-Google-Smtp-Source: AGHT+IFpsK01+CwlbsFoYmQf+BqpjL/htaA+QQZ0SejRORHhBq9z5qQVYVUTr58AHUH++K8/tQNk2lIakI7f X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8991:d3fd:38a7:c282]) (user=irogers job=sendgmr) by 2002:a25:c50e:0:b0:e30:d5cf:775a with SMTP id 3f1490d57ef6-e30d5cf7861mr1003276.6.1730241895245; Tue, 29 Oct 2024 15:44:55 -0700 (PDT) Date: Tue, 29 Oct 2024 15:44:20 -0700 In-Reply-To: <20241029224431.167623-1-irogers@google.com> Message-Id: <20241029224431.167623-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: <20241029224431.167623-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v4 08/19] 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 8a510d6412cc..93caaad62be5 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.163.g1226f6d8fa-goog From nobody Mon Nov 25 05:34:01 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 67B7820CCDD for ; Tue, 29 Oct 2024 22:44:58 +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=1730241900; cv=none; b=rcTUXAHJC7yi2qlquL12qNoWS6Bepbhl3X/m5PYsYWVwml7cG4+ufMskvR63QDSFnD3ra/lmUKO9PH2MrIHnoDQILqpQ9T5hyZyDr3KA8r4cw1afVHWet8Pdgj7+MzHFIefo0WI1WicZbaW5INOwnWloNIdoSnU0OOiOjzEE7wo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730241900; c=relaxed/simple; bh=aO36UEaQorN0wJLMM37nAL3q1wmtiUXsxaeDEmj3NUw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=X9ycdbgxWDjROcCg2jsOkvDyHLp1lJ2MJquyXConcW09vOa0eRWykKfFvmLDvLRnIWK+KNQd44shtK9I0Uw2lZkU+IppLkpb987iWsEzY0Plh4fKQ1BWZhGsZcEDBvs3jXIXk5SHKnjtqHn6mv4iTwGCi60Z9GF+FAOXSQAGzKY= 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=O2a3Dhgh; 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="O2a3Dhgh" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e2946a143efso563301276.1 for ; Tue, 29 Oct 2024 15:44:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730241897; x=1730846697; 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=FvsfdXmE5fY3ABkdgbstYkDwSen4YCtrrcTKLwjDguU=; b=O2a3DhghehHUDvLgsOoqrIorjzgMkSp4ffMRxTJ2nbmXLBDODzOQUKRC1Qg9QP+8f9 Fakiu/rvL5Ko3OEt8mGon1plQp0yrvcdMdYz0AkY/xlXIrDnCJwyt+s5lkynNj0r3iFu 5t1IjguoiPN1EbREuM2gamIBFuT5PChKmmexuOId+kgt/0JkhyZRdun9IrjwC4Xn5J2K 6RboSO9yakumnl14Fylbp3fkjhJ7FjBmCkSlK6p73Tcubb2G5rOv3Ih2NkN0wZz/78tL Dcz10glCT5jOcPAfLjnGgLYFQxJ1eXOkn1JuAOKkk+wJGQbFrrzt9LqUSbkgIhf2Xr9Y NSCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730241897; x=1730846697; 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=FvsfdXmE5fY3ABkdgbstYkDwSen4YCtrrcTKLwjDguU=; b=VpmIY/DQ6liQrMsZzc0emWSF3bOEvGO5+RrE0LmVoHUmJBO3crfNfnoeaw9vmcoy6R +ucu00q0Ei5BeuvuiWqF4lRsELly3VuP14AtNUDNt9zMWak40d17vJARiSGElNfIPjU0 tQW7yPtpGG5p26VmY/OU3nispsFFaPF8ZRnwyF2Ee9WWcXYYvgnkyVkpLBnhDX3X9ryY 9mdiGaJm++fGox0+ClYWYXo8LDYfkxSASXrILF4snKO8PJL99NrrkHtIS1oqNPIv1U0R +n9Vd5EGMmpcwV+Rc8qi5CQEP7b6hDBJFzMolWunQCI45NSYbsgYDk9nva0DlZB9/0zW zaUA== X-Forwarded-Encrypted: i=1; AJvYcCVSz+tBFy+VB1jSLYlLNmgUtAKImi7c82HE2bgTSSpN1rTIvMUE2svHqRN6UwhKJ2cTENNSLIkVqiLFjd8=@vger.kernel.org X-Gm-Message-State: AOJu0Yw9vzy1qDZGqVtRQqyhiezp8FHUewdMPtMpSzEPXKlyaOEud10q y+Zt3GwNa880NSZljGWZqfM5/7axDKm5fjo/hxEUNKfNu5iw4KS4JTiwosOJtR1M7f0El3OTVs7 3Jms+Jw== X-Google-Smtp-Source: AGHT+IGstHnLW42vEOqpPUHHb62KZ5zvU+TpLx+NqShj3UN3ugCJjQb7yQN51h7FfvP1Wb6/qwNtUOAB8GF8 X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8991:d3fd:38a7:c282]) (user=irogers job=sendgmr) by 2002:a25:8241:0:b0:e2b:db24:905e with SMTP id 3f1490d57ef6-e30c1a27054mr33196276.5.1730241897313; Tue, 29 Oct 2024 15:44:57 -0700 (PDT) Date: Tue, 29 Oct 2024 15:44:21 -0700 In-Reply-To: <20241029224431.167623-1-irogers@google.com> Message-Id: <20241029224431.167623-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: <20241029224431.167623-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v4 09/19] 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 93caaad62be5..3311104afd0a 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.163.g1226f6d8fa-goog From nobody Mon Nov 25 05:34:01 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 CEAFF20D4FC for ; Tue, 29 Oct 2024 22:45:00 +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=1730241903; cv=none; b=QhIQG2IK7rL8rXUXoXAxUEYzjSVrpgqRptRSb1noS5iS7zfy0eBkbyVXnIpWPkzuQmwDI7KiCnNTaP3Lbj4w1Gj0XPatiJNLAyTQmzGhEUWHe0NN3M8ZSG6mj5Rqh4puK4AMslTGRIf26QfcJqFZ6igXk7mYzqwDWK5TEAGSa08= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730241903; c=relaxed/simple; bh=2RLqSBB/TH3eqXmo+uvGIzA+Ahy1X4l+jKCnNyaVyG0=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=oyOdQ5JCSK6iiytGCIcfrHFpM6e4MM1sQYnUb0+iVOj1KnXe4YNyoCb7X36G+J7f7Rt8zHwiHMJxZk3Sx+kkJb9YGysQAZ3A0vYmC48S4JyoxLRe4nFcp10AY1aWd1/zU5zDSL0TKwVxDZ3q5w8ynf/kuG5l6+Wl7ssFabJey4k= 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=qGm0XGpX; 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="qGm0XGpX" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e5bdb9244eso100030307b3.2 for ; Tue, 29 Oct 2024 15:45:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730241900; x=1730846700; 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=YFooUYpvA2QCgKuBD+acIjpV9rrKINB0QYlfb7ETy8k=; b=qGm0XGpXxx1ndJAnoMYD42M4xEKYKHRctuOOQezjJ/hz9vxdxPDC0uejnDlHGE/GpQ 2reQbYzZkL/mkAgChT5X22tA7wGt6byKvmlRP9Q3OhZy2TKAEHm/vuS3WAL3d2TBUUjO GoJZhSj9DVcY4DUE6MZyvST0z/KWAiOfF4mGFE5tkDIt3ACqtOVNEPccSNpy8voHzPbF 6ORybBJuxLk17V3odMlCl1WeOis04rALBfwoxGDSbRyMgZrsPDkwGOUF1WQ6KhrQQ0vR mEdQT/Ow5xXrCUvJFX7xYF2waa4JkHN6lBorEEbiuhGxEXdsD3tGKdIHV8toJzVI4lQ9 KPCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730241900; x=1730846700; 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=YFooUYpvA2QCgKuBD+acIjpV9rrKINB0QYlfb7ETy8k=; b=eabvfOFojzrbCuKofpOQd8WnQrDkIDaGD2DbgKeC0syzQlbcsR/ln8YLiTpWEu1glv L4Dhak9Ss/c/LKMdUehN2c4VQ2f6lPLWVBscMLTvg7uUvxPDrGOI5aXEYvI/0/0O8gvu E9XzQ6ZSHTQHZ4ANKkRHulRtwdiIqWyAcehrqXB9Uc4epTQ06VZScp9/ifTqMs/bk6nM m/YIJQwqm0eKFrGtlhyVNr2jAxw30pEgA/EQO9SByIi7COqd2Du28aIN4wG/IUID4LiU 83OHf+fV/R4byrb4kv2MiDU04lM616I5gLJoBma+FQWWpuXpz1DgW1TwbCcXUQzXpQsr TtRg== X-Forwarded-Encrypted: i=1; AJvYcCXck9ERcbo9XhVX7A1zgdS6k39VACIBx437uITRCzedSXDwlf3hFQRigx00mWTPHEgohTkCjz7BUYMXEu8=@vger.kernel.org X-Gm-Message-State: AOJu0YxwSNRQQwGeB6PxyqVmpQMo2YOM0kNDh+w2QckC3gRYzR4/pGJX h8dQdiz1amCf4uf40HOhfutUoNR/D3PRjH8xfKhdEI43IEXDyKrmihwSnZt/IokPcpooPxOlKQn qHuun2w== X-Google-Smtp-Source: AGHT+IHsda3l+iVF5g+/UtdYvrqebD+bSxw3aG7nkMqoFu1dOTOBjYF7ur1twgDhzThChjiw9T8T+2Jya7DT X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8991:d3fd:38a7:c282]) (user=irogers job=sendgmr) by 2002:a05:690c:4b0d:b0:64a:e220:bfb5 with SMTP id 00721157ae682-6e9d88ad9a3mr7734307b3.1.1730241899913; Tue, 29 Oct 2024 15:44:59 -0700 (PDT) Date: Tue, 29 Oct 2024 15:44:22 -0700 In-Reply-To: <20241029224431.167623-1-irogers@google.com> Message-Id: <20241029224431.167623-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: <20241029224431.167623-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v4 10/19] 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 3311104afd0a..1eda065dcb2b 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.163.g1226f6d8fa-goog From nobody Mon Nov 25 05:34:01 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 83D5720E020 for ; Tue, 29 Oct 2024 22:45: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=1730241906; cv=none; b=myM1z5Q+i7g3KJH0cfjy3zXarmt0i+CWtj35b5AVp2rh1ZIC+T4cpy3F91JIcmBIJF3MGmso4aLbSJ7VspOaQR7dS2ZPVBD1PnZvE8Qs3xvRMx06MibrmPJvL5XHHVeviNRs0QRspS2p/75TR1ce4mzrC8HBSXDkCI5snqPYJEY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730241906; c=relaxed/simple; bh=fwmYWdU7N7URJAGtQhLxs2/TrwKA2MxnPVgK6daSthY=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Rk2llIHSTL8VG7qFKDFTiLujaO/f//ws1aYZ670GpKkJxpCq8k/V7DUXHgnda6vJ+j59MU7Vkk9J7yH7topR73uZeGbR7t3uvh2UAkLv/qAMaWEWH3RJ1KbqmRCPTNKaAGnwbs6eSweK32LMDeptivZAbLusx411iJGO0b7+nqU= 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=ndsBI4q3; 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="ndsBI4q3" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e9d6636498so85657817b3.2 for ; Tue, 29 Oct 2024 15:45:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730241902; x=1730846702; 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=ObTCP+/V1RG4e6j09kWPCLIxYn8jcx1wj19Z/KXwVRo=; b=ndsBI4q3o6Fs7hz81cR+tWq8oM9ynL3uNBUqSOSrdNkgWRS1vPna6Qpkt4aqWc+PWb 9gaBCWm04lzj8k842oh3+NPaY0DQAMUBk5u6tkGgXbGAlQJDnP+shntKjUaY2CjxGEC5 DedrJIEAkjBvOf+9qvg5hhsDRl13VKlhgaZ7eN7yvQ2uuYqBs4BAfghi0dgB5CkfYSv+ V7upKhFJzrM3lF2IvVb5fae+RQOR4AJZ04sV1hBIKLhMfx0xCYsMJ+UTh9g14DouNkif z5B2YEIcw06pjQFHJ80yJONdGb5pP57quGlm3/ln/GJY+DYit5uNWDTGJ0QX/R5ft6St ppqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730241902; x=1730846702; 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=ObTCP+/V1RG4e6j09kWPCLIxYn8jcx1wj19Z/KXwVRo=; b=lb6S8VbxAlI5UYWFvlk1YosVi7H3EDpyk7qVrnAWd+e2WdhZfJetWyse59KD9Ogjua JRtNtVeoGGtsoMFoSJlKf+rEUcwb2AN0AkOnQECVUe5De35HdNIMgMY6YW1LEfQdhZWd TaYTNi1Ak0zsVsqn52+XTjh/WLcnAF28FtG2Zc3mi7RpX9GYFhJ2drHrRre3UPZ1n9cv N5dk3V03wIfVxjEqIE3o6pGPQCGkVDey405JY2d4BlX8ZBjGmDSxEqrJQ8ueRnpEr07i 2RxihUjHNjbKQLndmwwANCgDdDtQG9QkM/9R9YJxmHpgwpKoJhacBF4GRgiJM3JCAFhL Axog== X-Forwarded-Encrypted: i=1; AJvYcCWz+jXP9R0A5MUZ6i6MkcNniXqNYCywh+ZynpCgOi3ihx8K52oK/jkgZqG/AEOXMiat0pTu9hxeYmuyXk8=@vger.kernel.org X-Gm-Message-State: AOJu0YzsGNX7AawdT54ij1gBv+irdMbiEuRCoS2bOz+tZw3DgrYinLIB 3cF3UNzRW4QR6PlACHoCG0NvyR5zvxFB0PEXsnScaMktPuS/tKpL+HJwSaDJwPY2MSx1DhvXSZ/ U0JCgoQ== X-Google-Smtp-Source: AGHT+IHOi4rYCRTPSIBfrSYRS9C66jwrDwv7mNQnq1I9ksD1zgayYtaGJpbrPAO3NxXtBeNYrXhD/TUf77Jh X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8991:d3fd:38a7:c282]) (user=irogers job=sendgmr) by 2002:a25:eb0d:0:b0:e28:e97f:5394 with SMTP id 3f1490d57ef6-e3087a55327mr8751276.4.1730241902419; Tue, 29 Oct 2024 15:45:02 -0700 (PDT) Date: Tue, 29 Oct 2024 15:44:23 -0700 In-Reply-To: <20241029224431.167623-1-irogers@google.com> Message-Id: <20241029224431.167623-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: <20241029224431.167623-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v4 11/19] 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 748b061f8678..5d0345480140 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 ccb464026642..b3fc7d32cc1b 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -23,6 +23,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 ae604c4edbb7..e9db89395dab 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.163.g1226f6d8fa-goog From nobody Mon Nov 25 05:34:01 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 2A37120E03E for ; Tue, 29 Oct 2024 22:45:05 +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=1730241909; cv=none; b=N3DD5n0t4VI+vB9xJUILjKTQ2GUNH3tnhVJ9aHYbb3Z+b81VRZwT09mIt+DoWpwwcUN+Raq+9itjLYMLdm53WyLTTFa4d0cKi51ZepC8WvUAAxNzO+8TuKxtXX0yAEJsHlXzO+GCOMQLhCJOCV6QazYge8lWYmsiR3gXhQ2oRQw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730241909; c=relaxed/simple; bh=VDsV7b3OX/emG3gjapt2R1JtoaiE0+25N7pa2k/w/TA=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=gXw4s1bkm+2lYedfQuHWGvsUJE/GuBZJ9ENf046BOw9zR/ckTYaXJ9gmEmAILoPry1Si0Nxqhi59OdLt69lxLX5kJb38glDno1FGeBEE7fbLYtptZdbi5O30eB7TY/tFEcSjMn3wCDnXOJQpFWi8lPtYMQh4gQ7Wdg3MzCX/Cag= 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=GM6qnQyW; 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="GM6qnQyW" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e38562155bso88018197b3.1 for ; Tue, 29 Oct 2024 15:45:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730241905; x=1730846705; 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=bq7Yn07vcD3vGYwxT4kETwlahqFzcX5Rgl53aad5ETM=; b=GM6qnQyWvhQ6jsh6irPkfvcKDBOFAgD+c0uLrxoZl8KOUqM12Nz5kpimv6BMSaJgjb PX5PHV58yUqRoQRjhAyaiHHLEW0JvH0Me8cm4JfGl/iej0fPxLygC9FxJxnBnPMWv5ES foQL9tS8xyjNgiC73rh1o2SeUprNAdGKPzQFSfT9bFSsOkTs/0q76o/yiuqqU/X4QyLp JU3HrF9KPtlx60jsic4xOBim3Nly+uLahPxIkoQPACMeKVZDp5LD70BZk5qUemucjGI7 D7QHDF4DB2KmYQIqNldsTmQl5irgmThF8eJAMYMXyFPl9wFxiFE3kbSNhGU1jOuSQ0Kk hedQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730241905; x=1730846705; 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=bq7Yn07vcD3vGYwxT4kETwlahqFzcX5Rgl53aad5ETM=; b=bvLUxb/Nb5mFi5gXkZEHqqTD6QLXFrjlXBODgJdxmXQ/xjRbC0KnUnaoObgNxxA0JK PyRDTjtapAmW1aQtKnS4+yIwEDXYLcoBHUTNFXLtBXF760R7kR+QYDDVzHer9aOBnwMK Sy2ivF3nXxa5kh+3mS/kC0b66FR0vBcxnk7PLMaCaa4ydMRjy0FSDISqkbxq/ik1r9pV A0FE9m8MctQW0KGj62LYfTomjH4HLFs9ZWEMDlSGEklCscCHKc81YldX7GMQbBgwJpoW /wMhpOinQDpULoYt+OxV3aEOiQhNk+BDUfA+lBjRw0+cW33iwg219FQyRDa0dXaAQ9yx nNiQ== X-Forwarded-Encrypted: i=1; AJvYcCWda2f85fhuN7l65ZZMy4I9bOQLZnhRXdBg75OjROcjXVtLmvtgbXszku10gLl9uPt5ySeE91Yd6Y6/BUU=@vger.kernel.org X-Gm-Message-State: AOJu0YzC2KeGAGmFWbvFtO7DuTZRcsU6pbLvv1z8NvNfOjYKk56o/X9H SoxRTk4CXowTycglIVWo3ThLVkuCZoOA8YhoCgqRREZHYUAo7HeSdn9o7IIB4mYQ8jwVxBOW51B rBn0YSQ== X-Google-Smtp-Source: AGHT+IHOuhal+mAGelAxUnrI8QP+h//1b0G8Ky0o5eO4R/EMlbmG9cgGa1znQd0Et9hMZhFTYOtvQwYOX4aj X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8991:d3fd:38a7:c282]) (user=irogers job=sendgmr) by 2002:a05:690c:4a02:b0:6e3:b08:92c7 with SMTP id 00721157ae682-6e9d87070a8mr8170337b3.0.1730241905103; Tue, 29 Oct 2024 15:45:05 -0700 (PDT) Date: Tue, 29 Oct 2024 15:44:24 -0700 In-Reply-To: <20241029224431.167623-1-irogers@google.com> Message-Id: <20241029224431.167623-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: <20241029224431.167623-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v4 12/19] 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 650974413849..e6404d2c598b 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.163.g1226f6d8fa-goog From nobody Mon Nov 25 05:34:01 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 92191209693 for ; Tue, 29 Oct 2024 22:45:08 +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=1730241910; cv=none; b=srgF4QwNg+DAtxyyaADkRBqpM3Qf+2fl+xfoksW9zWGDXfe4fvKkpWOtVHoNyHjQp8A2cRwjC9fGeTTOk0Wtp+DhxERiQ3OnVhdQdXJcHLJc0uqMaBmbreMKNrVrDqSBqqmYQPVmPp1QvThrYTFoyubL/VrWKHxMwMAnI99ZtFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730241910; c=relaxed/simple; bh=wvbasbr/bHT6byIIBcUUP6y+LhSLf7VNj3pt+3TFKi0=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=ZRywEIV41hjvA++tRTslKVag0M03sPpWJRCcaEAKiU/v9AQvBBumNlc9t5rZzxSj7/nmkIU6CrgrC8rzCJMvBzq2sDVHChlJ0CwDloi5Kri6yag+qfbfIkmHUjkcwiMdXPHX5U3VqRcwsTwpvvCRLWFstydael9Vvsq+x70YVBA= 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=4mnQLxbQ; 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="4mnQLxbQ" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e31d9c8efcso116507247b3.0 for ; Tue, 29 Oct 2024 15:45:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730241907; x=1730846707; 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=R2ba9KAPKd1ye/yPm45C2inPyTurG9rFVVaZ7EYtd/Q=; b=4mnQLxbQZbhxhBKiC24HNvUNtSz2MVdvmR3TpuUnXEfdT1xzdnxJQrqS0gNJOfJpC2 Jg9oxULsxpXMgGJIpJsTDWD49WynXlUAOH1yodpRw8GaCt9flB0qbomdYYUrMbYv6Wmo mSzmMOKFknqK7cRlJCDqu+mgvEHJCSa33qGYJOoQKfmWTOOkASHcjVXBwjaDeD83ixyJ 6bwQ1fFPqtl3voPgaRKgFOZ2xA4CxBCIpg+Xfi5g6BpzKGeaObFfJiVmWzAGwG1PXLI7 trWnK6rFhuQQa1iVTEHBYboYxTiQUE2fHZSOz9mYrTq/EMNTZrTx7HGv43NAFBklg60d RL3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730241907; x=1730846707; 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=R2ba9KAPKd1ye/yPm45C2inPyTurG9rFVVaZ7EYtd/Q=; b=cUpyWQmVkS7Lu1uKLiun0k71DEZLPj33njSGnjiSZb98wU+LBsPBFWie6Q0QeJExAX oNqq3ENFR2/ptYIvFgpMyxy3DHgZhTrvL+cOdtW5BwOsCKGxEUj+QmbIVV1dt21sih2A DBNnOe7zzL5xmdDKyKUPnDSx6y1c62RG3YDWIMzbvvg6VOWp/eUnpZOtD9Orz1ynX+2d 9zt9CeoyaF41saf/u+c+ZAPfU2Tz/cy4oJlGCqO3ZncYhDFNsk+uzEG9x83cbdxb4rOo eMGXHivuzGn7hYb2qML98PTvzxlz9vCCU2/0e8/jSJMP2pkeXkroFX+q/lIKi2lYhPBu 7D3g== X-Forwarded-Encrypted: i=1; AJvYcCV/QSHtCvU2B6t+L2TxwVHmniSC0iRRCVQmZJ9kUSuX07ttQSCd8ZlTKYUWF5xkEhTslBSDcHzUhfhVLAQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwbSGDPX139DcnuFNVF3k5o5X+aXQhJBkTdbtAMA3Co+yS/Rdtf e9FdtrEnxJGaxQ8Tt7IE4tOyN8lZ9WYZDkXkX7T5cdoPf3kJNrNnqF7m42UqbH66uI53JyhkHkm oFvmjRQ== X-Google-Smtp-Source: AGHT+IHMg4oEBPGAdsa5I6NDoxgxKClXhHgelcHadpQwzimB+n9qtTEd1pVdcb9I7LFH7agKESsocE1qb8cx X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8991:d3fd:38a7:c282]) (user=irogers job=sendgmr) by 2002:a05:690c:3381:b0:648:fc8a:cd23 with SMTP id 00721157ae682-6ea3b88cefbmr748647b3.2.1730241907384; Tue, 29 Oct 2024 15:45:07 -0700 (PDT) Date: Tue, 29 Oct 2024 15:44:25 -0700 In-Reply-To: <20241029224431.167623-1-irogers@google.com> Message-Id: <20241029224431.167623-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: <20241029224431.167623-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v4 13/19] 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 b4dee7c20ed1..ef1b39b5042d 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.163.g1226f6d8fa-goog From nobody Mon Nov 25 05:34:01 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 B8B5E20BB49 for ; Tue, 29 Oct 2024 22:45:10 +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=1730241913; cv=none; b=DBbMgj3l+X4rmzI0BQ5hy4vSundHqGudG5RSMbUM1mKvqMwJgsgrLsvzZ+HD2iygzERekUhWnlavgWiwEOQ78YRNpLv3nwb+4rnrSRRUqdhDU3Wq7hfVXttbrWWioRQ+AisaERcgblmICW4PCKl+JEVGXVSLHJIMwEZ6J9IBOfQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730241913; c=relaxed/simple; bh=lW07OjyjtiP7BSeHvWrJwzhwe6xJuxZ4Ci6QSD1wU8E=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=cf1x7/f7vIEXTxEaEhSFp4vEOXQWo4kJlxs8fP+bJtwed4zCJRaPXi75ysJJSVNZQsOUz1avhvQaXEiFcV+SEpzjOac6//X9EBLW8YZKOrNt+mnYvt8ConxkQjFrIqLtdFLyUXOL60NZtZcKD1q+0Fxau7iwo3pvblVanX72vUI= 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=xglZCLe9; 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="xglZCLe9" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6ea33140094so20088377b3.1 for ; Tue, 29 Oct 2024 15:45:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730241910; x=1730846710; 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=t8Sn8jdbA+NjEGCeG6Gm1wYYNvd28v2iQntXlq3XUm8=; b=xglZCLe902GPEY1YcFGswTibeH3MMl5tzJYPe0OS37yEQNOJvtdqMaaZp/ROW9p8Km oQkm5GVTsg+8Ui9XpIqphToyMuJKaqHO38wn8SVxDwrb6OrjmSAJPv3YP5vBC/xoUvr0 eU0dWXZbGyeaVONhf6RXjLvZsHh6CNDj4mLqxkI/44NQQc46rve32xgPVQH2/aNEvmhg Rt2PMb2QvzWtNhxO69665DTrCs5giSO5AQgtDoWSCEmVGFXzLvhrHifN5WD5Nob8/EDN RD/Q7VNe0vpeyDwm9BqCWLPdKsExwzD9qVNB6KXTWdCzd4sasWrgnRyTDymbavDCHsNL wuMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730241910; x=1730846710; 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=t8Sn8jdbA+NjEGCeG6Gm1wYYNvd28v2iQntXlq3XUm8=; b=TgPsxeDWtqcm8TvU31qfxjhv/tqXb0hb16RuY3UyFXDoyPBV10K5wbIcO5fnXbOum/ LmH3xzVY9vuqpen6kntb83Vsulll5vfL6CM6/YEYaTk4kWH27ws+Rey5Km3uMal65Z5l k+YpDSryAUhn1clT+M3tqwtCOQnlSzYaKkpFtVepsuvdQAsr8AXXsmdsuPI3GvKgUcoi QVnoBSIZvayYryVy59ol9bBpSkFlEnfUHWePHpbGu9os4HWA+DuayF86siI4MWws8XXs WJ/RC9L1d/q7HAwtlM4bgKITeFYOS0FxJkyQPxgKUmRU1GHpSIK8SFsiNP4Xg9CXQs7q eGIQ== X-Forwarded-Encrypted: i=1; AJvYcCV1COmKy0kTPaOS9IyGFwxeWQRCCnSe8Y8/Not0mF8guSdvr3IZp2EyKM7E0MEkTj+CKUUUAlhadCzniJQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxPCepD0KfB4tfGd5Gk06qCkdiPYscZRLbIc+zjplge950MZ+BM sX+f52NU6nKIk/fQehq8ZAAgdrTai337NnyxJZ6f7yAr/297d/YikB0IiwDldBUlPWFXP+M1TaF kA5iCmQ== X-Google-Smtp-Source: AGHT+IFKiD6Vt5O33DxVSXqakkHGLWhwNffm+KUxsCr8mueF5TZLFaA+FFpMTOgPigeazM/Bd0+g9+cXZ1mG X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8991:d3fd:38a7:c282]) (user=irogers job=sendgmr) by 2002:a81:a884:0:b0:6e7:e493:2da6 with SMTP id 00721157ae682-6e9d8b16e66mr2352317b3.6.1730241909596; Tue, 29 Oct 2024 15:45:09 -0700 (PDT) Date: Tue, 29 Oct 2024 15:44:26 -0700 In-Reply-To: <20241029224431.167623-1-irogers@google.com> Message-Id: <20241029224431.167623-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: <20241029224431.167623-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v4 14/19] 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.163.g1226f6d8fa-goog From nobody Mon Nov 25 05:34:01 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 3D4B920ADE0 for ; Tue, 29 Oct 2024 22:45: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=1730241915; cv=none; b=pymMPqbRPasdGgertgw2i6/F2x1XhcT0t6LAZPuxDXpM0NG56tYvDhMVah85mY9ZuqsjvybsD7CSgfJIH/Bmu/Ltm2IGtLzIA1dG9iPsadyWhj1vCY1iz6QlErqBYc3QcAQ3pBs/ztxhlifY3xDFh2WRqtPD3XB7zJ4N9oMTzZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730241915; c=relaxed/simple; bh=iNS6gSj7D1lsvc1g5KMcNyPf5WgHbLQ5ta+6ZtnweO0=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=RhsiR//t8Oi2bBYYLr+gkFTYbn8q4HmKfpj1O/jchePSRPFXgEkSVI1o8qQvIHBnzFsShDKSm81hUotWXUh07IoIWTtDs7M9jF4SN2en+YBkJa7YfIzB4rdBUSpyMAfRNnfgWHLLdr0L4QL0ssqrDBiS4ZbnjfalFZ8NCYOtjgo= 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=PBaggpb1; 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="PBaggpb1" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e59dc7df64so5025137b3.1 for ; Tue, 29 Oct 2024 15:45:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730241912; x=1730846712; 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=T1shwZLFPVJttCYQn91hD7eEDXA/86MDDB/52gfDhUo=; b=PBaggpb1CbQkG95scbZ7LNvGfd4HtiUSGm6Ssqi+74tRSniFcQvTmYk7zKo+aT89JR 6VTd9qY2Gll85k2lyrv0Yb2BYABCX7Lb6VuDsHVmHYCGz4bRekpntE7HJt5738lugyED LadxmgI6+qhm26FYV7RFQpvED8fYGC9jZtEbQLJIkedB4ZNmrPmDz7YS3avo4LyWDju8 DYs8/rcNAW5eRtNLN96YMmWkpg7PECHdn/lno8KGFWkt8vadgHsaD3eXQYmRYQc7lAnt UVgkpbjtD4zkuHDcpiYq016idostTRE/uGug0Ca40wf2AcBXmfbDjzBba7C++QCmdFDJ pBMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730241912; x=1730846712; 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=T1shwZLFPVJttCYQn91hD7eEDXA/86MDDB/52gfDhUo=; b=m2Wlgqf89B40zq8HrHIt8EcO7r7D0da5fbmX2eN2hhb6FS19uFtRHgxkvgIXa1AwA6 gAHh+12Xee0g9KyNCTxn75S8FBHuySHBbHkZJjRazrPySYDRJEUB2O44tVyXf8W0u8o0 f29SgofjHp7CkuRvt3NkDEp0pYc6uFPRI3qgIXrXK8DKeHLDt7mMNkflMtUmrMLtS9k2 VPV/OuuNIhOqQZo5CcNqdOMzfbXqRnis5dYbdp0HMOEtJ+nm9OJCzelFc6ByvEGAyU5u A0dbywNia7qX74S1dcPs78aqvibiJvdR44obqNavtL3cP6S+uGeHdEk33ph61RriCoxM Aeow== X-Forwarded-Encrypted: i=1; AJvYcCWbjJ+Hd/DrSLGgpQ5cGbEE1UegPL6gudWlreZ4fswcp+7UrnkksLnGr6W0jHkw5lkL+/TkH3a5D5JK4aM=@vger.kernel.org X-Gm-Message-State: AOJu0Yw2K6V3ttQt0byPkESDqBTGaSjIrI897nicp+IMYVIUZGhhUqL/ VSduyfQzuHhdHTh4V3zOg0e79/+fKjHjsEW4WE0PRx1J4yx+z8K5hteye+tLfXO/jB2NXqB89dF 5STzVvw== X-Google-Smtp-Source: AGHT+IEwTaJlXSQRR4sx+ZQnzVzk15DS6veFG4A3cQyhb+cmNvvvPfy1YzJ3tWyEoBvgx2hnMXYELCvii+HH X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8991:d3fd:38a7:c282]) (user=irogers job=sendgmr) by 2002:a05:690c:3582:b0:6d9:d865:46c7 with SMTP id 00721157ae682-6ea3e721cdemr176997b3.2.1730241912105; Tue, 29 Oct 2024 15:45:12 -0700 (PDT) Date: Tue, 29 Oct 2024 15:44:27 -0700 In-Reply-To: <20241029224431.167623-1-irogers@google.com> Message-Id: <20241029224431.167623-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: <20241029224431.167623-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v4 15/19] 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 ef1b39b5042d..2059f1c4b78d 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.163.g1226f6d8fa-goog From nobody Mon Nov 25 05:34:01 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 7C1CF20C005 for ; Tue, 29 Oct 2024 22:45:15 +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=1730241917; cv=none; b=Lt1Km0sEtJZK3WTERyQjMs0nfV0IG6xBP7/DqvBr2bt8xC0Nh7bKHpan473kBqps4c8FP500coOFEnSe6TRkt47IxDMUXxZK1SgeIOa3mbWHtklQQKCuGvnc3oWytt5bNSCGCr7DQwD/wcTfr0EcWmAnwVbBAgsAJ8g/DpxAIuk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730241917; c=relaxed/simple; bh=wFg8rXKhwSk+/WnE2Ybco7HPsV496JVgIBfe+G5oj+I=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=jd5zmDMgTCz1f6RzxqcsARoGT0Pz2qiU5/RNVcOw7gKA+jfopxSnzR850A2eB2kiqKS74A/mCaPbAu4iHnqkx/PYQ8xycOtmNl8OEB1zLFYd/rBA9EOgK7lDv7bJpoJaM1ylCLICUL8Ke+nXfGZpTxiDRi0TXgfi96MgofagMGU= 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=lVk1HH/G; 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="lVk1HH/G" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e31d9c8efcso116511087b3.0 for ; Tue, 29 Oct 2024 15:45:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730241914; x=1730846714; 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=ACBWh/O4/X4qiB3oXOqHhx7Z60zaZQtrFXt6UTS1Yas=; b=lVk1HH/G04RNpalDAb5ZxZPb0029+qThAA8htVxpr8ZWj79Er0aDAv0VSGp2GMVQp0 5wkjSLri36LlYrx1ZOU6OXkIKPenrU9a3nali3ZRxTRLV6bLFx9R9NoTAbN/RfxTcDCT Y2aS2qn4GsNbEMfuIjP4rEUpg6KYA0as4sqyW+kkOQHv3iSUCWn2H8q7FgKblPbQe7Vr afrLRNdnFyy9kFNqIu9r9hTes0wNv+QmV3++UBdLo/j5kMxcgNOk4mzZdvrYWbc8Bpg7 zD4ff//8SBUpoXVprtFPT2tg+9dlwHDRBeI9zIX2ezAEQVNGILrgJvzEX0XoBnwV9xm2 fIMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730241914; x=1730846714; 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=ACBWh/O4/X4qiB3oXOqHhx7Z60zaZQtrFXt6UTS1Yas=; b=pbRBrsvBlmKWEf0ZA4wgyLB6drDhC5YK2ieZ5BtYoBqwwCeym/CELc69dcGGLHe3yC YMmSQdHsjYqv7l3DuQClou7pzljaD4vkTUhUJllK7eMFrHM4CSpY0sNBwSj7bINMIiMX dyed7dVzZo2/FXOWZ0ZBlEvUN0cMIQLWy1BUig4OgK51JOcJCqKuHKB3okkU29EXPbil n1yUkt6ql2tmkiDz9P/+mBlWmSWNkkIaQ6rF/KleDJiShbvP4D/U/rwU/4qweDyqwcuC Gz5yqcQ88s9c0ffM+FkinTCCwerYxP9+ppnhlPVj/GhP+PL9QAX84CoZf9Kb4wp0yiCn 8kkg== X-Forwarded-Encrypted: i=1; AJvYcCX7QTtr4PbksluXaLRXnfvxGSsCcHpfz4I17M3a9dQElWVvyBTx+j627gvW+3pzjT1EuaIkfdQGPyDG8JY=@vger.kernel.org X-Gm-Message-State: AOJu0Yyvmos4l8w9nHlhPWsZMkc4bDNCowj2OnuhBU+y3rS7vN6PJlHE RFt9UIRQ2eKP/9ulw0FTTLlEgDyUiufVOY1nkjqKa19sqTVyEMWzfEmDUi7i7JjseNefeyA9fcb 5xEjQrw== X-Google-Smtp-Source: AGHT+IHMWAy13SQ+8+uIKYT+wWyqA6f4LfReuZMtkZDb3SMdJ6/mM831/a5FCW0qA1CcmYiBgEyIDuXzCQXZ X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8991:d3fd:38a7:c282]) (user=irogers job=sendgmr) by 2002:a81:be02:0:b0:6a9:3d52:79e9 with SMTP id 00721157ae682-6ea3b94f7famr436597b3.4.1730241914417; Tue, 29 Oct 2024 15:45:14 -0700 (PDT) Date: Tue, 29 Oct 2024 15:44:28 -0700 In-Reply-To: <20241029224431.167623-1-irogers@google.com> Message-Id: <20241029224431.167623-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: <20241029224431.167623-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v4 16/19] 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. As the python evlist is embedded in a pyrf_evlist, and the evsels are embedded in pyrf_evsels, copy the parsed data into those structs and update evsel__clone to enable this. Signed-off-by: Ian Rogers --- tools/perf/util/cgroup.c | 2 +- tools/perf/util/evsel.c | 19 ++++++++----- tools/perf/util/evsel.h | 2 +- tools/perf/util/python.c | 61 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 9 deletions(-) diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c index 0f759dd96db7..fbcc0626f9ce 100644 --- a/tools/perf/util/cgroup.c +++ b/tools/perf/util/cgroup.c @@ -473,7 +473,7 @@ int evlist__expand_cgroup(struct evlist *evlist, const = char *str, =20 leader =3D NULL; evlist__for_each_entry(orig_list, pos) { - evsel =3D evsel__clone(pos); + evsel =3D evsel__clone(/*dest=3D*/NULL, pos); if (evsel =3D=3D NULL) goto out_err; =20 diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index f780e30aa259..4213ffacdc3c 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -453,7 +453,7 @@ static int evsel__copy_config_terms(struct evsel *dst, = struct evsel *src) * The assumption is that @orig is not configured nor opened yet. * So we only care about the attributes that can be set while it's parsed. */ -struct evsel *evsel__clone(struct evsel *orig) +struct evsel *evsel__clone(struct evsel *dest, struct evsel *orig) { struct evsel *evsel; =20 @@ -466,7 +466,11 @@ struct evsel *evsel__clone(struct evsel *orig) if (orig->bpf_obj) return NULL; =20 - evsel =3D evsel__new(&orig->core.attr); + if (dest) + evsel =3D dest; + else + evsel =3D evsel__new(&orig->core.attr); + if (evsel =3D=3D NULL) return NULL; =20 @@ -511,11 +515,12 @@ struct evsel *evsel__clone(struct evsel *orig) evsel->core.leader =3D orig->core.leader; =20 evsel->max_events =3D orig->max_events; - free((char *)evsel->unit); - evsel->unit =3D strdup(orig->unit); - if (evsel->unit =3D=3D NULL) - goto out_err; - + zfree(&evsel->unit); + if (orig->unit) { + evsel->unit =3D strdup(orig->unit); + if (evsel->unit =3D=3D NULL) + goto out_err; + } evsel->scale =3D orig->scale; evsel->snapshot =3D orig->snapshot; evsel->per_pkg =3D orig->per_pkg; diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 04934a7af174..7f41d6f8cf6f 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -241,7 +241,7 @@ static inline struct evsel *evsel__new(struct perf_even= t_attr *attr) return evsel__new_idx(attr, 0); } =20 -struct evsel *evsel__clone(struct evsel *orig); +struct evsel *evsel__clone(struct evsel *dest, struct evsel *orig); =20 int copy_config_terms(struct list_head *dst, struct list_head *src); void free_config_terms(struct list_head *config_terms); diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 6e2ff0076daa..1a53a97c513d 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -13,6 +13,7 @@ #include "evsel.h" #include "event.h" #include "print_binary.h" +#include "strbuf.h" #include "thread_map.h" #include "trace-event.h" #include "mmap.h" @@ -1201,6 +1202,60 @@ static PyObject *pyrf__tracepoint(struct pyrf_evsel = *pevsel, #endif // HAVE_LIBTRACEEVENT } =20 +static PyObject *pyrf_evsel__from_evsel(struct evsel *evsel) +{ + struct pyrf_evsel *pevsel =3D PyObject_New(struct pyrf_evsel, &pyrf_evsel= __type); + + if (!pevsel) + return NULL; + + memset(&pevsel->evsel, 0, sizeof(pevsel->evsel)); + evsel__init(&pevsel->evsel, &evsel->core.attr, evsel->core.idx); + + evsel__clone(&pevsel->evsel, evsel); + return (PyObject *)pevsel; +} + +static PyObject *pyrf_evlist__from_evlist(struct evlist *evlist) +{ + struct pyrf_evlist *pevlist =3D PyObject_New(struct pyrf_evlist, &pyrf_ev= list__type); + struct evsel *pos; + + if (!pevlist) + return NULL; + + memset(&pevlist->evlist, 0, sizeof(pevlist->evlist)); + evlist__init(&pevlist->evlist, evlist->core.all_cpus, evlist->core.thread= s); + evlist__for_each_entry(evlist, pos) { + struct pyrf_evsel *pevsel =3D (void *)pyrf_evsel__from_evsel(pos); + + evlist__add(&pevlist->evlist, &pevsel->evsel); + } + return (PyObject *)pevlist; +} + +static PyObject *pyrf__parse_events(PyObject *self, PyObject *args) +{ + const char *input; + struct evlist evlist =3D {}; + struct parse_events_error err; + PyObject *result; + + if (!PyArg_ParseTuple(args, "s", &input)) + return NULL; + + parse_events_error__init(&err); + evlist__init(&evlist, NULL, NULL); + if (parse_events(&evlist, input, &err)) { + parse_events_error__print(&err, input); + PyErr_SetFromErrno(PyExc_OSError); + return NULL; + } + result =3D pyrf_evlist__from_evlist(&evlist); + evlist__exit(&evlist); + return result; +} + static PyMethodDef perf__methods[] =3D { { .ml_name =3D "tracepoint", @@ -1208,6 +1263,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.163.g1226f6d8fa-goog From nobody Mon Nov 25 05:34:01 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 A098720F5B8 for ; Tue, 29 Oct 2024 22:45:17 +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=1730241919; cv=none; b=sWSUY6FUov27sfvjsvziL4gAESqk40HumuyLzAh5BBH2X7ppZnPM33B7/I0gpthKCd45fKKkr5a6MkzXSXGKHcySJ4kNTzONL12RZy4a4D+rF9cpoMTKmpy6aO3gSLWTdZ7aWyq5nw7CpU0pUiwh3vwUKY4sCIZu/X4iwzdrR+w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730241919; c=relaxed/simple; bh=8nfaXceOAmgiqk2t3wMeEWNA4KSjqafBiascjUECmpw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=MRGDWV7ktLD8++q/GlZ8Tdus1lfFjBkqg3T7lfQfqCsSuTQZ8bZFip6qVh4/WebZSQyMGdc1jpElNuyg4G1efSIEciYVzGNPK9+XlRxhJfFyK4GGvnVJTlMEXy11IYp1/UKfMN6PiGKydxFR0R1osxLV4smFgh8yUnbzPGlFTVc= 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=JMtZx3By; 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="JMtZx3By" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e32b43e053so89921977b3.1 for ; Tue, 29 Oct 2024 15:45:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730241917; x=1730846717; 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=dis7RmFKQzQzt6CCLpk0OQW/Lncdns24hHlJR2bLa6w=; b=JMtZx3ByDfCcrjnRCuT0Ed/BoikpbyYICxgdUDfgxnoTzZ2DOBWObv6XlPNpORrhIC 8/UAWwwmemBFJsz7j9jG2pKUadBhbpkpKTYWA9/cn6T8WfjEcgQETwkyycs7xT66Xb2+ EDVk+fd/sPA56hc7qFXyKDq+bNoPwr0cdLMUopeYfef1c2DIn5VpUYM6h55ExPDXvYo2 qMg4UM/OD+cFSwx8pxnRDrKYLJCQl0luZCtCtAuf5blahFwAei9QZpR5+SsT9ELljzZ9 hBx4sgUqaaWOtTxF+JfjJnJnE/Uz73NTS2o9Wegc2eBcFcLdya+TrOyL8nbzoGigOFH8 c7Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730241917; x=1730846717; 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=dis7RmFKQzQzt6CCLpk0OQW/Lncdns24hHlJR2bLa6w=; b=v5o1VTQsQQKwLgGoof5D1Y2Ls4t0Qly2aJVTF0I1W785vibEc9KYE9qvUx1XP2P3eE D0Ja8EfL56DfRd55AMK6iDLotezik7XeTjhXk7TkSCfYCVqr/9Xp/FOk8ztpaeqZFidR FJzC24RKI9YhkLKn4PcsVg8cATypF0eqly5GqwM3DAXwHFuAnZ64sX7RukZ08AYzUKB+ hK9PHX1TPExmDnG02L2V+isSkcWfhXTI0VPodOXdhMAtBvjkWh9bx4gHAIIqoQVH7pEX jmwJ7uNz8OBx00VeUkXybuLc9ALXdpls2pCr/kWc8mnFab+xwLBcAfmTh0vpbP0q3eUS GPrw== X-Forwarded-Encrypted: i=1; AJvYcCUj2nxjpkMs8Br0bfxoy51+wZ1jf/6SdZSmSLwjgfDRiOCIcex6vKQR3XXNDcNHGgexLG0ohzzBJdg5B/M=@vger.kernel.org X-Gm-Message-State: AOJu0YyfSE1z9QWfLYoZSidqLqrg/FCW/g0hApgcIGbYF+QWTQJSzOkd pBqpp/9ixk0GMrwPqPPUA3GkrMkPzm+EhryQJaHxAKPUjxtFDNxBC+p4txnDmAzMNxF13G/nQQg 0GQkYKg== X-Google-Smtp-Source: AGHT+IGYQb3NSPl3DR97IU9T7cti91p37aPy5/ZWo/WZtAv7Pe5mvapiQjRvDTW00VykvHHfDTyVqK+CdDi+ X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8991:d3fd:38a7:c282]) (user=irogers job=sendgmr) by 2002:a05:690c:7092:b0:6ea:1f5b:1f54 with SMTP id 00721157ae682-6ea1f5b2d06mr3253077b3.0.1730241916675; Tue, 29 Oct 2024 15:45:16 -0700 (PDT) Date: Tue, 29 Oct 2024 15:44:29 -0700 In-Reply-To: <20241029224431.167623-1-irogers@google.com> Message-Id: <20241029224431.167623-18-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241029224431.167623-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v4 17/19] perf python: Add __str__ and __repr__ functions to evlist 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" This allows the values in the evlist to be shown in the REPL like: ``` Python 3.11.9 (main, Jun 19 2024, 00:38:48) [GCC 13.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path.insert(0,'/tmp/perf/python') >>> import perf >>> perf.parse_events('cycles,data_read') evlist([cycles,uncore_imc_free_running_0/data_read/,uncore_imc_free_running= _1/data_read/]) ``` Signed-off-by: Ian Rogers --- tools/perf/util/python.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 1a53a97c513d..a71bad3418da 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1069,6 +1069,30 @@ static PyObject *pyrf_evlist__item(PyObject *obj, Py= _ssize_t i) return Py_BuildValue("O", container_of(pos, struct pyrf_evsel, evsel)); } =20 +static PyObject *pyrf_evlist__str(PyObject *self) +{ + struct pyrf_evlist *pevlist =3D (void *)self; + struct evsel *pos; + struct strbuf sb =3D STRBUF_INIT; + bool first =3D true; + PyObject *result; + + strbuf_addstr(&sb, "evlist(["); + evlist__for_each_entry(&pevlist->evlist, pos) { + if (!first) + strbuf_addch(&sb, ','); + if (!pos->pmu) + strbuf_addstr(&sb, evsel__name(pos)); + else + strbuf_addf(&sb, "%s/%s/", pos->pmu->name, evsel__name(pos)); + first =3D false; + } + strbuf_addstr(&sb, "])"); + result =3D PyUnicode_FromString(sb.buf); + strbuf_release(&sb); + return result; +} + static PySequenceMethods pyrf_evlist__sequence_methods =3D { .sq_length =3D pyrf_evlist__length, .sq_item =3D pyrf_evlist__item, @@ -1086,6 +1110,8 @@ static PyTypeObject pyrf_evlist__type =3D { .tp_doc =3D pyrf_evlist__doc, .tp_methods =3D pyrf_evlist__methods, .tp_init =3D (initproc)pyrf_evlist__init, + .tp_repr =3D pyrf_evlist__str, + .tp_str =3D pyrf_evlist__str, }; =20 static int pyrf_evlist__setup_types(void) --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 05:34:01 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 53E6220F5DF for ; Tue, 29 Oct 2024 22:45:20 +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=1730241922; cv=none; b=MjJDfUzSm+NG19Bc7gmSkvdD7pvYrEyThqCuFGmDdze4JQvARuLjG3oZSl0cqr/bLN8VaAHs4I1feWGH6CESsmsTRzEafxgWP87qTX0WwswNEIQxzUDwB22YbIYYfGkbJvpGy412aHB9Vn2mQwCPmYHIUs/qFLALxwJ7YieL+mg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730241922; c=relaxed/simple; bh=/jY2Cqs+V3l7u/rQt+XOfsCTPd6q/qZBAn7EK80i8Ms=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Co0FLHNApUD3HigXdmX3RvHWomus2VwiEnYsDm0nxJOAUvli5r9/U2syTcdIaJgXe0nnBqIlQnvOOxUcIQV9akNOKNpDUd+H8E+XbYUZ+A10dRqByas+CPp181XEfCRkAqnrRhvVNBGQx9/XEoM4cW1cCSv8iuugiuBjyHux49U= 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=a6XqIUOq; 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="a6XqIUOq" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e30c7a7ca60so1395854276.0 for ; Tue, 29 Oct 2024 15:45:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730241919; x=1730846719; 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=IhmE2mCwcXnI6RxZJjd/8LP8gD2HSvEYfpFi71K4cps=; b=a6XqIUOqzKP/XV0jY1oWePOGAb6Mea78tL0+Dr6neLM0gJjlIM7cJZawP1C6ocWjDm WUfQ6vE9rFxFe4ejyCzhD1dWoKBAK74JsAFZKlJ0rfi8TJo/druO3PpOH6ojY28eR+fT zNQk/1ifr/Nzau4GFRobzfPaE0lO5G0IYViwhcbPBq584CqcvHe3Q1iPSliCaxVzCQmr EOIYu6InjZe4osTrGLTA42VjCrbd+dRbWDXJNXMkKS+0LBe8WgxOEyXMxEN83TElOT7F bDkhtRn9M35K+JFdentZIFbDKYJEsmwfZafu0uvQWFIZIa/oxyHkLgvGy4hDtJR4XM6k uVCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730241919; x=1730846719; 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=IhmE2mCwcXnI6RxZJjd/8LP8gD2HSvEYfpFi71K4cps=; b=u+GUW4NW7rW+xJOZ7tTKAbbxQy4R7wV2uAvDTzdPDqPcaFoxXviEQtCB55oi7FuJvS Q6dk6SZLoRU4gnGhhJSvqMo8p1ZIzPbjl0J6DS0tcboH+TQHVUwdDJ9pXXUl385kglgo 5EjF5Ay29EG6WIhnRRCbWpcV1Lb552v31wmKeeCNhod19BvKl6+q2hXQUVtWx3i1uvfo qNWaApgvZhWa67hHkFzESlnhJMZOMvt/TReGDCw3EQIGgGtRp4iRg/T7NJxeVHxKsHz2 akMBXtmVkEvnFaA+xIJsUgu41lvxGGv/zn5ZQ63d4WotUHeehC+F21KYKTAzt1A8twxY LERw== X-Forwarded-Encrypted: i=1; AJvYcCX32GUhk90hYIAtRsCLz7D5MH/zmAsdCnclx/vYKAaa9pRimsEpsX3SQDxX2T+zyPm+nsPYrJVEcdOWzDE=@vger.kernel.org X-Gm-Message-State: AOJu0YzoElxU5Hk3n01w2uRPYcAKNGLun8Ob7sZfhIlN1VS9yCRmznLr fk6w+fog2DNrgPEQ7PB6cHdkchjOiIgcHXIPlVJIJ3hIn2VeShY9fIY4JVgQZuwIXtzqb3RdNXt xoH48bQ== X-Google-Smtp-Source: AGHT+IEiwTyu3FXtnESAFQEUBUGxhe21zhV1ho+p/YYW5zq+ZRw72RrLe0MyZ5+jU5pdkeqoFDMgoTSLuJw4 X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8991:d3fd:38a7:c282]) (user=irogers job=sendgmr) by 2002:a25:e04e:0:b0:e30:cd7e:c0b5 with SMTP id 3f1490d57ef6-e30cd7ec150mr1471276.3.1730241919095; Tue, 29 Oct 2024 15:45:19 -0700 (PDT) Date: Tue, 29 Oct 2024 15:44:30 -0700 In-Reply-To: <20241029224431.167623-1-irogers@google.com> Message-Id: <20241029224431.167623-19-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241029224431.167623-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v4 18/19] perf python: Add __str__ and __repr__ functions to evsel 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" This allows evsel to be shown in the REPL like: ``` Python 3.11.9 (main, Jun 19 2024, 00:38:48) [GCC 13.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path.insert(0, '/tmp/perf/python') >>> import perf >>> x=3Dperf.parse_events('cycles,data_read') >>> print(x) evlist([cycles,uncore_imc_free_running_0/data_read/,uncore_imc_free_running= _1/data_read/]) >>> x[0] evsel(cycles) >>> x[1] evsel(uncore_imc_free_running_0/data_read/) >>> x[2] evsel(uncore_imc_free_running_1/data_read/) ``` Signed-off-by: Ian Rogers --- tools/perf/util/python.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index a71bad3418da..0d71ec673aa3 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -781,6 +781,17 @@ static PyObject *pyrf_evsel__open(struct pyrf_evsel *p= evsel, return Py_None; } =20 +static PyObject *pyrf_evsel__str(PyObject *self) +{ + struct pyrf_evsel *pevsel =3D (void *)self; + struct evsel *evsel =3D &pevsel->evsel; + + if (!evsel->pmu) + return PyUnicode_FromFormat("evsel(%s)", evsel__name(evsel)); + + return PyUnicode_FromFormat("evsel(%s/%s/)", evsel->pmu->name, evsel__nam= e(evsel)); +} + static PyMethodDef pyrf_evsel__methods[] =3D { { .ml_name =3D "open", @@ -802,6 +813,8 @@ static PyTypeObject pyrf_evsel__type =3D { .tp_doc =3D pyrf_evsel__doc, .tp_methods =3D pyrf_evsel__methods, .tp_init =3D (initproc)pyrf_evsel__init, + .tp_str =3D pyrf_evsel__str, + .tp_repr =3D pyrf_evsel__str, }; =20 static int pyrf_evsel__setup_types(void) --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 05:34:01 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 7B0D920FA9B for ; Tue, 29 Oct 2024 22:45:22 +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=1730241924; cv=none; b=EoTbUGHYRrx13hw6gRpx/NyAnXy+/gbpR7h/menGb6VWxqUrbOjTcdIsjCu2WFB3HyPxvsYF+JKxZJ9SwqnR/Jnd7dbOMI5JXt/w+MTEpTrk0zHifUI6s6EQEKGB988/ZbS6MXqqCH2pJWYOsiASWiSbUM93wWw7jHk/cF0G+J4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730241924; c=relaxed/simple; bh=RYBqniKAr0HDr9QavuDpVba3HWcJbNfezQsIwVzha5U=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=p4GUxezGGWxT6VGMp5J8DAY+5rDJSkLBgUjMppU1dUg+wZlz77/0ctsBjyiSGILcWSFxb00iDSx42UuNlAw/xm29ReSuFsQZuOkOe9/H9C+P7ADpse63BPNdKAmYHaxWflkwUQ8W+WKCeoT294wxwKsC2rMakP1HRg0QGqLIj6U= 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=YMdwHvK4; 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="YMdwHvK4" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e290947f6f8so10658572276.2 for ; Tue, 29 Oct 2024 15:45:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730241921; x=1730846721; 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=XAPItomQeEHLPhkkwn1yLotANahBFAs02uwcMpYu9h4=; b=YMdwHvK4cu7zDl4efOaJaGJLGxdCtsvRB4kNMFppq9wv7PsSam6clvJtLwaeOHZZjB xnhjRUtWBseUotqpxRpP8oh8uYUETfWKKOA2w92Potm+JEAIn3HISz6ObitxePinJHeF YXUsB3clNhfyu1gjCy5ChyH/D3wa+PlMzIBxl7ueCOAqz8fSlPie3F9ootTEDAWquhDb GaxcA58mZ3evYhw7aC6oMDOBFSTY0nS1qXc1lkv//JMNhI9j1p7X+JSIHIVzVFgjA7eA 11Z+b7Y9726vNBMJ5s6gZwakWNOHAoRVEuIUkaGpmomkve1+jargZl4SwAFPXCDgYWqA 8djg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730241921; x=1730846721; 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=XAPItomQeEHLPhkkwn1yLotANahBFAs02uwcMpYu9h4=; b=RQXWg7LZsBXTYeMVtEa3VxptvVxCkTgcZDXmxz8Fsika0MCyqDBtkNWyLUeJRt7b4W UVFU21K1Jr5hPJsIQm68TlnV9jbg5/GVGN35TXIRLjyo8+QJYBxuZAWhVPM7b3KcQXo2 qfreAPjcp5OfX5/eynsDk6HuJwF4XMV+bIlcq8zqtha+kHL6FCLNRYFo1NWNuib02wLF AzhNL2gd9e/w+W++QNMKR2lgl/rP0+h4H+argsIKG9BCpzRnExnHmiVEcW3QdWxzEE9C BMkWnMnB8WMt0kWJMDGMFTUZnOy+SaUUTO2ZJ3L6TJcc4Tc0ZpNhPCK0i4vQ2ZqvGXIg R2NA== X-Forwarded-Encrypted: i=1; AJvYcCV/rOYm+Kr9kf64LjCNtRB+fAkj7uFzqlnwcTwjddf/uQ3ggWg/kYDcKOPutK3Q4kR1rhKbWBPdOj8epxg=@vger.kernel.org X-Gm-Message-State: AOJu0YyQkY+tdvdoNI0RQ1v/Tim+6sIuJ6s/1SkD9kLxfs8eGnqdQdih 1fp9Nl2xmQBz/0Z/MJxXbL06DldBXWCy4fmnxpugl4jzcMmf9PMd+lknf1etkWhjtyw2q15DHBz BjSeIQg== X-Google-Smtp-Source: AGHT+IHjq9xY7rwYPlkiyef9KSLjkmkqOtnvQiFEzFzKfn6tQMOtFng+3YAEfFlHM7RYYXpf4xW/4PrJmeHq X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8991:d3fd:38a7:c282]) (user=irogers job=sendgmr) by 2002:a05:6902:3297:b0:e2e:2e79:207c with SMTP id 3f1490d57ef6-e3087728d56mr12242276.0.1730241921523; Tue, 29 Oct 2024 15:45:21 -0700 (PDT) Date: Tue, 29 Oct 2024 15:44:31 -0700 In-Reply-To: <20241029224431.167623-1-irogers@google.com> Message-Id: <20241029224431.167623-20-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241029224431.167623-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v4 19/19] perf python: Correctly throw IndexError 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" Correctly throw IndexError for out-of-bound accesses to evlist: ``` Python 3.11.9 (main, Jun 19 2024, 00:38:48) [GCC 13.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path.insert(0, '/tmp/perf/python') >>> import perf >>> x=3Dperf.parse_events('cycles') >>> print(x) evlist([cycles]) >>> x[2] Traceback (most recent call last): File "", line 1, in IndexError: Index out of range ``` Signed-off-by: Ian Rogers --- tools/perf/util/python.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 0d71ec673aa3..25114dcadd21 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1071,8 +1071,10 @@ static PyObject *pyrf_evlist__item(PyObject *obj, Py= _ssize_t i) struct pyrf_evlist *pevlist =3D (void *)obj; struct evsel *pos; =20 - if (i >=3D pevlist->evlist.core.nr_entries) + if (i >=3D pevlist->evlist.core.nr_entries) { + PyErr_SetString(PyExc_IndexError, "Index out of range"); return NULL; + } =20 evlist__for_each_entry(&pevlist->evlist, pos) { if (i-- =3D=3D 0) --=20 2.47.0.163.g1226f6d8fa-goog