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 scripting python: Assign perf_script_context

The scripting_context pointer itself does not change and nor does it need
to. Put it directly into the script as a variable at the start so it does
not have to be passed on each call into the script.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: https://lore.kernel.org/r/20210530192308.7382-6-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Adrian Hunter and committed by
Arnaldo Carvalho de Melo
cf9bfa6c 67e50ce0

+35 -1
+7 -1
tools/perf/scripts/python/Perf-Trace-Util/Context.c
··· 91 91 NULL, /* m_clear */ 92 92 NULL, /* m_free */ 93 93 }; 94 - return PyModule_Create(&moduledef); 94 + PyObject *mod; 95 + 96 + mod = PyModule_Create(&moduledef); 97 + /* Add perf_script_context to the module so it can be imported */ 98 + PyObject_SetAttrString(mod, "perf_script_context", Py_None); 99 + 100 + return mod; 95 101 } 96 102 #endif
+28
tools/perf/util/scripting-engines/trace-event-python.c
··· 1599 1599 Py_DECREF(t); 1600 1600 } 1601 1601 1602 + static int perf_script_context_init(void) 1603 + { 1604 + PyObject *perf_script_context; 1605 + PyObject *perf_trace_context; 1606 + PyObject *dict; 1607 + int ret; 1608 + 1609 + perf_trace_context = PyImport_AddModule("perf_trace_context"); 1610 + if (!perf_trace_context) 1611 + return -1; 1612 + dict = PyModule_GetDict(perf_trace_context); 1613 + if (!dict) 1614 + return -1; 1615 + 1616 + perf_script_context = _PyCapsule_New(scripting_context, NULL, NULL); 1617 + if (!perf_script_context) 1618 + return -1; 1619 + 1620 + ret = PyDict_SetItemString(dict, "perf_script_context", perf_script_context); 1621 + if (!ret) 1622 + ret = PyDict_SetItemString(main_dict, "perf_script_context", perf_script_context); 1623 + Py_DECREF(perf_script_context); 1624 + return ret; 1625 + } 1626 + 1602 1627 static int run_start_sub(void) 1603 1628 { 1604 1629 main_module = PyImport_AddModule("__main__"); ··· 1635 1610 if (main_dict == NULL) 1636 1611 goto error; 1637 1612 Py_INCREF(main_dict); 1613 + 1614 + if (perf_script_context_init()) 1615 + goto error; 1638 1616 1639 1617 try_call_object("trace_begin", NULL); 1640 1618