Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf python: Remove python 2 scripting support

Python2 was deprecated 4 years ago, remove support and workarounds.

Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Colin Ian King <colin.i.king@gmail.com>
Cc: Dapeng Mi <dapeng1.mi@linux.intel.com>
Cc: Howard Chu <howardchu95@gmail.com>
Cc: Ilya Leoshkevich <iii@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Veronika Molnarova <vmolnaro@redhat.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Link: https://lore.kernel.org/r/20241119011644.971342-2-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
e7e9943c 4c7f9ee2

+15 -139
-18
tools/perf/scripts/python/Perf-Trace-Util/Context.c
··· 24 24 #include "../../../util/srcline.h" 25 25 #include "../../../util/srccode.h" 26 26 27 - #if PY_MAJOR_VERSION < 3 28 - #define _PyCapsule_GetPointer(arg1, arg2) \ 29 - PyCObject_AsVoidPtr(arg1) 30 - #define _PyBytes_FromStringAndSize(arg1, arg2) \ 31 - PyString_FromStringAndSize((arg1), (arg2)) 32 - #define _PyUnicode_AsUTF8(arg) \ 33 - PyString_AsString(arg) 34 - 35 - PyMODINIT_FUNC initperf_trace_context(void); 36 - #else 37 27 #define _PyCapsule_GetPointer(arg1, arg2) \ 38 28 PyCapsule_GetPointer((arg1), (arg2)) 39 29 #define _PyBytes_FromStringAndSize(arg1, arg2) \ ··· 32 42 PyUnicode_AsUTF8(arg) 33 43 34 44 PyMODINIT_FUNC PyInit_perf_trace_context(void); 35 - #endif 36 45 37 46 static struct scripting_context *get_args(PyObject *args, const char *name, PyObject **arg2) 38 47 { ··· 202 213 { NULL, NULL, 0, NULL} 203 214 }; 204 215 205 - #if PY_MAJOR_VERSION < 3 206 - PyMODINIT_FUNC initperf_trace_context(void) 207 - { 208 - (void) Py_InitModule("perf_trace_context", ContextMethods); 209 - } 210 - #else 211 216 PyMODINIT_FUNC PyInit_perf_trace_context(void) 212 217 { 213 218 static struct PyModuleDef moduledef = { ··· 223 240 224 241 return mod; 225 242 } 226 - #endif
+12 -61
tools/perf/util/python.c
··· 26 26 #include <internal/lib.h> 27 27 #include "../builtin.h" 28 28 29 - #if PY_MAJOR_VERSION < 3 30 - #define _PyUnicode_FromString(arg) \ 31 - PyString_FromString(arg) 32 - #define _PyUnicode_AsString(arg) \ 33 - PyString_AsString(arg) 34 - #define _PyUnicode_FromFormat(...) \ 35 - PyString_FromFormat(__VA_ARGS__) 36 - #define _PyLong_FromLong(arg) \ 37 - PyInt_FromLong(arg) 38 - 39 - #else 40 - 41 29 #define _PyUnicode_FromString(arg) \ 42 30 PyUnicode_FromString(arg) 43 31 #define _PyUnicode_FromFormat(...) \ 44 32 PyUnicode_FromFormat(__VA_ARGS__) 45 33 #define _PyLong_FromLong(arg) \ 46 34 PyLong_FromLong(arg) 47 - #endif 48 35 49 - #ifndef Py_TYPE 50 - #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) 51 - #endif 52 - 53 - /* Define PyVarObject_HEAD_INIT for python 2.5 */ 54 - #ifndef PyVarObject_HEAD_INIT 55 - # define PyVarObject_HEAD_INIT(type, size) PyObject_HEAD_INIT(type) size, 56 - #endif 57 - 58 - #if PY_MAJOR_VERSION < 3 59 - PyMODINIT_FUNC initperf(void); 60 - #else 61 36 PyMODINIT_FUNC PyInit_perf(void); 62 - #endif 63 37 64 38 #define member_def(type, member, ptype, help) \ 65 39 { #member, ptype, \ ··· 91 117 pevent->event.mmap.pgoff, pevent->event.mmap.filename) < 0) { 92 118 ret = PyErr_NoMemory(); 93 119 } else { 94 - ret = _PyUnicode_FromString(s); 120 + ret = PyUnicode_FromString(s); 95 121 free(s); 96 122 } 97 123 return ret; ··· 122 148 123 149 static PyObject *pyrf_task_event__repr(struct pyrf_event *pevent) 124 150 { 125 - return _PyUnicode_FromFormat("{ type: %s, pid: %u, ppid: %u, tid: %u, " 151 + return PyUnicode_FromFormat("{ type: %s, pid: %u, ppid: %u, tid: %u, " 126 152 "ptid: %u, time: %" PRI_lu64 "}", 127 153 pevent->event.header.type == PERF_RECORD_FORK ? "fork" : "exit", 128 154 pevent->event.fork.pid, ··· 155 181 156 182 static PyObject *pyrf_comm_event__repr(struct pyrf_event *pevent) 157 183 { 158 - return _PyUnicode_FromFormat("{ type: comm, pid: %u, tid: %u, comm: %s }", 184 + return PyUnicode_FromFormat("{ type: comm, pid: %u, tid: %u, comm: %s }", 159 185 pevent->event.comm.pid, 160 186 pevent->event.comm.tid, 161 187 pevent->event.comm.comm); ··· 186 212 { 187 213 struct perf_record_throttle *te = (struct perf_record_throttle *)(&pevent->event.header + 1); 188 214 189 - return _PyUnicode_FromFormat("{ type: %sthrottle, time: %" PRI_lu64 ", id: %" PRI_lu64 215 + return PyUnicode_FromFormat("{ type: %sthrottle, time: %" PRI_lu64 ", id: %" PRI_lu64 190 216 ", stream_id: %" PRI_lu64 " }", 191 217 pevent->event.header.type == PERF_RECORD_THROTTLE ? "" : "un", 192 218 te->time, te->id, te->stream_id); ··· 221 247 pevent->event.lost.id, pevent->event.lost.lost) < 0) { 222 248 ret = PyErr_NoMemory(); 223 249 } else { 224 - ret = _PyUnicode_FromString(s); 250 + ret = PyUnicode_FromString(s); 225 251 free(s); 226 252 } 227 253 return ret; ··· 248 274 249 275 static PyObject *pyrf_read_event__repr(struct pyrf_event *pevent) 250 276 { 251 - return _PyUnicode_FromFormat("{ type: read, pid: %u, tid: %u }", 277 + return PyUnicode_FromFormat("{ type: read, pid: %u, tid: %u }", 252 278 pevent->event.read.pid, 253 279 pevent->event.read.tid); 254 280 /* ··· 283 309 if (asprintf(&s, "{ type: sample }") < 0) { 284 310 ret = PyErr_NoMemory(); 285 311 } else { 286 - ret = _PyUnicode_FromString(s); 312 + ret = PyUnicode_FromString(s); 287 313 free(s); 288 314 } 289 315 return ret; ··· 317 343 } 318 344 if (field->flags & TEP_FIELD_IS_STRING && 319 345 is_printable_array(data + offset, len)) { 320 - ret = _PyUnicode_FromString((char *)data + offset); 346 + ret = PyUnicode_FromString((char *)data + offset); 321 347 } else { 322 348 ret = PyByteArray_FromStringAndSize((const char *) data + offset, len); 323 349 field->flags &= ~TEP_FIELD_IS_STRING; ··· 406 432 !!(pevent->event.header.misc & PERF_RECORD_MISC_SWITCH_OUT)) < 0) { 407 433 ret = PyErr_NoMemory(); 408 434 } else { 409 - ret = _PyUnicode_FromString(s); 435 + ret = PyUnicode_FromString(s); 410 436 free(s); 411 437 } 412 438 return ret; ··· 892 918 893 919 for (i = 0; i < evlist->core.pollfd.nr; ++i) { 894 920 PyObject *file; 895 - #if PY_MAJOR_VERSION < 3 896 - FILE *fp = fdopen(evlist->core.pollfd.entries[i].fd, "r"); 897 - 898 - if (fp == NULL) 899 - goto free_list; 900 - 901 - file = PyFile_FromFile(fp, "perf", "r", NULL); 902 - #else 903 921 file = PyFile_FromFd(evlist->core.pollfd.entries[i].fd, "perf", "r", -1, 904 922 NULL, NULL, NULL, 0); 905 - #endif 906 923 if (file == NULL) 907 924 goto free_list; 908 925 ··· 1199 1234 1200 1235 tp_format = trace_event__tp_format(sys, name); 1201 1236 if (IS_ERR(tp_format)) 1202 - return _PyLong_FromLong(-1); 1237 + return PyLong_FromLong(-1); 1203 1238 1204 - return _PyLong_FromLong(tp_format->id); 1239 + return PyLong_FromLong(tp_format->id); 1205 1240 #endif // HAVE_LIBTRACEEVENT 1206 1241 } 1207 1242 ··· 1215 1250 { .ml_name = NULL, } 1216 1251 }; 1217 1252 1218 - #if PY_MAJOR_VERSION < 3 1219 - PyMODINIT_FUNC initperf(void) 1220 - #else 1221 1253 PyMODINIT_FUNC PyInit_perf(void) 1222 - #endif 1223 1254 { 1224 1255 PyObject *obj; 1225 1256 int i; 1226 1257 PyObject *dict; 1227 - #if PY_MAJOR_VERSION < 3 1228 - PyObject *module = Py_InitModule("perf", perf__methods); 1229 - #else 1230 1258 static struct PyModuleDef moduledef = { 1231 1259 PyModuleDef_HEAD_INIT, 1232 1260 "perf", /* m_name */ ··· 1232 1274 NULL, /* m_free */ 1233 1275 }; 1234 1276 PyObject *module = PyModule_Create(&moduledef); 1235 - #endif 1236 1277 1237 1278 if (module == NULL || 1238 1279 pyrf_event__setup_types() < 0 || ··· 1239 1282 pyrf_evsel__setup_types() < 0 || 1240 1283 pyrf_thread_map__setup_types() < 0 || 1241 1284 pyrf_cpu_map__setup_types() < 0) 1242 - #if PY_MAJOR_VERSION < 3 1243 - return; 1244 - #else 1245 1285 return module; 1246 - #endif 1247 1286 1248 1287 /* The page_size is placed in util object. */ 1249 1288 page_size = sysconf(_SC_PAGE_SIZE); ··· 1288 1335 goto error; 1289 1336 1290 1337 for (i = 0; perf__constants[i].name != NULL; i++) { 1291 - obj = _PyLong_FromLong(perf__constants[i].value); 1338 + obj = PyLong_FromLong(perf__constants[i].value); 1292 1339 if (obj == NULL) 1293 1340 goto error; 1294 1341 PyDict_SetItemString(dict, perf__constants[i].name, obj); ··· 1298 1345 error: 1299 1346 if (PyErr_Occurred()) 1300 1347 PyErr_SetString(PyExc_ImportError, "perf: Init failed!"); 1301 - #if PY_MAJOR_VERSION >= 3 1302 1348 return module; 1303 - #endif 1304 1349 } 1305 1350 1306 1351
+3 -60
tools/perf/util/scripting-engines/trace-event-python.c
··· 58 58 #include "mem-events.h" 59 59 #include "util/perf_regs.h" 60 60 61 - #if PY_MAJOR_VERSION < 3 62 - #define _PyUnicode_FromString(arg) \ 63 - PyString_FromString(arg) 64 - #define _PyUnicode_FromStringAndSize(arg1, arg2) \ 65 - PyString_FromStringAndSize((arg1), (arg2)) 66 - #define _PyBytes_FromStringAndSize(arg1, arg2) \ 67 - PyString_FromStringAndSize((arg1), (arg2)) 68 - #define _PyLong_FromLong(arg) \ 69 - PyInt_FromLong(arg) 70 - #define _PyLong_AsLong(arg) \ 71 - PyInt_AsLong(arg) 72 - #define _PyCapsule_New(arg1, arg2, arg3) \ 73 - PyCObject_FromVoidPtr((arg1), (arg2)) 74 - 75 - PyMODINIT_FUNC initperf_trace_context(void); 76 - #else 77 61 #define _PyUnicode_FromString(arg) \ 78 62 PyUnicode_FromString(arg) 79 63 #define _PyUnicode_FromStringAndSize(arg1, arg2) \ ··· 72 88 PyCapsule_New((arg1), (arg2), (arg3)) 73 89 74 90 PyMODINIT_FUNC PyInit_perf_trace_context(void); 75 - #endif 76 91 77 92 #ifdef HAVE_LIBTRACEEVENT 78 93 #define TRACE_EVENT_TYPE_MAX \ ··· 164 181 { 165 182 int arg_count = 0; 166 183 167 - /* 168 - * The attribute for the code object is func_code in Python 2, 169 - * whereas it is __code__ in Python 3.0+. 170 - */ 171 - PyObject *code_obj = PyObject_GetAttrString(handler, 172 - "func_code"); 173 - if (PyErr_Occurred()) { 174 - PyErr_Clear(); 175 - code_obj = PyObject_GetAttrString(handler, 176 - "__code__"); 177 - } 184 + PyObject *code_obj = code_obj = PyObject_GetAttrString(handler, "__code__"); 178 185 PyErr_Clear(); 179 186 if (code_obj) { 180 187 PyObject *arg_count_obj = PyObject_GetAttrString(code_obj, ··· 1876 1903 tables->synth_handler = get_handler("synth_data"); 1877 1904 } 1878 1905 1879 - #if PY_MAJOR_VERSION < 3 1880 - static void _free_command_line(const char **command_line, int num) 1881 - { 1882 - free(command_line); 1883 - } 1884 - #else 1885 1906 static void _free_command_line(wchar_t **command_line, int num) 1886 1907 { 1887 1908 int i; ··· 1883 1916 PyMem_RawFree(command_line[i]); 1884 1917 free(command_line); 1885 1918 } 1886 - #endif 1887 1919 1888 1920 1889 1921 /* ··· 1892 1926 struct perf_session *session) 1893 1927 { 1894 1928 struct tables *tables = &tables_global; 1895 - #if PY_MAJOR_VERSION < 3 1896 - const char **command_line; 1897 - #else 1898 1929 wchar_t **command_line; 1899 - #endif 1900 - /* 1901 - * Use a non-const name variable to cope with python 2.6's 1902 - * PyImport_AppendInittab prototype 1903 - */ 1904 - char buf[PATH_MAX], name[19] = "perf_trace_context"; 1930 + char buf[PATH_MAX]; 1905 1931 int i, err = 0; 1906 1932 FILE *fp; 1907 1933 1908 1934 scripting_context->session = session; 1909 - #if PY_MAJOR_VERSION < 3 1910 - command_line = malloc((argc + 1) * sizeof(const char *)); 1911 - if (!command_line) 1912 - return -1; 1913 - 1914 - command_line[0] = script; 1915 - for (i = 1; i < argc + 1; i++) 1916 - command_line[i] = argv[i - 1]; 1917 - PyImport_AppendInittab(name, initperf_trace_context); 1918 - #else 1919 1935 command_line = malloc((argc + 1) * sizeof(wchar_t *)); 1920 1936 if (!command_line) 1921 1937 return -1; ··· 1905 1957 command_line[0] = Py_DecodeLocale(script, NULL); 1906 1958 for (i = 1; i < argc + 1; i++) 1907 1959 command_line[i] = Py_DecodeLocale(argv[i - 1], NULL); 1908 - PyImport_AppendInittab(name, PyInit_perf_trace_context); 1909 - #endif 1960 + PyImport_AppendInittab("perf_trace_context", PyInit_perf_trace_context); 1910 1961 Py_Initialize(); 1911 1962 1912 - #if PY_MAJOR_VERSION < 3 1913 - PySys_SetArgv(argc + 1, (char **)command_line); 1914 - #else 1915 1963 PySys_SetArgv(argc + 1, command_line); 1916 - #endif 1917 1964 1918 1965 fp = fopen(script, "r"); 1919 1966 if (!fp) {