From nobody Sat Nov 23 21:23:22 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 DB90013BC35 for ; Sat, 9 Nov 2024 06:18:24 +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=1731133106; cv=none; b=nLZpyOO5LgZgPMZrRVvI6jmzuZuTj+bY1anYP9wmEoWnfNHUgHYoCjCL2k3P4rCzxHOOq9k0Q7MKnkVAlkIvL+YqpzMGvdFjhYapd5f3gpyMqpWP1hO+q/EA2RnIs1m+Wos/Wn8FgKHJvx27svoXQze+UAyZBEjBuExSF3Odr4E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731133106; c=relaxed/simple; bh=vC6VDGUd7M5nDdVYGfpAA4B9K/qTvKH80O1wB+ap9vo=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=QMIKGHZkuHQ/zmyNj1MstnNgCIipY7ExFKHSBHc7AY3q/gL47V8G3ujf0M5KCkHAmIHLL4O0vyiTYuNkhwm7KoYENBxVhNfLzyVTFh9V/AIkQmp3ROqnyk8wsqdWe1v8IcuQYV7HZ6djmDYUoR6SHYkoaeuKCi3cTejZDvh1FIE= 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=qSddyWkY; 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="qSddyWkY" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6eaae8b12bfso51021407b3.3 for ; Fri, 08 Nov 2024 22:18:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731133104; x=1731737904; 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=rMx8WS7Or6vnwP2Wj4AZt+dV2nEuWPARZ88hJH/Dy3s=; b=qSddyWkYcdqPY7IIq7oLe78gzk+sFY3r/vOEKdj9HB1K0MfbBzT0FHwBad2h3IbGAJ J74pOGyguVjUdhhCPdt8X7gC0uycJRo8wwWlskEM0gvwgK+94hRMCFq/IrtEpQsEAH5h E5dmhH5v+DKpYCu9oKXZUXk0pn3N+QPUIxeOS8LPe4sLPlaWBPh1ocROkpPwF1M7IS5i JM2wNbWAlflqESnBAmyP3hbat4EWmDc6ce4Fp/F8RcSV1Wz10U8sTUTZut2gDffL3hgx cU7rZvYnmPI5NdWJbeQD8/pYUfDzJxvJpVBYOgQfv8jh8iogRlz5OP1CfRss5Qthg+2V prtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731133104; x=1731737904; 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=rMx8WS7Or6vnwP2Wj4AZt+dV2nEuWPARZ88hJH/Dy3s=; b=k4dIOby8RTWhAukIp9ged0R3DOA61nIGNLciD5iC0iQ8XDUxJMmyLkGi4r94RBgRzM i+Z9Uh614ccFWg0t44BtqpU+T7GYoynQw6guvpReJlqIFchHi+785gh/pIM9ABEFnOPj LVEBO8LhBG9Te/jq0Jvdjzs+Q+dA8XWJXQunWJOAlohEg5+sRLwjsixuINLKt3LRBuOa hlR+m0BLAGWLafVUyEhuQfYbLhxMHYXlCLYibSfT3sV70QPpNVCk47JsfIFNSQ/8Ppgs ArnNK1u3B6YYzPfNg4QlgJK18JW/gaG90MiApDjOp0KkXofwJ3ojcQvFTw5LAlqAw0wz L6rA== X-Forwarded-Encrypted: i=1; AJvYcCVI2L9jrAfrscnYM7a+mCABY/rzp8UOE0XSxQnqskCS+tR3yGO5t8Sy46HELidAOxbI9yjP17dUH9iUBQ8=@vger.kernel.org X-Gm-Message-State: AOJu0Ywt7YUO3zMMzgBxEgHsB9q9d5oyBomPJ4Shtj+gz70ksTjE1gNa gW0UDwMCNs+a90AUYQZd1jqIv9l7XdyecAyPyVIz5gk2kQNJBBKsVFKskva6jPSwxKQPypWp4oh k8s0HsA== X-Google-Smtp-Source: AGHT+IEjNBHFWLiQ81KvGKqFcr70m8pZFWDCNN4WKYA/AhNrwEI9W/Zw1LoiQw1RnfmPL53/rxWDaFJZlLAo X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc2:d48f:a998:5915]) (user=irogers job=sendgmr) by 2002:a81:a789:0:b0:6ea:1f5b:1f5e with SMTP id 00721157ae682-6eadde3c8d3mr59237b3.4.1731133103476; Fri, 08 Nov 2024 22:18:23 -0800 (PST) Date: Fri, 8 Nov 2024 22:17:48 -0800 In-Reply-To: <20241109061809.811922-1-irogers@google.com> Message-Id: <20241109061809.811922-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: <20241109061809.811922-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v6 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 ee3d43a7ba45..6fc283ac5498 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 d7183134b669..f1d461d47d73 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -58,22 +58,6 @@ #include "mem-events.h" #include "util/perf_regs.h" =20 -#if PY_MAJOR_VERSION < 3 -#define _PyUnicode_FromString(arg) \ - PyString_FromString(arg) -#define _PyUnicode_FromStringAndSize(arg1, arg2) \ - PyString_FromStringAndSize((arg1), (arg2)) -#define _PyBytes_FromStringAndSize(arg1, arg2) \ - PyString_FromStringAndSize((arg1), (arg2)) -#define _PyLong_FromLong(arg) \ - PyInt_FromLong(arg) -#define _PyLong_AsLong(arg) \ - PyInt_AsLong(arg) -#define _PyCapsule_New(arg1, arg2, arg3) \ - PyCObject_FromVoidPtr((arg1), (arg2)) - -PyMODINIT_FUNC initperf_trace_context(void); -#else #define _PyUnicode_FromString(arg) \ PyUnicode_FromString(arg) #define _PyUnicode_FromStringAndSize(arg1, arg2) \ @@ -88,7 +72,6 @@ PyMODINIT_FUNC initperf_trace_context(void); PyCapsule_New((arg1), (arg2), (arg3)) =20 PyMODINIT_FUNC PyInit_perf_trace_context(void); -#endif =20 #ifdef HAVE_LIBTRACEEVENT #define TRACE_EVENT_TYPE_MAX \ @@ -181,17 +164,7 @@ static int get_argument_count(PyObject *handler) { int arg_count =3D 0; =20 - /* - * The attribute for the code object is func_code in Python 2, - * whereas it is __code__ in Python 3.0+. - */ - PyObject *code_obj =3D PyObject_GetAttrString(handler, - "func_code"); - if (PyErr_Occurred()) { - PyErr_Clear(); - code_obj =3D PyObject_GetAttrString(handler, - "__code__"); - } + PyObject *code_obj =3D code_obj =3D PyObject_GetAttrString(handler, "__co= de__"); PyErr_Clear(); if (code_obj) { PyObject *arg_count_obj =3D PyObject_GetAttrString(code_obj, @@ -1899,12 +1872,6 @@ static void set_table_handlers(struct tables *tables) tables->synth_handler =3D get_handler("synth_data"); } =20 -#if PY_MAJOR_VERSION < 3 -static void _free_command_line(const char **command_line, int num) -{ - free(command_line); -} -#else static void _free_command_line(wchar_t **command_line, int num) { int i; @@ -1912,7 +1879,6 @@ static void _free_command_line(wchar_t **command_line= , int num) PyMem_RawFree(command_line[i]); free(command_line); } -#endif =20 =20 /* @@ -1922,30 +1888,12 @@ static int python_start_script(const char *script, = int argc, const char **argv, struct perf_session *session) { struct tables *tables =3D &tables_global; -#if PY_MAJOR_VERSION < 3 - const char **command_line; -#else wchar_t **command_line; -#endif - /* - * Use a non-const name variable to cope with python 2.6's - * PyImport_AppendInittab prototype - */ - char buf[PATH_MAX], name[19] =3D "perf_trace_context"; + char buf[PATH_MAX]; int i, err =3D 0; FILE *fp; =20 scripting_context->session =3D session; -#if PY_MAJOR_VERSION < 3 - command_line =3D malloc((argc + 1) * sizeof(const char *)); - if (!command_line) - return -1; - - command_line[0] =3D script; - for (i =3D 1; i < argc + 1; i++) - command_line[i] =3D argv[i - 1]; - PyImport_AppendInittab(name, initperf_trace_context); -#else command_line =3D malloc((argc + 1) * sizeof(wchar_t *)); if (!command_line) return -1; @@ -1953,15 +1901,10 @@ static int python_start_script(const char *script, = int argc, const char **argv, command_line[0] =3D Py_DecodeLocale(script, NULL); for (i =3D 1; i < argc + 1; i++) command_line[i] =3D Py_DecodeLocale(argv[i - 1], NULL); - PyImport_AppendInittab(name, PyInit_perf_trace_context); -#endif + PyImport_AppendInittab("perf_trace_context", PyInit_perf_trace_context); Py_Initialize(); =20 -#if PY_MAJOR_VERSION < 3 - PySys_SetArgv(argc + 1, (char **)command_line); -#else PySys_SetArgv(argc + 1, command_line); -#endif =20 fp =3D fopen(script, "r"); if (!fp) { --=20 2.47.0.277.g8800431eea-goog From nobody Sat Nov 23 21:23:22 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 66DBD1448E4 for ; Sat, 9 Nov 2024 06:18: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=1731133109; cv=none; b=Cq6nwY4KMd/pNRQWuw6SqErfvzLewxDDm7uUfvOW5hjrj+NjB7OaWTfQa5QPv/FbSVhSWn0Obk0qkSk+jrow3fPptPGMtgAnTf/bVAe0owekNwvrk+LvFQRwiQ+jqaVRDBas67s0lSEi+AG9Oy7QqOHXO8VYAw3+2PUxc2JCK0I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731133109; c=relaxed/simple; bh=3yk9PpgwraYwaRwWxmBpDhmZtrZFnMyP8x564LNvuBs=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=jjQOtSDc/nfkvCrJZtupy1xI4OePAGN2RoCZDrO6aTUg/8it0g7HQz5wT8KHvETRo4WS9NT6LhQjK0yTL34oX9C0gzNFhktaAZ0ePxEDHKzTfYhe5psjarSTeIGUs8AVsKuui/c9uvF7vpG+GH93MBgp44xQnqPEH5EP/FaG0+Y= 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=0fNjbexT; 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="0fNjbexT" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6eae6aba72fso20472267b3.2 for ; Fri, 08 Nov 2024 22:18:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731133106; x=1731737906; 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=6GW4rcpEOeG5zpcEUV+SUt4543oe133BrPkrMN5I9x8=; b=0fNjbexTe57jXv8dS9X9cXKRHbCdrad8vjWz+CENDs/YrDodvUOAGByQbs5AzMo6Ui prw1b/NEW3TGn2l2ycnh0hNee3NKlvvlIJiQeUOlz3+L33Zc4I6ad+lsjnZCsmzk8JrY Ghp38NTJhE1mSDFvKDvxP/BjRY4UZ9tNxiDLID/+rxhdj/s20QLyGY94Wc0wVjiey/jR X2zpVVUya0Y+mmQ5fD0jTfR+C5P9s6lUm7AqjgpcL/8Y+efzydBsTyWq15ELJbzYNUaf 5h38HhnYzHAHuytU8gkI1ANfEOqczUlF7xVaGqfK9Xwjhxx3xktzCfZjbSU2ufkgAzYY Kr8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731133106; x=1731737906; 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=6GW4rcpEOeG5zpcEUV+SUt4543oe133BrPkrMN5I9x8=; b=LiZGrEvvJQMHhHq1RrVtDHxrwq+Cr0yKv+QSE2tniSS+AHLVwqrnQVu2aPVzSAgIEQ xbbHrnfRGwgMf0HP/0JLALPoPyE1usrkVz+xE7rhe2dssf3zC7RWcGwyA5wbQ5G0pRV6 IVqf56rn3lpTstQFKcqWWUvK4nUtdD91mtI1AS4X4Eml4P0rhYque+0GEPB0tEbGNWlC 4CqgbDvTatUDdFmISG4BxofUIzK68vMN+yQ3Sa1KZ9SLJrKe/ciP54+mtF2UhMnw1jZO MBHp+zadTDmNSznBCUq37AKGh/qsFxYpYOeLowLSF9n1Sh+HbAcwctEaHKnwdGoltQkC r4gA== X-Forwarded-Encrypted: i=1; AJvYcCX2qrGaFW/ePgiDovCUvl4QWVjF8lAI2I6FyTamL578vz4Wig7xWNF9M1MYACEJdgAaaww/cEMPkWQqe7I=@vger.kernel.org X-Gm-Message-State: AOJu0YytApmExVuTmzykEqbn0IY/iQKFiAaPapt2hocZYa2pa7Jf4uiX DcG5Pjo0cuz+JQlimuLLFslE/eDds0quUYc4c9XNX8Hc1oTdSVhaBY1igHaPV7T8Jq5JWKI8lIN 5uMpdXw== X-Google-Smtp-Source: AGHT+IFDgmAMs3JPq43zy7HBUOp1PcUR2SHsOmdzAOIEQMLLUWyryinwOHZv6g2gpi9+foev90I+RmRiOSEc X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc2:d48f:a998:5915]) (user=irogers job=sendgmr) by 2002:a81:ad0d:0:b0:6e3:39e5:f0e8 with SMTP id 00721157ae682-6eaddfb8845mr281637b3.6.1731133106199; Fri, 08 Nov 2024 22:18:26 -0800 (PST) Date: Fri, 8 Nov 2024 22:17:49 -0800 In-Reply-To: <20241109061809.811922-1-irogers@google.com> Message-Id: <20241109061809.811922-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: <20241109061809.811922-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v6 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 6fc283ac5498..945fb7bee0af 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.277.g8800431eea-goog From nobody Sat Nov 23 21:23:22 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 8490F145B27 for ; Sat, 9 Nov 2024 06:18:29 +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=1731133111; cv=none; b=J2rv2eUCiu9ThM5EbDlBiPEEtNlpyuins1ExDpBCZKwMvddMHPjoaQ77ngDJPwPH9ZNkd1zMpqQx+8Br3IfiH9FH5kUGXZ53cWnvloI/sIQfCK9j1B69uXJM2wXr9jdITPA/0pRFGvahGL9JD7tfhdIrwua5d+amXwYFAXkub9Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731133111; c=relaxed/simple; bh=M3EhLoWJpiHkO7fgF6UjV6G4kHXEsbbL6KnzJZ3Q2AM=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=AvN8mlLopM06hjkh7u50IXwfu85/Lyuybqgm345cxIh8zaoOfCsSMr+3jGB0Y47nu0vyxm3eFqTCVuqqzjMqpPlk2weaBupJANVYQkSmZo+F9GEO9LpF4ucwm0ONx5hPqE9yQEMSDXuqe28C7am8hzZwb3raJ29RybzM8/KnWhI= 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=PddJg+Mb; 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="PddJg+Mb" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e0b8fa94718so5167463276.0 for ; Fri, 08 Nov 2024 22:18:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731133108; x=1731737908; 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=AnTa2k5fRDqNj4DNNGYm75Ty05e5sRFryTTBArq6LA8=; b=PddJg+MbNmfUgvfN6D6aEWqf3oAVitMmeQTelKqfyJyRQTK5RMYku6tps8uWeQzdMy cVsAXi6h+ZSN9yjsCkW3Atlwne52t6RW5aDjHeVYo6HLokLx7WjVLfJ4nPYHayk9WM6R WF0uLQ+FzrN/wsXvkxEz4rkg24iJW8Ii9GGi5UuwbzUdIU4W174H47Y0AY2HT64WS0FM zCd82Tw+usjLhLajombFL9ua/TzNLqLpASTYtT4MRL30u+RqbmRB5Gwk2h74Y4BFmr/V DMPdEd6kfXVL8wx3diOgM978DWbXs1wY/5O92YcILNGWCpUoy16txMmIynz+SeA5Igbm B86g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731133108; x=1731737908; 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=AnTa2k5fRDqNj4DNNGYm75Ty05e5sRFryTTBArq6LA8=; b=lHLAc9SeiiCOqgftRO35WY4BSY9a3YZHtlcs1VVinYawntyqNaBUVv0sNXpQrbyDSW 94rCzNA8/40WcgFXxRbRJJlTonz5yHYyVhsUwX1/uPnuFwn39mv4Mh2+wL7gY8G0h0Zk avAA4T6UIJnExL1aTtTNCYxP3ROy4e1ul4Hce0Gp91NAMeAqk7/NItAl1qf6ayAqG2qh zKmRDiPuBQFEYYZu7Dea2J2XggAkZfcqAYaugvf4ceQkzE0e39NmMPY3FqLpsRMlR8BB 5ILfcf5qbmDcLxxQPLkWG8aEsh3ah2P9hokdKnDfF+Hs2ouPK6oQ/p5ZW/Y80gLyNGCY /9mg== X-Forwarded-Encrypted: i=1; AJvYcCUSZ5VAdxNe8Eip2cdLsX1PP8Ofz/IaIp4MMCY8EiaVHhaxVLztUk7ZHrd9c5aRDqGmny3/Qn8wQBj40AM=@vger.kernel.org X-Gm-Message-State: AOJu0YzBPrPMu8C7qi6MfXHgYwy+O1OsQQN1u7sFBQwCnckRevg6JdeM B+JkAsr6ckqTnmLv/5nzqeHirzFthN5SSiNv8nfVTPV3q3Oh+/5RBomrH4qSaSZeiNdoQEAD0gR Gnl5WgQ== X-Google-Smtp-Source: AGHT+IEMEIMjqxRWxqS6oH5RjgG4gu+/sTgO3rKvWlcSAlAsgGnQ/nQ6Jr8n34KT+JS6rn74DaEcoK6IaK4W X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc2:d48f:a998:5915]) (user=irogers job=sendgmr) by 2002:a25:aaea:0:b0:e2b:d28f:bf28 with SMTP id 3f1490d57ef6-e337f844036mr13183276.2.1731133108599; Fri, 08 Nov 2024 22:18:28 -0800 (PST) Date: Fri, 8 Nov 2024 22:17:50 -0800 In-Reply-To: <20241109061809.811922-1-irogers@google.com> Message-Id: <20241109061809.811922-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: <20241109061809.811922-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v6 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 945fb7bee0af..e2109f6c7ead 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.277.g8800431eea-goog From nobody Sat Nov 23 21:23:22 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 08E9F146D76 for ; Sat, 9 Nov 2024 06:18:31 +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=1731133113; cv=none; b=nOqTjxv+Gfo9kwN9260fgGW++3oOmwY0NdKgV3TP9fNteSBUlR1z4zZPtnjw5TgrIPOm9MW91MJ+7S3TikUb4MqeWk94aPEg+/x0cNjbkAF5paZ1FPcYgKWj85f7UZgGxlXFTxMjF/BsYbOS4VmWPRJv9hb2iKnjZnn52W5R2OI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731133113; c=relaxed/simple; bh=jjW/Mdo4ZJpee7DWegXh1qo6a5tS0N+f/pHHyUDeYmQ=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=duHm1J2HDnTkIrB/uqmSkbAUNfDhsDFHk8gO8+3Y27BkufjhVWe5b+mai2KgopkVNFxkcjDUAqfvl0HqjSiqrZH7vumRmx+ixQhbOrlKlrsMcSr130Rpi84rOpA6Gx5Zp8iizPxrcg/giud12znZMvvqU/dM1wdEV0XX7o+UlcE= 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=aJGqfvpE; 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="aJGqfvpE" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e292dbfd834so4912810276.3 for ; Fri, 08 Nov 2024 22:18:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731133111; x=1731737911; 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=mKtLelHwLhS+FdJ2cDeNqQNGycDHJZPn6HtFfn+lcrc=; b=aJGqfvpEzZ5Z7Njz5rl5JeSQ++2EwJ2zelI8LiKlksDY7/PbfXwIXyK7NBy71tXEtW L9dYpAyJPhiBkDiLvDgAq7cfQNtVA0qGsVOPW1QiBdk8NA7y7kTFYWvkeseHT4cRwxOz 3YaCfny5odP7hdzljA+ryvsyFcVyGgLQWOKXys3G8I4t+YCSDdQi8Ci3TkMG87swafgY qYsm5OPlSUwKr98sR8Vh2doi4ES0N9fivIaNZAzvSMOrVY9rPx/70gCzYieH9pY0BPv0 THjR1/s1aoBY/KOh02lsAAVoqwB+OOeFFzY7rQXVpTad2WHfeMB1vhkyJqhVfiTy4N5i wzWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731133111; x=1731737911; 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=mKtLelHwLhS+FdJ2cDeNqQNGycDHJZPn6HtFfn+lcrc=; b=Lo04O3N/Gvmkxih5IqXMCdbYargUBeSACQkH5YO8CkF5Ggpai+MtHd1Ctq60g8qg7R Rz895vmPKAgV/0JYxJmocK23D0uz+0MmRB/iSJwkjBaDCx1hjg3s1KO1XGQiXpRHNMEt 1rfuk04QhtNrWMkXMEaKp39dCtwK2+w7Q64P72cV/SqYYwwLChWhqgmDC/x75suzftoo lMeFJyOCGl4kAmm+j9F0J4ARgUOOeghB+pqx3tkVqNuuIzgbYveXz5Z1gd6h38N81qQo RdNt/uRJTGPFRQQ6HP76AAQ593YprZN7xyV4bUNn3fTwTpH1iYOKNECdf6tFmC+GhwQQ Y22Q== X-Forwarded-Encrypted: i=1; AJvYcCVxTJuZB201LtTilZWltVAGBHT1Od1iZ3criCm4+Yh5W7ztN8+kn9lc9YAI1n5RGbbJNBk5lzrEqn+uHPY=@vger.kernel.org X-Gm-Message-State: AOJu0Yx+u0cZQRkMBwP1He+UGXZcuHpX3lgPnuyzv0gnpM/hG14KeXeV +W+qKlZ/3mZuUyP+CZ3aNZw7WuITVG5JwASy8gEvcodUxENNLBJPgoZvDaB2S2JGkMnbOLoypZq Eh9mPcg== X-Google-Smtp-Source: AGHT+IGhIeNLPRZK5O/PYT2qqHEwmo4Z8fY+bYdkwDZDWI3k5DZ9o8bTRsCOjM4Mj3m73yhcoJua6oaDQxoH X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc2:d48f:a998:5915]) (user=irogers job=sendgmr) by 2002:a25:aaea:0:b0:e2b:d28f:bf28 with SMTP id 3f1490d57ef6-e337f844036mr13186276.2.1731133110711; Fri, 08 Nov 2024 22:18:30 -0800 (PST) Date: Fri, 8 Nov 2024 22:17:51 -0800 In-Reply-To: <20241109061809.811922-1-irogers@google.com> Message-Id: <20241109061809.811922-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: <20241109061809.811922-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v6 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 6b6d4472db6e..5d5a1a06d8c6 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 e2109f6c7ead..f82e8a968e24 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 bd0000300c77..8abb7a7b6888 100644 --- a/tools/perf/util/trace-event-scripting.c +++ b/tools/perf/util/trace-event-scripting.c @@ -16,9 +16,12 @@ #include "debug.h" #include "trace-event.h" #include "evsel.h" +#include #include #include "util/sample.h" =20 +unsigned int scripting_max_stack =3D PERF_MAX_STACK_DEPTH; + struct scripting_context *scripting_context; =20 void scripting_context__update(struct scripting_context *c, --=20 2.47.0.277.g8800431eea-goog From nobody Sat Nov 23 21:23:22 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 19141149005 for ; Sat, 9 Nov 2024 06:18:33 +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=1731133116; cv=none; b=BNhuF1VHdgpOO1Z4SNydQXn6CCdy12VeuA0O2XQQ0lS0PGqOWVpokGpPZwAsKdilMhMVV0L+erJgSFNvGeHEvRBRIW1XqMNPNMo/OpCPv3t79hWzVfFqcpS5n4v3nTmSo9LlDuo+Qu5t0zv79V72yYoYyTEwQ0tXgCa6lOZbLkk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731133116; c=relaxed/simple; bh=ME2AZmwamAaxLUxl/n4fQb9W7X1LdXUNBLV0PhT15RU=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=CA+jmBNC6UnVOZ8HvByU8+a9j8ymyOXBL+C8gU4JizCtF8FWQkEqRGde3PJeC8dnyLnrEtk/+tOY6iIw1hGjrvIrvyYq47eSCCggbMX2BLQm7v26Rv67RyjY1kHmYa3+6uUVGgCLYuD0+PK4OvuNjyjrXpFhyNT3OViGA2bU4XI= 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=dnXeT+VR; 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="dnXeT+VR" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6ea527764c3so53533477b3.0 for ; Fri, 08 Nov 2024 22:18:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731133113; x=1731737913; 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=0vxvGl5vYfQ4Qd5F6bBw1bO/cdktsUuMIT15kf42GtQ=; b=dnXeT+VRbC6RHvaW9eDa2sDhYBaYT5q7DK7ICpuof/Obqwn14xS6mzq2Crn+gkLp+9 29EgwgsMjlIdJnnpKn5lenP9C4nP7UfIJCY3UKUdAPF7yU4BBtqQ9LQar+3RwPZXlOCM wGjGpZBOkn+1eI/2wipaV6iGibD77eSeyE4tvMLOn/Bp10ewVkPDA5ck+AYwfLjYOlz+ 3e6eYBqm8T5eTR78StVtG6Prjw1k4lnuHfaVs33SLRd9h1Ws7BJN4BLht+VwW0A3SJvV BjxSV1gz2lpbUsNLTapkFYIdyI34uk/YALYHQ+CUc6ciDIUFOcvV9qgVXl7+zNFWGSis 93gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731133113; x=1731737913; 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=0vxvGl5vYfQ4Qd5F6bBw1bO/cdktsUuMIT15kf42GtQ=; b=j9RHMjOJIsndrpEUIFss2mF59FNsQJS+mu1CmhL0hqNJH9Q8e3II+BIublC30jHFLx OZBAeRg7tQTGt4muiq4QkEkF1pxMFBg2yJ10SaX7xnDWjkV52jL0zEDm8fiNBMJU5uAe M05uTcuIhDepGdLyBlJr75Oajcp2A4sX+FnO28zVZggLIHxqc7fkVSqs4An3sBzwEPa7 RSzwFaArCDkrCkcZBQgk4K0D814Qsu6k5z19bDVbGAen0+4my3SwUngTZM0LppZtuOje Z/Aa4vVyqrjy1La7kMW1APwiYSIAfbMIc/rsaiRObDHiqtBDNaUaO2nHqfKMr3129T95 x6Ew== X-Forwarded-Encrypted: i=1; AJvYcCWkV2K4Heh1j/a95fj0g3bc6lKCtvb9r+4pnCCtyXrp48G+1CbkjL33eJmq/Zh3cl8I3towVltpgs7yPNQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyPd17M58K65IbjhGgHxBcyYpZcP74EnCny9b6OVXyEPcDFHfuk Q+3T3xeLy7b1SinJ3rC3wAVje6tmcnDlKbdUpeoLSo8vuDcJC0lUDHpkythL3yteGFRX4LfOszH pRE5w3g== X-Google-Smtp-Source: AGHT+IEfG4TB30bVTiocdZ7kQXgcw5C6ysvWB7xUMUoxLuqo3Co0e5PtXrMrwI+6ndfy0XGF1pxJGm+cp/bF X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc2:d48f:a998:5915]) (user=irogers job=sendgmr) by 2002:a0d:ed43:0:b0:6ea:7c90:41f2 with SMTP id 00721157ae682-6eaddfbb341mr214977b3.6.1731133113036; Fri, 08 Nov 2024 22:18:33 -0800 (PST) Date: Fri, 8 Nov 2024 22:17:52 -0800 In-Reply-To: <20241109061809.811922-1-irogers@google.com> Message-Id: <20241109061809.811922-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: <20241109061809.811922-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v6 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 099ce3ebf67c..e50cd04e3725 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -615,67 +615,6 @@ static const char *get_filename_for_perf_kvm(void) =20 #if defined(HAVE_KVM_STAT_SUPPORT) && defined(HAVE_LIBTRACEEVENT) =20 -void exit_event_get_key(struct evsel *evsel, - struct perf_sample *sample, - struct event_key *key) -{ - key->info =3D 0; - key->key =3D evsel__intval(evsel, sample, kvm_exit_reason); -} - -bool kvm_exit_event(struct evsel *evsel) -{ - return evsel__name_is(evsel, kvm_exit_trace); -} - -bool exit_event_begin(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key) -{ - if (kvm_exit_event(evsel)) { - exit_event_get_key(evsel, sample, key); - return true; - } - - return false; -} - -bool kvm_entry_event(struct evsel *evsel) -{ - return evsel__name_is(evsel, kvm_entry_trace); -} - -bool exit_event_end(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, - struct event_key *key __maybe_unused) -{ - return kvm_entry_event(evsel); -} - -static const char *get_exit_reason(struct perf_kvm_stat *kvm, - struct exit_reasons_table *tbl, - u64 exit_code) -{ - while (tbl->reason !=3D NULL) { - if (tbl->exit_code =3D=3D exit_code) - return tbl->reason; - tbl++; - } - - pr_err("unknown kvm exit code:%lld on %s\n", - (unsigned long long)exit_code, kvm->exit_reasons_isa); - return "UNKNOWN"; -} - -void exit_event_decode_key(struct perf_kvm_stat *kvm, - struct event_key *key, - char *decode) -{ - const char *exit_reason =3D get_exit_reason(kvm, key->exit_reasons, - key->key); - - scnprintf(decode, KVM_EVENT_NAME_LEN, "%s", exit_reason); -} - static bool register_kvm_events_ops(struct perf_kvm_stat *kvm) { struct kvm_reg_events_ops *events_ops =3D kvm_reg_events_ops; diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 1eedead5f2f2..650974413849 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -120,6 +120,7 @@ perf-util-y +=3D spark.o perf-util-y +=3D topdown.o perf-util-y +=3D iostat.o perf-util-y +=3D stream.o +perf-util-y +=3D kvm-stat.o perf-util-$(CONFIG_AUXTRACE) +=3D auxtrace.o perf-util-$(CONFIG_AUXTRACE) +=3D intel-pt-decoder/ perf-util-$(CONFIG_AUXTRACE) +=3D intel-pt.o diff --git a/tools/perf/util/kvm-stat.c b/tools/perf/util/kvm-stat.c new file mode 100644 index 000000000000..38ace736db5c --- /dev/null +++ b/tools/perf/util/kvm-stat.c @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "debug.h" +#include "evsel.h" +#include "kvm-stat.h" + +#if defined(HAVE_KVM_STAT_SUPPORT) && defined(HAVE_LIBTRACEEVENT) + +bool kvm_exit_event(struct evsel *evsel) +{ + return evsel__name_is(evsel, kvm_exit_trace); +} + +void exit_event_get_key(struct evsel *evsel, + struct perf_sample *sample, + struct event_key *key) +{ + key->info =3D 0; + key->key =3D evsel__intval(evsel, sample, kvm_exit_reason); +} + + +bool exit_event_begin(struct evsel *evsel, + struct perf_sample *sample, struct event_key *key) +{ + if (kvm_exit_event(evsel)) { + exit_event_get_key(evsel, sample, key); + return true; + } + + return false; +} + +bool kvm_entry_event(struct evsel *evsel) +{ + return evsel__name_is(evsel, kvm_entry_trace); +} + +bool exit_event_end(struct evsel *evsel, + struct perf_sample *sample __maybe_unused, + struct event_key *key __maybe_unused) +{ + return kvm_entry_event(evsel); +} + +static const char *get_exit_reason(struct perf_kvm_stat *kvm, + struct exit_reasons_table *tbl, + u64 exit_code) +{ + while (tbl->reason !=3D NULL) { + if (tbl->exit_code =3D=3D exit_code) + return tbl->reason; + tbl++; + } + + pr_err("unknown kvm exit code:%lld on %s\n", + (unsigned long long)exit_code, kvm->exit_reasons_isa); + return "UNKNOWN"; +} + +void exit_event_decode_key(struct perf_kvm_stat *kvm, + struct event_key *key, + char *decode) +{ + const char *exit_reason =3D get_exit_reason(kvm, key->exit_reasons, + key->key); + + scnprintf(decode, KVM_EVENT_NAME_LEN, "%s", exit_reason); +} + +#endif diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index 3e9ac754c3d1..4249542544bb 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -115,6 +115,8 @@ struct kvm_reg_events_ops { struct kvm_events_ops *ops; }; =20 +#if defined(HAVE_KVM_STAT_SUPPORT) && defined(HAVE_LIBTRACEEVENT) + void exit_event_get_key(struct evsel *evsel, struct perf_sample *sample, struct event_key *key); @@ -127,6 +129,7 @@ bool exit_event_end(struct evsel *evsel, void exit_event_decode_key(struct perf_kvm_stat *kvm, struct event_key *key, char *decode); +#endif =20 bool kvm_exit_event(struct evsel *evsel); bool kvm_entry_event(struct evsel *evsel); diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index f82e8a968e24..94902652e371 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.277.g8800431eea-goog From nobody Sat Nov 23 21:23:22 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 8E9411494CE for ; Sat, 9 Nov 2024 06:18: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=1731133118; cv=none; b=Y3ky9BPHO1K8Jw2uCi2YKyWgfBKBvoFyN78GUWFmcw1OCUPkLPMWmuHkgG6FPoG7HyABz8xrGyySPJrJ5P6kB8bNLoYnrjO80klv+Xz0TPjUsBGT9nN8BGpwl//z5fUeAsaAK4/PlrN2v/R6W6PUyNrTtGi3yKBYqHmxwDZSucE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731133118; c=relaxed/simple; bh=YYtvRxCX/8ofSsiGiywJUusvMbgIjREiaLL6Eyo+6Dc=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=VhfIQ3VgL/QAfiy/U+leJgV2qi64vXJNiiNpaQNKCJFDIdtM7KEAf8IX+n9Vsn6Cl7OOeOaChIk76zfIWqPjv/3xSF/ANDS3ZKYPQHEmTi46wMatkfBCvkmnT1w5Vk+OtGWreWQzoUCKZNsNuOY2CXXYuYDe5lLP5YVfsHmPck0= 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=E3Pjp+lt; 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="E3Pjp+lt" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6eaae8b12bfso51022437b3.3 for ; Fri, 08 Nov 2024 22:18:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731133115; x=1731737915; 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=9GoQivGoNWmT9gaE1TJbS6tMzpRjpjMvcsKtvvg35Zs=; b=E3Pjp+ltrE5x84U+RUsgy0dsj1eoeko2Q0vb53JUUlAW+9JyOjUyNeCuJTmZDGEqKB yTBiwKEYtyUA90mULmzoq2NZumy51YsF6Nbe/SuEFnk1g1QcIMPYfDbenbfG4NsS1q3F IUQeS2bdrpJXbFzk16uQJh5rGjS+YDzQUCKE0nJGGYs5y4qCcTdrD1yPb+p7HC589YWL aN25C38fTq9pGOnAuWqFW6ElWbidCQicYp/ywZn5+eFWbIVf0QDLIHzggttdBOD58+bQ D/p4N7dpH76sbo+C/lDuI4w68ESg+0W8CMuyaSCZsQyRRpPvtFdpj7LQPgwfHCoQ+cYH Ouyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731133115; x=1731737915; 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=9GoQivGoNWmT9gaE1TJbS6tMzpRjpjMvcsKtvvg35Zs=; b=wR3DnvcOFyUaKYnHJroffBs+xAay1LuB/YsEEMztLi0LIJ76Ud/Wkhz7BM63nOcRnW AtthQwb2tBbt17PN7l7piYe3v0euHDA+1A5que8ntgOGyR+a+q1d5Rp1xQQv9Byhspqg KHXNQzQfKeovxJq7l/m6t4Sc0+OLSSbRGKnudO4QUZw8SpbcrUEb6TrpAgOkwnpyX9YW /4kKp+kB/IKOXtiOYMbBZFcuIQEEqHONeSRcQYcT6LLERvdAsebrFY7OIRpcj3ej6KRS A7fP++Ntrapv4if7LKb7lQ+ZVntsElHAT6u40Elk3tyyzyhDh96QmEAOkzxiESt9wZ9d ko5Q== X-Forwarded-Encrypted: i=1; AJvYcCXBJZNQMcz8RaQBsJOh74DIIW+zf0hGLXAtpCKfGPrj3+5MqitGyPUagX3CmbfCniTUp90/dvq4hSMUczw=@vger.kernel.org X-Gm-Message-State: AOJu0Yz/wY+oTxz97dHxbXSGcy1yT43jd7g0oSvKYWHpoNjVO08mHlpG ZpHf/1WHXK2k+YkPEwoXHxoDoJ+3aEQ/CGEuwbeeDOAFKW+QNKmEXAT76vGD+pP5uV3akJSIRZU /TnwJOQ== X-Google-Smtp-Source: AGHT+IHN8AifqxPtJuLxZYkfsnYSnHbvgQJ2hKIeIjxdRVDK9jcOgpIpfRgTpb20QsgGDAYn7wzspuDMBXO7 X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc2:d48f:a998:5915]) (user=irogers job=sendgmr) by 2002:a25:d8cb:0:b0:e30:d717:36ed with SMTP id 3f1490d57ef6-e337f8ead19mr3757276.10.1731133115271; Fri, 08 Nov 2024 22:18:35 -0800 (PST) Date: Fri, 8 Nov 2024 22:17:53 -0800 In-Reply-To: <20241109061809.811922-1-irogers@google.com> Message-Id: <20241109061809.811922-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: <20241109061809.811922-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v6 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 5d5a1a06d8c6..e20d55b8a741 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.277.g8800431eea-goog From nobody Sat Nov 23 21:23:22 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 BED041428E3 for ; Sat, 9 Nov 2024 06:18:38 +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=1731133120; cv=none; b=s45zWF7FSkzfxFWYJG7sYhqJ+RjDIRc1vonFvWS5hCD++FUWnt1LbVbWDglXilw7nmoWlcpLulqUlPM7xlSXqFjqUXNBIjcIw/5nHGIfcKGA57JjwlhqMKpMrCitT7GzUTKAOeT6Bnpycw8gEY/i0nTIfI8KKLTJDTQCXnC8NwY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731133120; c=relaxed/simple; bh=7TgB0AcBPzEPV7nSAaJTGLcx062mAxvJSe8i+Y/G1nQ=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=ZKSPYFEQhB11VUeQeSIzkY+UpFpm+KzUUIYveKUrWTrnjfulGkObD0GWjpYrTOenottgAyIVZI1t8U0meiAjBQhz28oOrfXLazAGnJn5UimjDq81RZFJegmsjjteRRQRO3qNb6GD8ajiSvFhFlAagqQmonC/bKDBdLy0kw3woOk= 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=O5CC7YOG; 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="O5CC7YOG" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e30cd709b40so4945305276.1 for ; Fri, 08 Nov 2024 22:18:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731133118; x=1731737918; 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=nD/NdnGAGoeL3cAcfuS47/M7Ih34fBwBdXC2Llg8WuI=; b=O5CC7YOG+6dhjYFS6DH6AQHU+wzN1gNqghD9V2R++uHyDWuZ3Qc3yrE4FhOjM8cuRk 2Ip+uBzHU7Wg1aVcwg8qJbZI1rGyWRGUSl7BRwLSfzoUaHf63RmepU0akYQOTLbJFDZ3 /1s5HDkreGrd690+Lb8YHAGox2e+T7FOZS/cz3QEznH7RmCINGM1NrX4wFNpJWfyYNid heWjphMJI6+ZKznYuPrjW1QU51jFGhZkWGLz7eYxZnRJKCRZPwmGNlHzCUauXwBDmRon H5KwIFFisZ/RmI7NxpctPSo4C0DDfDUytX38mhgbdRgOAa4Sd43yJr4qBAN3osHc4aXR GjtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731133118; x=1731737918; 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=nD/NdnGAGoeL3cAcfuS47/M7Ih34fBwBdXC2Llg8WuI=; b=C/VLunn1CQIgGAFa0kzr04jmXtPNeufaHuGiuQH41zhjIjnrI8NQoNst1Z5NwyE58w BOocYlfWC1kl1Ro/27Gk8OeamteyzH6yoT0M/aGAXTNNrSJPfrQTMf9wEhDaCoaMa/o7 Bt1+Ws6TJ9DlK3FMHDDnN133j82ioOQ5dsNRcPmUrWzuzOzmOWt/EGDy7zWKpK19b6Rj h7I0Z4CwzBd8g0Z3b2HpgCB8obW9Pb0I9u3lVUPw5Y535C4DSY6spg+TrUr+y4w5GDLq xbeK9LYCtU8rHqJPOAOM1kUgGZGM3KBxoUE1IlNWVboodP8dyhBEFuObodWGSI7ER1bH /Njg== X-Forwarded-Encrypted: i=1; AJvYcCVKvoQRhTaaKllRjf3g+SuEs7upbbnQnk3HFatU0dw2cbgzBQg5WP5IR23kp3wQpLe1YkuouLOETueuruk=@vger.kernel.org X-Gm-Message-State: AOJu0Ywu5NtLGrg2hgriXGLT6QLI7oXgcwXQMp7NRNyz3fKGWwdqASnp 63amSUY5Yf9j17nhRH3fnmE+HZgt9isF20JVyK8R0Lu1x9RWRdrWwVI080v9tAntAE32B25jIft j643ufQ== X-Google-Smtp-Source: AGHT+IGn5Cj5p/savbBcVXiDFCm/wa6fgQ+a4h8u/+LC3CFC15OcIo4Q7tebFb0apBRRgESmBpVaMSkxWyIF X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc2:d48f:a998:5915]) (user=irogers job=sendgmr) by 2002:a25:aa53:0:b0:e2b:ce2f:787a with SMTP id 3f1490d57ef6-e337f861f01mr9642276.3.1731133117850; Fri, 08 Nov 2024 22:18:37 -0800 (PST) Date: Fri, 8 Nov 2024 22:17:54 -0800 In-Reply-To: <20241109061809.811922-1-irogers@google.com> Message-Id: <20241109061809.811922-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: <20241109061809.811922-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v6 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 e20d55b8a741..e9ec74056f71 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 94902652e371..eb15f3b6c4f5 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.277.g8800431eea-goog From nobody Sat Nov 23 21:23:22 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 EE83014D2BD for ; Sat, 9 Nov 2024 06:18:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731133122; cv=none; b=uWX2Iqd/t8ck33L9OcCpqNRvj7TI+t7qdzhCZmg+tW6BcYzvBVMJ4UhsdfqiLyxdHps2pFtlqwjXfbYzKsA7psftNNLPAugyC9KnKK3vcY7ER2xCwy2VrQMZc/qEoUZjosE+ocDFgynZ6ODqaYXe0Xsqqu0GHkUkQ+0HMnVFx2U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731133122; c=relaxed/simple; bh=lIF4ebo07Qn3lWBc2oG9EBvdP9eqb50Xz7CoIVuhSUw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=TLcFY5YBqng/lRtV5rBlTGZQsMX3ieAaObCuKdczi2jU+EjxSsWnykqr48SgX1YMHcJJpdRyr1+yBQZE8MfD0Wi/7ekuHuGcW6GHQZX+lwLltEoVfXdzMNwdDyBSG8usGugdkFZ7sDyUJTKYTrHWQ6fYM5howwtd/74yLYzGnXA= 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=uJwPxb0/; 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="uJwPxb0/" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e32ff6f578eso5103896276.1 for ; Fri, 08 Nov 2024 22:18:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731133120; x=1731737920; 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=vceMdfPQzvji0lr/wplVMHDa75Ua/B62DqNFCz+YnAQ=; b=uJwPxb0/TDrD9t9pVdwdXaRib4PJnF/CsfLkYtPrplQcHxtmK6KAes4GJfp1NOaM4W db3Ajqm2Jf5xGnKbqu/1+fbgXFiVEVl4Fv7ImUgp5jX2xQ79oH9Y02BxcYG9QLdAMYAA TxrppipmFBSjMRZEiojRSZIeVrwMSwLhqVxag2fekbNXqAYo4dSD3cwqZ4Ec3+Srg7/8 /t220SPzOcTGqqYab3IQwnz7FYbHNUeHbP9nu08Vx8X9iHGMGhwohFKtIUmCwEZ7/sCP 319qvcEV8XcvY6OOtC/J3c8nDeFzA8jt+r5U92j2/AdOIJuuO3GHjDtu/j4uLGmacXf9 crgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731133120; x=1731737920; 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=vceMdfPQzvji0lr/wplVMHDa75Ua/B62DqNFCz+YnAQ=; b=q9ck4OiMVtTCsCbpgO2kh6yjGPnsf8b73wGDpqhloLM1ldVTrBLenz4AOZS0xwnJxZ F32N/b67CiW8YHz9hCbEYl43O+tj5MvgsTC7BxEbdjwAFeP0CA19j7QJcqXndK0o5iUT hUw9hAQYmy09qI+nWS8SYxQfosN687A1WtchJxEsDOGyfzmxurHZj901FOwxrHMwY2vE BcpoFPvuau2IrAQKCXJNq/Tf1KdnF9M+nPqEzN+JKsD2eVjfD7Mg9I8A3lyfa7ZJ+C4z id/OWG2bE7yk0/H+C1P2W3az1RwlZbYRJzeyLdLc9iu35KQDKJwnDcvZEv5sJlqHeDGO aIgQ== X-Forwarded-Encrypted: i=1; AJvYcCWj6Zu8b/LQf5PBqrlX9K4aS3N0W1AWD+yFZNozEQGNgA3tTnyATZDbTsqvn7IcYx6IOpWGHPXZ/HR/654=@vger.kernel.org X-Gm-Message-State: AOJu0YxCsjiZGZt9xBArGPIM2kIR8qiNp9TCug1y3gYN2VK+8NBg+g83 ha5e0MABIv78w/F73gSYp12L96NlriLepECHzAfUMh+zgH2Z/K9kOX2QgQOUUxoHTPnFDx7WL6+ IyFa8fg== X-Google-Smtp-Source: AGHT+IFJj6ezwbroN2Z6Ou2WY5hJS2sWu4kbUw+Vh0YtYjC8+aP4yPS52d8ZHSESFDq6c+smKt4xwsnGJPhL X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc2:d48f:a998:5915]) (user=irogers job=sendgmr) by 2002:a25:c2c7:0:b0:e29:9c5:5fcb with SMTP id 3f1490d57ef6-e337e1b0c47mr26916276.4.1731133119967; Fri, 08 Nov 2024 22:18:39 -0800 (PST) Date: Fri, 8 Nov 2024 22:17:55 -0800 In-Reply-To: <20241109061809.811922-1-irogers@google.com> Message-Id: <20241109061809.811922-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: <20241109061809.811922-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v6 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 e9ec74056f71..62e851fdf5ca 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 eb15f3b6c4f5..0fa8e27769be 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.277.g8800431eea-goog From nobody Sat Nov 23 21:23:22 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 1A92614F9CF for ; Sat, 9 Nov 2024 06:18:43 +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=1731133124; cv=none; b=HIok2Pl3T7BcnUFtvrgpbGEs3eFGGjwjzMDR9ewvQbkzNLuCt+NiL82eI76ICNqySiMQ0SV1vD9Re5gwfjSw5rtePEXg2f4ev4QOmtceNaNxydyXKaX/dYYCNt0cODxXSS0gUmodbNQVIDy6RvTyas328Z/JIUaaq2WzsyEdkSU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731133124; c=relaxed/simple; bh=1KD3qfASQAWB+cYLT7zEMIy73hp9Uzy5o9ptaOoxOOI=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=l3KXI9YapC4Vm8iGtODaZGg21OJxAtjaOCTZsrDQKUOYOh5wOrpDuMerO8cd6vMvpejFZOd4iz36pSJpVm32RsmXxWKQ1TlfBHe7VSc7X7kQNWwgiDkktM40ZRwtohokGESPgfP9p9sU3zuDYCnSLK8xEA4wC9FqdflZRaei+Os= 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=FMtbyEBP; 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="FMtbyEBP" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6ea8a238068so52951177b3.1 for ; Fri, 08 Nov 2024 22:18:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731133122; x=1731737922; 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=UL0YJWtaGtLk38A4PwPckFN98loHPl8Fal+YozKgQvE=; b=FMtbyEBPDyUpQxCE7L7yXC1QwYV0NT/isgd4xMpvsiqe7XXsi7A9ua7kqNxgCMxDs/ wC4/6OUVNQYij0x9EL+oKU26bFNdci5rqT2hxKUdbBhjlYeKp3G7lZRlVBQuOqAqG4Df qD/P2p4zn6aFrhXd3ljS05c4TORUl0ibYeDDZvZWm8RQrX7px1wTzBugyo116S5x26e/ WmPyeDN3b3PSXoNutfmUFyiF0KtksiF0x7gcEEFtWQNEokgFtRLiCnj16WeCdP7rrUxZ xoGxjhxXB4W7IR3tjwwtSLrV6cCa/E6KMekBCCxxml1K1di1kxz7ToS8WawisUkgGD+C XxcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731133122; x=1731737922; 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=UL0YJWtaGtLk38A4PwPckFN98loHPl8Fal+YozKgQvE=; b=dJtzUESNTrsVs0k4KUBNoYR/Jgr4eAopbsddBYQGfroOYQzXX5ZGHoB722N0R1kxEW uKWcJepvqflrIqot9UQMbedZKXcNFyW+Sjz2qcjbDA7Tktql1245Kmiz4jALLt37xwKN KsHV0n8rHSiNbiFa9phnER7oXB3quU0zJKdMoJeePHFEoo4YPQsAtZhXRZ/2GIEbVyLQ 93qPKDeXiTBxYfoPktAKIIpVrfHCEqjk4ET3iQu+hfwW7VkpEREsofOwqw5V0JPXLyTW Ua8HQ7HLL+RHBzUJKzCZ2Y/wmv+uSeV5tBuw8bKFBaU8C9sc3fj3BYaXYPsdGNRf3Abu Cs9w== X-Forwarded-Encrypted: i=1; AJvYcCX7FlZkNwEyrvZ50qW6PsM6Nl04TSphJI+eFPjuU97HehZ2x0QNSL0IGVs1FS0ivEVE1kxKRuN8I7jHgFo=@vger.kernel.org X-Gm-Message-State: AOJu0YxjPlPm7oLXeb6zmEVRsrJF15i1CIOywzNMtfXFdNnSeBV4Rmjo OgWpmOIvdlru/IWLrfoTZIGhszRWa/If1f+XFSuH7d3IleZkbUx6ZmYOZh7hLl4G7Yz0br0wJcP TgvfKrA== X-Google-Smtp-Source: AGHT+IFV5YgKbuTWNs3EdWbrO21Ryr+az9efGuM2U4bETysi56ys4TKKig1sDrsdjWBgktyLOxZNXpz9xixH X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc2:d48f:a998:5915]) (user=irogers job=sendgmr) by 2002:a05:690c:6d13:b0:6e3:cb96:f577 with SMTP id 00721157ae682-6eaddfe2f28mr665497b3.8.1731133122256; Fri, 08 Nov 2024 22:18:42 -0800 (PST) Date: Fri, 8 Nov 2024 22:17:56 -0800 In-Reply-To: <20241109061809.811922-1-irogers@google.com> Message-Id: <20241109061809.811922-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: <20241109061809.811922-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v6 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 62e851fdf5ca..11c0ee8c1afc 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 0fa8e27769be..3d938fe2de6a 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1305,11 +1305,6 @@ PyMODINIT_FUNC PyInit_perf(void) /* The following are stubs to avoid dragging in builtin-* objects. */ /* TODO: move the code out of the builtin-* file into util. */ =20 -int script_spec_register(const char *spec __maybe_unused, struct scripting= _ops *ops __maybe_unused) -{ - return -1; -} - arch_syscalls__strerrno_t *arch_syscalls__strerrno_function(const char *ar= ch __maybe_unused) { return NULL; diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trac= e-event-scripting.c index 8abb7a7b6888..ad62d8e5a368 100644 --- a/tools/perf/util/trace-event-scripting.c +++ b/tools/perf/util/trace-event-scripting.c @@ -24,6 +24,81 @@ unsigned int scripting_max_stack =3D PERF_MAX_STACK_DEPT= H; =20 struct scripting_context *scripting_context; =20 +struct script_spec { + struct list_head node; + struct scripting_ops *ops; + char spec[]; +}; + +static LIST_HEAD(script_specs); + +static struct script_spec *script_spec__new(const char *spec, + struct scripting_ops *ops) +{ + struct script_spec *s =3D malloc(sizeof(*s) + strlen(spec) + 1); + + if (s !=3D NULL) { + strcpy(s->spec, spec); + s->ops =3D ops; + } + + return s; +} + +static void script_spec__add(struct script_spec *s) +{ + list_add_tail(&s->node, &script_specs); +} + +static struct script_spec *script_spec__find(const char *spec) +{ + struct script_spec *s; + + list_for_each_entry(s, &script_specs, node) + if (strcasecmp(s->spec, spec) =3D=3D 0) + return s; + return NULL; +} + +static int script_spec_register(const char *spec, struct scripting_ops *op= s) +{ + struct script_spec *s; + + s =3D script_spec__find(spec); + if (s) + return -1; + + s =3D script_spec__new(spec, ops); + if (!s) + return -1; + + script_spec__add(s); + return 0; +} + +struct scripting_ops *script_spec__lookup(const char *spec) +{ + struct script_spec *s =3D script_spec__find(spec); + + if (!s) + return NULL; + + return s->ops; +} + +int script_spec__for_each(int (*cb)(struct scripting_ops *ops, const char = *spec)) +{ + struct script_spec *s; + int ret =3D 0; + + list_for_each_entry(s, &script_specs, node) { + ret =3D cb(s->ops, s->spec); + if (ret) + break; + } + return ret; +} + void scripting_context__update(struct scripting_context *c, union perf_event *event, struct perf_sample *sample, diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h index 0e5133f1b910..0520dd269374 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.277.g8800431eea-goog From nobody Sat Nov 23 21:23:22 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 59B621547CD for ; Sat, 9 Nov 2024 06:18:45 +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=1731133127; cv=none; b=C4juxQuw91mw0QyGRziPSf+2KV+VMYIlNJA5DE9srK+5+cOoywvARzuA9CGyGMd7KYXB76+nAEtN1ApoIt1QyCt1Ping006xdK1f4L7uOt/TAAXYc4IGScWXpYncCKluEUmYq/JvrCFOdgSijoYjVmxudyW8TpF8gVa2582bc14= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731133127; c=relaxed/simple; bh=DmhyKML5p5uyc9lw30xgAkik7ISJn6DGddaiJ31l+m4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=BYWuc5DRdE0VwWlTMa7Gqa+P34e7UjpAAkVDlbBdQjSTNTnlZuCiTwIHsSHO986EBP9Et2x5L/qt8dESJHz8vkZHatxn/xMQaUKYrGn12THD2TLyjz8B9ZPSiE/Txm3enwPrI2l2hzamsLQ9E/xeotluaQpzcKVNfkcQCd3hY9k= 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=bHCyNPeA; 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="bHCyNPeA" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e59dc7df64so35469867b3.1 for ; Fri, 08 Nov 2024 22:18:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731133124; x=1731737924; 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=IOrkvPcvHjQedYd3c7yfUgCb4BbIK+zJ8VChcGJxjag=; b=bHCyNPeAWm2xGOvuTnrtTRm+1j6k0Dw5XaeNhHC9gSr0m+4C8tmgtGdWs/JmCF1yk8 5i7F7p64tqTc3s/w7b0F54KcycWPk7fcUZAePcjTbxdM/5aAHbjRQkD4zlIuygiTfdx5 iR7SP/SgOqtD3Aq6UJtLnAJP3UfsM3IsUJU3yo4FzxUXfwxc48gR3eJOidqg4cwNCcpr LZtxYqgo29KHwdEhWw2eezEU99UKutn6+aqUNhTvu30McCYxQb1qC2So2glg1lICNOiE x4gImp6f5WHlz0svnLdpDGGYRbIHzI7bPqVmIE30zmqCFGI7bbLDdypH4Kar7DpiLPb1 n7qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731133124; x=1731737924; 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=IOrkvPcvHjQedYd3c7yfUgCb4BbIK+zJ8VChcGJxjag=; b=FDWhUkjuqRR22C5oL4PauDCv63iCklz9MRc8acePgPHH/ne+vqA+nMT69k+XkXhQsY Tc36xYkILl4qt2rwtxHlADEqqRQ8pFNpAJzHeGWkDXTpH8v7/f6e6ART3jwKkfqwBhkI S3ltC4V7vd74cnNfc+9am76OXIX1jtEEPWnmjbcobzbU4lHJwTwgPOPEmtyqEhONvc19 1bTCP3/7GPZPaEpf11joTYIfhWw3hIqVhS+3iEKqiJrQdA2bUKhv8TNcI52oZ5XTAfPk QeWpPCbjf6qG3RIcKAfPzaF4HkxQOeC4F3s7w+7+qnvtCH6/K65fMGLP19R+kGduQKgd NYLw== X-Forwarded-Encrypted: i=1; AJvYcCWXWX8FHLtrB6glBhBEN3YV89yaZfiF66SY0n6qXZBCXLudqopQINgK6iZjiSJfezBpq2aRq+z4o0dAnF0=@vger.kernel.org X-Gm-Message-State: AOJu0Yws3AycX5t/AKV5Gdp7sw1OLCD4cIeDPQqU34Q3AiERgs177OFF gMY7uE1Z0hxO+CntuWcjWDO90PpkKcr1RGxQgYoDrESj/3KurC7Dug4n1USO1A7S4HBVro+MJOS UHFFUow== X-Google-Smtp-Source: AGHT+IHac+QX1KxOp8UsOxuSd1Rqf23eoUA4r9Vn5FImDMoRE/tizKeMfe7trdWWCoUnRf6amqqkLOLu5pII X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc2:d48f:a998:5915]) (user=irogers job=sendgmr) by 2002:a0d:c302:0:b0:6be:523:af53 with SMTP id 00721157ae682-6eadc114281mr562767b3.3.1731133124450; Fri, 08 Nov 2024 22:18:44 -0800 (PST) Date: Fri, 8 Nov 2024 22:17:57 -0800 In-Reply-To: <20241109061809.811922-1-irogers@google.com> Message-Id: <20241109061809.811922-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: <20241109061809.811922-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v6 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 11c0ee8c1afc..22d78a9d8f27 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -1586,19 +1586,6 @@ static int perf_sample__fprintf_callindent(struct pe= rf_sample *sample, return len + dlen; } =20 -__weak void arch_fetch_insn(struct perf_sample *sample __maybe_unused, - struct thread *thread __maybe_unused, - struct machine *machine __maybe_unused) -{ -} - -void script_fetch_insn(struct perf_sample *sample, struct thread *thread, - struct machine *machine) -{ - if (sample->insn_len =3D=3D 0 && native_arch) - arch_fetch_insn(sample, thread, machine); -} - static int perf_sample__fprintf_insn(struct perf_sample *sample, struct evsel *evsel, struct perf_event_attr *attr, @@ -1608,7 +1595,7 @@ static int perf_sample__fprintf_insn(struct perf_samp= le *sample, { int printed =3D 0; =20 - script_fetch_insn(sample, thread, machine); + script_fetch_insn(sample, thread, machine, native_arch); =20 if (PRINT_FIELD(INSNLEN)) printed +=3D fprintf(fp, " ilen: %d", sample->insn_len); diff --git a/tools/perf/scripts/python/Perf-Trace-Util/Context.c b/tools/pe= rf/scripts/python/Perf-Trace-Util/Context.c index d742daaa5d5a..60dcfe56d4d9 100644 --- a/tools/perf/scripts/python/Perf-Trace-Util/Context.c +++ b/tools/perf/scripts/python/Perf-Trace-Util/Context.c @@ -93,7 +93,7 @@ static PyObject *perf_sample_insn(PyObject *obj, PyObject= *args) if (c->sample->ip && !c->sample->insn_len && thread__maps(c->al->thread))= { struct machine *machine =3D maps__machine(thread__maps(c->al->thread)); =20 - script_fetch_insn(c->sample, c->al->thread, machine); + script_fetch_insn(c->sample, c->al->thread, machine, /*native_arch=3D*/t= rue); } if (!c->sample->insn_len) Py_RETURN_NONE; /* N.B. This is a return statement */ diff --git a/tools/perf/util/dlfilter.c b/tools/perf/util/dlfilter.c index 7d180bdaedbc..ddacef881af2 100644 --- a/tools/perf/util/dlfilter.c +++ b/tools/perf/util/dlfilter.c @@ -234,7 +234,8 @@ static const __u8 *dlfilter__insn(void *ctx, __u32 *len) struct machine *machine =3D maps__machine(thread__maps(al->thread)); =20 if (machine) - script_fetch_insn(d->sample, al->thread, machine); + script_fetch_insn(d->sample, al->thread, machine, + /*native_arch=3D*/true); } } =20 diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 3d938fe2de6a..22edadd64e5f 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1317,12 +1317,6 @@ struct kwork_work *perf_kwork_add_work(struct perf_k= work *kwork __maybe_unused, return NULL; } =20 -void script_fetch_insn(struct perf_sample *sample __maybe_unused, - struct thread *thread __maybe_unused, - struct machine *machine __maybe_unused) -{ -} - int perf_sample__sprintf_flags(u32 flags __maybe_unused, char *str __maybe= _unused, size_t sz __maybe_unused) { diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trac= e-event-scripting.c index ad62d8e5a368..beac456260ae 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 0520dd269374..0c5becc822f9 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.277.g8800431eea-goog From nobody Sat Nov 23 21:23:22 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 A49CF14D2BD for ; Sat, 9 Nov 2024 06:18:47 +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=1731133129; cv=none; b=HkG5CYdS/cl80sFvkJtoV0kID0TjbFPCH43VISvwYkvieuWrUoxSSAxl9kTYIMjffYFNZ5hBI66J0R0TQO3vb3q4AYFJo0n/J1SnaLA1Ntckl6oEazZxvIHHFA7hJIRL8rWFfVap/ecBnUrjgjx2bAmD1pSSScgT5NUWDMavkec= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731133129; c=relaxed/simple; bh=Augzyo1sYVN9zYVhVZ4NaRoQNcTkw/sM8pJhd9s/eM4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=hvc3eOlbUlE5YuKSNrRxhp6/Gapij1DfJ5VDIAbR3DxLi5SR9IM54U6UxV/GdFyTjF9mUVAt2n+NVp7qlYs8UqutPrgbyTBu4/iv79s1MEvSB26E5JN116skuMyvJ2pJY5W7bBm5QngbEYEmrGCPpXKTZ82lsg/QcVrj9Zp3k/4= 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=jTLmBXKv; 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="jTLmBXKv" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6ea8a5e862eso35712077b3.0 for ; Fri, 08 Nov 2024 22:18:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731133126; x=1731737926; 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=f4MoZVp4dieOlqSAjdWWI2h3A4ytuGiHKSKJVgig114=; b=jTLmBXKvuI6suxEbRBqjCN+S4bb6Ep/nRP8aiSwJxoH0GZsUEaScHAPMVT37DojoHi /a5eH8z4nt1oeGuk7bpHi5oXZy95URKIXPPz8QwXdK0HMuNaR0KIK05h6q3oQVgKPIyo qJzmDYi3avPFImXgwOp5FD1yL+4BpNfXz1tJZ0ZzSmWo7iBazIUEeCfpHEV7RmqqdhSN HWDi+6LTA6grEBFfCZjF3C5kJLA6Csdv6F13Vd/WT5Sfj/ZDSz9ocoMcxAjMZX3EzLhh WhvMIJ6BiyCGqq1dsJg4OYv3Gs09rkEjPWV7tOm4QAY6cr2jfVfr2upo3tskBA053uIF HzpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731133126; x=1731737926; 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=f4MoZVp4dieOlqSAjdWWI2h3A4ytuGiHKSKJVgig114=; b=oLVoZVfrKBTfvQha/J/W8bPVeLPXocWLVqMoPLEkv4UWzYoSc3ALXR0m5yAec2w3gx JzZ1s1OMxMLBwC5kxVAiSYNaWKmmaWMowZUDRIdWYnQ6Cb7Ud3y3TBdbc7vUsTqr8e7K BN9CM/g4/MgdyHDv+ezdVOpb3/v25sQpjww2BEgpl8SaVzr7qOCewWtHFvko5zrVqIUk SUb6gZkmhbck/I/iVWi7HxR2iYqX7Hi/IGmYGZpMKcyqGGlIi5Ds6ku8Y4DvhzyRva4R tvwfoOedCmEA2CVqNrzf0Rr+Drl8GGKEKjZmAK0jntBhCZBDTSXnJOMtjsPKZrqOVU0t b50w== X-Forwarded-Encrypted: i=1; AJvYcCUwWZLWYGmBUBM3vUbXazqstIqryjuaxcFLms+FR34TpKxqa/y8nGL2pQQKTi+582pjWeeAeutpXsIqs9o=@vger.kernel.org X-Gm-Message-State: AOJu0YwUEuQw9S6Zp12qzkKtcDZioPVI4OT0bKRmFe3m2IgAN71WEYtq /J1UfedGL9apFa3O3lxyFKZfxWsN66U6Sa8/gKfgeUKIK0vPzRLX9YP1B946Gz4GlyKZO8Yn4DU Oh79REg== X-Google-Smtp-Source: AGHT+IFLb4XAQByOO4JIkgmoGuImEbxVT2BiME7WaRVcEAmSkc6DCftAzVLY1+6duaclE1eArEYgqXodgsLg X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc2:d48f:a998:5915]) (user=irogers job=sendgmr) by 2002:a0d:e545:0:b0:6dd:bb6e:ec89 with SMTP id 00721157ae682-6eade40bbf7mr880687b3.2.1731133126645; Fri, 08 Nov 2024 22:18:46 -0800 (PST) Date: Fri, 8 Nov 2024 22:17:58 -0800 In-Reply-To: <20241109061809.811922-1-irogers@google.com> Message-Id: <20241109061809.811922-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: <20241109061809.811922-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v6 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 22d78a9d8f27..1eda065dcb2b 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -1693,87 +1693,6 @@ static int perf_sample__fprintf_bts(struct perf_samp= le *sample, return printed; } =20 -static struct { - u32 flags; - const char *name; -} sample_flags[] =3D { - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL, "call"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_RETURN, "return"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CONDITIONAL, "jcc"}, - {PERF_IP_FLAG_BRANCH, "jmp"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_INTERRUPT, "int"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_RETURN | PERF_IP_FLAG_INTERRUPT, "ire= t"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_SYSCALLRET, "sysc= all"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_RETURN | PERF_IP_FLAG_SYSCALLRET, "sy= sret"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_ASYNC, "async"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_ASYNC | PERF_IP_F= LAG_INTERRUPT, "hw int"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TX_ABORT, "tx abrt"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TRACE_BEGIN, "tr strt"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TRACE_END, "tr end"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_VMENTRY, "vmentry= "}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_VMEXIT, "vmexit"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_BRANCH_MISS, "br miss"}, - {0, NULL} -}; - -static const char *sample_flags_to_name(u32 flags) -{ - int i; - - for (i =3D 0; sample_flags[i].name ; i++) { - if (sample_flags[i].flags =3D=3D flags) - return sample_flags[i].name; - } - - return NULL; -} - -int perf_sample__sprintf_flags(u32 flags, char *str, size_t sz) -{ - u32 xf =3D PERF_IP_FLAG_IN_TX | PERF_IP_FLAG_INTR_DISABLE | - PERF_IP_FLAG_INTR_TOGGLE; - const char *chars =3D PERF_IP_FLAG_CHARS; - const size_t n =3D strlen(PERF_IP_FLAG_CHARS); - const char *name =3D NULL; - size_t i, pos =3D 0; - char xs[16] =3D {0}; - - if (flags & xf) - snprintf(xs, sizeof(xs), "(%s%s%s)", - flags & PERF_IP_FLAG_IN_TX ? "x" : "", - flags & PERF_IP_FLAG_INTR_DISABLE ? "D" : "", - flags & PERF_IP_FLAG_INTR_TOGGLE ? "t" : ""); - - name =3D sample_flags_to_name(flags & ~xf); - if (name) - return snprintf(str, sz, "%-15s%6s", name, xs); - - if (flags & PERF_IP_FLAG_TRACE_BEGIN) { - name =3D sample_flags_to_name(flags & ~(xf | PERF_IP_FLAG_TRACE_BEGIN)); - if (name) - return snprintf(str, sz, "tr strt %-7s%6s", name, xs); - } - - if (flags & PERF_IP_FLAG_TRACE_END) { - name =3D sample_flags_to_name(flags & ~(xf | PERF_IP_FLAG_TRACE_END)); - if (name) - return snprintf(str, sz, "tr end %-7s%6s", name, xs); - } - - for (i =3D 0; i < n; i++, flags >>=3D 1) { - if ((flags & 1) && pos < sz) - str[pos++] =3D chars[i]; - } - for (; i < 32; i++, flags >>=3D 1) { - if ((flags & 1) && pos < sz) - str[pos++] =3D '?'; - } - if (pos < sz) - str[pos] =3D 0; - - return pos; -} - static int perf_sample__fprintf_flags(u32 flags, FILE *fp) { char str[SAMPLE_FLAGS_BUF_SIZE]; diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 22edadd64e5f..77e02fcc51dd 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1317,12 +1317,6 @@ struct kwork_work *perf_kwork_add_work(struct perf_k= work *kwork __maybe_unused, return NULL; } =20 -int perf_sample__sprintf_flags(u32 flags __maybe_unused, char *str __maybe= _unused, - size_t sz __maybe_unused) -{ - return -1; -} - bool match_callstack_filter(struct machine *machine __maybe_unused, u64 *c= allstack __maybe_unused) { return false; diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trac= e-event-scripting.c index beac456260ae..2e9da0b089ef 100644 --- a/tools/perf/util/trace-event-scripting.c +++ b/tools/perf/util/trace-event-scripting.c @@ -15,6 +15,7 @@ =20 #include "archinsn.h" #include "debug.h" +#include "event.h" #include "trace-event.h" #include "evsel.h" #include @@ -283,3 +284,85 @@ void script_fetch_insn(struct perf_sample *sample, str= uct thread *thread, if (sample->insn_len =3D=3D 0 && native_arch) arch_fetch_insn(sample, thread, machine); } + +static const struct { + u32 flags; + const char *name; +} sample_flags[] =3D { + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL, "call"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_RETURN, "return"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CONDITIONAL, "jcc"}, + {PERF_IP_FLAG_BRANCH, "jmp"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_INTERRUPT, "int"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_RETURN | PERF_IP_FLAG_INTERRUPT, "ire= t"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_SYSCALLRET, "sysc= all"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_RETURN | PERF_IP_FLAG_SYSCALLRET, "sy= sret"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_ASYNC, "async"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_ASYNC | PERF_IP_F= LAG_INTERRUPT, + "hw int"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TX_ABORT, "tx abrt"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TRACE_BEGIN, "tr strt"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TRACE_END, "tr end"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_VMENTRY, "vmentry= "}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_VMEXIT, "vmexit"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_BRANCH_MISS, "br miss"}, + {0, NULL} +}; + +static const char *sample_flags_to_name(u32 flags) +{ + int i; + + for (i =3D 0; sample_flags[i].name ; i++) { + if (sample_flags[i].flags =3D=3D flags) + return sample_flags[i].name; + } + + return NULL; +} + +int perf_sample__sprintf_flags(u32 flags, char *str, size_t sz) +{ + u32 xf =3D PERF_IP_FLAG_IN_TX | PERF_IP_FLAG_INTR_DISABLE | + PERF_IP_FLAG_INTR_TOGGLE; + const char *chars =3D PERF_IP_FLAG_CHARS; + const size_t n =3D strlen(PERF_IP_FLAG_CHARS); + const char *name =3D NULL; + size_t i, pos =3D 0; + char xs[16] =3D {0}; + + if (flags & xf) + snprintf(xs, sizeof(xs), "(%s%s%s)", + flags & PERF_IP_FLAG_IN_TX ? "x" : "", + flags & PERF_IP_FLAG_INTR_DISABLE ? "D" : "", + flags & PERF_IP_FLAG_INTR_TOGGLE ? "t" : ""); + + name =3D sample_flags_to_name(flags & ~xf); + if (name) + return snprintf(str, sz, "%-15s%6s", name, xs); + + if (flags & PERF_IP_FLAG_TRACE_BEGIN) { + name =3D sample_flags_to_name(flags & ~(xf | PERF_IP_FLAG_TRACE_BEGIN)); + if (name) + return snprintf(str, sz, "tr strt %-7s%6s", name, xs); + } + + if (flags & PERF_IP_FLAG_TRACE_END) { + name =3D sample_flags_to_name(flags & ~(xf | PERF_IP_FLAG_TRACE_END)); + if (name) + return snprintf(str, sz, "tr end %-7s%6s", name, xs); + } + + for (i =3D 0; i < n; i++, flags >>=3D 1) { + if ((flags & 1) && pos < sz) + str[pos++] =3D chars[i]; + } + for (; i < 32; i++, flags >>=3D 1) { + if ((flags & 1) && pos < sz) + str[pos++] =3D '?'; + } + if (pos < sz) + str[pos] =3D 0; + + return pos; +} --=20 2.47.0.277.g8800431eea-goog From nobody Sat Nov 23 21:23:22 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 18667156F24 for ; Sat, 9 Nov 2024 06:18:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731133131; cv=none; b=nZwtiYTUVUi9eZg/Ixg+ZxV9KrCgKDaFZI6BVdBOFnr02wMvH+mdvgvl4EunOYjKBIteCYMJNNGLuBecUE07sxry8nLIADptk5ngtpp/FA2yqfBlpjcLl7GFVVUejCZL+um0qnQioNRArlzFh4UmzIgDyfXfITZ7uv5tIxQqS9c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731133131; c=relaxed/simple; bh=pAXQqpIWa0LYLnnCiagfBMCxcQEkPLFbkh484k/DoZU=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=uQPKCUsluAlmm/hvDh61i/z570s1DJiE0IpXMorxSuGrFDx62cg+okfPJ+EGUkkllmq5DOA8svXBD+KIswU4aW+nAEyzLpdKcxw3U3ZM3vANL2VjlZs9PQ+fTkUgIBfrrsUx9YmVc4VEv1CN0gZtFboblkY9EBtNwfzh9TVymDo= 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=XSVDcXKJ; 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="XSVDcXKJ" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6ea863ecfe9so58924427b3.3 for ; Fri, 08 Nov 2024 22:18:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731133129; x=1731737929; 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=NNpFEdljNjn4YHB86JN+vwHrvAgwAz/em65+hZvbLSA=; b=XSVDcXKJ6PomFdiLZrehVMi1e2bC3bHBBECtjUmj93/lgufuaGc+Yz3Nf9sO2dPWF3 gMdcogGJmdTS5qM7tzAts4PTBq0HiK8xf9LmGzq1EbIVAA0SIKTt2i6WIfYZM1j8Y5zj Pnjdsa0M2WTxNoeJ8A17QLLu1WMHbeqLz3Sw1o5nRrdaDIHmZZw7RtBKdsvl1vvXs9lY xZ390crG8G/PjPV9Rsz3R8cX4rWdUIxYIliu4Ws7ovS8PTiTdGacYdkgpSKVG9GY/rMK QRper8wjW9Ho6sG9Q4TMl+y5nsdjQUxZsNVDlov9PC8gDfvB8uf+RM3W4jg+Ase2nABf XTAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731133129; x=1731737929; 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=NNpFEdljNjn4YHB86JN+vwHrvAgwAz/em65+hZvbLSA=; b=mKPy4O8TPUj8DpuOmivqtFiNbhcKvu3mWOr72RMhHDuUjkzD/j/61DNUHcPzRJVZ4G 2Laul7zG6U96qwg9TDtIi8ea4UaaJvaygp7g+PVchlZKLRG/ofHRWGk56iGH3cq1/rvI gO9avhfyL0bQI3lKn0Yrtgr1fQOFT6vzr3lAOjf5Gc4PccED+9UhANp9l8ZqNX0s4BDa W+7u8qaD2UwVY6UKh25tdn0TlHP+emsm9JLEozrU912rTUOAFrMKFCcMEV2fNOnswdfq sAnLMS2V/MvsNHUO44gxQARNkhDwcgvJZjAI4Sno4c2hsDFk5w8NxNQ2iqb8gjKX7V9Y qXww== X-Forwarded-Encrypted: i=1; AJvYcCVn+YlbJKwN4V+x/axq3hYIxPGpswzOxueP14FzRgnudBtCFBUWi8Ru2vykmWwUL/0/oxVXMfpjB/H7DFM=@vger.kernel.org X-Gm-Message-State: AOJu0YyyEaWN54e3Vl7xFF83IqsPtGCkmPwuvpEZTNKh3IlHOdlCbHcX 35ldvhgz7qFry6/FjV5FmqtIYv2/tCuCGRydLFF8pG5FL/I1KooJlMVhRn1atzB2gTlwkxmRCln oEhKKRw== X-Google-Smtp-Source: AGHT+IHBz1DzCs25wFnpS+hrkIGaGnqfLGqytn4OYFpA0dqiuyktNOQMHkXGZaEFY5qq9xiWZkSKzUyPu9uD X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc2:d48f:a998:5915]) (user=irogers job=sendgmr) by 2002:a25:949:0:b0:e1d:912e:9350 with SMTP id 3f1490d57ef6-e337f8beb2amr11248276.6.1731133128821; Fri, 08 Nov 2024 22:18:48 -0800 (PST) Date: Fri, 8 Nov 2024 22:17:59 -0800 In-Reply-To: <20241109061809.811922-1-irogers@google.com> Message-Id: <20241109061809.811922-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: <20241109061809.811922-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v6 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 bc56a8e70f34..c5df4a2cf180 100644 --- a/tools/perf/arch/x86/util/Build +++ b/tools/perf/arch/x86/util/Build @@ -18,6 +18,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 650974413849..340544a6f5ec 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -122,7 +122,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 2e9da0b089ef..8d71998a9ecd 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.277.g8800431eea-goog From nobody Sat Nov 23 21:23:22 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 6764416C444 for ; Sat, 9 Nov 2024 06:18:52 +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=1731133133; cv=none; b=GtHyi79OYKkVGHe2ejaYBN9ICfc0WvZrHntsxJamoVOBRq2DBAjIb/PxtPsHSIhMqM3OjEvTjh1tMhzjCr0FMwunn7A2n5OCsqpC0rBH13X52y2Tk+UQ7Vr+x17ZyiIhQMRXIH2cRuxEHok6fHdop+dk74LPu+UWUgl8yZlakTU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731133133; c=relaxed/simple; bh=PrI8H7tlGg1LCekPP/1frVMROvXCGUe9rAOwO2eGntE=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=G4HxoC3ZvOav9YXPZgdoSXuXPN25GhXDJAcqmTnAsg5XeIuwBnf1fazqUu01kh15uoDn8+wwKwkE7yZv2ltNCRmkP1/lSi+6yW5iHcHIZsrhOOG/kX2AfBl7ttnWLJ5xT1ynG8sTX9idjbf/oYgDljQF1xmqkGfx3Ap5/F95P4g= 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=zB9jMJNo; 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="zB9jMJNo" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6ea7cfb6e0fso58240847b3.0 for ; Fri, 08 Nov 2024 22:18:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731133131; x=1731737931; 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=X/OxRvItvp2GcJzeU66usK4CCv3xT9PTSZBKNZI0dSQ=; b=zB9jMJNoQpmCmq3Wior8m5mrlLSVakyXwXufV09vVERb2Mcz90vjHZCIXnNDjzt7E6 EZzXfAuyL21l9Wo51soyoATJePrue6Y81EmN9YKhD72ZT7TlL8+W+kZGWQakU/ChVA2l EYKYRTtwCHQChG8w77dRA/fj3iylWS36V3XPPSKlqnA+N02VGUvCMZa+y19C6jNHKsla 3X9cGHwdUZNDAsf1WzKgi9YiWz/H/O0y8bL8pR8wY2Au3ft54YzJtAPi59W0R6GwRwlQ /ZPnFb4UGNNOTY+jMoswMA0uhIMtaAX4SfJi0ARQzEa1QBlw0lMOWL50PBgnzRYiEXvj OsWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731133131; x=1731737931; 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=X/OxRvItvp2GcJzeU66usK4CCv3xT9PTSZBKNZI0dSQ=; b=oJK0EIfxhC8V/LIMMbBELUNCUlkflAkHc1mDLtwllrZamzIpxbQSZA5lDdcZk5/EaW dXQ+MFEXzwHwMIBi/0mXd5oM0rgMYcBYN+aYwzx5YIjhvDUy8U3rK/bPwF55Z0o5CQhd oz26RJyOqbHSt+i5vL1iJfKmKrOQq8NC2biBK+59M/m4PFyMmSUatUjLclWg07MjlJPB XtdMUQa9igaGWsW+NpmONehuqiIzyWtQ15AKEqN4c9226uOPonSnm9uNywJYRbI1wIGL AgkacS9iEq3Mxmo9Q0oiHBApUugIk8Rz92xXLfgk9Qz/rvlC953kqcAG5iFRBWDVLJ7H 9YFQ== X-Forwarded-Encrypted: i=1; AJvYcCUtA+iYWLvLehy9zGaK+9n5b/ax6T41hNARd2zs++WOWsaJhiJrqZ+y1tV8EZKg01J1CG5s+PmskGZ06rU=@vger.kernel.org X-Gm-Message-State: AOJu0YwFJcPua8nnn+BZ/zdeyLCeCzRKTCY3abF9QLUURqwR145iwD9D pQDyJNiryWhvgKwUaKjNBlbbp55v/wT+GNGSBSdMBkhnJedL07mGXrmrPijxE/OKouamu0VbHsN VxFrXAA== X-Google-Smtp-Source: AGHT+IF9zCEp+SsozjY07KdCJXudhDuS1WnIXH4lCviR6Xwd8Iwv4jVR0d7DV230Wl432lyc/AOOkh4pnxTS X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc2:d48f:a998:5915]) (user=irogers job=sendgmr) by 2002:a05:690c:6084:b0:6dd:bf69:7e06 with SMTP id 00721157ae682-6eaddfe59c9mr620837b3.7.1731133131394; Fri, 08 Nov 2024 22:18:51 -0800 (PST) Date: Fri, 8 Nov 2024 22:18:00 -0800 In-Reply-To: <20241109061809.811922-1-irogers@google.com> Message-Id: <20241109061809.811922-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: <20241109061809.811922-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v6 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.277.g8800431eea-goog From nobody Sat Nov 23 21:23:22 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 51B3B17E01B for ; Sat, 9 Nov 2024 06:18:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731133135; cv=none; b=tiEoNg9hI9EeliCLx6+nJom+UcdKQwlt3EqQx19r2jXGMZ4uHeqKyBUNpalUKmrZRV0tZtrXieqBEM5hE+jFeW4BVuUFuuYYbs7diw0Sa+1Ucr4TpGJRL6CdIH1w1IMulDxBR/MUVMYJu9Sda95cHYqYY2MxHXElQ9bEyMq+pGc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731133135; c=relaxed/simple; bh=Wbl/xP4VdR5ZVYx+gs/s7yb4T91c4UvpqUcjo9rjNDg=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=grWH4D5TdmcUeVjBmatDnX/yPS7XP5rbRB7Sf21V6mOuL58RVtxxXl6ZJxuOeBnsS5TcizCRUikJmFujvirxfQdNvHYrGpqAihdyxURwd88UAKWVD6+q3YT+InLUfcthsudP9YUHKN/rWlLlC0ltK6xZhAveHBhUpIGQfUf7fmE= 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=LLUMObdA; 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="LLUMObdA" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6ea33140094so56190247b3.1 for ; Fri, 08 Nov 2024 22:18:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731133133; x=1731737933; 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=8Vx9oh/oHlJIJYsgb8VChVGCOrMitkPgbmFPZ/WsME0=; b=LLUMObdAGtbQ4ghMJveZHOCxdf54ntWHKV51/J+GAlGaHoX12QS4MjCaelqFKlborI Lmwgo1Y4It+lqPM4SCrETB4jmSwxxAWUGLqO4GThWQPvzFVCnL5XEVN8qDHpk29D1gYC iU8tfgE03R1wHXXAf4/OKq3WmJEBBuUQNVhRRwlsnlb7XPyKrwuuRMs+OE8DH/i4EUXu j6RDLJUXbFiqhHNh9wZz2AvzUfh6p6ljNrmBN4O8aH7+CObpa3+sH8mlc0tJeN78o9Av yU56f1qFyDS3SdYLDvuZp00FzTKOihOyAmYwRiWmIxf97nGevhq6QmDpZ36kdiJXIQUI JEbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731133133; x=1731737933; 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=8Vx9oh/oHlJIJYsgb8VChVGCOrMitkPgbmFPZ/WsME0=; b=h0jzDI+fPqG6hPrMKh9cxFCHQUyiVlMb86o78JSfEzjlFYTYk7TRErB+w/US9HqiX5 xtkvHLqJZZ1GubVb+VZ/0vN+SKehCXPtzt39AymqokwN8QEI4KE0Dyi8OyAXx1kDjfGw 5+jMgps3KrhQF7FSnYXiRepxvItY+Yr3j0HvOjiO3G8zSqrVtnvc8+TRnYPHXnUO5nW7 RUhOzF3+TK/2WdrIGPldy0ZInpYzedOYJ+Y8oYFbb9O1oRQ5JYoKoWBYvtAUtKeGUMNM 4i4Ti42Av7GEOv5RvcrAFsazxnycWYP+D1Mdz5+LlLxv1Ptb9/mZ1bFxo6vnEWStrYw2 N8eQ== X-Forwarded-Encrypted: i=1; AJvYcCXIl8kj3/9Jgk/Qww4HicPLwDr9fuqlXyKxqFzyTPZkzmi6Oqj6IYqQ7I5BHdB6g5bWqNN1iygSA0VRgoU=@vger.kernel.org X-Gm-Message-State: AOJu0Yy3272QyhOHHylnjywQ+cDIYvI1Phn6I/xlAypi4DKpNrKNImII rhHIAqKwpBMRQGqem7MXV5eUgkfmoJiy+akg0dt/fJvr5uOLZOXN21grQAglFLnflkoVHywDISF 8UhUMkA== X-Google-Smtp-Source: AGHT+IFpNFhlI/CNVGIaK6Ib11HgYVVc8sX3OtfxqRD2FvGZdFxE8hca2Bt5p4qyWlKorL+a5Jw0t7j7k1RD X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc2:d48f:a998:5915]) (user=irogers job=sendgmr) by 2002:a05:690c:6f12:b0:6e3:f32:5fc8 with SMTP id 00721157ae682-6eaddd6a3e4mr397097b3.1.1731133133585; Fri, 08 Nov 2024 22:18:53 -0800 (PST) Date: Fri, 8 Nov 2024 22:18:01 -0800 In-Reply-To: <20241109061809.811922-1-irogers@google.com> Message-Id: <20241109061809.811922-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: <20241109061809.811922-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v6 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 a661fbd870e7..29f64a4352dd 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -1108,7 +1108,6 @@ static bool syscall_arg__strtoul_btf_type(char *bf __= maybe_unused, size_t size _ .strtoul =3D STUL_STRARRAY_FLAGS, \ .parm =3D &strarray__##array, } =20 -#include "trace/beauty/arch_errno_names.c" #include "trace/beauty/eventfd.c" #include "trace/beauty/futex_op.c" #include "trace/beauty/futex_val3.c" diff --git a/tools/perf/trace/beauty/arch_errno_names.sh b/tools/perf/trace= /beauty/arch_errno_names.sh index 30d3889b2957..b22890b8d272 100755 --- a/tools/perf/trace/beauty/arch_errno_names.sh +++ b/tools/perf/trace/beauty/arch_errno_names.sh @@ -57,7 +57,8 @@ create_arch_errno_table_func() archlist=3D"$1" default=3D"$2" =20 - printf 'arch_syscalls__strerrno_t *arch_syscalls__strerrno_function(const= char *arch)\n' + printf 'static arch_syscalls__strerrno_t *\n' + printf 'arch_syscalls__strerrno_function(const char *arch)\n' printf '{\n' for arch in $archlist; do arch_str=3D$(arch_string "$arch") diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index ccb464026642..e58f56412fbb 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -470,6 +470,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 77e02fcc51dd..35d84a96dbec 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -16,7 +16,6 @@ #include "thread_map.h" #include "trace-event.h" #include "mmap.h" -#include "util/env.h" #include "util/kwork.h" #include "util/sample.h" #include "util/lock-contention.h" @@ -1305,11 +1304,6 @@ PyMODINIT_FUNC PyInit_perf(void) /* The following are stubs to avoid dragging in builtin-* objects. */ /* TODO: move the code out of the builtin-* file into util. */ =20 -arch_syscalls__strerrno_t *arch_syscalls__strerrno_function(const char *ar= ch __maybe_unused) -{ - return NULL; -} - struct kwork_work *perf_kwork_add_work(struct perf_kwork *kwork __maybe_un= used, struct kwork_class *class __maybe_unused, struct kwork_work *key __maybe_unused) --=20 2.47.0.277.g8800431eea-goog From nobody Sat Nov 23 21:23:22 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 D7FC3189BA6 for ; Sat, 9 Nov 2024 06:18:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731133138; cv=none; b=pR6WmtNmmUzNtDhhC1GY7+AxfLxD1MxhUvoji/bVhtYPsMSHZQl3a06Rb+OLmk1UEtNE6rJQtsCihKgM11PkidCqGJjAXKb99fksZfA8NGw4uf/Of+/g1BU2o1KM4hk3//2MfGhybEH4rc4+QyTumVWbefvEga8SABqHq9OR5lA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731133138; c=relaxed/simple; bh=Wf2VDsFtfq7d0fqSAIg4TBCOQAJUYor7+AF0sqv4SgA=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=mrlFrjw37eJ/pf5X+PCO32T4t82d025PnajYi28fLzgd8ueZVoocatQLCdtMvwqtH7ItHivLUm8XL9LwxwfjhdoASWq6R37g5ETc43AsZosEqan9NYaoiBjPqDojDhqNQgrmNa7NZmcL/RKbPxnc6pq5Gk0mIo95XpRWs0XqSTE= 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=CpOcW6NB; 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="CpOcW6NB" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6ea86f1df79so54995287b3.1 for ; Fri, 08 Nov 2024 22:18:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731133136; x=1731737936; 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=uPQ3aTez9N2PJdDPdgTJjGEL+gTCQmT4cdEl7SyznXA=; b=CpOcW6NBOfqFa8d9ISh+NJL1Gk5WVCNOzA+4J/02KEfd3+AiS+2uT8DBaUqMeeFt/z 6UfWoMWFFf08gxQkQtQLjeKMJL0BPnYn8GEszOl139UEybgy9alOQGeTcERz9WZseeH/ RTwazblIuhyCMEIfu8IoodcUuCuHWJqCBEsxkQ8oncyvpv4Rh3hX7N5D97hKGJDjIvhH jdFc5vEd9Ty9QroYclQHj2YmKj9dxkejmf1LAB4sixwDAQhFhpOXbCfdU2oWnEwwXhtx 9Uop71uQjIpoao54ky7WANQTKBFGZjQ5L9bJaiWVnXia4rK+GawOsJbgPQX/QCtUmpOZ tHJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731133136; x=1731737936; 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=uPQ3aTez9N2PJdDPdgTJjGEL+gTCQmT4cdEl7SyznXA=; b=gZQADxsGkUJHYDsNPeeU5FAFqgOYO5HnyeVZfZthmaCFJ9Cziotu0WdOgeFRISI5V8 CMXmr8ETUs8/KCdJZApPIHArMttdHgBVRkJ0/A/1NrdPFXf65to8lFrlhvf6g6Mad5oi Dae/qotp+tXqR8lkEYTNpgNd/wsXOyBbiAnHxqZAKD+cvx96fd1Qx58AlingI2JQUvpu 52RGm4DLjusKxX12fShJTRMeh2xf/6E/t6bH9YHCTxJwhF+4T2dLlLfHCrqAvQL3My+z LQAo441kZa44O4Cvuh+aqbP1UMuTZ2JgQthI1UN9QPSzDTlhbfx+ulXdcZgjM0tqkEuq 2q8g== X-Forwarded-Encrypted: i=1; AJvYcCX3k3R8dRBG+izsAEYkB09kdJwijBTKhm3fWWZLNBKz+g7np35gf0cWqKNrqyehb7PtKzMQnEUJjx9flDY=@vger.kernel.org X-Gm-Message-State: AOJu0YwmxHuEw2FrjmcwWmKGl4/db6KhSomkxeu+rqIi4SK9tQBzQai1 4PpxuDDGjkiVHcT0Ikq82RSzVjAyTzh5azoiCJNADIUH+u7yM4mA/Uq2OqPYDukZ9vQEoAAdr0W L6f782A== X-Google-Smtp-Source: AGHT+IGttmknS5N9QjAmd3P21M+NEtkHBx7mH5NFJkoaUqiMUvoD00tjRMCQiICoczfjyJNEkNb3xvvDGuAo X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc2:d48f:a998:5915]) (user=irogers job=sendgmr) by 2002:a05:690c:200f:b0:6ea:34c3:742b with SMTP id 00721157ae682-6eaddfad76amr531597b3.6.1731133135754; Fri, 08 Nov 2024 22:18:55 -0800 (PST) Date: Fri, 8 Nov 2024 22:18:02 -0800 In-Reply-To: <20241109061809.811922-1-irogers@google.com> Message-Id: <20241109061809.811922-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: <20241109061809.811922-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v6 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 --- tools/perf/builtin-lock.c | 137 +-------------------- tools/perf/util/Build | 1 + tools/perf/util/bpf_lock_contention.c | 2 +- tools/perf/util/lock-contention.c | 170 ++++++++++++++++++++++++++ tools/perf/util/lock-contention.h | 37 ++---- tools/perf/util/python.c | 17 --- 6 files changed, 185 insertions(+), 179 deletions(-) create mode 100644 tools/perf/util/lock-contention.c diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index 062e2b56a2ab..f66948b1fbed 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -46,15 +46,6 @@ static struct perf_session *session; static struct target target; =20 -/* based on kernel/lockdep.c */ -#define LOCKHASH_BITS 12 -#define LOCKHASH_SIZE (1UL << LOCKHASH_BITS) - -static struct hlist_head *lockhash_table; - -#define __lockhashfn(key) hash_long((unsigned long)key, LOCKHASH_BITS) -#define lockhashentry(key) (lockhash_table + __lockhashfn((key))) - static struct rb_root thread_stats; =20 static bool combine_locks; @@ -67,24 +58,13 @@ static unsigned long bpf_map_entries =3D MAX_ENTRIES; static int max_stack_depth =3D CONTENTION_STACK_DEPTH; static int stack_skip =3D CONTENTION_STACK_SKIP; static int print_nr_entries =3D INT_MAX / 2; -static LIST_HEAD(callstack_filters); static const char *output_name =3D NULL; static FILE *lock_output; =20 -struct callstack_filter { - struct list_head list; - char name[]; -}; - static struct lock_filter filters; =20 static enum lock_aggr_mode aggr_mode =3D LOCK_AGGR_ADDR; =20 -static bool needs_callstack(void) -{ - return !list_empty(&callstack_filters); -} - static struct thread_stat *thread_stat_find(u32 tid) { struct rb_node *node; @@ -477,93 +457,6 @@ static struct lock_stat *pop_from_result(void) return container_of(node, struct lock_stat, rb); } =20 -struct lock_stat *lock_stat_find(u64 addr) -{ - struct hlist_head *entry =3D lockhashentry(addr); - struct lock_stat *ret; - - hlist_for_each_entry(ret, entry, hash_entry) { - if (ret->addr =3D=3D addr) - return ret; - } - return NULL; -} - -struct lock_stat *lock_stat_findnew(u64 addr, const char *name, int flags) -{ - struct hlist_head *entry =3D lockhashentry(addr); - struct lock_stat *ret, *new; - - hlist_for_each_entry(ret, entry, hash_entry) { - if (ret->addr =3D=3D addr) - return ret; - } - - new =3D zalloc(sizeof(struct lock_stat)); - if (!new) - goto alloc_failed; - - new->addr =3D addr; - new->name =3D strdup(name); - if (!new->name) { - free(new); - goto alloc_failed; - } - - new->flags =3D flags; - new->wait_time_min =3D ULLONG_MAX; - - hlist_add_head(&new->hash_entry, entry); - return new; - -alloc_failed: - pr_err("memory allocation failed\n"); - return NULL; -} - -bool match_callstack_filter(struct machine *machine, u64 *callstack) -{ - struct map *kmap; - struct symbol *sym; - u64 ip; - const char *arch =3D perf_env__arch(machine->env); - - if (list_empty(&callstack_filters)) - return true; - - for (int i =3D 0; i < max_stack_depth; i++) { - struct callstack_filter *filter; - - /* - * In powerpc, the callchain saved by kernel always includes - * first three entries as the NIP (next instruction pointer), - * LR (link register), and the contents of LR save area in the - * second stack frame. In certain scenarios its possible to have - * invalid kernel instruction addresses in either LR or the second - * stack frame's LR. In that case, kernel will store that address as - * zero. - * - * The below check will continue to look into callstack, - * incase first or second callstack index entry has 0 - * address for powerpc. - */ - if (!callstack || (!callstack[i] && (strcmp(arch, "powerpc") || - (i !=3D 1 && i !=3D 2)))) - break; - - ip =3D callstack[i]; - sym =3D machine__find_kernel_symbol(machine, ip, &kmap); - if (sym =3D=3D NULL) - continue; - - list_for_each_entry(filter, &callstack_filters, list) { - if (strstr(sym->name, filter->name)) - return true; - } - } - return false; -} - struct trace_lock_handler { /* it's used on CONFIG_LOCKDEP */ int (*acquire_event)(struct evsel *evsel, @@ -1165,7 +1058,7 @@ static int report_lock_contention_begin_event(struct = evsel *evsel, if (callstack =3D=3D NULL) return -ENOMEM; =20 - if (!match_callstack_filter(machine, callstack)) { + if (!match_callstack_filter(machine, callstack, max_stack_depth)) { free(callstack); return 0; } @@ -2449,34 +2342,6 @@ static int parse_lock_addr(const struct option *opt = __maybe_unused, const char * return ret; } =20 -static int parse_call_stack(const struct option *opt __maybe_unused, const= char *str, - int unset __maybe_unused) -{ - char *s, *tmp, *tok; - int ret =3D 0; - - s =3D strdup(str); - if (s =3D=3D NULL) - return -1; - - for (tok =3D strtok_r(s, ", ", &tmp); tok; tok =3D strtok_r(NULL, ", ", &= tmp)) { - struct callstack_filter *entry; - - entry =3D malloc(sizeof(*entry) + strlen(tok) + 1); - if (entry =3D=3D NULL) { - pr_err("Memory allocation failure\n"); - free(s); - return -1; - } - - strcpy(entry->name, tok); - list_add_tail(&entry->list, &callstack_filters); - } - - free(s); - return ret; -} - static int parse_output(const struct option *opt __maybe_unused, const cha= r *str, int unset __maybe_unused) { diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 340544a6f5ec..3c6cd8d81d88 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -121,6 +121,7 @@ perf-util-y +=3D topdown.o perf-util-y +=3D iostat.o perf-util-y +=3D stream.o perf-util-y +=3D kvm-stat.o +perf-util-y +=3D lock-contention.o perf-util-$(CONFIG_AUXTRACE) +=3D auxtrace.o perf-util-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..841bb18b1f06 --- /dev/null +++ b/tools/perf/util/lock-contention.c @@ -0,0 +1,170 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "debug.h" +#include "env.h" +#include "lock-contention.h" +#include "machine.h" +#include "symbol.h" + +#include +#include + +#include +#include + +#define __lockhashfn(key) hash_long((unsigned long)key, LOCKHASH_BITS) +#define lockhashentry(key) (lockhash_table + __lockhashfn((key))) + +struct callstack_filter { + struct list_head list; + char name[]; +}; + +static LIST_HEAD(callstack_filters); +struct hlist_head *lockhash_table; + +int parse_call_stack(const struct option *opt __maybe_unused, const char *= str, + int unset __maybe_unused) +{ + char *s, *tmp, *tok; + int ret =3D 0; + + s =3D strdup(str); + if (s =3D=3D NULL) + return -1; + + for (tok =3D strtok_r(s, ", ", &tmp); tok; tok =3D strtok_r(NULL, ", ", &= tmp)) { + struct callstack_filter *entry; + + entry =3D malloc(sizeof(*entry) + strlen(tok) + 1); + if (entry =3D=3D NULL) { + pr_err("Memory allocation failure\n"); + free(s); + return -1; + } + + strcpy(entry->name, tok); + list_add_tail(&entry->list, &callstack_filters); + } + + free(s); + return ret; +} + +bool needs_callstack(void) +{ + return !list_empty(&callstack_filters); +} + +struct lock_stat *lock_stat_find(u64 addr) +{ + struct hlist_head *entry =3D lockhashentry(addr); + struct lock_stat *ret; + + hlist_for_each_entry(ret, entry, hash_entry) { + if (ret->addr =3D=3D addr) + return ret; + } + return NULL; +} + +struct lock_stat *lock_stat_findnew(u64 addr, const char *name, int flags) +{ + struct hlist_head *entry =3D lockhashentry(addr); + struct lock_stat *ret, *new; + + hlist_for_each_entry(ret, entry, hash_entry) { + if (ret->addr =3D=3D addr) + return ret; + } + + new =3D zalloc(sizeof(struct lock_stat)); + if (!new) + goto alloc_failed; + + new->addr =3D addr; + new->name =3D strdup(name); + if (!new->name) { + free(new); + goto alloc_failed; + } + + new->flags =3D flags; + new->wait_time_min =3D ULLONG_MAX; + + hlist_add_head(&new->hash_entry, entry); + return new; + +alloc_failed: + pr_err("memory allocation failed\n"); + return NULL; +} + +bool match_callstack_filter(struct machine *machine, u64 *callstack, int m= ax_stack_depth) +{ + struct map *kmap; + struct symbol *sym; + u64 ip; + const char *arch =3D perf_env__arch(machine->env); + + if (list_empty(&callstack_filters)) + return true; + + for (int i =3D 0; i < max_stack_depth; i++) { + struct callstack_filter *filter; + + /* + * In powerpc, the callchain saved by kernel always includes + * first three entries as the NIP (next instruction pointer), + * LR (link register), and the contents of LR save area in the + * second stack frame. In certain scenarios its possible to have + * invalid kernel instruction addresses in either LR or the second + * stack frame's LR. In that case, kernel will store that address as + * zero. + * + * The below check will continue to look into callstack, + * incase first or second callstack index entry has 0 + * address for powerpc. + */ + if (!callstack || (!callstack[i] && (strcmp(arch, "powerpc") || + (i !=3D 1 && i !=3D 2)))) + break; + + ip =3D callstack[i]; + sym =3D machine__find_kernel_symbol(machine, ip, &kmap); + if (sym =3D=3D NULL) + continue; + + list_for_each_entry(filter, &callstack_filters, list) { + if (strstr(sym->name, filter->name)) + return true; + } + } + return false; +} + +#ifndef HAVE_BPF_SKEL +int lock_contention_prepare(struct lock_contention *con __maybe_unused) +{ + return 0; +} + +int lock_contention_start(void) +{ + return 0; +} + +int lock_contention_stop(void) +{ + return 0; +} + +int lock_contention_finish(struct lock_contention *con __maybe_unused) +{ + return 0; +} + +int lock_contention_read(struct lock_contention *con __maybe_unused) +{ + return 0; +} +#endif /* !HAVE_BPF_SKEL */ diff --git a/tools/perf/util/lock-contention.h b/tools/perf/util/lock-conte= ntion.h index 1a7248ff3889..bfa5c7db0a5d 100644 --- a/tools/perf/util/lock-contention.h +++ b/tools/perf/util/lock-contention.h @@ -67,10 +67,11 @@ struct lock_stat { */ #define MAX_LOCK_DEPTH 48 =20 -struct lock_stat *lock_stat_find(u64 addr); -struct lock_stat *lock_stat_findnew(u64 addr, const char *name, int flags); +/* based on kernel/lockdep.c */ +#define LOCKHASH_BITS 12 +#define LOCKHASH_SIZE (1UL << LOCKHASH_BITS) =20 -bool match_callstack_filter(struct machine *machine, u64 *callstack); +extern struct hlist_head *lockhash_table; =20 /* * struct lock_seq_stat: @@ -148,7 +149,14 @@ struct lock_contention { bool save_callstack; }; =20 -#ifdef HAVE_BPF_SKEL +struct option; +int parse_call_stack(const struct option *opt, const char *str, int unset); +bool needs_callstack(void); + +struct lock_stat *lock_stat_find(u64 addr); +struct lock_stat *lock_stat_findnew(u64 addr, const char *name, int flags); + +bool match_callstack_filter(struct machine *machine, u64 *callstack, int m= ax_stack_depth); =20 int lock_contention_prepare(struct lock_contention *con); int lock_contention_start(void); @@ -156,25 +164,4 @@ int lock_contention_stop(void); int lock_contention_read(struct lock_contention *con); int lock_contention_finish(struct lock_contention *con); =20 -#else /* !HAVE_BPF_SKEL */ - -static inline int lock_contention_prepare(struct lock_contention *con __ma= ybe_unused) -{ - return 0; -} - -static inline int lock_contention_start(void) { return 0; } -static inline int lock_contention_stop(void) { return 0; } -static inline int lock_contention_finish(struct lock_contention *con __may= be_unused) -{ - return 0; -} - -static inline int lock_contention_read(struct lock_contention *con __maybe= _unused) -{ - return 0; -} - -#endif /* HAVE_BPF_SKEL */ - #endif /* PERF_LOCK_CONTENTION_H */ diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 35d84a96dbec..91fd444615cd 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -18,7 +18,6 @@ #include "mmap.h" #include "util/kwork.h" #include "util/sample.h" -#include "util/lock-contention.h" #include #include "../builtin.h" =20 @@ -1311,22 +1310,6 @@ struct kwork_work *perf_kwork_add_work(struct perf_k= work *kwork __maybe_unused, return NULL; } =20 -bool match_callstack_filter(struct machine *machine __maybe_unused, u64 *c= allstack __maybe_unused) -{ - return false; -} - -struct lock_stat *lock_stat_find(u64 addr __maybe_unused) -{ - return NULL; -} - -struct lock_stat *lock_stat_findnew(u64 addr __maybe_unused, const char *n= ame __maybe_unused, - int flags __maybe_unused) -{ - return NULL; -} - int cmd_inject(int argc __maybe_unused, const char *argv[] __maybe_unused) { return -1; --=20 2.47.0.277.g8800431eea-goog From nobody Sat Nov 23 21:23:22 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 02E6B190074 for ; Sat, 9 Nov 2024 06:18:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731133140; cv=none; b=iOZj/lsqFMa6BHb7RIk+8lmYR1JCrV+20F7MKrmKBcOpn2jDC01MqL21pMQAOEgXcSzccLipU/pfJcKBabxL3aw5kQyyoaU4GsLU+wNB7hqnkLKYiKZIDHJgol2YRlp0hxUajrBJXvwQ5dbC9G06WHNUTdVJU3Nv/7isAUg5KCM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731133140; c=relaxed/simple; bh=w8HaB/UZZ8fjRZSrgVSw7XPmtOqwKAnXaljOTleBeY8=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=qGlPsww+xd0YvuIYkhjDJByGlDqI22m9H+U1dDkrFT8qrMQsnOvgQ+EtxjRS6AELQj1huFeHwxBc2SHp/ERzwjYNc0X4Kexv6Ff3wOVg8zvo9MLhe0NBS6vu+wtsMkjvChLeZ1h78iZzoPjUuxGjSCbyKvtnAko1y0NfTsQGp5Y= 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=o+38z74n; 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="o+38z74n" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e38fabff35so3294637b3.0 for ; Fri, 08 Nov 2024 22:18:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731133138; x=1731737938; 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=K3lOW3KhmOwWh4gGD39AVpZawRDyngvbS6RFQf8pauU=; b=o+38z74n0989CAjkTnPNS+GwyGeML9zttEiy9R97nz2bLHxgnk6WKuCDuHPqb7yV+h /9rE1oS9KWR+QQtxfmqG0snk60TDH5rMuM0pvnatMPgWd6BWBbQVI7HsH0BTJOyP3ssG z2t+jnz6SHKROJs0CXEazqk9NJARu76zNBca8YZtBnYiX7n8+xKgUJ6T0QBjVSy5yz6c KdsRULWuCc9y74tcMn9wG8ReHvI2XYDl7MOBa09zV8gn0BOSkekwpcVC6qc49MAiLAcU z1GemscZtj0Ww1LdTZZxLmarQ3YB6gvT1NJMOA1hqsBFmEE2i6fYeHlcZI2f4ldfMCyp TU2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731133138; x=1731737938; 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=K3lOW3KhmOwWh4gGD39AVpZawRDyngvbS6RFQf8pauU=; b=a/1pHmuXQTRwnUt0D03jeEnDb4Ta3e3wFMJuaWcSK85R0YXTBpaXngC/T6t+gVmZeh JKEQbKHe/2P9YjVW5Vn7GvmtYXzkz7dI+zkUF/iviaycyWI6pT9xOa/bEZUUGi6wEWmt eAElT6t9paoMV7P1fxC6HqDS5a52lw9PMufIR65n+FIVwUkOIlk55uRFuY7a2oHTVprz geNPJjLtlwGMEgi4jWk1uYoslKmEuHSHbpavIOTy4WAw3VYaQQwIzDzCElZBII9UHLnw LE40ZiH5nWXfj9WvDQbQ1w/8KAg5sioTnLS8xIy3/qUBU1w7qhmNsDSZCyusULL06qmc ln1A== X-Forwarded-Encrypted: i=1; AJvYcCU5TDqPNUHlaFInFCvPG7SL8Aw0cCOMkAfP5VqnxMROhe5iOZe0xBiaMe3WH77BpXcRuKEX3FF92Ki/Xlk=@vger.kernel.org X-Gm-Message-State: AOJu0Yw0q6IL3SoadA7pd7sT8hn9+VjfbKf10/0PWxovsroZ98XoEcsf oTyCy/6/KDAo67jN0ddsCNuRX/lz+gTPMZqflH0AZnT3OvlZyMiCE8ndbzUMCLkQX3YcvQ47Xjg nSG7wug== X-Google-Smtp-Source: AGHT+IG9mZ2Uxz3PTmRVxavk0ppfRpa8BCEprXGc9sKj57y4LQOFJhg5BR8resUQ3qTazUHGf7DdZdHSbWxr X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc2:d48f:a998:5915]) (user=irogers job=sendgmr) by 2002:a05:6902:4d1:b0:e0e:4841:3a7e with SMTP id 3f1490d57ef6-e337f8da4fdmr10466276.7.1731133138130; Fri, 08 Nov 2024 22:18:58 -0800 (PST) Date: Fri, 8 Nov 2024 22:18:03 -0800 In-Reply-To: <20241109061809.811922-1-irogers@google.com> Message-Id: <20241109061809.811922-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: <20241109061809.811922-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v6 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 91fd444615cd..c52da509ae58 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -19,7 +19,6 @@ #include "util/kwork.h" #include "util/sample.h" #include -#include "../builtin.h" =20 #define _PyUnicode_FromString(arg) \ PyUnicode_FromString(arg) @@ -1309,8 +1308,3 @@ struct kwork_work *perf_kwork_add_work(struct perf_kw= ork *kwork __maybe_unused, { return NULL; } - -int cmd_inject(int argc __maybe_unused, const char *argv[] __maybe_unused) -{ - return -1; -} --=20 2.47.0.277.g8800431eea-goog From nobody Sat Nov 23 21:23:22 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 26B37193078 for ; Sat, 9 Nov 2024 06:19:00 +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=1731133142; cv=none; b=WqAiyXAIbG0Yy2d5GzxB2+OFZ90/ClcbXe2QvSxoArIixmQQ0xVAtMKz+GY+kLTdNmHzKWsA3oXXEqCdbsyrvgSg5xv0Gllrw3PgyUMc6N4jt4hj2Gis81T4mTTkh36iGwhei8hHKuPNceDxUPeEbaYYrlC2PlDofY7SD1OkcsM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731133142; c=relaxed/simple; bh=4UPmvdOjJHxQuYsG0yPx07gvw/66IIUoV1gQ16Uzk7g=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=TD152ZzHoyi9ujdgILmkUKRKjXTcj3x2jqP59cQeKiU1UtqMRiyYC5BgdfFG3LycHAsRNhuPvS/JwJcia0ZCBATzh9Xt6pqo0qujhmRzCvxulFwglgqRUarU5Q74vqt+4NCEpDF15tYSOJHaUzjxbifsbaAkC4AxAqyb9sYlbGY= 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=y3fDoWvs; 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="y3fDoWvs" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e330f65bcd9so4289713276.1 for ; Fri, 08 Nov 2024 22:19:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731133140; x=1731737940; 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=2Q2ReAKc0amQKBCEhLF6CVvc9yuVwJ/Jj6yfY9rXEp0=; b=y3fDoWvs9Ao/B8qetVMInU94Ovid1q9SR48jiai4xxe8lmqKs4iSOkYFX5HlHh+oVw 9dP5F32p26ZrraZmIGnZ2H/N/KumorXnHBsIu+AsnTIgICAboTpah+w/QDZpeuDy/chp cLzybJEQCvRneC4AmmTvLeRiE+IL903AXMYzw24tZ2cJQcHEGxxP9UhA8d/0gbMeE48y EdOPxhLTwVnqOa9P3hEN98hLVrz0YEB6giBZ874iRw/3F5I7rLGcKVcSxDeu7KhlptBL Kv95R1RUbOcWZcvEfojCIwknR1u7ZWnwXecjNbv0YQ72fsz6WZazQYUDuRQ0yrDT1mn/ sLGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731133140; x=1731737940; 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=2Q2ReAKc0amQKBCEhLF6CVvc9yuVwJ/Jj6yfY9rXEp0=; b=w7lVynjKYYbdctVdR6cVqGHbQ3KoRy0o3PHml23vRNgzE88YVQpdQxpxvecwLH2qPq UODPkaux8e8lJP8MFm6QRrQlWbwYQ4Civ+b3jmv/sTmpv0R+6h2BzXrJPCUMu6mkTmn8 bJNB9nSZJAaB+T7BN+ivK0gmuNYFtWCT0byjJ6Dv0iL1FnE75tSTbZAFhbhE9JhVu6Zt 6UMSAgLAk/w04PqkT1GLJzJPRHV1XfhDP/qMyYYZC/BkjXESjiYQcbEEKk3SIonxqyR4 tjkfFcctU2ZZPluMUOPaa3g9eQw34QRww+i2qachUMPndBggBr9NUbck2nLSmRkQ8nlc O/DA== X-Forwarded-Encrypted: i=1; AJvYcCXG/TISfgQ3JZLH1EPiiqwnIu7JYIRvZ8YhGBrb90QZcfkCNht7rxocw4F0jMXU+Xx69p4VcKwyWIz++8A=@vger.kernel.org X-Gm-Message-State: AOJu0YxXdIJ1NyhJBKIJMW2LsefpTC/VxWrXu+RpJY+mwTlb3Qen8E5w qH+MZiKAm9yPMXjq/mAcNZzqfH7Cx22Vrg2Q6pq+2G498V1Bw4XN2461wEtP1A5GzNESE+sYSZu 802TceQ== X-Google-Smtp-Source: AGHT+IHh4ZHM0I2UXpNWh/5ymHpo3CJW8uS0Jkit6pBWN+9b5hyD+0SxL1crj5yzx+lyNzbojn1jHM1z2PkW X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc2:d48f:a998:5915]) (user=irogers job=sendgmr) by 2002:a25:d652:0:b0:e30:cbcf:181c with SMTP id 3f1490d57ef6-e337e0f8f50mr24749276.2.1731133140188; Fri, 08 Nov 2024 22:19:00 -0800 (PST) Date: Fri, 8 Nov 2024 22:18:04 -0800 In-Reply-To: <20241109061809.811922-1-irogers@google.com> Message-Id: <20241109061809.811922-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: <20241109061809.811922-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v6 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 c1daf82c9b92..fabfcb74800b 100644 --- a/tools/perf/builtin-kwork.c +++ b/tools/perf/builtin-kwork.c @@ -1846,7 +1846,7 @@ static void process_skipped_events(struct perf_kwork = *kwork, } } =20 -struct kwork_work *perf_kwork_add_work(struct perf_kwork *kwork, +static struct kwork_work *perf_kwork_add_work(struct perf_kwork *kwork, struct kwork_class *class, struct kwork_work *key) { @@ -2344,6 +2344,7 @@ int cmd_kwork(int argc, const char **argv) .all_runtime =3D 0, .all_count =3D 0, .nr_skipped_events =3D { 0 }, + .add_work =3D perf_kwork_add_work, }; static const char default_report_sort_order[] =3D "runtime, max, count"; static const char default_latency_sort_order[] =3D "avg, max, count"; diff --git a/tools/perf/util/bpf_kwork.c b/tools/perf/util/bpf_kwork.c index 6c7126b7670d..5cff755c71fa 100644 --- a/tools/perf/util/bpf_kwork.c +++ b/tools/perf/util/bpf_kwork.c @@ -285,7 +285,7 @@ static int add_work(struct perf_kwork *kwork, (bpf_trace->get_work_name(key, &tmp.name))) return -1; =20 - work =3D perf_kwork_add_work(kwork, tmp.class, &tmp); + work =3D kwork->add_work(kwork, tmp.class, &tmp); if (work =3D=3D NULL) return -1; =20 diff --git a/tools/perf/util/bpf_kwork_top.c b/tools/perf/util/bpf_kwork_to= p.c index 7261cad43468..b6f187dd9136 100644 --- a/tools/perf/util/bpf_kwork_top.c +++ b/tools/perf/util/bpf_kwork_top.c @@ -255,7 +255,7 @@ static int add_work(struct perf_kwork *kwork, struct wo= rk_key *key, bpf_trace =3D kwork_class_bpf_supported_list[type]; tmp.class =3D bpf_trace->class; =20 - work =3D perf_kwork_add_work(kwork, tmp.class, &tmp); + work =3D kwork->add_work(kwork, tmp.class, &tmp); if (!work) return -1; =20 diff --git a/tools/perf/util/kwork.h b/tools/perf/util/kwork.h index 76fe2a821bcf..29352ca1d497 100644 --- a/tools/perf/util/kwork.h +++ b/tools/perf/util/kwork.h @@ -251,12 +251,14 @@ struct perf_kwork { * perf kwork top data */ struct kwork_top_stat top_stat; -}; =20 -struct kwork_work *perf_kwork_add_work(struct perf_kwork *kwork, + /* Add work callback. */ + struct kwork_work *(*add_work)(struct perf_kwork *kwork, struct kwork_class *class, struct kwork_work *key); =20 +}; + #ifdef HAVE_BPF_SKEL =20 int perf_kwork__trace_prepare_bpf(struct perf_kwork *kwork); diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index c52da509ae58..6e2ff0076daa 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -16,7 +16,6 @@ #include "thread_map.h" #include "trace-event.h" #include "mmap.h" -#include "util/kwork.h" #include "util/sample.h" #include =20 @@ -1297,14 +1296,3 @@ PyMODINIT_FUNC PyInit_perf(void) PyErr_SetString(PyExc_ImportError, "perf: Init failed!"); return module; } - - -/* The following are stubs to avoid dragging in builtin-* objects. */ -/* TODO: move the code out of the builtin-* file into util. */ - -struct kwork_work *perf_kwork_add_work(struct perf_kwork *kwork __maybe_un= used, - struct kwork_class *class __maybe_unused, - struct kwork_work *key __maybe_unused) -{ - return NULL; -} --=20 2.47.0.277.g8800431eea-goog From nobody Sat Nov 23 21:23:22 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 638AC194A54 for ; Sat, 9 Nov 2024 06:19:03 +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=1731133144; cv=none; b=kzo0ZuBQOAPjXyOiEbUpMPEJ2L0MsR+sT7i9UwXmHTHsPrJvJSJ1nD2ACrV8xqS6WsWhUF+OrlW56mibeYy6dZHztRZnzCDCToIz8xcqyhyYkAu3vNYzk8Qz9zr0rU+N0tR15p/CSldz18BKXG0bd/5iLc6jfxZniOA6aYKirOc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731133144; c=relaxed/simple; bh=0iUYu8ZIw3nC+tEYsru/9b2KOk5bw5n11avghkE86XA=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=V4pGDDvPqfrTgyZYGN/2Cf5/mUQSLNWuhMNTsWiGMw4GZijfmMjJ0n3dnDRG2uF3pt+OlZvmAuDpgK12RsUWbd4PMkUxUuDS0LZEhSrAv9BDZVG4oLnp2CWPSta/Bn4VxxPycS9sH00W5g2SH9lhgDGd6m1XTr3vADYN4LBQk1g= 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=pe0PyR/b; 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="pe0PyR/b" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e2b9f2c6559so4455925276.2 for ; Fri, 08 Nov 2024 22:19:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731133142; x=1731737942; 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=S5SFBUvJ8uwJxM/+aez6JFuBLxdqirz/XmWsuAyloP0=; b=pe0PyR/brtyINSUrq2YTH4JmbZYi3hReROvO0OEF6Ey8JmnRYdQRaZIkIob624UDNt c0dflv/Yc88+fTaoh0mPokfV1pDlHh+Z8U+H5yzHsSE0XxcVrvHstRekv22XGREvqGn4 6IwAyT8TxQrOLgVW/CiKM50T+zK5rEKoJYcR1lA6AFM3ZxAfJVUAMaeRrwf6jS/t51zf EpnHhx0vcxuCVYnkp8ablv6enA3tuvLNbsTQ01ta68TKMWQFTKEj9P4YNKBgf8pX6fXY ORI/KuAzmSa0pQ49B4PhfTd3WAK85i/OpXigEHwJqDSYZFlVhM6ukkFsHJaJuItrdyf4 9D4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731133142; x=1731737942; 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=S5SFBUvJ8uwJxM/+aez6JFuBLxdqirz/XmWsuAyloP0=; b=RJwUfrD6auAtLWYIraKKJhvCu0oHxFzoM/ZZItrUcm/Zc6a9BcpryX0/XhdNUfUhgF BnezkBcojwJgDmqLUmCywezykgZ3sla3VVz7dex63+dksUXY/DcY2LtoiZaqsgL9TS6S 8XLs5khIqNe83wNp9taG9Z1d0WmIgWm589Sxj2Nulin7KwSAeDB4iX0kOf1G5ywynC6Z LHpRuaAycfHofKP2WT0//057nHK9fU9G4T7TGJUZPPo7JMbIqLHfI9q5+33sZTdTWh4D P4PZCydzhO2W/aYWrTrPhcni0R5k+qjSrOEHnJbc04OjggN+zp2OeTIUz6to5jM0MsbI 0l9A== X-Forwarded-Encrypted: i=1; AJvYcCXNS19ljEk/yECOJcyhZoeSZHx/VUN7JpqWBMXnMWXu08zDOfCbjYTfsRP1Xgl5JUTzKj+GHnUT6gHtpCw=@vger.kernel.org X-Gm-Message-State: AOJu0YwYR/L+CbWiSIOn6jYTlTU7TNwyXqrdCmwX5eLrbQs8ir4zhaPx J7xeiyfPyP9nJCS/3o7k87sJx0F/UiXRHNBu5N2KETK9azvbQZTtf7nO87Rv3Pw+yRGzSZbS3su 1t8aeqg== X-Google-Smtp-Source: AGHT+IH9AHh43wZI95SDyksqtxouXEyTkhOjimgLo4B9ZLCzen6gdneqeJ2en9MS4bz5JA8JbbcbHNuqPciu X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc2:d48f:a998:5915]) (user=irogers job=sendgmr) by 2002:a25:3355:0:b0:e2b:cd96:67a6 with SMTP id 3f1490d57ef6-e337f8c133dmr3844276.5.1731133142342; Fri, 08 Nov 2024 22:19:02 -0800 (PST) Date: Fri, 8 Nov 2024 22:18:05 -0800 In-Reply-To: <20241109061809.811922-1-irogers@google.com> Message-Id: <20241109061809.811922-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: <20241109061809.811922-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v6 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.277.g8800431eea-goog From nobody Sat Nov 23 21:23:22 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 80783195FD5 for ; Sat, 9 Nov 2024 06:19:05 +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=1731133147; cv=none; b=nL1A0hs0flKhuPxTdCE7BxNlfEBEtLKxQEKj+43FcGQNiWI6Zhgf7MOa2czOkFCGcUMlyxcOM1zpmvtQY9vM9VK2dCCBOTRFyI4Fhgbgt/j5c8jRe5HnMWS8RPpJCB7mq7tgOjQenv8wKvqX2uQtsfyNWGt50nxf7qB5CAVjdZc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731133147; c=relaxed/simple; bh=lsCvQUmYtGoOUuABRkiGOOa4iuLoBIgGZXe26jet8vc=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=BtGWvKSXVOlR/atNkvb/uU/VhjUtRNyv61raE9euphQkvMeGTV3Rvhz8eNU0VegT+365JE8F2DF7C1VKnlZfavifku1Zd2Opn37IheuRD6k6Y4/wXtqOvY6AMzcmBIFL3aA1FKc3tAJ4Rb+jzdVkCiotrd4LGynvpWlw3aOp8gk= 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=wV2wEInt; 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="wV2wEInt" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e30df208cadso4907554276.0 for ; Fri, 08 Nov 2024 22:19:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731133144; x=1731737944; 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=idekZ5mqOfUQ8Rvlee93oJIg5nGKfz7rEzSROqbRTzY=; b=wV2wEInt4kSlduo9QPAd0HBYDCvjZWSdBUWyN4/5qrXYZGhmwJVK0nsY6jY5UGlqFe KSxY7WlPY4WS+EODXIChsoXe70/u0Kcw4jZf1EymInnf60J0kZAen0Lta2/Pv3KQ1al/ HlNrLr+5pf3nj5lg3/813es27ypdUCcnUuGCOGfCbhqybQsCFtOLelkouqQ2faYy72hF AVMGn0CP8RQXExMOz1JiKVo2Zu/T19aEDSYM2iMeaArB9MHlQZKMjerzBJ05OGQdMyXU F9Y/tD/7RM5FoPIkUhRiJNNUx8/oE08Nx5cT/qFUUveUqeZ3h0FkH6UkeRk2SBbXTMZI 1g5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731133144; x=1731737944; 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=idekZ5mqOfUQ8Rvlee93oJIg5nGKfz7rEzSROqbRTzY=; b=eBu4Q9wr/+jXx80djvEWqjGtYxGPPz6MBzMweJkxd9qg/ZIaWl/uHU16zIsFd9suEB XibtPwAOIJzdu6yFrLQKlJXUzxAaPAbciIttmSEmze74ccb1jGdEZAHvgEee4qOXnmTI /NTgYnt2XeVUqEC/cDGS493RoCro8hocIE3975rEVbTvYWQL20nEpDGvZYoZ+nMev1eA mP6yv7TwFmNOiWjqDN8tGjjDlo2fihM9LsE474zHVQXMGAcxJjg7mcyJUhrAwoIUzq2x eNAxEWP2C0L8OmKRtmFWuRNPC/5w7bCYKW0G82F4yATITC2UbSFZOWmLHtokZZDJaXo9 Q/Fg== X-Forwarded-Encrypted: i=1; AJvYcCWlF4GejYofyCWvQe7FZP7gnmEVAzhqHD5dF0JFxI6oayoIQYnBDe5M0Q7+2Yv6UdveXX4kP6GPv8rZnoQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyPbV2VVJkx3dcG+JITQiX0+CG5dXFs056gxDNFt7wg8SFa+zXt TMFvW49eHBD9lcruhHDLRYPNeUdA31qxLu2HfuLvwW60jtJwwSoTRYkwn59b6N+YUoTV5DKUq2Z dTJ1N/g== X-Google-Smtp-Source: AGHT+IGyOAbd6LiSlb+ikd+ZVqoL5bSigFnDGrfGby57ISP6b83CZyVUuKPP6kDcoDs0PsD9QvYPcMUj0gmZ X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc2:d48f:a998:5915]) (user=irogers job=sendgmr) by 2002:a25:d843:0:b0:e29:7454:e773 with SMTP id 3f1490d57ef6-e337e1d738cmr23283276.5.1731133144532; Fri, 08 Nov 2024 22:19:04 -0800 (PST) Date: Fri, 8 Nov 2024 22:18:06 -0800 In-Reply-To: <20241109061809.811922-1-irogers@google.com> Message-Id: <20241109061809.811922-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: <20241109061809.811922-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v6 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 f780e30aa259..4213ffacdc3c 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -453,7 +453,7 @@ static int evsel__copy_config_terms(struct evsel *dst, = struct evsel *src) * The assumption is that @orig is not configured nor opened yet. * So we only care about the attributes that can be set while it's parsed. */ -struct evsel *evsel__clone(struct evsel *orig) +struct evsel *evsel__clone(struct evsel *dest, struct evsel *orig) { struct evsel *evsel; =20 @@ -466,7 +466,11 @@ struct evsel *evsel__clone(struct evsel *orig) if (orig->bpf_obj) return NULL; =20 - evsel =3D evsel__new(&orig->core.attr); + if (dest) + evsel =3D dest; + else + evsel =3D evsel__new(&orig->core.attr); + if (evsel =3D=3D NULL) return NULL; =20 @@ -511,11 +515,12 @@ struct evsel *evsel__clone(struct evsel *orig) evsel->core.leader =3D orig->core.leader; =20 evsel->max_events =3D orig->max_events; - free((char *)evsel->unit); - evsel->unit =3D strdup(orig->unit); - if (evsel->unit =3D=3D NULL) - goto out_err; - + zfree(&evsel->unit); + if (orig->unit) { + evsel->unit =3D strdup(orig->unit); + if (evsel->unit =3D=3D NULL) + goto out_err; + } evsel->scale =3D orig->scale; evsel->snapshot =3D orig->snapshot; evsel->per_pkg =3D orig->per_pkg; diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 04934a7af174..7f41d6f8cf6f 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -241,7 +241,7 @@ static inline struct evsel *evsel__new(struct perf_even= t_attr *attr) return evsel__new_idx(attr, 0); } =20 -struct evsel *evsel__clone(struct evsel *orig); +struct evsel *evsel__clone(struct evsel *dest, struct evsel *orig); =20 int copy_config_terms(struct list_head *dst, struct list_head *src); void free_config_terms(struct list_head *config_terms); diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 6e2ff0076daa..1a53a97c513d 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -13,6 +13,7 @@ #include "evsel.h" #include "event.h" #include "print_binary.h" +#include "strbuf.h" #include "thread_map.h" #include "trace-event.h" #include "mmap.h" @@ -1201,6 +1202,60 @@ static PyObject *pyrf__tracepoint(struct pyrf_evsel = *pevsel, #endif // HAVE_LIBTRACEEVENT } =20 +static PyObject *pyrf_evsel__from_evsel(struct evsel *evsel) +{ + struct pyrf_evsel *pevsel =3D PyObject_New(struct pyrf_evsel, &pyrf_evsel= __type); + + if (!pevsel) + return NULL; + + memset(&pevsel->evsel, 0, sizeof(pevsel->evsel)); + evsel__init(&pevsel->evsel, &evsel->core.attr, evsel->core.idx); + + evsel__clone(&pevsel->evsel, evsel); + return (PyObject *)pevsel; +} + +static PyObject *pyrf_evlist__from_evlist(struct evlist *evlist) +{ + struct pyrf_evlist *pevlist =3D PyObject_New(struct pyrf_evlist, &pyrf_ev= list__type); + struct evsel *pos; + + if (!pevlist) + return NULL; + + memset(&pevlist->evlist, 0, sizeof(pevlist->evlist)); + evlist__init(&pevlist->evlist, evlist->core.all_cpus, evlist->core.thread= s); + evlist__for_each_entry(evlist, pos) { + struct pyrf_evsel *pevsel =3D (void *)pyrf_evsel__from_evsel(pos); + + evlist__add(&pevlist->evlist, &pevsel->evsel); + } + return (PyObject *)pevlist; +} + +static PyObject *pyrf__parse_events(PyObject *self, PyObject *args) +{ + const char *input; + struct evlist evlist =3D {}; + struct parse_events_error err; + PyObject *result; + + if (!PyArg_ParseTuple(args, "s", &input)) + return NULL; + + parse_events_error__init(&err); + evlist__init(&evlist, NULL, NULL); + if (parse_events(&evlist, input, &err)) { + parse_events_error__print(&err, input); + PyErr_SetFromErrno(PyExc_OSError); + return NULL; + } + result =3D pyrf_evlist__from_evlist(&evlist); + evlist__exit(&evlist); + return result; +} + static PyMethodDef perf__methods[] =3D { { .ml_name =3D "tracepoint", @@ -1208,6 +1263,12 @@ static PyMethodDef perf__methods[] =3D { .ml_flags =3D METH_VARARGS | METH_KEYWORDS, .ml_doc =3D PyDoc_STR("Get tracepoint config.") }, + { + .ml_name =3D "parse_events", + .ml_meth =3D (PyCFunction) pyrf__parse_events, + .ml_flags =3D METH_VARARGS, + .ml_doc =3D PyDoc_STR("Parse a string of events and return an evlist.") + }, { .ml_name =3D NULL, } }; =20 --=20 2.47.0.277.g8800431eea-goog From nobody Sat Nov 23 21:23:22 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 096FC198853 for ; Sat, 9 Nov 2024 06:19:07 +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=1731133149; cv=none; b=RuaZbg8ZbLOLxAaozCXd/gxDQd1orzR/tmAUfLmto3AOuzsR5936BSv6I1fA/Fc+84n3Dv3iG5rLi0qe+mQQWTFBNKtkhxK4EhdmR7HHb0TGzwgikZ9gTkjruSuYKLUrQgXAZpK/7IpHBHYd0DEqaLSJD36SD9mhLUbOHm8baI8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731133149; c=relaxed/simple; bh=lo8v/8lzKi2C37iCsrx8frWOHW56Z3pjRjxD2LGxcBk=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=iOAVULEGtTNyeibsz8jJBDjy2DXZEEeYQSoInPSfqwhNNJCK2+uTvZcDEgRtVL1ke0LhOfmCWNnsGu4yiBsi5sSCXzHqPbrtqZ7Bqc5ChWg2Wkt8v8wt1Pbfl8MZd81WDp6/TVPesHb7xTJ+fnSDxL8PJB1uQyCc7f7QdaVX7X8= 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=I9FpMQe2; 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="I9FpMQe2" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e29142c79d6so4458887276.3 for ; Fri, 08 Nov 2024 22:19:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731133147; x=1731737947; 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=mcNbzzRS5VSvLqueZ2osfH4cEHyPpkywFOwBXdLSQFY=; b=I9FpMQe2pyHsb/CNCIjalnEQ1Zc3BEbSJ3vYug9zZSpT5zE0BVqBujrOxFAGyfwIS6 3GPRVi0SI5uAhCr2Y61IzBmpuPo6Z1pF+3iBGiVHzNRUoJ8YqPaFJfCNLQZ4z/SqYSW/ PNG5/ZP2d9gK7JAkYn0rhcIWy0wuWCEQrh0fSJ2DgB+iPiOmfxuOVfSrI3C8AXNVZ7Ef nEJY4ptMNEzx5TjpIDHwEXuE03f/tLChh7VfaSx0mrtOngVVX8ZmWlIO/uga4P66uwVJ P77nzC9NUa5Nta8vfGsn9oUZQxm77ZXSFlBi0TgtiFgZRdpuVgdpRIgZuz/sV9o56qQF Y1+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731133147; x=1731737947; 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=mcNbzzRS5VSvLqueZ2osfH4cEHyPpkywFOwBXdLSQFY=; b=A71C1+SsAiIYKc1mKKRPri22Gg8OTlIgal3rcBYxDpITAXQVx2opjun0mEJUQw3ZfY bNfL7oI0SV/cVNHPgnAhSZQohZacBSAWfejoCukmxCWeo5hmyqCsJ8Nm2VyE0L4l0KoJ Nfy8E057ZG67sW2sDf5uw7QWzu7X1MM32xehaXgoOaK0n3d4QPkdIql7P9lfwj48gqS/ cdp6no2Q57Wm6c8BoHhddwPO4oakj9SGmq+PQacR4Sr7OYOX5bprrJu86UQFjYmy/s8z K3N95giEdrWfbzA7w9xi07GYoNh7uBL71meAxawNtoIT2/4meb+cjqQmXe+8oeUPaV4U 31TQ== X-Forwarded-Encrypted: i=1; AJvYcCVfYj32W4BwMdPGJjl/hdj2ok4UmrHHKeA3Y+/Jhh37AP6Vn+KHQmX0YHwFAZ7slCKeiyDr24db/4IsAOo=@vger.kernel.org X-Gm-Message-State: AOJu0Yzd7FQUVRPI/8z9DtepML7xgwSMWERjhlE1kbafQnmRD5Tfsp9o DthzWj5+czepZDtx/oXlCMuYe827Eore279zeNYgI5WRBM6+pi91m6JFJUuRTT76rtTG8XgJ71L I8/0uuw== X-Google-Smtp-Source: AGHT+IEKaG3zlJt89Q/3pdQFukKpZBajf0ZNkUqR0ExiOk8/EXoIs6qi0VEv8zHURZeQDLRlnyhNsZA6ER1Z X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc2:d48f:a998:5915]) (user=irogers job=sendgmr) by 2002:a25:3355:0:b0:e2b:cd96:67a6 with SMTP id 3f1490d57ef6-e337f8c133dmr3846276.5.1731133146758; Fri, 08 Nov 2024 22:19:06 -0800 (PST) Date: Fri, 8 Nov 2024 22:18:07 -0800 In-Reply-To: <20241109061809.811922-1-irogers@google.com> Message-Id: <20241109061809.811922-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: <20241109061809.811922-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v6 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 1a53a97c513d..a71bad3418da 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1069,6 +1069,30 @@ static PyObject *pyrf_evlist__item(PyObject *obj, Py= _ssize_t i) return Py_BuildValue("O", container_of(pos, struct pyrf_evsel, evsel)); } =20 +static PyObject *pyrf_evlist__str(PyObject *self) +{ + struct pyrf_evlist *pevlist =3D (void *)self; + struct evsel *pos; + struct strbuf sb =3D STRBUF_INIT; + bool first =3D true; + PyObject *result; + + strbuf_addstr(&sb, "evlist(["); + evlist__for_each_entry(&pevlist->evlist, pos) { + if (!first) + strbuf_addch(&sb, ','); + if (!pos->pmu) + strbuf_addstr(&sb, evsel__name(pos)); + else + strbuf_addf(&sb, "%s/%s/", pos->pmu->name, evsel__name(pos)); + first =3D false; + } + strbuf_addstr(&sb, "])"); + result =3D PyUnicode_FromString(sb.buf); + strbuf_release(&sb); + return result; +} + static PySequenceMethods pyrf_evlist__sequence_methods =3D { .sq_length =3D pyrf_evlist__length, .sq_item =3D pyrf_evlist__item, @@ -1086,6 +1110,8 @@ static PyTypeObject pyrf_evlist__type =3D { .tp_doc =3D pyrf_evlist__doc, .tp_methods =3D pyrf_evlist__methods, .tp_init =3D (initproc)pyrf_evlist__init, + .tp_repr =3D pyrf_evlist__str, + .tp_str =3D pyrf_evlist__str, }; =20 static int pyrf_evlist__setup_types(void) --=20 2.47.0.277.g8800431eea-goog From nobody Sat Nov 23 21:23:22 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 21944198E93 for ; Sat, 9 Nov 2024 06:19:10 +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=1731133151; cv=none; b=sFaYOr7pQKfqAksvJv4rqw064yg+kZXjm22OdXxhup4CEI1/aH7h5ZmboNJ3+Y5Tzp33p775GFOXP7J8YaRgcAH+K7/7QeOgX9vcsyvr/ovlOde9/Rkzy7vDMdSwIBHJl+zYiqcvDqpFu7VbSnY2k3POOBirlAwJKYAJEKOO50E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731133151; c=relaxed/simple; bh=MCTzfXp2410npPWMxPnIy//KFfI1FnSlwqErfN8AdVw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=uHF7rFPNqM0nMH4QkVN1wU0Dif1IJKJ/qpY5Z9UiFlsBiJIwJ8WMtlbjlXIrORZZhShlqOR7dTB0vvw+XS2dYa3m2wbXPtXK+ssJ8CD68se1H6va3677rLV4yg08ZpQgim91sok2I7n2Hs++wvZWuNjaTnQ4EGUEu0alNMHBr60= 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=Vlwx+UF6; 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="Vlwx+UF6" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6eaa08a6fdbso52466047b3.3 for ; Fri, 08 Nov 2024 22:19:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731133149; x=1731737949; 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=wQC+nYVZnsSIPtVomujUJB9/ZDMtc8fpB8iG7KWs9rs=; b=Vlwx+UF6Og1P1ohXLNFHkKtMyIAUHT79LeNk9pPckNTWLiwPqXCfe64X/WrIyhHp1x M3OIIaQyFCT7jKM9GcW5EuAL3JqoWteU2D98/4wIpBsg3D4FuIxDnffjUVlq0bJpkAGw +QWZArYxdJlFOxDgzpG0OEv1GU1wowea/4WRp6ltcyTTcqbo9tB24n7nJNz47zzEM49z ZHP+YhpjyGz9GQwLiMgvcFU0uHNbglWXL4D6vRt7MgxjFunlqvXCDplQa4sfhMY/iYaU xRuDaHSnmCGU+GKem+KeKRJrJ30hCbb8nHzXE+m5gxqH//FcPbklIGwGnTyMAgXu8MQW 5fmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731133149; x=1731737949; 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=wQC+nYVZnsSIPtVomujUJB9/ZDMtc8fpB8iG7KWs9rs=; b=rZPJR/DtILjAYBbt8OIlA8/mEQMnMfMxRhWMYkFKTMXf/OaH0eAwD+2LsFShsL9RZQ R3ytm4HeuQiDYH6BBPrgjfsWUz1b/oOVcY2kyPLkP3rIYH1YZup/ENBV7QZteCvYcSoy CF1duV7JZ2RlJ7K4C+uJdz0GKv5KOFXBjzFFwc3KwSWRGpcn6pHMs8Bg9f0rqiJ12SfR YPgHYemDchVdA0lWU9eKpBIPIkgs9bjiSvNZ3y5MJGmGMIUU4i5qUeNthtDw9z1YfyTi b1njRVqSC/rE9pN35JmFU7oaMF0/B3biScSe1ogDSwIa0TjZSWcnGSROldYUTPJbjneq G2eQ== X-Forwarded-Encrypted: i=1; AJvYcCXcjVpaPyIZMm64u3IJVTcG9tBYNuF3eDzR9Emzq7RgD7t8VkwJXEd/7mK4AlKsdN4x7vt7boWP77JQe94=@vger.kernel.org X-Gm-Message-State: AOJu0YxUa33a1Dgr9QvDLJTQz+xUWKgmnMbTzVkitrrUiaLBcii43tO8 UveR3HYS+du0hCY490GH/LF9ptOlcQ2hso+hKkUbhx/bnV5612nztclOVvq9irZKn61VBl+4Sgz cfmP4SA== X-Google-Smtp-Source: AGHT+IG2J8xhYT2nRn4RChEQkkMF8wDYoMqfx5nMQX1zyrXP8KIbZkwthsd8g0UJFa4g+kK5T8mO25tIMjc9 X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc2:d48f:a998:5915]) (user=irogers job=sendgmr) by 2002:a05:690c:620a:b0:6ea:e559:d69c with SMTP id 00721157ae682-6eae559d710mr212777b3.5.1731133149313; Fri, 08 Nov 2024 22:19:09 -0800 (PST) Date: Fri, 8 Nov 2024 22:18:08 -0800 In-Reply-To: <20241109061809.811922-1-irogers@google.com> Message-Id: <20241109061809.811922-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: <20241109061809.811922-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v6 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 a71bad3418da..0d71ec673aa3 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -781,6 +781,17 @@ static PyObject *pyrf_evsel__open(struct pyrf_evsel *p= evsel, return Py_None; } =20 +static PyObject *pyrf_evsel__str(PyObject *self) +{ + struct pyrf_evsel *pevsel =3D (void *)self; + struct evsel *evsel =3D &pevsel->evsel; + + if (!evsel->pmu) + return PyUnicode_FromFormat("evsel(%s)", evsel__name(evsel)); + + return PyUnicode_FromFormat("evsel(%s/%s/)", evsel->pmu->name, evsel__nam= e(evsel)); +} + static PyMethodDef pyrf_evsel__methods[] =3D { { .ml_name =3D "open", @@ -802,6 +813,8 @@ static PyTypeObject pyrf_evsel__type =3D { .tp_doc =3D pyrf_evsel__doc, .tp_methods =3D pyrf_evsel__methods, .tp_init =3D (initproc)pyrf_evsel__init, + .tp_str =3D pyrf_evsel__str, + .tp_repr =3D pyrf_evsel__str, }; =20 static int pyrf_evsel__setup_types(void) --=20 2.47.0.277.g8800431eea-goog From nobody Sat Nov 23 21:23:22 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 56787146D78 for ; Sat, 9 Nov 2024 06:19:13 +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=1731133154; cv=none; b=GSxw4C48ViqrGyv60s99MIvQWMChnHEHk708/phfHBqkBuA7oHf3GnbXyI/p9Nb6AsFPLXwO9vAVSzsDMkVbODIm6zGuz+IKj3ldpetGvHXdn8l5VAKtrl+p6RLDg89WtbV9fqSsw/TQWmmmqy1Y2+twcpkDtu4WAYR1X0YbUfU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731133154; c=relaxed/simple; bh=cdFXS6YbU6dHLZsfKNNJ3CV8t/rR/3/1BmnroI/EmI4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=bBOHkRp9Dmu7TF/m5TV1AIbWXOf89nsdpS/JlMWQ+YmDnZ2R+dL9dOPpOswXTBnMYhrGMcf7s88zjLf/z9ByPgGPoLiaOddSUhduKyZ3Pq8n4he/+JWDC4VO8FdQYFVQAAdqyk0j7tqmgVcP/ZHBYAVS1GDuGMqH2BDs18z9zns= 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=LINTWF0L; 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="LINTWF0L" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e2e3321aae0so4834872276.1 for ; Fri, 08 Nov 2024 22:19:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731133152; x=1731737952; 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=m24ezova7J3GENnmHxuIJrSil1dVDJzqrtZznCoBSNI=; b=LINTWF0LAIkda7RAlnxKvdOE3C7bfMMXN5ShsIeQUoXQpCo0iqUk8x4o0umNVtMzqc HBCrCrFxfM8N4MD/xVpLflfSujsLaW+BRXmnU3iJao8YYb8+J0KCved325i9xfROA9/v XnFuI6OROMHXm0N7NYvTOtxbNzbP47oC7hX2Dwg3hbMQAEoDgo64Wi1waTBxRmtvF6Ha vIfVm9V90k8vXQ8qutwwUyHGjaC9lOuPwI6PxCYq88mbCUjnzOebf6CBXNPLfrs2X3vn DeiDoKSPHLAgLsX67ZXGnXEwjBFQtkVjYjGcuPQiywIDdW34MYVfd/ncNhwlw6XdpWYH tRKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731133152; x=1731737952; 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=m24ezova7J3GENnmHxuIJrSil1dVDJzqrtZznCoBSNI=; b=gHzXYGTNg7mSQT6jUPrBuWkYIHzGrtJ+fEdpGixDEMwk4Ihl0zwCOuoIl/Twd4Murb iF+OlkaQ+wknAuMTe+hO170gACTK+goOpytwNjQQZOkmZ4u6/f4IDWmblf1EPKiSTauB L5wru2dMMOi4SYTVouqUeixdE99OTmXrk5UmLENVLR2h+0VuqPcQ8BENSFTfrupdQrRv jkSI8GxHQuET5650kXl6fbCCIHIzTWj76/uXR9g7B3/wfUq57eizE+2q+SK8j6dFBybW d4QMl/rl/u1Ny0c2Ce/AlmW8z8AY90u7pFquN5HNa9/TBYWrTOXC0081Rw4d33YDRLfz H9Yw== X-Forwarded-Encrypted: i=1; AJvYcCVewYQECxQwwfjRce12TnXdhIio0oI30CkKBcVaa7k69heHMHduX7Sej8HGnDFWNPpY4i1OVaK2N7Ejtb4=@vger.kernel.org X-Gm-Message-State: AOJu0YyPU2Yx0tNPEKEgZ4xva4EBW7Y7Ut+wzxViKQGzE9bzfA6l0bLL qWwMRIrWf/5BJEgOfZlrZSGCplyU3KwdvM74umhkvaGl+Hd/i/A5cm+FU7AX759GJqFbvhnd6H+ m0yqC1A== X-Google-Smtp-Source: AGHT+IEjWicK5LpMHUtvdfgpqNM6nhMioZKKQMcNun1xBlhB3GtyO6nVCSa+gmCfKwcqfavz2sH0Ixj1poWJ X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc2:d48f:a998:5915]) (user=irogers job=sendgmr) by 2002:a25:8b81:0:b0:e2e:3031:3f0c with SMTP id 3f1490d57ef6-e337f8d41a3mr4031276.7.1731133151533; Fri, 08 Nov 2024 22:19:11 -0800 (PST) Date: Fri, 8 Nov 2024 22:18:09 -0800 In-Reply-To: <20241109061809.811922-1-irogers@google.com> Message-Id: <20241109061809.811922-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: <20241109061809.811922-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v6 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 0d71ec673aa3..25114dcadd21 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1071,8 +1071,10 @@ static PyObject *pyrf_evlist__item(PyObject *obj, Py= _ssize_t i) struct pyrf_evlist *pevlist =3D (void *)obj; struct evsel *pos; =20 - if (i >=3D pevlist->evlist.core.nr_entries) + if (i >=3D pevlist->evlist.core.nr_entries) { + PyErr_SetString(PyExc_IndexError, "Index out of range"); return NULL; + } =20 evlist__for_each_entry(&pevlist->evlist, pos) { if (i-- =3D=3D 0) --=20 2.47.0.277.g8800431eea-goog