From nobody Sat Nov 23 15:22:07 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 370256F2F2 for ; Tue, 19 Nov 2024 01:17:04 +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=1731979026; cv=none; b=uKXDbaNK7YAhrLwWha928av20mtpxOwNpWZ6RU4pxGXSS+95AlwZ7LqmPIUDo9dDadjXQetXc65//FzcACKcMQwPznIM+k4G9XwVguqfNEmzMAJ7HQuzOUIQt8dNLPtSp+INPABGcURYzwfc6UwElNyPBbp8HyzyAf1+yeCef3s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731979026; c=relaxed/simple; bh=TRzdyrr83yFOHaaZp1XKONQ1u8411y5W18H7l2Lixew=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=ZXi6JrJHIGdNiSjZVBN2oMbqCLoXfbC69/n9gbBA49c2upuK5yoLBswcK/UcFXpn33yjJMePXLpg3zetqhXFeysabL8wmOya21KgyBVziBefP7BdlkWnBjYBZk3RM7V2uuli5MbjRyAdwzLAs6zvcTP0xgzh3VQoU8/67oMmUQE= 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=wpMvXUCi; 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="wpMvXUCi" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6ee426e3414so64352057b3.3 for ; Mon, 18 Nov 2024 17:17:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731979023; x=1732583823; darn=vger.kernel.org; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=e5R7N5m+a9zmfRArLdBFQ3oPGXQCBbIT9nqOcsc0Xic=; b=wpMvXUCikEG8xPXAfP6G/hg+WYfCfr9d/zAmn+SVUcIrHWi/Nz3s3okgYdbe2d6Kwe aTlN0sotq25bfUoxWoqU0AmgJzi5SKWbhOKd5znX/PvKPzsvYflLmDnka6YvlkgnsNkq eM25Lp9+6NENYmy7pfrs5cxNCdtvN+0Q15qmoajCNjpcOx+e1GdlwK03zq+0C/ulzSR0 43aUWpJPKJqbBtBqtowdu5yH9k+0l6sW5zJR2k3Nqq/S3Nxwoqp/JKLLj2i/oWKaa4x4 wJxm7r5KtMihnGBUmcrdDvwEEDxXVOgG1I6OlrlQKEIHvnS8nKfXvl7omff0Xhwf/ni8 DSDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731979023; x=1732583823; h=cc: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=e5R7N5m+a9zmfRArLdBFQ3oPGXQCBbIT9nqOcsc0Xic=; b=gilccgfs5jzjnUMkILJ/GhigWv7mSdgy5aH+oJB4+F2mTREhxJrBJ3Dhd4YMzo1jTp MpIvtU6MdcMQn0hKa10uHOY8mQe47DiD1BHMYJj2AO6X1gmT9BjfRCe6eebn2LzItDBv WZJoDL37M6/wWzbS5TGX+gVx7PYKovYz2w4H1i17nj17Lf1zLZDa7hIN/ifAJI5f5ecq TKLEI2sKAry64lfrRMwZ6njMjoARgpBCv5Z4iWEOzsickHVrmXXaU892Ym3Zxz1Y+g/F qRXZDn/dTZyk7brLFXIFhb1qOJz7HNfCJd1EfchmEnZjOABvOYdHUVQ7P3ZXra2y4Df/ uw0Q== X-Forwarded-Encrypted: i=1; AJvYcCVDrlpeBPi+3m6z4VhhnbCTxJGgEOTrJ+r4aP2m7DKFQILRWc9k82msvM+GOvJpb0fJhIYBaGzYXuP+v4I=@vger.kernel.org X-Gm-Message-State: AOJu0YylHcayN25ZI37uFEboKou6N22tqxVSf6seYDpj2einUpe3Gc6a 3vCgjJrR42u7Q/LMZ/wbxv6Lq2Bx50R6yg2sG/s7WAmIkC1gWWPxElkWqI58qsU616OZf0T+HV6 Fl6FQeA== X-Google-Smtp-Source: AGHT+IEVB+QEv1B58NiPQwBfZyIOt1tj2t1pVEM3PPvhzdzHVO4jhLeP34Iu6kgscgaXruipXnyyh0ugXJnn X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:22a4:ded5:5c37:fcc7]) (user=irogers job=sendgmr) by 2002:a05:690c:8110:b0:6ee:3f5e:1c1b with SMTP id 00721157ae682-6ee558f3375mr446637b3.0.1731979023191; Mon, 18 Nov 2024 17:17:03 -0800 (PST) Date: Mon, 18 Nov 2024 17:16:23 -0800 In-Reply-To: <20241119011644.971342-1-irogers@google.com> Message-Id: <20241119011644.971342-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: <20241119011644.971342-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v7 01/22] 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 , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo 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 Acked-by: Arnaldo Carvalho de Melo --- .../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 2096cdbaa53b..ea6dbe6e4317 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -26,40 +26,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, \ @@ -117,7 +91,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; @@ -148,7 +122,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, @@ -181,7 +155,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); @@ -212,7 +186,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); @@ -247,7 +221,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; @@ -274,7 +248,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); /* @@ -309,7 +283,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; @@ -343,7 +317,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; @@ -432,7 +406,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; @@ -918,17 +892,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 @@ -1234,9 +1199,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 @@ -1250,18 +1215,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 */ @@ -1274,7 +1232,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 || @@ -1282,11 +1239,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); @@ -1335,7 +1288,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); @@ -1345,9 +1298,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 8bdae066e839..19eadce50ca1 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, @@ -1902,12 +1875,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; @@ -1915,7 +1882,6 @@ static void _free_command_line(wchar_t **command_line= , int num) PyMem_RawFree(command_line[i]); free(command_line); } -#endif =20 =20 /* @@ -1925,30 +1891,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; @@ -1956,15 +1904,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.338.g60cca15819-goog From nobody Sat Nov 23 15:22:07 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 5B9EF839F4 for ; Tue, 19 Nov 2024 01:17:09 +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=1731979031; cv=none; b=YELPCj+ivOE0rSPXjB5SawUlBLyZc3Y6r4kgqJy0VKCJxhnPb5rQxF9qd/0jvCJQOj+B0cLTD7fYvX1K76c/OxmHJd0ey9lytQtlQT70+W2BIZzGar73w9IdRdO1X3Vz4DZoV+3eNd5pnnq92MisBkjlZK3yOfgMUZWr+pKMcSQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731979031; c=relaxed/simple; bh=XkHI5vkt+p0utWgVFkj1bE6/MPtZ1e5+uRY99mTndWo=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=cH6YcvYoMEnh8ISQjMpUuleqG+8N+kaHYHQG+ezHaC9x6+zkbnoRxhkDLYB7oVChKjyW6AFdvdU6O+WV6VIjOmceSaya4tHD++8CVCPAmDA+k5JNb6jL/gQlVCmVe/NIPl/hq0HRlV62GZ9mZysAp9N83+zZMysRaffWO0ZJJFY= 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=UOEjkkXn; 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="UOEjkkXn" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e3826e5c0c0so763344276.0 for ; Mon, 18 Nov 2024 17:17:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731979028; x=1732583828; darn=vger.kernel.org; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=c715NU8W48BvJWXkpfehEr5nm+el313VPIVccpZyvRA=; b=UOEjkkXn4qWdRJZBplkqxtxmwf/qOy63zp2LNjdpw1yfC98Syh+2N+qbbs3TK1SNyp jN9LBMijPUW2zzy3U4KdkLGuw3yyE+g1BPh8Rugsl98eYIJ7cVf7Q9/E9c9854QRSZfC 3ifbd5k8xB/+wMdtYXTGz0Izdw46qgvD15rkhyj9jLI1lADaMCJiEQxXE91jpWwnDc3a zRvsOjLJ819OTt67A/nSefPCNgMHdoOozW9UVG9KQx0qOb6T22hoxbvtGAdiMGRG8m2z 7P/D5zlB29/pZXK+VxjSWqtbtj+wDp4oKQzHpbhU586d1lKNANMLIIOpQ4v8a8gDVjSX 9zSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731979028; x=1732583828; h=cc: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=c715NU8W48BvJWXkpfehEr5nm+el313VPIVccpZyvRA=; b=Y6+c7lfcF8Urs8BKF7GByFI9DuX9fIS5mw5vOBXNeedxf5eioCoKJj7m5CnXBPMBT7 Drhy0bWy6RWeWjX9JWFFlQgLP+ZA1tx2ZNgiikgoovYJyY2UhjNlFu2RgICmtzldm4jO fq0NDZP0fLoldr7Fi1k+OWsUKOS1GPz9GfoO+g88xTnISAyY4uFSG4AIz0Prp33MdOgD a1yNZPa8jRdSvo5B9u14E7cHGKlzmfZbH4euyB/4vc2/yGiUXntHvz9G5YefZ5UZ8N6M F90BeSznUZTE4eMgkEYrqsJk8RTWy1zh4UE5wOHjfqdWwQb8C/8NzUe8fg9IOnSXGy6R +B8g== X-Forwarded-Encrypted: i=1; AJvYcCWpo2PL1eWSH6FzEG2W66KxxWHeOzUCEvLa3qSRc5UL1uts9M5+9WrLkihe2Yy5+mz4Uw+llsbAth/237k=@vger.kernel.org X-Gm-Message-State: AOJu0YxPqXzEsqQwDGrRpwwgQirugwV6o+n/ly37Ags2UItrnf+M8Jcz aObL5r/OeCtwRHQRaTqN08Ll0X28NfIW1H+h7JTSLrO1Jiw6EaLCz5gY168Zz7GvGFleCPwUv2L Dy7Ty6A== X-Google-Smtp-Source: AGHT+IGaTeSVsjLRPzmVL0dXDXl9jkDBCCuHJQ6ccoYtwMoM7COuqWxF+pdfj2SUmTUVYrTqwGlJzEz2ZRuM X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:22a4:ded5:5c37:fcc7]) (user=irogers job=sendgmr) by 2002:a25:ef0e:0:b0:e28:f231:1aa8 with SMTP id 3f1490d57ef6-e3825d14d07mr148005276.2.1731979027876; Mon, 18 Nov 2024 17:17:07 -0800 (PST) Date: Mon, 18 Nov 2024 17:16:24 -0800 In-Reply-To: <20241119011644.971342-1-irogers@google.com> Message-Id: <20241119011644.971342-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: <20241119011644.971342-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v7 02/22] 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 , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Opportunistically constify variables and parameters when possible. Signed-off-by: Ian Rogers Acked-by: Arnaldo Carvalho de Melo --- 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 ea6dbe6e4317..e04c05612830 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -63,7 +63,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 @@ -78,7 +78,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; @@ -107,7 +107,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 @@ -120,7 +120,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 "}", @@ -142,7 +142,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 @@ -153,7 +153,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, @@ -171,7 +171,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 @@ -182,9 +182,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 " }", @@ -202,7 +203,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 @@ -211,7 +212,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; @@ -237,7 +238,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 @@ -246,7 +247,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, @@ -267,7 +268,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 @@ -275,7 +276,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; @@ -290,13 +291,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; @@ -385,7 +386,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 @@ -395,7 +396,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; @@ -475,7 +476,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; @@ -543,7 +544,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) @@ -612,7 +613,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) @@ -796,7 +797,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) @@ -1079,7 +1080,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) @@ -1101,10 +1102,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.338.g60cca15819-goog From nobody Sat Nov 23 15:22:07 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 7FCF312C7FD for ; Tue, 19 Nov 2024 01:17:13 +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=1731979034; cv=none; b=XxtdRkrNG8XMfU6CL7dZzcKACPzNG1BXFrcGe893DPyozKgqPVdEbzWnqMaYG+Dy2J/Nr/uGAxp6VgTxaoyvzOsVOcQnQDGa3yF+X3oz0YGnPC70KrKIaC6aKZ0C2Z7URM3DqxW6smpd0eKlTRRXqUVw0HCl3cjYC+YKuB5+u8I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731979034; c=relaxed/simple; bh=S7D5C+bJCAzeCBN5GGs2u5xl+eAkYpdmeT4lCCcMaUQ=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=I6QGud9gZNXz9ugqSNqIGj9WUrynSRJEVEn3/baLFtuqhWuFS1ZlhhOl+4y3629eHh0YXlYolGUgyGtbXAwU6bq75aICwNiut5bTyTzc6dJ+1rVdqdZG7o0qn/QTv9CWbMeIzdfqEa3gy7EO7qpqivtdh2QdXYbNSRdmDRu7EG8= 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=PeBEjwDP; 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="PeBEjwDP" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6ea8a5e862eso64360217b3.0 for ; Mon, 18 Nov 2024 17:17:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731979032; x=1732583832; darn=vger.kernel.org; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=3DnKYRzLOBQKhpteQUA9RyoAZyPDDZS21UzXGtb/zXA=; b=PeBEjwDP2QVlC/QgMOtFUZs2d0FfrktZLMm75AcSr2Vmlpm6MVz/6NVosce507R5lR UkWNfXCoB0HCc4tba4ucJzQs5Tf88NgV5I+6HYzqOYDJ6aJAw2EP29mVrqs/AhFMlyZJ I2O7DThR2djeADJUiPoI6DcXjlVbgM7HcEHOokcm3eo3ug6hSiagMhCAbZm+38NPbJkA vfPUxEha/nl87TCkrqXpR2RGlB+optM+TuN5J9FYu7VslYFV8rjU99OrP00hFpTAUlPV 2q87YKsHY59QxuHhqjTQyhuB2Ricjbdka5V9dcpI/ZGLi6/MiAkie0qyE2ckOGE/ysLV +otA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731979032; x=1732583832; h=cc: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=3DnKYRzLOBQKhpteQUA9RyoAZyPDDZS21UzXGtb/zXA=; b=Z7L0CxhPAjfPxNzEbwkSk/Tb0jnHmNP8B/SGoF6iiHM9xzsT5Z89Ug0QscChr9cwOF +2BI1lwJE4pgZPrUS0ytl9xxwZ4eyNCdQuvtWd0aA+fo5VHUQ5h4Tf40V6wHYkHzgBNf KrCvwCo189PNMuU37T88CBk+AwxKKjwx4lKZEfGy/VTFeB1e+AIE6N/UGGpWsCfy+tmU 8cK+XLRdshkDMHJ+jFsn79nsk6NkcN/1gsh5jw00zVGjvkDmedFPvnZG0DSIa1LDU6Pq 0eelVxSGUx71TyBegqBM9JhjJx60VoFdK50mQ1LIaqNX+9kSYswuNZeAM7MYoQFNOVGY j4Eg== X-Forwarded-Encrypted: i=1; AJvYcCVGRzUK/I/Mroj4TjYLMWfOyobG5DFqfoMqJhLHh+eltV/vK+qLqoDEwFtERkTBlyu6bLSQlj/QG+i0P+o=@vger.kernel.org X-Gm-Message-State: AOJu0YyF0nfHLMUW924vjQ4lnU2jtzMaeQDJrVHOfjXjV45lsVbHUAWK fDOAMQ8O4nBknOEu3AnvrnbPsL4QlFj1/OMuamcRMA9xIfu/k9aZ07M662ESUEgwEVXr7DJo+wK 9fwMcYw== X-Google-Smtp-Source: AGHT+IHd/+TZ9+u78b6TEoIZfyfyrMfN24E3uv7SGJBfMn+KQioUQ8Q0p8Ds6Xew41S+Veno0J/9F7rO5Vrh X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:22a4:ded5:5c37:fcc7]) (user=irogers job=sendgmr) by 2002:a05:690c:6d0f:b0:6d3:e7e6:8460 with SMTP id 00721157ae682-6eeaa3008b1mr489367b3.1.1731979032547; Mon, 18 Nov 2024 17:17:12 -0800 (PST) Date: Mon, 18 Nov 2024 17:16:25 -0800 In-Reply-To: <20241119011644.971342-1-irogers@google.com> Message-Id: <20241119011644.971342-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: <20241119011644.971342-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v7 03/22] 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 , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove unused #include of bpf-filter.h. Signed-off-by: Ian Rogers Acked-by: Arnaldo Carvalho de Melo --- 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 e04c05612830..140437042a73 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/stat.h" --=20 2.47.0.338.g60cca15819-goog From nobody Sat Nov 23 15:22:07 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 2ECB84F21D for ; Tue, 19 Nov 2024 01:17:18 +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=1731979039; cv=none; b=tQaRYm3/C5qh6P/ATaYP00s9xG6MbNxzHi5SFhG8giO8PrAguJ8i2yOA7rVzh/N6RPGTYLwUM1fvW6gWykozdss7kOkSd8FEMeRigpB6eBMVDb4E0zTHfMrQDdeaj5q3vRdSr+QLb/btXfrUzgvv4mU1Y5IZ3J9Nxx/EXV09/0Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731979039; c=relaxed/simple; bh=VhNtNpqyWTEY8C3GHcgOI2AXz6yHFJu2f13WAuVuTq4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=ZZNC/BcFWYyy2NubalwOdqFwf34ALam6chWZyiDFpRVbTIxhc2f3xDG2sRiZfnQWJ7oFC1F1Xep5Faj2dJjRYHtkn37QE/tls3MYAioFDtGGd3siTCIGZMa3JId+3NOqtsBOge7SbxcJaNs5KnEdjcTNGXTGZMHCKGRiF56d47Q= 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=PaBgaLVo; 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="PaBgaLVo" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6ee6a218044so44984907b3.3 for ; Mon, 18 Nov 2024 17:17:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731979037; x=1732583837; darn=vger.kernel.org; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=J0328NUHtrNZJQm86x76xiznvoVOH1WYLNLC3OdZCsg=; b=PaBgaLVoomZECZ9Aw/pIM/zvdD3ON000cr2fQpWHPxbUtRLcOCFVFaNSpI1PjzREJW a4MEzjFhWgRCLoXBD+9A5sOFTC1/yc0/ZF+y4mT3pnFoLVv8+XGYw4um11iNFSqpHWs+ AACfsFIExuBMZmxS+wambFmGnwjAuaCr+4PfB0qc9AJbIVe2dP/u2jmFgdVTj5mXZJRv pUg5K1mYbFr1KmZkUibxutlxmLyv8Hk2fyFx72Z6CCL+GMBpuuM+wzuhm5tlziqj5ylM crCjaw7dXulnu7gqifBSnsI8dY4dDvlwLISNUbVZ83JvoXiClbzW0pWHgBlHqZhYZfCt oUHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731979037; x=1732583837; h=cc: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=J0328NUHtrNZJQm86x76xiznvoVOH1WYLNLC3OdZCsg=; b=HIQD6des+2Z9wj2zJ78HrGL+VdF5GQa+dDt8Fnb7439XWfIQlhe5+I8EyajYpmUsub Pf9YdfM8DPdzHKdPyf7zC5wpsVgs4k+9kTDwKOyqJ1LjKqmgyaZ3WNYGEswJDDR5rif5 abZwxJ9Q2wDLv3G7ihe81IS0JuyvC+a47aT753UZ1QFCw3MjaBsuny1tPBp8+iyv+I+f gRY6xlmkzEnnF1rvI8JTxtcm/bZc+kG0O4yntr7wBxuKbP5JfdwiZGQBYwyQO8GyU+mU 1tDeDyR9PJ3t3plewK6UETdG6hDyrx9EJ5sBdibLx2clGITlL5EQnBADfFLDtWVVykWZ tZCQ== X-Forwarded-Encrypted: i=1; AJvYcCV4JLmKDX9uwlh3c8INlqotMeQAZVaSvQmA75qzjG/pAk2bcerDfgPMV9TImUs04GI8b9RujgjIw11Cxcw=@vger.kernel.org X-Gm-Message-State: AOJu0YygtJrw3Tk5fmztyYgdq3bx5jowIcu+B0pIUho+lIsrOzh5tmaQ 5HNIdSEk6p6Yk8SqaFHvzETW9fZKSY7LxipQDTQHUoNVK4tTtTxXikGeuLhR19CAJx+/JDo8sgc 4SxgulA== X-Google-Smtp-Source: AGHT+IFFILUsD5rAHW7HYokLe9DALJLU6QVneLadKpvxX95BkXN6BnzrHQz86joi/76PNMJsY6nit++nZQf2 X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:22a4:ded5:5c37:fcc7]) (user=irogers job=sendgmr) by 2002:a05:690c:424a:b0:6e2:1ab6:699a with SMTP id 00721157ae682-6ee55ccc2e3mr1091367b3.7.1731979037241; Mon, 18 Nov 2024 17:17:17 -0800 (PST) Date: Mon, 18 Nov 2024 17:16:26 -0800 In-Reply-To: <20241119011644.971342-1-irogers@google.com> Message-Id: <20241119011644.971342-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: <20241119011644.971342-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v7 04/22] 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 , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo 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 Acked-by: Arnaldo Carvalho de Melo --- 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 9e47905f75a6..2a7e704c0a54 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 140437042a73..029536c1fabc 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1307,8 +1307,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; - #ifdef HAVE_KVM_STAT_SUPPORT bool kvm_entry_event(struct evsel *evsel __maybe_unused) { diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trac= e-event-scripting.c index 5596fcda2c10..d514db1df27f 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.338.g60cca15819-goog From nobody Sat Nov 23 15:22:07 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 E515013B792 for ; Tue, 19 Nov 2024 01:17:22 +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=1731979045; cv=none; b=ugfNQ0/170nzBpPUzttVdtwAnhSf3o/obx+kn3doLXOtIyU8sOKdPfzo26WfKMqWKSQPtiUq+4/m35P+RWRdR76Pb981LyguLctyEfvF35N7iwREM710rGzHIJ7NQn/wQ9pqridDNUkMQw9MJEGwKk1c1E0EtpRaYj4wVUAlI9k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731979045; c=relaxed/simple; bh=a0x2GWPMzmDHCU///fMeR9OGwGDZuoq3My+P5rsc7LQ=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=YOjAn7/oUzrtdQHmiZ5wvUT5X1wBvLBCgCjlbac5Y5gdi5rTSHMcGy/kmAZdXrvP3iWZMfSXCuXWfDACOUHxdtVY6pNtOShO3jxr6yac/A3rHh8oja9Fx+qwuAk6SGUCUot9kxGAUhQHzfA5/dELUwf7Nw8EV4E2ycrM0bjBNao= 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=GsFnoFAs; 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="GsFnoFAs" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e6101877abso44403327b3.0 for ; Mon, 18 Nov 2024 17:17:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731979042; x=1732583842; darn=vger.kernel.org; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=DoPLEO76Qn6qjJVT4M/omIJSIRXBMHxrz0L3FzCobVI=; b=GsFnoFAsNG+ddJAcCdjx9F2AsOkhqmcJYahn1wS5LX/L8REb5SHomfEpYCfy80M5Om CbDK2YDz7+kPwUnHql9ci6XPI1stT/GadopZ0eJldKrM15tGU3ZWP/8g0bhUcjc1bQ7v LbIoVacNcvPnfv1UlctduoTIe/CUPiGORLIEtMr3ACvQCLCnYpZly9HE/mEhk7jwaav/ C6P7Wf3+1bLWqkYIRqMlo0scsFIwGX59Ox1N7Lwtj0x7rz/oEZe57R6ek3GZspNunf+D Lse4+X7EDHtWUKNVL+Az/XKKKTdRPFjhKgpPOn45pVQZbUzrIIz6vO0OYt8jKx/kbgmS 1AIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731979042; x=1732583842; h=cc: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=DoPLEO76Qn6qjJVT4M/omIJSIRXBMHxrz0L3FzCobVI=; b=ChnpnT9X79N6pCPaJ4IkmbdT/c4jMeAA/MrRiRoGltmdCa+J7b1k8gcOKbRhB6ItC5 COEktizLviZ5yqk4UanprX5lBxJ8VhTVUq25ljfI/XVCm2ts/uqaR5jN3b5w6Nc/mrjO nv3rL6BHDo16KmfRVF18xIila2viJwMlbs/l9YbJMDDBFjYhdTUgXgZxSj0hpwlFP30i m14SSfWm/gnNrXYl71K84lCJ/JcUKsAH0MHr+1Y0ywAKfW9P0KaC0ID3IU0k4wLAdsVw kGV47DOkK1IcF1euKnMfb6mF34HgZmIEB++CpSGllaUQxsuJwvnxuOioelYjqphKaPcS Cw3A== X-Forwarded-Encrypted: i=1; AJvYcCW0BPjnEc5rVgOwdq47PdcKm7geB1LFm2DB7QuLnp5kL7ESNbW8pAEghwE2Z6dMG3CYT5ewOTR7vnygK84=@vger.kernel.org X-Gm-Message-State: AOJu0YxVFLcfxvJ+M3+SFNttcIZnmfD0m+dG+qsrq4Knp3WQbqfnmm2Z 3C34xm5WkSDemIVoTHA5oQCeqSO1u8GWp0hlfMWAiHvNHszSS8dnaktZ4w+Fhlmu//gpAyKBMLR vfFqhyg== X-Google-Smtp-Source: AGHT+IEDUY7uikFm0PLLoa4SWCag4yDK2cFssmBI7rVcELRd/96KcIDLXNCeeDSTCU2mUUxx9oFMyzZKR+Ij X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:22a4:ded5:5c37:fcc7]) (user=irogers job=sendgmr) by 2002:a05:690c:46c4:b0:6db:c34f:9e4f with SMTP id 00721157ae682-6ee55ce2ed7mr6320877b3.8.1731979041911; Mon, 18 Nov 2024 17:17:21 -0800 (PST) Date: Mon, 18 Nov 2024 17:16:27 -0800 In-Reply-To: <20241119011644.971342-1-irogers@google.com> Message-Id: <20241119011644.971342-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: <20241119011644.971342-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v7 05/22] 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 , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo 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 Acked-by: Arnaldo Carvalho de Melo --- 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 | 32 ----------------- 5 files changed, 74 insertions(+), 93 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 274568d712d1..67fd2b006b0b 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 c06d2ee9024c..cc6962407376 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -121,6 +121,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 029536c1fabc..f8b291143884 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1307,38 +1307,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 -#ifdef HAVE_KVM_STAT_SUPPORT -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) -{ -} -#endif // HAVE_KVM_STAT_SUPPORT - 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.338.g60cca15819-goog From nobody Sat Nov 23 15:22:07 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 9879D13D893 for ; Tue, 19 Nov 2024 01:17:27 +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=1731979050; cv=none; b=fAFZH9UpTj1xD4RJwAgqGzwr4naYyffDDrsA8OFf40m5NIGvH6dmPh9zz3po2eUrsG+opWKV6vwCcbFtAmLiW80co6Ebmrkrqq2PtbMGgJT5092A2ubx7bO7gUo0xQGT3uYfglVd1uaeRzlNUD5lSVP0fyOtS8ZbSQHBu3ze7Nk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731979050; c=relaxed/simple; bh=/CbhJo0NIgUB0KCfbS3Ow1Hrm07M2ACCA+WmmfLTdk8=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=SIUOpgk7FoB9MOkqBg/xnaoikd8J5GWvmDqpBiNzu1uEwXYSyJ0RN/xb9o+7GzuSlgt+d4DZBOM1fOazxOw9fM0MScDOxum97tuIej+ngMGiYk+mvQZgqpS8Ihv3X9Vphwxx2Dn6kEVRNTOD3Ciidh6gwkzvFgg8drN52+GTMRs= 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=p0RqEjdJ; 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="p0RqEjdJ" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6ee51558e90so67604857b3.1 for ; Mon, 18 Nov 2024 17:17:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731979046; x=1732583846; 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=isAY0YfEtXbULouihI9XfHEkMTzWUigK0hJ8gnm8q9k=; b=p0RqEjdJ46evA/Uh7bKlxORrcu1zvfoJQQAFC98bsbDp6w4UIiVcZEpSwhvqHTQjMp FYyMTd62UGCTBPY/qosGnQRtVE5EKbjSSbwYBK/falJg+qH4zWlrZRXpa/J8e0OIrMB6 7LiE+04fssqlAwxP8z2eAUgY8os4VHEMDKCVydKrTaeB/F+W+9CFO9woMw54D5QM5qZ6 TYy8l4kPr1lSloAhZaj2u7R8ogarZoAZ+WwEFalMEj5Grlm2Iq6Slr8G2tfDsAgbiCSK IFATpiU4ynoB1t3/G9/9ZhwA0f4k0IOwM2OH8Zel9MgPDEF/4yA2G1i7NI2j3gAy7bZm 6ZTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731979046; x=1732583846; 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=isAY0YfEtXbULouihI9XfHEkMTzWUigK0hJ8gnm8q9k=; b=SjOvzDflCcGHibOMQTZQKmVob6OoLEhvUk+B7XZibAzVPD2Ct1jyJUEJDHhh1Iw9hd 17ylSXrTRTeOzSM4N/BAzuh19oFZihplef0paS5MnXAvfx5qVrgGrqzXLK5NeSmGrd0A FUzEkRfXfytn+WoDJPAayfj7aMm0FuhM/9C6TxcCD7HWoeavGdu2JW3j2P66+2iWxkBh T9phs38pWMGStnYERVnMR7KHtnZbVTUVbrmP6ikVRvYxZ1WSxQWoTOgKJX04/UnR3drq Mcps1dLSnRciTzC8SlKQD06XzMoV1yX5GeRMwp/fQ6PR/wDFUKxp4qbV9UWExXJBo7gH SFNQ== X-Forwarded-Encrypted: i=1; AJvYcCXR3rg1YvGG9L6u2grMLFLloK6wUCsW+GWb5WOcXweC/gI+tGmOdUKS744d3O1iTpHf8u0thed4FfeOjBA=@vger.kernel.org X-Gm-Message-State: AOJu0Yz4grxjVX+L7VWXB2VVQuDELUkOPHxNUyISdhRCdgKOJGWraZgZ jZIYjO+Vn6t52OcqcaCpNFoa4A6CaDxtQTdDJx2GJwJ7F/ne2uc/djgmCtqjRKEaGxL3DbCrEU+ GdKSBNg== X-Google-Smtp-Source: AGHT+IHZX+7Jb+2d4opeVjrsbxJXniCxR+KBCLpT/d/Kur/EzCUs9u2aJWg9HoZ3agM9btcjLB8/iGdTa753 X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:22a4:ded5:5c37:fcc7]) (user=irogers job=sendgmr) by 2002:a05:690c:3348:b0:6ea:8395:9af9 with SMTP id 00721157ae682-6ee55cb5a1cmr2057947b3.6.1731979046564; Mon, 18 Nov 2024 17:17:26 -0800 (PST) Date: Mon, 18 Nov 2024 17:16:28 -0800 In-Reply-To: <20241119011644.971342-1-irogers@google.com> Message-Id: <20241119011644.971342-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: <20241119011644.971342-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v7 06/22] perf script: Use openat for directory iteration From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Howard Chu , Athira Jajeev , Michael Petlan , Veronika Molnarova , Dapeng Mi , Thomas Richter , Ilya Leoshkevich , Colin Ian King , Weilin Wang , Andi Kleen , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 when the code exists in a single C file. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/builtin-script.c | 87 +++++++++++++++++++++++++------------ tools/perf/util/path.c | 10 +++++ tools/perf/util/path.h | 1 + 3 files changed, 71 insertions(+), 27 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 2a7e704c0a54..ebf9ac7a97b1 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -3530,27 +3530,35 @@ static void free_dlarg(void) * 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) +static int check_ev_match(int dir_fd, const char *scriptname, struct perf_= session *session) { - char filename[MAXPATHLEN], evname[128]; - char line[BUFSIZ], *p; - struct evsel *pos; - int match, len; + char line[BUFSIZ]; FILE *fp; =20 - scnprintf(filename, MAXPATHLEN, "%s/bin/%s-record", dir_name, scriptname); + { + char filename[FILENAME_MAX + 5]; + int fd; =20 - fp =3D fopen(filename, "r"); - if (!fp) - return -1; + 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; + } =20 while (fgets(line, sizeof(line), fp)) { - p =3D skip_spaces(line); + char *p =3D skip_spaces(line); + if (*p =3D=3D '#') continue; =20 while (strlen(p)) { + int match, len; + struct evsel *pos; + char evname[128]; + p =3D strstr(p, "-e"); if (!p) break; @@ -3593,7 +3601,7 @@ 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]; + int scripts_dir_fd, lang_dir_fd; DIR *scripts_dir, *lang_dir; struct perf_session *session; struct perf_data data =3D { @@ -3602,51 +3610,76 @@ int find_scripts(char **scripts_array, char **scrip= ts_path_array, int num, }; char *temp; int i =3D 0; + const char *exec_path =3D get_argv_exec_path(); =20 session =3D perf_session__new(&data, NULL); if (IS_ERR(session)) return PTR_ERR(session); =20 - snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path()); + { + char scripts_path[PATH_MAX]; =20 - scripts_dir =3D opendir(scripts_path); + 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; } =20 - for_each_lang(scripts_path, scripts_dir, lang_dirent) { - scnprintf(lang_path, MAXPATHLEN, "%s/%s", scripts_path, - lang_dirent->d_name); + 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_path, "perl")) + if (strstr(lang_dirent->d_name, "perl")) continue; #endif #ifndef HAVE_LIBPYTHON_SUPPORT - if (strstr(lang_path, "python")) + if (strstr(lang_dirent->d_name, "python")) continue; #endif =20 - lang_dir =3D opendir(lang_path); - if (!lang_dir) + lang_dir_fd =3D openat(scripts_dir_fd, lang_dirent->d_name, O_DIRECTORY); + if (lang_dir_fd =3D=3D -1) continue; - - for_each_script(lang_path, lang_dir, script_dirent) { + 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; - snprintf(scripts_path_array[i], pathlen, "%s/%s", - lang_path, + 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); =20 - if (check_ev_match(lang_path, - scripts_array[i], session)) + if (check_ev_match(lang_dir_fd, scripts_array[i], session)) continue; =20 i++; 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 */ --=20 2.47.0.338.g60cca15819-goog From nobody Sat Nov 23 15:22:07 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 476A7140E2E for ; Tue, 19 Nov 2024 01:17:32 +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=1731979054; cv=none; b=hEGb20XDRWt9S0p5VApRCj7+1VOjafNswBe5dJbmTDjFSe2R9tbJHR1Plt70B9kn9F/Hv4groffsGeLUhITD57GMb1cNXy68Mh371ovplMn/YZwkKxs4o9lsuCn4oUJ4YLw2nYJ/Wf8ZaMC338vRkAgaiiKWIVjmPfHMMtPGTeI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731979054; c=relaxed/simple; bh=rHwHHBC1gblY1Eotv4xOB/p4hXgB658TOIe86c0QPHY=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=V6Ss7pHGyG3/jCSED8dLoHN1Akf0KlZekvYeu7dE9PGuibqvyHYNDs4IfG4S+1HFxKt0iIr7bpo1xH+H1ICaH7gsLbw0E1fRj81tHY/9BFqWmSNl9MDsP9svmEp4yHPwaydU548pGJgIg0S2btsgu7k5xamBke9vF1EUyzuF24k= 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=uEWMLPKS; 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="uEWMLPKS" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6ee51558e90so67606157b3.1 for ; Mon, 18 Nov 2024 17:17:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731979051; x=1732583851; 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=S6d3NnEtZrqDPZDd85+OpARaP/oSw/tn+LnVNwTbe+g=; b=uEWMLPKS8nUp4TsZ8gM1JJq3KErnIN5H9yLwfcYrCtZ9uv27VgXfYAESzup9jUTANb I1k7llMOaNygdKr/GWIsxdsZ5B5mJUEbCebtDVFTyIw/h+29bE8va2iCGI7L0jCWyMa4 5f0+hBSOKoN475QMbKg8LJXyPmW+usju93CdQ6I0ZSw+MhExkOVvsaWzVKqNwylT01/T iMiZna0t6tpucfkz0l6nTNAwMqBJgjaiCzdTHS5aFHyeP/3rvK4SeYvgn3N3/7FHcZLG qdY1QcTNZRFY32h6I3VWZaVPpKL38CuwEDeBAT9bNfwX6/N5Nqk2e01pUucomN0Eh/lz oA2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731979051; x=1732583851; 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=S6d3NnEtZrqDPZDd85+OpARaP/oSw/tn+LnVNwTbe+g=; b=HvXduPgFy9KOaLr/Y7mBLdW9EIx4yDucFstwFgL/MPMKWx1nO8apIhsVMD1wOSY7ex rd0Jxkq2GKC+6E+2CiKfSoT4jolbFiar3FJKhzGqb8dZy9zYLm6jxGMUWoehRvR4JB7P BJu8X6mbK3AmjjIdyOFT3shQ53/sP+HTfDzCcbfNAUlAsZ50hD9yBkuyy8+ioC90xDhn naWPGh7e8+QbkYHlYCTwEh4S4J2PeSud/UKODazsPQSPS2RgkK8XLEqkWCv6kUrEYqI8 hG88IujaVdxW4/m7D6vpm0LtazWUZv6d/C3IlZJbnBdWvI2OPrCJSGBPhRqacPbilqgd Iw8g== X-Forwarded-Encrypted: i=1; AJvYcCVYyy3uYKPGg2UBsyu53qVvdEmy3BXiVYEqBuVswVZWbvCEux1WGXVy7rQx2F0Op/BeLe85Au1fU/WomeA=@vger.kernel.org X-Gm-Message-State: AOJu0Yzo5IWiQSvBQ+OTPUIGUsmZLt0cx5utcgBlazlmoYxujDYtygYs FH8rqA4k5onTQKkc6Ihm2OmGe7o5IEZdubFU0Xct+ueMLPSjGoR+WpFXjeXenT5V3p2c/MfK+a1 sZFQT5Q== X-Google-Smtp-Source: AGHT+IFZaHT2CJkG0agrDJb6LQCa/4cj+2AVXZD5gCLi1DBVTctbyMVHzwR7j8PooCS7GDEJe/WVAPAnengW X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:22a4:ded5:5c37:fcc7]) (user=irogers job=sendgmr) by 2002:a05:690c:39f:b0:6ec:b74d:9c59 with SMTP id 00721157ae682-6ee55bc4b7bmr1981227b3.2.1731979051315; Mon, 18 Nov 2024 17:17:31 -0800 (PST) Date: Mon, 18 Nov 2024 17:16:29 -0800 In-Reply-To: <20241119011644.971342-1-irogers@google.com> Message-Id: <20241119011644.971342-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: <20241119011644.971342-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v7 07/22] 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 , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/builtin-script.c | 171 ----------------------------- tools/perf/builtin.h | 6 -- tools/perf/ui/browsers/scripts.c | 177 ++++++++++++++++++++++++++++++- tools/perf/util/python.c | 6 -- 4 files changed, 175 insertions(+), 185 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index ebf9ac7a97b1..33f50a17338a 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -3521,177 +3521,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(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. - */ -int find_scripts(char **scripts_array, char **scripts_path_array, int 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; -} - static char *get_script_path(const char *script_root, const char *suffix) { struct dirent *script_dirent, *lang_dirent; diff --git a/tools/perf/builtin.h b/tools/perf/builtin.h index 94f4b3769bf7..a07e93c53848 100644 --- a/tools/perf/builtin.h +++ b/tools/perf/builtin.h @@ -2,10 +2,6 @@ #ifndef BUILTIN_H #define BUILTIN_H =20 -#include -#include -#include - struct feature_status { const char *name; const char *macro; @@ -56,6 +52,4 @@ int cmd_ftrace(int argc, const char **argv); int cmd_daemon(int argc, const char **argv); int cmd_kwork(int argc, const char **argv); =20 -int find_scripts(char **scripts_array, char **scripts_path_array, int num, - int pathlen); #endif diff --git a/tools/perf/ui/browsers/scripts.c b/tools/perf/ui/browsers/scri= pts.c index e437d7889de6..2d04ece833aa 100644 --- a/tools/perf/ui/browsers/scripts.c +++ b/tools/perf/ui/browsers/scripts.c @@ -1,16 +1,18 @@ // SPDX-License-Identifier: GPL-2.0 -#include "../../builtin.h" -#include "../../perf.h" #include "../../util/util.h" // perf_exe() #include "../util.h" +#include "../../util/evlist.h" #include "../../util/hist.h" #include "../../util/debug.h" +#include "../../util/session.h" #include "../../util/symbol.h" #include "../browser.h" #include "../libslang.h" #include "config.h" +#include #include #include +#include #include =20 #define SCRIPT_NAMELEN 128 @@ -77,6 +79,177 @@ static int scripts_config(const char *var, const char *= value, void *data) return 0; } =20 +/* + * Some scripts specify the required events in their "xxx-record" file, + * this function will check if the events in perf.data match those + * mentioned in the "xxx-record". + * + * Fixme: All existing "xxx-record" are all in good formats "-e event ", + * which is covered well now. And new parsing code should be added to + * cover the future complex formats like event groups etc. + */ +static int check_ev_match(int dir_fd, const char *scriptname, struct perf_= session *session) +{ + char line[BUFSIZ]; + FILE *fp; + + { + char filename[FILENAME_MAX + 5]; + int fd; + + scnprintf(filename, sizeof(filename), "bin/%s-record", scriptname); + fd =3D openat(dir_fd, filename, O_RDONLY); + if (fd =3D=3D -1) + return -1; + fp =3D fdopen(fd, "r"); + if (!fp) + return -1; + } + + while (fgets(line, sizeof(line), fp)) { + char *p =3D skip_spaces(line); + + if (*p =3D=3D '#') + continue; + + while (strlen(p)) { + int match, len; + struct evsel *pos; + char evname[128]; + + p =3D strstr(p, "-e"); + if (!p) + break; + + p +=3D 2; + p =3D skip_spaces(p); + len =3D strcspn(p, " \t"); + if (!len) + break; + + snprintf(evname, len + 1, "%s", p); + + match =3D 0; + evlist__for_each_entry(session->evlist, pos) { + if (evsel__name_is(pos, evname)) { + match =3D 1; + break; + } + } + + if (!match) { + fclose(fp); + return -1; + } + } + } + + fclose(fp); + return 0; +} + +/* + * Return -1 if none is found, otherwise the actual scripts number. + * + * Currently the only user of this function is the script browser, which + * will list all statically runnable scripts, select one, execute it and + * show the output in a perf browser. + */ +static int find_scripts(char **scripts_array, char **scripts_path_array, i= nt num, + int pathlen) +{ + struct dirent *script_dirent, *lang_dirent; + int scripts_dir_fd, lang_dir_fd; + DIR *scripts_dir, *lang_dir; + struct perf_session *session; + struct perf_data data =3D { + .path =3D input_name, + .mode =3D PERF_DATA_MODE_READ, + }; + char *temp; + int i =3D 0; + const char *exec_path =3D get_argv_exec_path(); + + session =3D perf_session__new(&data, NULL); + if (IS_ERR(session)) + return PTR_ERR(session); + + { + char scripts_path[PATH_MAX]; + + snprintf(scripts_path, sizeof(scripts_path), "%s/scripts", exec_path); + scripts_dir_fd =3D open(scripts_path, O_DIRECTORY); + pr_err("Failed to open directory '%s'", scripts_path); + if (scripts_dir_fd =3D=3D -1) { + perf_session__delete(session); + return -1; + } + } + scripts_dir =3D fdopendir(scripts_dir_fd); + if (!scripts_dir) { + close(scripts_dir_fd); + perf_session__delete(session); + return -1; + } + + while ((lang_dirent =3D readdir(scripts_dir)) !=3D NULL) { + if (lang_dirent->d_type !=3D DT_DIR && + (lang_dirent->d_type =3D=3D DT_UNKNOWN && + !is_directory_at(scripts_dir_fd, lang_dirent->d_name))) + continue; + if (!strcmp(lang_dirent->d_name, ".") || !strcmp(lang_dirent->d_name, ".= .")) + continue; + +#ifndef HAVE_LIBPERL_SUPPORT + if (strstr(lang_dirent->d_name, "perl")) + continue; +#endif +#ifndef HAVE_LIBPYTHON_SUPPORT + if (strstr(lang_dirent->d_name, "python")) + continue; +#endif + + lang_dir_fd =3D openat(scripts_dir_fd, lang_dirent->d_name, O_DIRECTORY); + if (lang_dir_fd =3D=3D -1) + continue; + lang_dir =3D fdopendir(lang_dir_fd); + if (!lang_dir) { + close(lang_dir_fd); + continue; + } + while ((script_dirent =3D readdir(lang_dir)) !=3D NULL) { + if (script_dirent->d_type =3D=3D DT_DIR) + continue; + if (script_dirent->d_type =3D=3D DT_UNKNOWN && + is_directory_at(lang_dir_fd, script_dirent->d_name)) + continue; + /* Skip those real time scripts: xxxtop.p[yl] */ + if (strstr(script_dirent->d_name, "top.")) + continue; + if (i >=3D num) + break; + scnprintf(scripts_path_array[i], pathlen, "%s/scripts/%s/%s", + exec_path, + lang_dirent->d_name, + script_dirent->d_name); + temp =3D strchr(script_dirent->d_name, '.'); + snprintf(scripts_array[i], + (temp - script_dirent->d_name) + 1, + "%s", script_dirent->d_name); + + if (check_ev_match(lang_dir_fd, scripts_array[i], session)) + continue; + + i++; + } + closedir(lang_dir); + } + + closedir(scripts_dir); + perf_session__delete(session); + return i; +} + /* * When success, will copy the full path of the selected script * into the buffer pointed by script_name, and return 0. diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index f8b291143884..4593c937febb 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1307,12 +1307,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.338.g60cca15819-goog From nobody Sat Nov 23 15:22:07 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 22BDE13EFF3 for ; Tue, 19 Nov 2024 01:17:36 +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=1731979058; cv=none; b=jP9oW06tygGg1THLXctk3g6VljNkejyjIgiYQTgSBJ+k9eE/q3gb12jwnysMtl/RusCH/RnUKAjRNOAY5P89lJ6u18CHVuGIouzcUpRJ0VYKpZLtS5uLIhxzCDTVKoX7FbFYqtRaBd+1kWUdd1ir5lvG8xuPhVZIPHDpOf7dU44= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731979058; c=relaxed/simple; bh=DGojOJgFDaGqdr6kKd74ATAbtPhpAzkCO8jJGHoxK6Q=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=IdRAAVa/Qsej0RR1aQcy87v8l/YGOM68p84NB8qmuAniwU8HRd4zmTWGtCalzSMblO/6OhELHo41uZPTrvnKk0jhO9PGwQEW71/IJUhElDgTAFeqZ7uCQVEPecOe1I9MJ7h7NiivkhRX4ri7ZN/JXQdHVWW7UXslA6afT0bkRVc= 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=YrLL/tzv; 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="YrLL/tzv" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6ee6122ea3fso9654217b3.1 for ; Mon, 18 Nov 2024 17:17:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731979056; x=1732583856; darn=vger.kernel.org; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=+xcdwNCXAapieDjq0EaB/I9Ayk4LLuR25v1wJQOOIu4=; b=YrLL/tzvGQ0/jZqM9j2ek+TLyqpXFhCKtK4s/x44h+TOs1ybLKGy96KFDMnJHLqOtw G+kRtCJaHEVvH6AbebwezaYfNXdj3iQVDydvpiTgfbDY/0TJ95BtdyY5ET6JuXGyMV6V qiN3K2mdXCh/oXzZ3oHOGt0Jv+Bbz5ckL7lAGUsH8zQVCZGQdymPzpTG1UwsFjkO+rC6 gUmpGKq5S3FJv0tttVLWqvbJCqwWhrrdHyDOVZ28W2R6J2jtvJVQwrwOSnVucW0fTYzf IqZs/nWVmOpdRPe4qo9dCr1XcjIaZcg3ohS7PvrEatKoqfk+shYjsBW04nKUJFTTqyHy bkwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731979056; x=1732583856; h=cc: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=+xcdwNCXAapieDjq0EaB/I9Ayk4LLuR25v1wJQOOIu4=; b=ib6enL1xPI0EyhpKIe7xdkHHiBJlJCpubIbazUjkXMlZ6IrV9IgoaYWjZwVeZBe/XA haEvYV6PTqDyYGaVj9quzE9B2NwyMlOR+2JJi56Ype0M+InyESr/ytY4A/7usNDuYuVw BgudxyI/xYRjgaY8l+wSghqgdA3NL+JHa2oRSYeJL98Bzpww6NB4SxYc/lPiMDn4ko6v HdAO86pA3VVha4jywPSzgc1AHgpX1sy1sFzfoBTDeCC0KaXxXe7i64jZR4I4lQV4odSM b+vrdD4xu8bx2nhIqPalcl0vK0MarN1kGWi2qbyGKgm6L6ydZKYAH3H8ycRTK1C4hgTu HeQw== X-Forwarded-Encrypted: i=1; AJvYcCUYgU+p+zw+7vtYkW2rv6OHgIE0LatNaJQlEUchU3pOo0pk0nTP2VxXTP1iGmQXu0g0jYcHwa3fZhPv9OQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzWTDpH+cqF/qxVDOj6poJf/v+DHreKBok4CsjAou0q5G/j2C4i Mi+PMCTQHTeM+uZU7vOoZB2OAa9N5yKwMdWcikRdz8myCoBY/HUiLdhioyeq7voJ+vPxxXbIM9t EiSZJSw== X-Google-Smtp-Source: AGHT+IEe+hj2e22w4ZCW8LOneiD3eQ1sChTs4Nn/28644fdsvqWLXr0L7ggq538XuoPZiS3IQfss1cZAksHU X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:22a4:ded5:5c37:fcc7]) (user=irogers job=sendgmr) by 2002:a05:690c:dc2:b0:6ee:93e6:caac with SMTP id 00721157ae682-6ee93e6ceebmr3218167b3.7.1731979056100; Mon, 18 Nov 2024 17:17:36 -0800 (PST) Date: Mon, 18 Nov 2024 17:16:30 -0800 In-Reply-To: <20241119011644.971342-1-irogers@google.com> Message-Id: <20241119011644.971342-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: <20241119011644.971342-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v7 08/22] 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 , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo 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 Acked-by: Arnaldo Carvalho de Melo --- 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 | 10 ---------- tools/perf/util/stat.h | 3 ++- 6 files changed, 38 insertions(+), 46 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 33f50a17338a..0ba1866dbeef 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 fdf5172646a5..77e327d4a9a7 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 4593c937febb..7fc3ec5684c3 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -17,8 +17,6 @@ #include "trace-event.h" #include "mmap.h" #include "util/env.h" -#include "util/kvm-stat.h" -#include "util/stat.h" #include "util/kwork.h" #include "util/sample.h" #include "util/lock-contention.h" @@ -1307,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.338.g60cca15819-goog From nobody Sat Nov 23 15:22:07 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 C7AC4146A62 for ; Tue, 19 Nov 2024 01:17:41 +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=1731979063; cv=none; b=hIFjJq+6qRvyx9/UaD3WtUK9meG8yrbiwdo/4gVvxOhS6Y66izqgYH9scBk9/ncH3Ldyd4V2bsUTajNWhvz7wFiy1jG7ETk+p+lo2DqCbhH79oNbD5V8Y6S4/eq0PwytyG8CSKCV9qViVunEPR/fIHnHpUYF1t7xPpp7YsKPqtk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731979063; c=relaxed/simple; bh=tNLAJ2pb8obJOYMSxFIC+cjFcupLOrxX//i30q8z1rA=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=m899No7TsfZ3eNdcOskS4LSJnv1Zdrhenn07qhFEt0IGkS4mQFux6eRH5+NuBFH90VMctY11BELcUMkrRIl9tbcCUfs2ESweIaw4LaEE2RLaaQztpBycnNCBNm6Mj/oig07NIrfo3rRS6JBWLn4Og6YanYPYhmkdMwv0JJvmePc= 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=gXn1bRk4; 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="gXn1bRk4" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6eae6aba72fso47282517b3.2 for ; Mon, 18 Nov 2024 17:17:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731979061; x=1732583861; darn=vger.kernel.org; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=zn6zJFygLNqQr5gPeWc0c56TIYgfhddx4cdxbohjhZs=; b=gXn1bRk4T/FJStWsXCnEhvCzvPyMs5LzhveUCYqPdbPS9UoC998mX7OCNGNjgSf9dd U82HyTXtB7P09IvGUPWUF6bzawfqEfIr+KLaTQaZzDPvRU/k0GVQPZK6ljj2NmJ8eoGa hpgAIEY62w1C1zfBalRrnpAfloatBw5Eb64QOp56ffqYz2AeGigPloUfWLykIRZKBxqw 8hG1z3Vg4KNkrLv5G0QCmRrFzAj2MKaK3MyFYKmpi+dlxFT6Nk9+iKUXXqhb5P+/Rf3x vUyAUp0T7OU0xfh3e3Kdy74aiAQCEFz0f2+DOHUYcupQ+kuFbZohOK5YfMudEQ/zQRDb 08PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731979061; x=1732583861; h=cc: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=zn6zJFygLNqQr5gPeWc0c56TIYgfhddx4cdxbohjhZs=; b=kf1SqouL8LwnylCHijsMBroEjm6uvQmCgIOqlCTnl7Yl22H+EbZyTZcIquWSGE+n/9 5ZVDVoixYacmN3nSNVujMevkJ6rCKaqRU484Z1ND/WZWIwTBpY2h4bNMlejAL3qrETcM OWa9Q227UYD9/ppTFHCbH/p0rQ37wIYdhQOFDmP1mW25UMisqW+gLyw4EG2iCNwJIkAN Tgt97E/WeIKH6vGkibS+A6jZUpfko2mDobXTKnr/DZc74ja5NQWbPpdse2Ravr9OaniJ utP+slxjS7UapyzwENrt8k+h8kcFxgBUGMjnx+RziOv5YiG4wlH4Q4jkNHm0L40emDfn Qwsg== X-Forwarded-Encrypted: i=1; AJvYcCWY9ja5WW4apcuPK4wCiff26vG6w5gS2o4ohbk+MTM1Cq/RCarAyLhVUx5UjNzHTRHs2S1VaQQrGQTuhv8=@vger.kernel.org X-Gm-Message-State: AOJu0YxZ6pCRG+Y1fbvPcnEpBv48fPm6fCaVvHbTyTGKFsTVuwRNllZR /PVVIh6qWuECbb+2Qzjren46m+Lis/sxrkxjXGf3gl+kpATDDFnRGxS13bO6PvjnmBQKqvZuXsE iBt2QqA== X-Google-Smtp-Source: AGHT+IGSCaZ/uVjD7usDHxw9ALNuw5YvhZD4nY+/OTM4rPAXQXTu362uAegaLMkp3WXzWDceXc5+BMM44IUn X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:22a4:ded5:5c37:fcc7]) (user=irogers job=sendgmr) by 2002:a81:ad0a:0:b0:62c:ea0b:a447 with SMTP id 00721157ae682-6ee55a3b7ebmr1874697b3.2.1731979060734; Mon, 18 Nov 2024 17:17:40 -0800 (PST) Date: Mon, 18 Nov 2024 17:16:31 -0800 In-Reply-To: <20241119011644.971342-1-irogers@google.com> Message-Id: <20241119011644.971342-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: <20241119011644.971342-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v7 09/22] 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 , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo 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 Acked-by: Arnaldo Carvalho de Melo --- 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 0ba1866dbeef..b4deae110dbe 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2956,79 +2956,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 7fc3ec5684c3..d157aaa4bb53 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 d514db1df27f..4b7f0592850b 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 79b939f947dd..29cae98695c9 100644 --- a/tools/perf/util/trace-event.h +++ b/tools/perf/util/trace-event.h @@ -113,7 +113,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.338.g60cca15819-goog From nobody Sat Nov 23 15:22:07 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 705821494B5 for ; Tue, 19 Nov 2024 01:17:46 +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=1731979069; cv=none; b=bZLLV5oy6s5xffzqTfQ4hSIxsID6ft5e73sxE4IFB3GrNj1i/txPQvRUb/PsP/7Wl0hYi9hz8vqtfhuU/q4gB5kvvp+3WEtdUIJc+3Ce83piQu+w0oaRnZjCxMoA1Ei3bL32Jxp9YoY/EyXxF+/IyTZ0eTP9p6dxu+C6rfXgSWI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731979069; c=relaxed/simple; bh=mJSrPca5xu9Il6Rd7sHhJRBEViSSDCLuBHlUxLuMNgc=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=p4vd95p2niGyWb4OssKYfaGd5DxsdkOUIi5TspEYB1VoqV57SHKQ/ziGWx9LEpaxWw5lu+qVrBa/X0YknQyIB91qxQHgZb+q9PlKVxi+XEDBV+pNJrTEAaaCwOL87tPI2DkWND7Q2QktVrL+BBiJGQiZdAV6Mg/qczAZJC0PJW4= 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=2jLXeoiY; 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="2jLXeoiY" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6ea8794f354so35943097b3.2 for ; Mon, 18 Nov 2024 17:17:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731979065; x=1732583865; darn=vger.kernel.org; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=eCE4YtIOIkBMj88bSVv4YKfyltH3locf0NanFOHXWYE=; b=2jLXeoiYhWGPfj5xpQky69r0Ii3Dac6G1CuUAaQVeJtpUGBqbD5NQxaz6vvMPupKWv pMYYB11rgaF9iOsBHzXzLjFDfAPqeN/vM+ammf+5Kcgs/oxSCHz2orNwLgzfSE5rUzZS R8NSEpBS4o6SmB+TcDNXTOhxfXC6gwimKYeNi4KXlNQ0vQuptdoWwKRP+apSvL6eZh/R MgGRQzo4ur9iWrGfRl5iCQ+OYagy5085HYBKJ0Vrm1logmW9h5lkVnfxBQ3wjwnjPnfq IPjR5SR+i3dNIFfXbhwPkI7YPGIVhhPsRpw3ltxcwiRIvVUyPZDU8kM0F0+P1uwcdx/m ekUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731979065; x=1732583865; h=cc: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=eCE4YtIOIkBMj88bSVv4YKfyltH3locf0NanFOHXWYE=; b=k/Q1l8OrsuZjZEkzF3+6VZZ7BgsJ6xLK1m5NJAC2bTwKdX29XgFiUsRUYHlblyfEnQ qmm50TFwyn2ejcGOXS/6/jc4V/Wv+LnL3KeIF9fRuaBYTzVaPnkGbJ0m2lgQiklQyXRU Oaaa7ARHYfS++PaeJyxDaNJQNvWBkPo6mg7HFyZdAwSE2JOtQ+SQytLnE7wLZlA2m30L Y1DF+cK+BOlGOkvDAjbyiMHHKrHgemsUNMMrdc27pJjx/pX/9BnB2g0iH7pwZ7JwpNWF TZa/zOQpU+NnYTpNC1/Gc/3WVu2qgj3FCpAHbRD3STSk30XcEqFaUV4yd7j35zcIDl+8 2bdw== X-Forwarded-Encrypted: i=1; AJvYcCUDAgajzzpO4SU3/OpnTiRuqykhX/v38lMVgOt0l0EjNhKwPKV2VAMRuy8oRrhlipo+AV5C2pkxccpiUM4=@vger.kernel.org X-Gm-Message-State: AOJu0YzhvTWFtUqfz2p4jNXH+0P/94YgRX2UTYOxkQsd1c10iHmkf+PZ op7cVWQORbGaqf+vK5fT2HkpCU8vnpzcOgfMYzeE2ugmXeKoGh66WECf9i0oiP3H/CvNMv9aitr XnudD3Q== X-Google-Smtp-Source: AGHT+IEOeFgVhKuEfshpZnlgHDjT1x9lft9uTCt8rPStqD2MYO/b9X3X43p9ST6WusPaV/SusARyQ27Xsuep X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:22a4:ded5:5c37:fcc7]) (user=irogers job=sendgmr) by 2002:a05:690c:80a:b0:6e3:14c3:379a with SMTP id 00721157ae682-6ee558cd218mr1669157b3.0.1731979065532; Mon, 18 Nov 2024 17:17:45 -0800 (PST) Date: Mon, 18 Nov 2024 17:16:32 -0800 In-Reply-To: <20241119011644.971342-1-irogers@google.com> Message-Id: <20241119011644.971342-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: <20241119011644.971342-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v7 10/22] 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 , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo 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. Signed-off-by: Ian Rogers Acked-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-script.c | 15 +-------------- .../perf/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 | 14 ++++++++++++++ tools/perf/util/trace-event.h | 2 +- 6 files changed, 19 insertions(+), 23 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index b4deae110dbe..035ce4bc1d22 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 d157aaa4bb53..3ade7b05def2 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 4b7f0592850b..ea32f89b9889 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,16 @@ void setup_perl_scripting(void) } #endif #endif + +__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, 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 29cae98695c9..88b178ecab80 100644 --- a/tools/perf/util/trace-event.h +++ b/tools/perf/util/trace-event.h @@ -117,7 +117,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.338.g60cca15819-goog From nobody Sat Nov 23 15:22:07 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 5D84C12E1CD for ; Tue, 19 Nov 2024 01:17:51 +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=1731979073; cv=none; b=KvOTVHd6oV6/vKjybiL827F/cGPxE1xARWXjREeZYqYKb1Y/MglCr2BplsoA4pTnvSUDVT/Jtb5PO+cm+zHAWOTQlbc0JeX2+SzNhuNCGFuTyORWYeIXVkDJvH0pVzldRVJxI7HrBNBfc4+dhKvrNa/jRc1iPx6lCCDYaTRn50c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731979073; c=relaxed/simple; bh=/w8NTIgr104Kfgj2zoZAYtgOROs+FMS0JjJMYTgXSLA=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=faTcoRyozN5AJJukazJRpp2tfe3kLaki8TVMk6NPHBhzSIwrw+ZtANGBJ6NasMiuNw09tLhNMB9WyF20QCTvzAq9USg0A0XvDyIXF1VFKe1LelvHymH2fRzgi8vXvKJGCeVpfQfwwIrmvyNAXmTP+fdMOC9hwC4YL6l2KnE0c2M= 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=VkCIQaRU; 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="VkCIQaRU" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e389ef22432so2554135276.0 for ; Mon, 18 Nov 2024 17:17:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731979070; x=1732583870; 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=yFPR9oauthi0aRn/j9trqG00Ts+P8WjslP9hmy4vrr4=; b=VkCIQaRUL7NOFxo+VR6R+PSiroJpBp5JDc/P+HBrS4oyV2dnpb8NwjvS/OTfIKZG/j 5XTnK/WpdpVb93lwe5kjyev4H1WtrhxjdXIHder3Tnv1+PIJjsriognaCLWE2onh4doh J7basLiGnTLIAPSgkBzhdZaC4TQu4eq5YKmPuSURqA7zJkU0g88C858YdupAEN/vQpSZ MJMtZ287LX8HmctKCBEaO7z/Bi9y9mHpxGaIFCz/19/BsZJ/DwA8X85eZKYTAKLqwMdI uL0TM18QJ+zPfDWW2VPzHNpWt34i+KeIIxLV8JdEZg/IoUxbBH+pydVY4KBwhD88ToPL xMxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731979070; x=1732583870; 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=yFPR9oauthi0aRn/j9trqG00Ts+P8WjslP9hmy4vrr4=; b=QpEpETClGMjJENgLUD9AJqYguosDUvqb2FFqtrgvMLs2lsVIS8FzPWGPflOLuyEY94 R+OUrkB6x+KOigkYYvU28NTaJB1RIsV/g0bku9H9LoEYP1AwZu2Q22HKMX/ad0g/Iv9Y Zu9v437x/Vx0hiLrSytfLt5tqFkr+U/8ToQhHmLJTZw5UPuFZJV9J8EK7L5lKmYTyc0W h/Ea1tSgNjAuzbs5JVDvsI4PgO4SV6jT+VPDk4giXKIHkntxZ/Po6Er35luwZwrS2U+K t4FNziP1UDVvnOHUeY0dzahSfv67OsfyEbpfT+sWWvrO297h56rq+frU8WAPjPHW5nsY Cblg== X-Forwarded-Encrypted: i=1; AJvYcCUeXLL0cFUw3DaELFZm7QZVEWadnT+hgsBdWzZG4n+LGn82jwZ4KJ2q68Dgwe+dPezH+YvZsZ2gqNaPf2A=@vger.kernel.org X-Gm-Message-State: AOJu0YzPZ7uoifjhSxVtQixTsNRgO3YL3hLWUOZjLbNGyi4ieNObQswC Mue1sdRVqwZGlh4zlFh7Liecq101W9iXOtxVIKlmUrgaoU8L83/UP60kpsO0AuwQMUQqu7YAuPu C1Otlww== X-Google-Smtp-Source: AGHT+IH3+3ZwXdwwGASzkD/cHnJw44DJg8SYtVWEp54QVryG4e3YjOAMS6dWrlBjd9SsvwVFIIYYwCBx6VBK X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:22a4:ded5:5c37:fcc7]) (user=irogers job=sendgmr) by 2002:a25:3d47:0:b0:e25:cea9:b0e with SMTP id 3f1490d57ef6-e38265e2cf2mr10475276.9.1731979070315; Mon, 18 Nov 2024 17:17:50 -0800 (PST) Date: Mon, 18 Nov 2024 17:16:33 -0800 In-Reply-To: <20241119011644.971342-1-irogers@google.com> Message-Id: <20241119011644.971342-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: <20241119011644.971342-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v7 11/22] perf script: Move perf_sample__sprintf_flags to trace-event-scripting.c From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Howard Chu , Athira Jajeev , Michael Petlan , Veronika Molnarova , Dapeng Mi , Thomas Richter , Ilya Leoshkevich , Colin Ian King , Weilin Wang , Andi Kleen , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" perf_sample__sprintf_flags is used in the python C code and so needs to be in the util library rather than a builtin. Signed-off-by: Ian Rogers --- tools/perf/builtin-script.c | 81 ------------------------ tools/perf/util/python.c | 6 -- tools/perf/util/trace-event-scripting.c | 83 +++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 87 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 035ce4bc1d22..33ad225d2b0d 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -1693,87 +1693,6 @@ static int perf_sample__fprintf_bts(struct perf_samp= le *sample, return printed; } =20 -static struct { - u32 flags; - const char *name; -} sample_flags[] =3D { - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL, "call"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_RETURN, "return"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CONDITIONAL, "jcc"}, - {PERF_IP_FLAG_BRANCH, "jmp"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_INTERRUPT, "int"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_RETURN | PERF_IP_FLAG_INTERRUPT, "ire= t"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_SYSCALLRET, "sysc= all"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_RETURN | PERF_IP_FLAG_SYSCALLRET, "sy= sret"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_ASYNC, "async"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_ASYNC | PERF_IP_F= LAG_INTERRUPT, "hw int"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TX_ABORT, "tx abrt"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TRACE_BEGIN, "tr strt"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TRACE_END, "tr end"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_VMENTRY, "vmentry= "}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_VMEXIT, "vmexit"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_BRANCH_MISS, "br miss"}, - {0, NULL} -}; - -static const char *sample_flags_to_name(u32 flags) -{ - int i; - - for (i =3D 0; sample_flags[i].name ; i++) { - if (sample_flags[i].flags =3D=3D flags) - return sample_flags[i].name; - } - - return NULL; -} - -int perf_sample__sprintf_flags(u32 flags, char *str, size_t sz) -{ - u32 xf =3D PERF_IP_FLAG_IN_TX | PERF_IP_FLAG_INTR_DISABLE | - PERF_IP_FLAG_INTR_TOGGLE; - const char *chars =3D PERF_IP_FLAG_CHARS; - const size_t n =3D strlen(PERF_IP_FLAG_CHARS); - const char *name =3D NULL; - size_t i, pos =3D 0; - char xs[16] =3D {0}; - - if (flags & xf) - snprintf(xs, sizeof(xs), "(%s%s%s)", - flags & PERF_IP_FLAG_IN_TX ? "x" : "", - flags & PERF_IP_FLAG_INTR_DISABLE ? "D" : "", - flags & PERF_IP_FLAG_INTR_TOGGLE ? "t" : ""); - - name =3D sample_flags_to_name(flags & ~xf); - if (name) - return snprintf(str, sz, "%-15s%6s", name, xs); - - if (flags & PERF_IP_FLAG_TRACE_BEGIN) { - name =3D sample_flags_to_name(flags & ~(xf | PERF_IP_FLAG_TRACE_BEGIN)); - if (name) - return snprintf(str, sz, "tr strt %-7s%6s", name, xs); - } - - if (flags & PERF_IP_FLAG_TRACE_END) { - name =3D sample_flags_to_name(flags & ~(xf | PERF_IP_FLAG_TRACE_END)); - if (name) - return snprintf(str, sz, "tr end %-7s%6s", name, xs); - } - - for (i =3D 0; i < n; i++, flags >>=3D 1) { - if ((flags & 1) && pos < sz) - str[pos++] =3D chars[i]; - } - for (; i < 32; i++, flags >>=3D 1) { - if ((flags & 1) && pos < sz) - str[pos++] =3D '?'; - } - if (pos < sz) - str[pos] =3D 0; - - return pos; -} - static int perf_sample__fprintf_flags(u32 flags, FILE *fp) { char str[SAMPLE_FLAGS_BUF_SIZE]; diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 3ade7b05def2..fa3ab954662c 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 ea32f89b9889..c5a122e3acec 100644 --- a/tools/perf/util/trace-event-scripting.c +++ b/tools/perf/util/trace-event-scripting.c @@ -15,6 +15,7 @@ =20 #include "archinsn.h" #include "debug.h" +#include "event.h" #include "trace-event.h" #include "evsel.h" #include @@ -283,3 +284,85 @@ void script_fetch_insn(struct perf_sample *sample, str= uct thread *thread, if (sample->insn_len =3D=3D 0 && native_arch) arch_fetch_insn(sample, thread, machine); } + +static const struct { + u32 flags; + const char *name; +} sample_flags[] =3D { + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL, "call"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_RETURN, "return"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CONDITIONAL, "jcc"}, + {PERF_IP_FLAG_BRANCH, "jmp"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_INTERRUPT, "int"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_RETURN | PERF_IP_FLAG_INTERRUPT, "ire= t"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_SYSCALLRET, "sysc= all"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_RETURN | PERF_IP_FLAG_SYSCALLRET, "sy= sret"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_ASYNC, "async"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_ASYNC | PERF_IP_F= LAG_INTERRUPT, + "hw int"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TX_ABORT, "tx abrt"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TRACE_BEGIN, "tr strt"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TRACE_END, "tr end"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_VMENTRY, "vmentry= "}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_VMEXIT, "vmexit"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_BRANCH_MISS, "br miss"}, + {0, NULL} +}; + +static const char *sample_flags_to_name(u32 flags) +{ + int i; + + for (i =3D 0; sample_flags[i].name ; i++) { + if (sample_flags[i].flags =3D=3D flags) + return sample_flags[i].name; + } + + return NULL; +} + +int perf_sample__sprintf_flags(u32 flags, char *str, size_t sz) +{ + u32 xf =3D PERF_IP_FLAG_IN_TX | PERF_IP_FLAG_INTR_DISABLE | + PERF_IP_FLAG_INTR_TOGGLE; + const char *chars =3D PERF_IP_FLAG_CHARS; + const size_t n =3D strlen(PERF_IP_FLAG_CHARS); + const char *name =3D NULL; + size_t i, pos =3D 0; + char xs[16] =3D {0}; + + if (flags & xf) + snprintf(xs, sizeof(xs), "(%s%s%s)", + flags & PERF_IP_FLAG_IN_TX ? "x" : "", + flags & PERF_IP_FLAG_INTR_DISABLE ? "D" : "", + flags & PERF_IP_FLAG_INTR_TOGGLE ? "t" : ""); + + name =3D sample_flags_to_name(flags & ~xf); + if (name) + return snprintf(str, sz, "%-15s%6s", name, xs); + + if (flags & PERF_IP_FLAG_TRACE_BEGIN) { + name =3D sample_flags_to_name(flags & ~(xf | PERF_IP_FLAG_TRACE_BEGIN)); + if (name) + return snprintf(str, sz, "tr strt %-7s%6s", name, xs); + } + + if (flags & PERF_IP_FLAG_TRACE_END) { + name =3D sample_flags_to_name(flags & ~(xf | PERF_IP_FLAG_TRACE_END)); + if (name) + return snprintf(str, sz, "tr end %-7s%6s", name, xs); + } + + for (i =3D 0; i < n; i++, flags >>=3D 1) { + if ((flags & 1) && pos < sz) + str[pos++] =3D chars[i]; + } + for (; i < 32; i++, flags >>=3D 1) { + if ((flags & 1) && pos < sz) + str[pos++] =3D '?'; + } + if (pos < sz) + str[pos] =3D 0; + + return pos; +} --=20 2.47.0.338.g60cca15819-goog From nobody Sat Nov 23 15:22:07 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 9562114C5BF for ; Tue, 19 Nov 2024 01:17:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731979078; cv=none; b=ik55Zji6hFZoQC/7uJxR9mC1fq8rmufZskreEiIi75gdsOAzBqaxDTvZfyK6qtpXECQFVcs1mqadYf0dmay0X/jvcZd32umfT1+GTLlZNoCs+JenecXFWfRTKtD5xhsBWi6AvT7sXUcXaVQpDdwQvUR8Qg+n82VGWYV3tU4vu3s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731979078; c=relaxed/simple; bh=lWHfr2rYjjTAVvjKQhVFfqILAs+IvHGudhgoCfezPS0=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=PFHZiYHz5x+WhJ3AmZzB1DJR0yUaym91WHKzOu0QElrFB5e/ybHNx+TqqTqDnKo9ceDXeO3h+nffXHN0rQguL5CdclW4nuI3eiZEW4skFsGYAkBSSSm7sLLtKDmhi5MdXu+b3ZDUE1by+ALy8RBxWLhlhTjqqV3wB+Si8FRj+Tw= 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=Vk8fSqqm; 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="Vk8fSqqm" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e389bce28b5so2362712276.1 for ; Mon, 18 Nov 2024 17:17:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731979075; x=1732583875; 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=YVLESGGD1kSFTjeckLJ+J+mJtCw8XRUyS8gkZ96eGT0=; b=Vk8fSqqm7LPFrPH7aZex0Fpp66p9eCveWkpl9jKMVAq+iGKBNxftHqhVszrKIoJZoS c06fxpdKmHD2SOHyQveicPp7V+5aGtCbTQN5tAT9eLkW18+/9udNByqd2WaKlUlVawIr n35QnO2D69gKYSkBoBZgf/7qd32THCjHNubXtju16Emfzipxn+0c6hyta6p/nI5cgLAy gLsVCilFG/Y9G1EGghxil2OKrRNJlrpSbUVjcAP4QEUn8WwusMnqnkrOzPBzC170/5T+ PlS/53+bH0psm7nzpbDyVhlm3w9faPo8zwozbiombVSinFhEH+nE+nyGOKpy4JtR1CTz 1Fng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731979075; x=1732583875; 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=YVLESGGD1kSFTjeckLJ+J+mJtCw8XRUyS8gkZ96eGT0=; b=MbdaEkTeNyJkFIJpxlvELcu4ajl5vOTsZuOSZXQoQAdL7BVADS5ZFVRufaPCUNBqyN f5AaX58U5FIAxwP9FkJlD1qrav74kXifQhBrSHqCQBn/pru2pXuF44PdHJrXFcdBTkW5 o850dlZIrVf/gl/cJmWoOSP+jActTSZfSLbVXB7VLxgYFH7N/EARr7MQ+yj8peBgy3pR VP0KqeISeA/SkKlHimR4tyTeBpWXI0fXVfPN+uGnhdOfXF+U/pLb+CuQa4ubldl5yNj7 gIBBQDAufgRKIBshSKH2AhYaXTg8k6EJoHqo59M89+1n4uPyHtn5tAPacUt+mO6C8ocg nIbg== X-Forwarded-Encrypted: i=1; AJvYcCWGllTcKlpqj2xblPAcNDg2Fz2KO2xnXHGXIq3dCpCsPJdGP+V5+BRiISCsb9kc+xrqo06r807530d8NkE=@vger.kernel.org X-Gm-Message-State: AOJu0YxULW6WsJt63yrP5Z7B7Meh654P6tKCW0emF/4SpSnuJyiqVT3/ g1caK6zZMTf3z2ytF0G2Z5euvIlOMklOcvxuLc7Z+d7bJ3spdwYx6BYccR6brEX8fGAjB9/HKqM TcB8UIw== X-Google-Smtp-Source: AGHT+IEa1qgxPOPkryHjLaB1j5uAeGIL4ppdRyvhyXVa78wKwCUiL+ccAaiAMsuVazxhkO7Sfql52w79TUtg X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:22a4:ded5:5c37:fcc7]) (user=irogers job=sendgmr) by 2002:a05:690c:8c1b:b0:6ea:decd:84e with SMTP id 00721157ae682-6ee55c8bd7amr491357b3.5.1731979074935; Mon, 18 Nov 2024 17:17:54 -0800 (PST) Date: Mon, 18 Nov 2024 17:16:34 -0800 In-Reply-To: <20241119011644.971342-1-irogers@google.com> Message-Id: <20241119011644.971342-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: <20241119011644.971342-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v7 12/22] perf x86: Define arch_fetch_insn in NO_AUXTRACE builds From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Howard Chu , Athira Jajeev , Michael Petlan , Veronika Molnarova , Dapeng Mi , Thomas Richter , Ilya Leoshkevich , Colin Ian King , Weilin Wang , Andi Kleen , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" archinsn.c containing arch_fetch_insn was only enabled with CONFIG_AUXTRACE, but this meant that a NO_AUXTRACE build on x86 would use the empty weak version of arch_fetch_insn - weak symbols are a frequent source of errors like this and are outside of the C specification. Change it so that archinsn.c is always built on x86 and make the weak symbol empty version of arch_fetch_insn a strong one guarded by ifdefs. arch_fetch_insn on x86 depends on insn_decode which is a function included then built into intel-pt-insn-decoder.c. intel-pt-insn-decoder.c isn't built in a NO_AUXTRACE=3D1 build. Separate the insn_decode function from intel-pt-insn-decoder.c by just directly compiling the relevant file. Guard this compilation to be for either always on x86 (because of the use in arch_fetch_insn) or when auxtrace is enabled. Apply the CFLAGS overrides as necessary, reducing the amount of code where warnings are disabled. Signed-off-by: Ian Rogers Tested-by: Adrian Hunter --- tools/perf/arch/x86/util/Build | 2 +- tools/perf/util/Build | 2 +- tools/perf/util/intel-pt-decoder/Build | 18 ++++++++++++++---- .../intel-pt-decoder/intel-pt-insn-decoder.c | 3 --- tools/perf/util/trace-event-scripting.c | 4 +++- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/tools/perf/arch/x86/util/Build b/tools/perf/arch/x86/util/Build index 848327378694..06d7c0205b3d 100644 --- a/tools/perf/arch/x86/util/Build +++ b/tools/perf/arch/x86/util/Build @@ -15,6 +15,6 @@ perf-util-$(CONFIG_LOCAL_LIBUNWIND) +=3D unwind-libunw= ind.o perf-util-$(CONFIG_LIBDW_DWARF_UNWIND) +=3D unwind-libdw.o =20 perf-util-$(CONFIG_AUXTRACE) +=3D auxtrace.o -perf-util-$(CONFIG_AUXTRACE) +=3D archinsn.o +perf-util-y +=3D archinsn.o perf-util-$(CONFIG_AUXTRACE) +=3D intel-pt.o perf-util-$(CONFIG_AUXTRACE) +=3D intel-bts.o diff --git a/tools/perf/util/Build b/tools/perf/util/Build index cc6962407376..21b497df440b 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -123,7 +123,7 @@ 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-y +=3D intel-pt-decoder/ perf-util-$(CONFIG_AUXTRACE) +=3D intel-pt.o perf-util-$(CONFIG_AUXTRACE) +=3D intel-bts.o perf-util-$(CONFIG_AUXTRACE) +=3D arm-spe.o diff --git a/tools/perf/util/intel-pt-decoder/Build b/tools/perf/util/intel= -pt-decoder/Build index 30793d08c6d4..f99d150059b9 100644 --- a/tools/perf/util/intel-pt-decoder/Build +++ b/tools/perf/util/intel-pt-decoder/Build @@ -9,14 +9,24 @@ $(OUTPUT)util/intel-pt-decoder/inat-tables.c: $(inat_tabl= es_script) $(inat_table =20 # Busybox's diff doesn't have -I, avoid warning in the case =20 -$(OUTPUT)util/intel-pt-decoder/intel-pt-insn-decoder.o: util/intel-pt-deco= der/intel-pt-insn-decoder.c $(OUTPUT)util/intel-pt-decoder/inat-tables.c +ifeq ($(SRCARCH),x86) + perf-util-y +=3D inat.o insn.o +else + perf-util-$(CONFIG_AUXTRACE) +=3D inat.o insn.o +endif + +$(OUTPUT)util/intel-pt-decoder/inat.o: $(srctree)/tools/arch/x86/lib/inat.= c $(OUTPUT)util/intel-pt-decoder/inat-tables.c $(call rule_mkdir) $(call if_changed_dep,cc_o_c) =20 -CFLAGS_intel-pt-insn-decoder.o +=3D -I$(OUTPUT)util/intel-pt-decoder +CFLAGS_inat.o +=3D -I$(OUTPUT)util/intel-pt-decoder + +$(OUTPUT)util/intel-pt-decoder/insn.o: $(srctree)/tools/arch/x86/lib/insn.c + $(call rule_mkdir) + $(call if_changed_dep,cc_o_c) =20 ifeq ($(CC_NO_CLANG), 1) - CFLAGS_intel-pt-insn-decoder.o +=3D -Wno-override-init + CFLAGS_insn.o +=3D -Wno-override-init endif =20 -CFLAGS_intel-pt-insn-decoder.o +=3D -Wno-packed +CFLAGS_insn.o +=3D -Wno-packed diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c b/too= ls/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c index 47cf35799a4d..8fabddc1c0da 100644 --- a/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c +++ b/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c @@ -11,9 +11,6 @@ #include #include "../../../arch/x86/include/asm/insn.h" =20 -#include "../../../arch/x86/lib/inat.c" -#include "../../../arch/x86/lib/insn.c" - #include "event.h" =20 #include "intel-pt-insn-decoder.h" diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trac= e-event-scripting.c index c5a122e3acec..ab90778b8172 100644 --- a/tools/perf/util/trace-event-scripting.c +++ b/tools/perf/util/trace-event-scripting.c @@ -272,11 +272,13 @@ void setup_perl_scripting(void) #endif #endif =20 -__weak void arch_fetch_insn(struct perf_sample *sample __maybe_unused, +#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 =20 void script_fetch_insn(struct perf_sample *sample, struct thread *thread, struct machine *machine, bool native_arch) --=20 2.47.0.338.g60cca15819-goog From nobody Sat Nov 23 15:22:07 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 0E54F14EC4B for ; Tue, 19 Nov 2024 01:18:00 +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=1731979082; cv=none; b=dld3bxHLYvRs5PARj0s5WuRM4ZcrDSEUjdt6QJxhLKdejmoViehmHlYo2PnKHJ00WaTfPbO8wCuaVtup15EQjfvhHMAplng5lt8tRO4Sfueh25q6+iG5KDB+1f9jZgcM7X5NoBqk/IOSfBoIvZhOUjfLDxFfiXTai8WFOfomDGg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731979082; c=relaxed/simple; bh=HtA+/VMRAFKGJnTE0aeWCJPRPsBs39WpjsNc7oQJRsM=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=r6vaTQDDT/MkpbDOYKlDFpSWmfYzBiBrYQTnUBY1q2YFR+BPAJc9kn7mXk+9uTPqfQbpNvi5YBIQDkknHv4o4t0Gqap16+fzRvB/eHZtnSnkbn/v2Mc38uXy6158QCPeN7abMzt92AXYHqghGJjIkEabmimZjWNrEe61Ou4lxBI= 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=EO4HASe6; 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="EO4HASe6" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e293150c2c6so5365008276.1 for ; Mon, 18 Nov 2024 17:18:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731979080; x=1732583880; 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=LiB6WPAUFBLTutmf66Jh2bwqLt5nfeR6J1OUSjouKLs=; b=EO4HASe6v7FXLPVIXY4Xof0r56VyfGIraxQWbBrsvYob0vUzp9aNuiwDkk9CM1q/4k mWdxyZbibHh3DuSvBfCzzUiBT3zAP6aRPOML7nHBBHPvaP2F0/kpDZQx1K145CI6S2bN xGuP3vBZh2iZRzlPNo9Nug+N6qE7HUIjUN1G2eNceiy1WBbHjA3MCbrWQOzQyh8jFCsU 7lUhqk/wUJe53rTw6QcGQh8PytnAzYtJDEuqrlxzjGMFz1DMoS9lERs6JpYuGyQCdrmj lkPAvqSc8oul1dVp37sGmYSGKzmPwZrjVAnkCcoV9u1ajl6rRJYYeg9AclmEJifl+HUc LwAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731979080; x=1732583880; 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=LiB6WPAUFBLTutmf66Jh2bwqLt5nfeR6J1OUSjouKLs=; b=WeNs2DYYG/ekBp/2+opnAFf8Cn/F05ItiMQrdv6z+Qjk1v4117IRot8MxGTmcXkaIq UF72c/dHmtyrJgZIGkQeYfj2BlFxoRWWByfcApBYwnGxUkz9TOPomJvEl+GA2F/dRK/X DyOYNkwW5UjOVsJcjFn79x/O7nh5iG2zKYwrYO5nHgXJnkgKqGEHP4luP3BgsTjtdE17 OwUBomma8K+kQMrUynVZt/kro+bbvtJDwP2q3smiqkDz39heD3wDTYaw0sd2n6X5WEtI RvqPGHTh1V1ROq/fKNzUXUltWwk/1sf+/OjhyOYPwZavH+KTV1rjafAvYbM8pAJUvDFe v/wQ== X-Forwarded-Encrypted: i=1; AJvYcCWD/s4h4A31hTPO/qC81O18EkqXa/uDlSRCQZX/Gzg2byE3mC9QxlZSA6bma1RqYsWAgBL/23duDqASH7g=@vger.kernel.org X-Gm-Message-State: AOJu0YzDH0vr2Spp8Agtqnp4MtrIAZGcqy1ZpFqz0ZDT6WWs6oTWUTcC TKIM09OKXO2TiXgh3p8sZfYNoJ6kC00fv2UjIyh8HW3W/sjUzJImJHlGd2hzaUb2K7sYO/3c/w3 dTRpUSQ== X-Google-Smtp-Source: AGHT+IEh5ChSTsDrAC1TFlUx0QvFRSJAlWCS1zQL12q2cVph1KJUN9j8LUTVNw9PTbQzwXll+E8g1c6qLQtG X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:22a4:ded5:5c37:fcc7]) (user=irogers job=sendgmr) by 2002:a5b:888:0:b0:e38:78c0:1a0d with SMTP id 3f1490d57ef6-e3878c01cb2mr8797276.2.1731979079542; Mon, 18 Nov 2024 17:17:59 -0800 (PST) Date: Mon, 18 Nov 2024 17:16:35 -0800 In-Reply-To: <20241119011644.971342-1-irogers@google.com> Message-Id: <20241119011644.971342-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: <20241119011644.971342-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v7 13/22] perf intel-pt: Remove stale build comment From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Howard Chu , Athira Jajeev , Michael Petlan , Veronika Molnarova , Dapeng Mi , Thomas Richter , Ilya Leoshkevich , Colin Ian King , Weilin Wang , Andi Kleen , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Commit 00a263902ac3 ("perf intel-pt: Use shared x86 insn decoder") removed the use of diff, so remove stale busybox comment. Signed-off-by: Ian Rogers Acked-by: Adrian Hunter --- tools/perf/util/intel-pt-decoder/Build | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/perf/util/intel-pt-decoder/Build b/tools/perf/util/intel= -pt-decoder/Build index f99d150059b9..5b8f0149167d 100644 --- a/tools/perf/util/intel-pt-decoder/Build +++ b/tools/perf/util/intel-pt-decoder/Build @@ -7,8 +7,6 @@ $(OUTPUT)util/intel-pt-decoder/inat-tables.c: $(inat_tables= _script) $(inat_table $(call rule_mkdir) @$(call echo-cmd,gen)$(AWK) -f $(inat_tables_script) $(inat_tables_maps) = > $@ || rm -f $@ =20 -# Busybox's diff doesn't have -I, avoid warning in the case - ifeq ($(SRCARCH),x86) perf-util-y +=3D inat.o insn.o else --=20 2.47.0.338.g60cca15819-goog From nobody Sat Nov 23 15:22:07 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 E43291527B4 for ; Tue, 19 Nov 2024 01:18:04 +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=1731979086; cv=none; b=uOAH+hqg6J2n1F54pLLOBgpqgOMp/BYVF9vgEfP9hvxjIwGemc2tS35SQ1d+Ub2UibHQd+AgjeaoV49zjD8UCY66bmGYz7NDQh7nhxqXIZ2Ta/W6m/vZ7LiT+4YSdSvoQaWscJfmFnsg4jOjqx968Fc+xFwRyKMcq6E+4XMaJp4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731979086; c=relaxed/simple; bh=iQQ3LZc5mw/4GGxCxzUwJSue+pQgAU0DqQT/hnMD0RM=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=UNfeScK5PlFhjdTojgC1+j2PAA6rG8jNzP515lTIRf2ukM10xwzxf+HIccP2xof57LycKc5u9lH5+sQAkrnsd21CKpp9ecFa2g9GaoY2eZXGHMyDel469PU8kw9SgDlRWCvokv8GjVeMR8v2lT8PYrH5wzah2jVAZk2GiyT84zg= 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=d/L6gwpu; 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="d/L6gwpu" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6eac7417627so9655687b3.2 for ; Mon, 18 Nov 2024 17:18:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731979084; x=1732583884; darn=vger.kernel.org; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=6ExKOlmjeTcZeT9jR1UaHUCOwESnyQFe7AeKOMV0tEs=; b=d/L6gwpuvPVgrx9+8UOYOxvcnc+bdB50I+4ehs7uJAD7s0qbMDtm0TFdxkUxbZw8zI GlL0QAmVDD5X76MKsU4hO0VuGqZfnRc8aakz/0JdKWzYfdtqPXWP8BlnBjbWUM6xiNON HU8OaRx6ITpjZZ1fXS470qJOvNglEx0lR/QD2hAi9qF1CCo+sKSyU3IqtR8HPKv/OsZE MuKNFlemXt00FLJWN2q1UU8zDT0n3xZ5yEhd6Ki+JySg4dpXkUq2G7UwjVGQGCFoZj3w PuCz8DmloKGruuE+lhGi2n7FfkEXccrGpYljlE4wL8MkT/lsqahIw1ZTLg/LWHRQk/LZ ye3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731979084; x=1732583884; h=cc: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=6ExKOlmjeTcZeT9jR1UaHUCOwESnyQFe7AeKOMV0tEs=; b=LwyqK/SV8ewYKSmx3ugVHGLzqS5rjICfJFIm3+yEuFj0PknQgrKQtxBcPiI45bmwpW /y3v73iBjaIzGqv5wl9aoTECpuAb1C4UmS91VBmW6oR491180m0NV9hPWPnWai/mJEcf Z66kE2bXI3KaXljIuJWaTiN0jwDAMPDHEYem+NIuHfzCCxYVDsMDX3Osl64XsVr7g+F2 XkYAvSzxKB/Mv8PetOCzo5OiNEnyKdiA43visrl6CBeElt3QAX6cVclz/+fPMcyAhrJg cHQZLkEIaI8WV/LbvBAo7HUDDYbID+ZAhF1ntQtWpV/eqnY+hLrd16Ln85NdNqz9mnjY 9bNA== X-Forwarded-Encrypted: i=1; AJvYcCXYXqAywpwQDPqEcG9sXnugf6wEbA4I7913+H2uDNPBL9To0UxaoNecKHZXHuKdMNghYiBgbAL++36Yl7E=@vger.kernel.org X-Gm-Message-State: AOJu0Yz6vGjY4X67cSMWQgTiyneqTT81tpFugkQ6ierG9UMYDA14cAaa W+Zm80qQskyyo6i7S2eirb1E5F9NXwrrd8FqB4XOuFa0GL6/KO1cSH0qOE2p8WdygSlB1/9pRDy fUubnWg== X-Google-Smtp-Source: AGHT+IHknBE0CtdUZdBequM0Ds1bydaymw8JachJZLvYhBrKfvT3sy/fvW2m74vrT7SCYwHMbLUjBXssdWoG X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:22a4:ded5:5c37:fcc7]) (user=irogers job=sendgmr) by 2002:a05:690c:5087:b0:6e3:1627:e866 with SMTP id 00721157ae682-6ee55c86077mr2811997b3.3.1731979084173; Mon, 18 Nov 2024 17:18:04 -0800 (PST) Date: Mon, 18 Nov 2024 17:16:36 -0800 In-Reply-To: <20241119011644.971342-1-irogers@google.com> Message-Id: <20241119011644.971342-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: <20241119011644.971342-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v7 14/22] 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 , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo 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. The include is moved inside ifdefs to avoid, "defined but unused warnings". Signed-off-by: Ian Rogers Acked-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-trace.c | 1 - tools/perf/trace/beauty/arch_errno_names.sh | 3 ++- tools/perf/util/env.c | 4 ++++ tools/perf/util/env.h | 2 -- tools/perf/util/python.c | 6 ------ 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 6a1a128fe645..d24ae46573b6 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 e2843ca2edd9..2238ae82ea70 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -472,6 +472,10 @@ const char *perf_env__arch(struct perf_env *env) return normalize_arch(arch_name); } =20 +#if defined(HAVE_SYSCALL_TABLE_SUPPORT) && defined(HAVE_LIBTRACEEVENT) +#include "trace/beauty/arch_errno_names.c" +#endif + const char *perf_env__arch_strerrno(struct perf_env *env __maybe_unused, i= nt err __maybe_unused) { #if defined(HAVE_SYSCALL_TABLE_SUPPORT) && defined(HAVE_LIBTRACEEVENT) 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 fa3ab954662c..fa25e7ed8a7f 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.338.g60cca15819-goog From nobody Sat Nov 23 15:22:07 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 91324153BC1 for ; Tue, 19 Nov 2024 01:18:08 +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=1731979090; cv=none; b=qU6buvJ2SCvEigvR7dcw3mjnZtdeFTZ9V4eEiDuL+vvVFH9TgF36YZSieukviNCPyteD3W1Qth7k25oYLgPASBCmSC+J0XOGYqPkXrw+Wf522zssWWKex5BiaKldalWLbsR1+Urt5O5w9FAOjqxanWuiu7Xdc0DesdhEbvPkikU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731979090; c=relaxed/simple; bh=ekmC66NOVNSgpMr3xsJfryonDUgmY+ot1N0WZtHvs3E=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=qwBglir/F3ecevWeH+TXUQYcZgj1I0QinDu3ItphEB7qTlPltUDl2Ujr1+GQQBQ0pXos2i2YbOIIDmdY8SJjCSRV3Oo+Ff7v+4hbkYHPXyV5wGLrvkG3q2yKfSbZIM4ZB47RWYvyhrSr1991zKUQlHaTXMOWlHdFebpBQ3lVqFM= 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=09qNdSFm; 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="09qNdSFm" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6ea86f1df79so9628167b3.1 for ; Mon, 18 Nov 2024 17:18:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731979088; x=1732583888; darn=vger.kernel.org; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=nLZCOhlOMtG0/qeJgzd25nzSdzp9WmUWu8UlS8oQxf0=; b=09qNdSFm6vMlxFM+hl9ixxMpu9ECOnMWdATrQJYxec61GxHBwzQM0gTwKNwXWVwxeq glywkWWhz14x9NDLN6t+1Ab6xS7c2dG/cMWabIEFb32pteDVLqT7RmrndUjVIZTAhN7G dZwsqfoOUPLsUYWfSUNPJ9wHAXTf42M8NIjPwAgsZjPA7aFZHqMbbRwebjq2+GX2kXkB RKn/Ol0wpAMjLV931Dwr/OBj+1/SMmntE7pGQO1kDJTw1i9LmK5oJUlk7iJYYyo5R30z xIwjIk3vPy2+DMJNvmLnDWqcosqlq6sUnYRHyAHeLNiyHozOSGLnAGgC2EAqte6oNHZM phig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731979088; x=1732583888; h=cc: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=nLZCOhlOMtG0/qeJgzd25nzSdzp9WmUWu8UlS8oQxf0=; b=SD7pwd+qFvsZRTAXIjF//Y/24luyr44V8lWcsOA+UphswD8BxBV2+GAcmK7fBbJwDy YpCAJv0KfDTtY7UKzv9jX5oGTYOYdeKEcObo4VQtLt+NXrjdMf1BqDWf846bx/HdxJ3r cXaRHqj7Lu0Y3QJ/Pv/8NyEEKPylPbTDCbzj9dnFaKQ+pansx7on1HGjntjF6O98BCcp 51A9tlX10Dx7YeVOFf7bpkIQGSpobtF9ZtL06+XlraihvZQGX0cgsKficKfmjSD/r97J +3RY3exgklHRLuSBYR3Eva+jwVHNjNCmNscEANV/FY4qPbMT2M0sr5wtCZvx9zvTr7R9 7hmg== X-Forwarded-Encrypted: i=1; AJvYcCWL+Qkd4RX4nugYXJmRXFxf2Qnjlwlob2HewWAqn2nTPdnSIK0zWEm8RSlz3wqrs8+eYWqar5i5/lgXC9Q=@vger.kernel.org X-Gm-Message-State: AOJu0Yy1LFVb5eMHLuCYdJSUN3wl89PT3xpw/pV4uyWHdeKCnrUZpebW h2wVevRl5CdcVu9Pawi/GgWxiGPgMJ+Gf0eaRpCjlncXFjYlH8cIfryuuxkoMxsZVFuol4MgXUK oI4DR/A== X-Google-Smtp-Source: AGHT+IHMI4Smzd88oNWzuljvIvishAISCpSxrbVFZGL6LgwOMJQh0gQhJwsZXkMDIxRpQxZuGUUxZYkbAcOi X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:22a4:ded5:5c37:fcc7]) (user=irogers job=sendgmr) by 2002:a81:b289:0:b0:6e2:6f2:efc with SMTP id 00721157ae682-6ee55c5cb1cmr1313467b3.5.1731979087091; Mon, 18 Nov 2024 17:18:07 -0800 (PST) Date: Mon, 18 Nov 2024 17:16:37 -0800 In-Reply-To: <20241119011644.971342-1-irogers@google.com> Message-Id: <20241119011644.971342-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: <20241119011644.971342-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v7 15/22] 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 , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo 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 Acked-by: Arnaldo Carvalho de Melo Acked-by: Namhyung Kim --- 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 | 143 ++++++++++++++++++++++++++ tools/perf/util/lock-contention.h | 18 +++- tools/perf/util/python.c | 17 --- 6 files changed, 160 insertions(+), 158 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 21b497df440b..f38eb8262370 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -122,6 +122,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-y +=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..92e7b7b572a2 --- /dev/null +++ b/tools/perf/util/lock-contention.c @@ -0,0 +1,143 @@ +// 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; +} diff --git a/tools/perf/util/lock-contention.h b/tools/perf/util/lock-conte= ntion.h index 1a7248ff3889..bd71fb73825a 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,8 +149,17 @@ 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); =20 +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); + + +#ifdef HAVE_BPF_SKEL int lock_contention_prepare(struct lock_contention *con); int lock_contention_start(void); int lock_contention_stop(void); diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index fa25e7ed8a7f..6851f9b07e04 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.338.g60cca15819-goog From nobody Sat Nov 23 15:22:07 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 E2CC91547FF for ; Tue, 19 Nov 2024 01:18:12 +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=1731979095; cv=none; b=KRbQMrBY7p062XiTWH6sTzN3iahqQYkHeXc28fHI+VeDGyhZU5hpySVHMifh00G1oqxex7KnKMQGvWPv+fIytz8qNHCEsQEl4o7HUSx3KEpU4zpnqfVYkSDvceBHm2IIZNFfLE2ashNMt0AO2FYa8gVyE1SzCuX42pxKWQJToGw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731979095; c=relaxed/simple; bh=TbR4BOS7mQPgSaQH1tcutfX+y86KQP6eWwApMmstiek=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=HAHaDDVydP9qDCv99MQaM7mj9CqfhwiHbkXKGblQyjqdUFHfj04izIyal7IDBEsD9Ode80nSGWuKKS4/44lXMCITUkC/ZXOD7ADXH1ejy+bLC7j9eG3W0y4ZLwyT4fQlzGqIWWwyrBujP4gtM2RVLOwioE5Q+LrlDw77stXuC2s= 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=qpaKDP7w; 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="qpaKDP7w" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e3314237b86so3452091276.1 for ; Mon, 18 Nov 2024 17:18:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731979092; x=1732583892; 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=wrXtQg5+ba7sDCX0vVayflm8VxueJWYimdy8axJrFZ8=; b=qpaKDP7w4gMaer+TNpEapxNciCXSt/vCaqUK7nXn4ZioLbdg+6sqsjPRr6nE5vzNCE 7RcgHPnKbdP1p1lmGlCw8k/sHQrN+Cl+gGw3qZWtEepdX4fA7rccs4XZ9yNq/tJdJ6uk yTsYYPd2oh9c+tG7GFLdKNHl7WEzN0eDuMjQ+XSLTUjYkH5rMLSyewX5U/VNTmDdo4Ko gDI2oYxoxAxlFkrb9s/UYH5v7bEzpKc2LqV4bfv8UHvxGYz01Xd5eyDB3SnNsEy4rMRS 64RT+wnlRyil+TQOPf0Z/mnY23w94O90AsyzWFy8dV0vpdvwPX/l1G7wyTYJK73ZECli L9zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731979092; x=1732583892; 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=wrXtQg5+ba7sDCX0vVayflm8VxueJWYimdy8axJrFZ8=; b=kvjjXAGCmbjgazYmpwvBho6oLhRLwMzNYF1jCa949ottPCSroS4tPb2+Uu8GXus0kI v+vWvEDkDNp2DR29edOrWv9vBO5ai/EnmMHirT2jSlPTxD3YzYJdknXF6QVnpWJZgAut BgNdf1SFYYuNDAiVug3505d90Dou2r8Gv6TAc6cFO/+nAFB5A/7c47EQHg9OssW2zwCE vBGzDWmBym8+Du2143kd8HMiTviHINJnsH2V/1fBOg+5jUfOH/2reHEF2vzRxHU62mwp YDAt1LpDAjb22hwPG2DSYERhnPgnmd0uvw57XNRejM64RalCkpXSh/Rm5EqSX4S3oV/y 1OUg== X-Forwarded-Encrypted: i=1; AJvYcCUxLhUjYfKMG92D0R5ZZXsaYqNHm4Mt11g40mylsviXl2ubjYjxvetjKXeYPLZVwHX/Xul7nhFcFCd2sy8=@vger.kernel.org X-Gm-Message-State: AOJu0YxXLnOmj3YMUmEiKRQP0kyK4GPhzYibaW02puW9qFNT1y4v++Mo WWSR4Immn4sFEQWEGn7T6cQZPhVRK2JXNrqOtt4+NNIy0OzGQaEobQqIjZzwHng+3n9mFc5mKyI rcdV2jQ== X-Google-Smtp-Source: AGHT+IEyRYVBQBZBqB+W3paPg6O1q0NERXZbtpznVI+9FR9vI2hLxhnsONIVMlmtNtw/uYgBLJjH//9eTJUQ X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:22a4:ded5:5c37:fcc7]) (user=irogers job=sendgmr) by 2002:a25:8392:0:b0:e38:1293:ee43 with SMTP id 3f1490d57ef6-e3825d2823amr11237276.1.1731979091806; Mon, 18 Nov 2024 17:18:11 -0800 (PST) Date: Mon, 18 Nov 2024 17:16:38 -0800 In-Reply-To: <20241119011644.971342-1-irogers@google.com> Message-Id: <20241119011644.971342-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: <20241119011644.971342-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v7 16/22] 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 , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 d74241a15131..cbcb698cea38 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 6851f9b07e04..5e6db4b143a1 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.338.g60cca15819-goog From nobody Sat Nov 23 15:22:07 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 620C31CA84 for ; Tue, 19 Nov 2024 01:18:17 +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=1731979098; cv=none; b=V4OEdH3aMnbEey7UH0CDMvTEtDqGs0UH8zFmEa6CCDpIHpV2rt4J92gwIehxW+XfTeCE2wdUfl5yPsatYnyiHL+kMzbp9/POT4PRZG5k8TeYxYti3DTeJw7Qpi4k9kf6JyVHxKowITDuxlHBiLfBoYFbOwuAcuo/mgzBOtrj9vU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731979098; c=relaxed/simple; bh=xvU4oEkRZu7oYlW7Ww69Sq84Htql0bu+vZScAWVdL6I=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=QQ9jlaUodb1hp9vOaQACB2ibZk8c5lkc8pzEQ/+uV3pEd/ugUx70L2/75S79C+Y9N1UJ0VofXKbr4qk2KXoVPBAvYH6hRoKtOXOZQq1yRTOZ+fJ1p6HiCm13n7ZQOzf3vwnMkt393wuVALj0+1f/jbeORMbbNZpkqbunijihAHI= 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=xy1RZK0D; 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="xy1RZK0D" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e30df8dbfd4so3347871276.0 for ; Mon, 18 Nov 2024 17:18:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731979096; x=1732583896; 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=/5CKH6QHuu2NcbrgRcRCJGUOGGvnBJyqKU+TkUSirYM=; b=xy1RZK0DMnXTMVF8kJYFxp5qvEGK6B+vZ4/JH7ZArhauqd8jU9RgLhzjz0dj0P84aj R7mTH5Otb8qDQdvmJQF/+u78NWhb7OIm3RsBsjSB/lIVY0Msu4vZpQVXpQgTm3tkx/RZ C4zKVzP0spZFPcPTYD3LTBmA6Y+8XOrPMwSMLqy4sPSwtxW7O5+xli8iaQxHRCONsK4h SypGA766fTD1hyygENE+wSxnvVuaahIFUTSpjqWCok0rXW4KFhOoCi32QFNsYepQ68eJ bHo/T6NW0lHE13rm6FNbxYQc6RprysfIyiY0lSg9XoFbs96wq1NoxZmAEZEVQ1Sp44Dy hD0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731979096; x=1732583896; 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=/5CKH6QHuu2NcbrgRcRCJGUOGGvnBJyqKU+TkUSirYM=; b=TblZtq0Dul18aaGk3m40l184cwKSFK8y1Scz45PlYlN5Qd3SNCBwLimm33AvMq7l3b HUovN+4B3nOhnRkKxBd5eAD94ubtzZ3O/GNO6YgFWigyoXo1JyA9uBXgHS+YFLm4bsS7 E4wuWgwPNta3BpGG+v9L/i9wDK0pCrruucxwXzwoiylMF1reJypaFVHt75OhdZkOWAyq wimRKgNl8ReQRyE8eLgtFIOjMLRUPrMwLJNxic/gXOqhqJxySj1SWGmdDb588FQ9Bm9H RnwsdpkZkTfl9XZh06WVgXZ4zA8C85y30VxiE56YlacwQNQCBJYijCWTrHl2fjD416kz WpXA== X-Forwarded-Encrypted: i=1; AJvYcCUGACdKd53pIt4w1/mkVG3Ekf2H3+hxgWYSBBWqRf0XP5I2N1Z+hUteteIGivZ7GpF4pXA5M0BshG3CPS0=@vger.kernel.org X-Gm-Message-State: AOJu0Ywnm2k2WHMJtRSfitqWBKGFMp8wYOgpkw59AimdLfODsnGx9Inb wkvvPDlaZ60D3XOwcBAzFCEm/JmCGqSQPKgd7Xta68y5MDNxobZx29wOJn3tZ+VUa/rPtlDrb+M XJLuHNg== X-Google-Smtp-Source: AGHT+IHfTA/+jlwQTYlf7NK8NSpShGCqN6NFIWxAxS33V7PS6uUzm2/q1MYOcgMQJqFrx6yl4FJ4vqULXI3g X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:22a4:ded5:5c37:fcc7]) (user=irogers job=sendgmr) by 2002:a25:b19d:0:b0:e30:d61e:b110 with SMTP id 3f1490d57ef6-e382638437cmr197260276.5.1731979096311; Mon, 18 Nov 2024 17:18:16 -0800 (PST) Date: Mon, 18 Nov 2024 17:16:39 -0800 In-Reply-To: <20241119011644.971342-1-irogers@google.com> Message-Id: <20241119011644.971342-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: <20241119011644.971342-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v7 17/22] 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 , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" perf_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 8234410cba4c..43239850256b 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 5e6db4b143a1..3e32a502a41c 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.338.g60cca15819-goog From nobody Sat Nov 23 15:22:07 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 68A0815854F for ; Tue, 19 Nov 2024 01:18:22 +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=1731979103; cv=none; b=tf0rJeWYBObeK68WwiMPg1DTxhLt2STBKXvMar6Xu9kh4NZstyQ0jRe7malgUjQQJ1ToPzxyE4On8aAA72dnA59UcnzZP+rtqcaOa17qXQPUOhEfRFDdN0him5a5gMswnHzfWsAXNaPnV2nRTB74fhXWBEI9ku1Bwc5KW78618M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731979103; c=relaxed/simple; bh=ccbfQ/FCxM0ajSqCRBtrUPwSJY3+AGZURkp9AUtPPf0=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=tXaA8jdOp5NJOigNJ7eMqganAlPNE7jjL8r+HJ43bFX00yx0DHVTPkbSes6qY/+pp2N6KtNbmZeJV9SOKjaOJDVegawr1LcRWa0MhDQw3sE7eWAzAlO4k+uWshW3063cQWKdBHSe8GGetLMM+MMv02wP2JiFFyVj1A743TAkfbE= 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=HE7JfFF6; 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="HE7JfFF6" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6ea8794f354so35948077b3.2 for ; Mon, 18 Nov 2024 17:18:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731979101; x=1732583901; darn=vger.kernel.org; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=frFU6vDMiuKwKS8oNBs9ivnCPNnXTA0sYwftgRN+B6Y=; b=HE7JfFF6eNF6eOmOwIZ6dAB4bQ6JSc5dKLDXox9CNchlsr3dzNGIUSfyXD3Wrs4/KY ZvcE7HY05DMPYMRjG9OzB8VVIXoecp/5mlzaV4pgu0ooeDJGwTvl81GKBz+9X2rEFRh9 QieFT8cbq7cRU7/b57hvwAgcr0JuiqLQWwgfYLY5bk4xa/UJwILuXl7pezXa0qqv1zsL LFONE4ljye9Wsilr9iZV9Wv1pk657f4GA0rHKnwTUyzIFVk7eHDcLkqWsDgtf/0OCtTP bdhP2cMn2ED/Z45PGZjIf6wujAuXaWR1lP8BccFc3V8b+WwIqmMTyVIF3wZFLqsvzjAf QL+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731979101; x=1732583901; h=cc: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=frFU6vDMiuKwKS8oNBs9ivnCPNnXTA0sYwftgRN+B6Y=; b=bcrwkznYZ3KxcfJJ1RmFErl7K+GLTKP2ywBDZaXWMsg/1BAOMl813LMWtMiwZQqgDn ciFI8aRkO06nbHKYyHfast74tJO5Hdb+JC7Nv+bb7xbw+QYCUAnC5/pR3ohl2x8XUWIo /7ihrumFLmNpBsRM+xeB/mQHWVgZi+VUhXBTiUgLCsivDi49EvZOQGYeKQ5Gnhi/saZr K9pdmRvGVMRxJ117H19yrArRZ4Y/+mCexXO8os+XMsnaqpWG+1FKRcG99qxPg94el7Kp 3WsZwJ5sxltuOTP0eD5XFtmLP9dU1KZL392Hgy871YAXw3p1RIDRrwxcT7O2t94HJx5h GjKg== X-Forwarded-Encrypted: i=1; AJvYcCX8FYJhVsrN0DKj3CCCaNpgRbBZTOOCD3ncgYZ8+pZhP3YfO5BTuLqkHvUsVMsYWXOgXRMcLaG/BVm1JAw=@vger.kernel.org X-Gm-Message-State: AOJu0YyB/GCERQUw0hTFElzXRmCUQsxoSQaxATUcYf1ZtjAhqdpbL6BG ZIwVTYjvrx61JobdohYiI9ihpFIKcsncFO+nrZlrBHOyXRZOMQUr9CoKlkp3EaiZvkShEwpfDj8 Z0m7hiQ== X-Google-Smtp-Source: AGHT+IEH6bm8HluA7jd0r6+9Cueqt8y2KXSiPCe2m7BpnNOtq6aGwuTd2RlX5z6Bdg0V8iHN7DjhyAg0Oq7b X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:22a4:ded5:5c37:fcc7]) (user=irogers job=sendgmr) by 2002:a05:690c:296:b0:6ee:aedd:bfaf with SMTP id 00721157ae682-6eeaeddbfe8mr7587b3.2.1731979101174; Mon, 18 Nov 2024 17:18:21 -0800 (PST) Date: Mon, 18 Nov 2024 17:16:40 -0800 In-Reply-To: <20241119011644.971342-1-irogers@google.com> Message-Id: <20241119011644.971342-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: <20241119011644.971342-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v7 18/22] 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 , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo 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 Acked-by: Arnaldo Carvalho de Melo --- 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 cbcb698cea38..adbc7ab325c7 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.338.g60cca15819-goog From nobody Sat Nov 23 15:22:07 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 CC83215854F for ; Tue, 19 Nov 2024 01:18:26 +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=1731979109; cv=none; b=GVauLukVmv8kwDeFHsQOLY/hu6+cdyqvs7snYNvmx8KCjKcky2DK+FQFT6F2B4vrkH2TTKdntavwYh6ERyBgOEvo4dE/JGuw37BOC9iXOPdQvT9axp0jSACnLWyweEl72V22pA/It4Ij62HtbwR1ohWMHnyB2jf+ZeCm0V9LI2s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731979109; c=relaxed/simple; bh=z6Pm8ATKpcVHRFX9lVjqQEXey9GaIdXlbaie6pTu+zw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Nj6wc71Z4gDdAFicjEng2vSgH30cAdpHx/6aHqRyXOyKD3LJvHZIaCWppmkDE+zvB65a4kZnigLdwvw8nUKd2ZTJ+2q2j1LVoPwdSI2maRf3shW2vPLu3JVR1CPzwVDFZvuy1JVUiktVtwf7Gk/5K7ye85lT8YxWiN3YF0gghAQ= 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=GLzZcWQ9; 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="GLzZcWQ9" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e3314237b86so3452331276.1 for ; Mon, 18 Nov 2024 17:18:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731979106; x=1732583906; 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=55R+aYCHOFQ2GhoTuF38RCq5QtZuRMd9/UXqCPviTZU=; b=GLzZcWQ9gXGow2uTxw6j3mqbnu8LNkA9T/hrLePUM67bo3imuRSyyMmJEHI3qGj+l5 lVNLXkPG6FRNGc9HZ+Hlo5kgSKc/NuOw8CndIJCuf1cKHtUZia2vcjsLg54DDd3JCyU0 gQw4kD1nYL9jWz+QlwKY6TX1Ye5f5vMzSem7/6Mq3Kql978G89EThky7JjzrK9a5VtGP 92pVNDHK7Mxn/hBQpRmw0eeJpGOW23n/Iy8e6MR2rnw4WRtUj+tS3nx24Z0tuY+NfjyL X5j8U5mWR57kNeTf79RNHDifWwscFC9bodQlY10xZH56Qn/X9p64CMZttuBmJENtFXYF 3dEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731979106; x=1732583906; 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=55R+aYCHOFQ2GhoTuF38RCq5QtZuRMd9/UXqCPviTZU=; b=sKiLBYTFSJpQ9WB8GquK7hqMpwcr8fU5M6dmuq52yFJaybuNaDcHdMfTnLp6TVBqeH d1KooUZrQYNF4n1E4tQ7CrsRb1kBDUTceli1EuL/rNqbTWfi90m0gBxl4ja5FTYjFOE9 Nkpfcuu53NRRSqUh21W5X+/71bnf511QUgJaW/vdycns1OGbtmNUEhGIJ3ic+A1+eOwU O1mOt8IkaqmpnJPQRK3u1ca58fUOiyQvd+vwO67y027CMebfj6VUn2NmUyxJrbNmNC4W UigVVKErEPBV01iUkInXlaCpYNRiknOt7ubQ3ZoWUSkWIg22eXw2V0xUqDr9PPClsuA4 DObQ== X-Forwarded-Encrypted: i=1; AJvYcCWNbdwFcCBtyqjNVHN2YyZHgNMJ2f8KZGDIX2jBuUj/7swKHYPxSN84xfMOFjDLlIHO9RCjkpxzXVxfgfE=@vger.kernel.org X-Gm-Message-State: AOJu0YxmHvDWiHemei5sv4OBoFNoj1nvdm6dTsWjdvwuEYR+yHtrjk7P thzwYqwj6/uFP4DVOkJdf3xGk9ieZT9bS4XYe7ZyxBonTo0u7atpybctTmWKPDzhPLnpCqkx2FI +PsJIhA== X-Google-Smtp-Source: AGHT+IEHz5EAkyZuzVFmLmsZNPk64z5IYcXA0UKpehcSG3KUXHBFmAD0H9nOd16MT32Tkcbkyrh54koqsWAj X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:22a4:ded5:5c37:fcc7]) (user=irogers job=sendgmr) by 2002:a05:6902:240d:b0:e16:68fb:f261 with SMTP id 3f1490d57ef6-e38263b0b42mr12215276.5.1731979105853; Mon, 18 Nov 2024 17:18:25 -0800 (PST) Date: Mon, 18 Nov 2024 17:16:41 -0800 In-Reply-To: <20241119011644.971342-1-irogers@google.com> Message-Id: <20241119011644.971342-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: <20241119011644.971342-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v7 19/22] 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 , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 f745723d486b..5fd32b6729b4 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -454,7 +454,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 @@ -467,7 +467,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 @@ -512,11 +516,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 3e32a502a41c..c84c912874b7 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.338.g60cca15819-goog From nobody Sat Nov 23 15:22:07 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 25BF51957FC for ; Tue, 19 Nov 2024 01:18:31 +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=1731979112; cv=none; b=s3Lmhkch50BDZNer0AkRlEJz07rzfZLqxS3Bcm52h1NtLwNLfzrrbDSDxrYMpYiQRNsZRaISsfJznBwnR7GRNJGs+nUN4cnsdOL79irKg53hbZk5nqmvmtjmzgtmivUrkv216m0gJ04WCERQUOX/CybY+jysxViZDw9zqJggmj8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731979112; c=relaxed/simple; bh=qNHR5Z1taMUuo089XQ85xElyxUlkv0ZkzX40B+6d4Ls=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=XC67Xw1tZtuMNrY3Ms8Q4zSWM9nJrLRhkpccrIaUBl4CnHYFxeY+hreKGfYn4zb8PRqyyutWBIuya9iCC7tJxU7hs3ap8UqTpaQtkiFirGKJplX9FJLOQQMlYfvkEbFUzOUz4cCO8MGR0iWfJNktgd5HaanNlqa/r3VKUuSDgcM= 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=ecgQ2sRQ; 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="ecgQ2sRQ" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6eea70c89cbso8570147b3.1 for ; Mon, 18 Nov 2024 17:18:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731979110; x=1732583910; darn=vger.kernel.org; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=0TlmDbRtQCgRVuOOv2LFWC25wlWVgj89vAp1aG6rmOk=; b=ecgQ2sRQMZAM5Q0L3Cmq7nGnJgugOQ7sjqAUGS6GYPr+vKDJeLfBk5+eso0Z7QTLKM gjU5wBQDxM3G+rsNDCsRCgLQ4YcYUJTu/k6GkvQuOIuaIWxaiHlwsVgKyJYUpOWfYr9H zE2i33X6bh3toPL2axWfLN5OjcYlewNTeecLY1MzjRxfnxSFu8Zt1jRcELE/v4i9XlE+ ZXnm1IqmBR9tdh4UDcCV3xjZjdqTflr+Pf113n/xlRKVW6E0QihzarJ+hJWA4ACcxiqS ShAdHGMqgy/81L7lT/vDKT9L+OKM+iUy9jMU/uDBWLfvFkUpShqMA8/LrsAtwp5Qe9R8 Nv5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731979110; x=1732583910; h=cc: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=0TlmDbRtQCgRVuOOv2LFWC25wlWVgj89vAp1aG6rmOk=; b=QvANexxh7Nf3g6cKnYJ5+z/bTVFiDGaDfcNeaAMlVPE5eb9q0delai0eVqiyj/Nik7 A0RPMqMSYB4X7Lg6w2Qit8OcxHz/LjiSa7544RYFQJKXpmdel5jcN3PKqiEGJjKTVHBw FqK2SSsxm8nH98HyGC4ZMHg25NUuBHDswY3OyxJTZkB9tIKu9eVYj2FLKVwzManuk1kW wIMrmZ20wnX5Nx4wIxtpABldd2P2nI4+eAnqrm2jBWf33oOe5gLHThFpltyXOGz6thoI rK20OuKPlxdDSXp3TAQMjFS6OsCB517NamHWTsYF3OGhLGLOuzzsfNw0U8s7exEngQV7 sZTg== X-Forwarded-Encrypted: i=1; AJvYcCUm8O0e8dlqwYSUKX4MO67+nr7CpnIL+jPy54mZQyHafGtMRk+1IUwcPT0kstP329er+Bht3IDjAgF1gyw=@vger.kernel.org X-Gm-Message-State: AOJu0YwbfZC3JUU4Fjaf6xqrUejaxt5fawqpSRq2kjPr4v/+4UsolhkG 1FQtcMhrGVnTPlEb5gqrjkDmGlAZNyrBhpk3smQbL8sYbSEfJVSstjPICdlxtxdHq43rVBYJPAz stD+gRw== X-Google-Smtp-Source: AGHT+IHr2CghJCzDEwgXBNpiOzi0hjXzKde/6Z3FZ8YQO8FElmB+t+txNjDfedjSK5sz4oA0+9wbjZpYGzUt X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:22a4:ded5:5c37:fcc7]) (user=irogers job=sendgmr) by 2002:a05:690c:498a:b0:6ee:a2b0:a803 with SMTP id 00721157ae682-6eeaa2e70femr62167b3.1.1731979110361; Mon, 18 Nov 2024 17:18:30 -0800 (PST) Date: Mon, 18 Nov 2024 17:16:42 -0800 In-Reply-To: <20241119011644.971342-1-irogers@google.com> Message-Id: <20241119011644.971342-21-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241119011644.971342-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v7 20/22] 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 , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo 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 Tested-by: Arnaldo Carvalho de Melo --- 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 c84c912874b7..c556cbc582ae 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.338.g60cca15819-goog From nobody Sat Nov 23 15:22:07 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 1444119750B for ; Tue, 19 Nov 2024 01:18:36 +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=1731979117; cv=none; b=h2wHUmn3xcpgGiF2Pg6a+ZB+PQVe9srNx1gmNACgj8KY+ECoZrwnhYPXqtbTHHkXg6bG6fy0ZI5vaQvUDTbWu7PKZfLc7L7/xWpNuN2W9VMEwtMb7XEV03E4bdp+hn7A0ycxWQCPUxYRhg986uwMncyREICx4Ox3jr/TYXUWWnI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731979117; c=relaxed/simple; bh=1/uQjVUHeicVOsHf6JAkjbXnJL4QBfvJdjKE/VYq2Hg=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=YrqNSuq2E7L1PPlbiZL7D6gyJ7UjHNLO0+mV7fiyvc3UmubOF4hyIKnFpICJb9aX1XceBI8elOZXVSf/7o44nTT/l1TseTpE8YzyHRbATYxjkYrtF0VkxwGgWfq2lSe8FmGlmhln+wIaSi+pDDMCI8+GE5QjAxJ2v5GRYkgf5z0= 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=Natkp/kE; 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="Natkp/kE" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e388f173db4so2471747276.3 for ; Mon, 18 Nov 2024 17:18:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731979115; x=1732583915; darn=vger.kernel.org; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=MEXus1VjTmWCZL7mZtlARX6uzWRhwXwnNIhwzEO1AVg=; b=Natkp/kE8Dmhqggeb6AEydmCmUZgTOw2lX5mvAZR0q5od587mzi2ZaVtdOgSU3hqxQ mHJ8e/BjQ9r0W3zSFKV0VeUydXLBGzqbj2ng8vhUX+CqBSw4i9l1QhawLgJy/D1Q0Hie 3AMiRGymkQRzrTjLkiCkZ0gyXazFsb5rMKQ4E8njB3aFxk6WCJVaafLZ5RwOU+vCrge/ isk5VVI3HWOUFB8h1zIGuU6g4fVap/Bu33boE50H0wn9EJxZCKvrHO1mbN/RMgMRNiL4 c0WP7hb7RZdUy6Qw8KaFIasOsFN7n5wnYNheiJ69EoCC2hhCiUR54GDLARxVI014QuFk fsAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731979115; x=1732583915; h=cc: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=MEXus1VjTmWCZL7mZtlARX6uzWRhwXwnNIhwzEO1AVg=; b=rNjBtXoj+IkQDiQhbKJUSycnIIU9te/SoZwCWLfI3XQCfylbO+IRnIcWpsWv2v/bIY dWh2bFVCAVdxsUTEcDnDMSnor0Ac8YEtjl4xRfEzUxtlcwa3iqeXyPDvyY7DFDo3q35t O5dbi4Kqjxo+GNzftfItnbX2T1srxDFVBM8/ehDB4PVpEaPxNPjwsswp8l906pg92iSs BguDkQPIzqmzMqMr/ImkOXmZDoBo7DP8izIOSmOX3BiKr3Rk2PYGeAG6J54Cn7+2Gxqf ozZZ7mSK4AmbsdUitAr1oMnVN4QEILv/bbb9pSQscM4TNh8XzTky7eoDF9wCG6J+OOJz VuAQ== X-Forwarded-Encrypted: i=1; AJvYcCVDpBxO/xdKSoBmBuhBZBkmBWvTHaHzqRqC/z0PMCT75FtwRgadMFZ54UjBYpOOP9Blh8TJBvZRDIrqwSs=@vger.kernel.org X-Gm-Message-State: AOJu0YwRcgRIik0/R549wjKAlwC2kqY7CFz25a1Bn/Z/Pq1kjJTgt3fK duY3XOVPNwOPu9H7/U4Bdavb8eBFXyIONINQVAiFpDAXw382Mj2ev4oV+HePF6iZUIqBiS4l5wd 88wkXog== X-Google-Smtp-Source: AGHT+IE0l/lVCzoB/5F9kgHVNu1aiAHNnvrmyEJm8D2E0OtwOFxbGmgFNGiM7iavdjs0oCGKa1aaFQLcNqOp X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:22a4:ded5:5c37:fcc7]) (user=irogers job=sendgmr) by 2002:a25:d092:0:b0:e2b:cd96:67a6 with SMTP id 3f1490d57ef6-e38263954femr9475276.5.1731979115075; Mon, 18 Nov 2024 17:18:35 -0800 (PST) Date: Mon, 18 Nov 2024 17:16:43 -0800 In-Reply-To: <20241119011644.971342-1-irogers@google.com> Message-Id: <20241119011644.971342-22-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241119011644.971342-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v7 21/22] 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 , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo 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 Tested-by: Arnaldo Carvalho de Melo --- 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 c556cbc582ae..893aa4185c03 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.338.g60cca15819-goog From nobody Sat Nov 23 15:22:07 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 BF80F19C54C for ; Tue, 19 Nov 2024 01:18:40 +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=1731979122; cv=none; b=b+ccHwwhTUAmRPdRTvviby4qd+HejL6H/q9IJKgD2BmuKZVCxLg3xBJxo9i4Eu7LZ4kJ0eRa9d8rfQOipjwGlD+2zxGQLjUuGBy2jDfB0EPcxiaz7DThM5HLHOfcGGj7db5bB9sanGBoee/Qy7DsdYvT+yaZMdzMcuTVUwkwrhE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731979122; c=relaxed/simple; bh=TibGVYLS+w6eFScQZIl1dSIHMEHWsRVbxEMEGktnWmY=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=B2beiH3N2pBEMefrYKe0mzgcr3+1CcAsGMtm+d54ZPpmx5Bf4IEwVC/WHU9urloRAcp0lpUa4AwO9j5KMMyNIZACfWjSWoJbsDLm9/fORUqkg5zgpLrjIwD17nGGSMvhlqgQVE4vH2xXqEg2ulv3S38rzZNy3qn/h/zWNO8HFY8= 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=cgrJ7bWm; 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="cgrJ7bWm" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6ee7856bcf2so40617617b3.1 for ; Mon, 18 Nov 2024 17:18:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731979120; x=1732583920; darn=vger.kernel.org; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=dG2rHpz+DZmFY69Ow240psf3XNCS4leK+RB0Jo+u5VI=; b=cgrJ7bWmasn1xpBTNITg2kNikmVVoqHm+sq/tvibdKnR4Yg6u0H4k0W8jbudlnfp8E 2DWn7Q5xSBrDegYAlg14QzxyaNY17XOXfGk7RxM9RceFlecc+8q89RbZYgXDTX8FVUKu Glub2Qy+rE1j/KLdJp+ZZvi5eD/+twvHxop61B5wl+25eS1R4CTBUpoA+AOSzOrIy12h 9BSRA56MTWsXqmqmvnrNzIrUspLkznWpsK7YR5571q0PdK3nh21cpW0Jbo3aBRJ1wAcA rqFx62jRJV+v1dkgaH/DWXEKyHCaP6SzS5qW7dh4eWnvXhEJNK8DinPW75cOJCz+sZS2 2XEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731979120; x=1732583920; h=cc: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=dG2rHpz+DZmFY69Ow240psf3XNCS4leK+RB0Jo+u5VI=; b=JbZNCEtvR783Q48YbSNkVqUMledTbctGXh7tdMIGRc/PvI8jlrklYdwlk47RSV3AYY Dm0PFFbuGWzUN/E8K6j8p5SG+dovHSM0dD0NFX2HG0jaMTALfU43AZAwicPJA4+Xs1ur O9+QO/yX9YdB32XgJPCZhDdeu5Dp2FWR7Ouv8UPjibnZpgXl7aCg0E8RM5NhsOyD/MhD FS6AnVAxWALt6kjBdIAO8ip6Nk4+wspH3UXUP9I1ND/PMwFXCJIGyPvcHTwUEYDM5vr9 InkoLNypbpWe3+8lB5nZL+u2JMHcX0zUqpzoD7zU9Y7OimMEvQfWugMN8Y6PruZRDfS2 DrNA== X-Forwarded-Encrypted: i=1; AJvYcCXHpg9oPGOBlk3G7T4ujQdCracvl/mqIZ2tlg5q2q3IG48rFB/r77SUSb2QayPjhZZZSdv77OBWcIhoryA=@vger.kernel.org X-Gm-Message-State: AOJu0YzO+9j1rpuDTF7R1yirbv4Zr/+oTlUhesmPG64KIQPXnNHg3LKC zhbAhKMsA7mqD6LGT5HK1Z/YomYNw4POtsNVddBk9te3NfWzN/ocpem3Rwodwt1+74HLdAJani3 UwJrqag== X-Google-Smtp-Source: AGHT+IH0fWK9l/ObxBt82Gee4SbsKlCa/RgYCuQgUP9WU5mzStOrp3fYvTUu8INRKh0lKzORqbt9AzCVDCVj X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:22a4:ded5:5c37:fcc7]) (user=irogers job=sendgmr) by 2002:a05:690c:8bc1:b0:6ee:5091:4254 with SMTP id 00721157ae682-6ee55cf1b83mr945287b3.6.1731979119740; Mon, 18 Nov 2024 17:18:39 -0800 (PST) Date: Mon, 18 Nov 2024 17:16:44 -0800 In-Reply-To: <20241119011644.971342-1-irogers@google.com> Message-Id: <20241119011644.971342-23-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241119011644.971342-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v7 22/22] 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 , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo 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 Tested-by: Arnaldo Carvalho de Melo --- 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 893aa4185c03..b4bc57859f73 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.338.g60cca15819-goog