From nobody Sat Nov 23 23:43:53 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