Python module cleanup
Ian Rogers
reviewercover Python module cleanup
Remove workarounds for Python 2 module support. Constify variables and parameters to functions.
Ian Rogers (2):
perf python: Remove python 2 scripting support
perf python: Constify variables and parameters
.../scripts/python/Perf-Trace-Util/Context.c | 18 --- tools/perf/util/python.c | 128 ++++++------------ .../scripting-engines/trace-event-python.c | 63 +-------- 3 files changed, 44 insertions(+), 165 deletions(-)
Signature · 1 line
2.46.0.662.g92d0881bb0-goog
Ian Rogers
reviewerPATCH 1/2 perf python: Remove python 2 scripting support
Python2 was deprecated 4 years ago, remove support and workarounds.
--- .../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(-)
tools/perf/scripts/python/Perf-Trace-Util/Context.c +0 -18
@@ -23,16 +23,6 @@#include "../../../util/srcline.h" #include "../../../util/srccode.h" -#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) \
@@ -41,7 +31,6 @@ PyMODINIT_FUNC initperf_trace_context(void);PyUnicode_AsUTF8 (arg) PyMODINIT_FUNC PyInit_perf_trace_context(void); -#endif static struct scripting_context *get_args (PyObject *args,const char *name,PyObject **arg2) {
@@ -202,12 +191,6 @@ static PyMethodDef ContextMethods[] = { { NULL, NULL, 0, NULL} }; -#if PY_MAJOR_VERSION < 3 -PyMODINIT_FUNC initperf_trace_context(void) -{ - (void) Py_InitModule("perf_trace_context", ContextMethods); -} -#elsePyMODINIT_FUNC PyInit_perf_trace_context (void ) {static struct PyModuleDef moduledef = {
@@ -229,4 +212,3 @@ PyMODINIT_FUNC PyInit_perf_trace_context(void)return mod; } -#endif
tools/perf/util/python.c +12 -61
193 lines not on this page · raw message
tools/perf/util/scripting-engines/trace-event-python.c +3 -60
113 lines not on this page · raw message
Signature · 1 line
2.46.0.662.g92d0881bb0-goog
Re: [PATCH v1 1/2] perf python: Remove python 2 scripting support
Quoted 1 line · Ian Rogers
Python2 was deprecated 4 years ago, remove support and workarounds.
Nacked-by: Andi Kleen
I don't see any advantages of breaking perfectly fine existing setups for no benefits.
-Andi
Ian Rogers
reviewerRe: [PATCH v1 1/2] perf python: Remove python 2 scripting support
Quoted 8 lines · Andi Kleen
Quoted 1 line · Ian Rogers
Python2 was deprecated 4 years ago, remove support and workarounds.
Nacked-by: Andi Kleen
I don't see any advantages of breaking perfectly fine existing setups for no benefits.
The reason is that since moving to linking libraries rather than building code we now have the ability to call functions like parse_events - previously parse_events was stubbed out because there was no way to build lex/yacc code. Calling parse_events is more sensible than existing logic that does things like open a legacy cycles event only on 1 PMU type. That is, the existing code doesn't support hybrid. Practically there is no way to test python2 support builds and works without having python2. We shouldn't be in the business of installing python2 in 2024, my organization has removed all support for over 3 years.
Thanks,
Ian
Namhyung Kim
maintainerRe: [PATCH v1 1/2] perf python: Remove python 2 scripting support
Quoted 9 lines · Ian Rogers
Quoted 8 lines · Andi Kleen
Quoted 1 line · Ian Rogers
Python2 was deprecated 4 years ago, remove support and workarounds.
Nacked-by: Andi Kleen
I don't see any advantages of breaking perfectly fine existing setups for no benefits.
Well, I think the benefit is in the maintenance. The EOL of Python 2 was 2020/1/1 [1] and we are targeting this release (v6.13) in 2025. So I think it's reasonable to consider removing Python 2 support now.
Quoted 11 lines
The reason is that since moving to linking libraries rather than building code we now have the ability to call functions like
parse_events- previouslyparse_eventswas stubbed out because there was no way to build lex/yacc code. Callingparse_eventsis more sensible than existing logic that does things like open a legacy cycles event only on 1 PMU type. That is, the existing code doesn't support hybrid. Practically there is no way to test python2 support builds and works without having python2. We shouldn't be in the business of installing python2 in 2024, my organization has removed all support for over 3 years.
I think the problem nowdays is the container images for old distro. I'm not sure how long we need to support them but it should be cut out at some point.
Thanks,
Namhyung
Re: [PATCH v1 1/2] perf python: Remove python 2 scripting support
Quoted 6 lines · Namhyung Kim
Quoted 5 lines · Ian Rogers
Quoted 4 lines · Andi Kleen
Quoted 1 line · Ian Rogers
Python2 was deprecated 4 years ago, remove support and workarounds.
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Nacked-by: Andi Kleen
I don't see any advantages of breaking perfectly fine existing setups for no benefits.
Well, I think the benefit is in the maintenance. The EOL of Python 2 was 2020/1/1 [1] and we are targeting this release (v6.13) in 2025. So
AFAIK it's still widely used, and supported by third parties. And even if not it's not that the python usage in perf needs any external support.
In Linux deprecation is generally tied to nobody using something anymore, and that is clearly not the case here.
Quoted 1 line
I think it's reasonable to consider removing Python 2 support now.
That's code that practically never changes, so I don't see any maintenance benefit. I mean it needs to be compile tested / perf tested, but Arnaldo's container collection will do that practically for free.
-Andi
James Clark
reviewerRe: [PATCH v1 1/2] perf python: Remove python 2 scripting support
Quoted 21 lines · Andi Kleen
Quoted 6 lines · Namhyung Kim
Quoted 5 lines · Ian Rogers
Quoted 4 lines · Andi Kleen
Quoted 1 line · Ian Rogers
Python2 was deprecated 4 years ago, remove support and workarounds.
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Nacked-by: Andi Kleen
I don't see any advantages of breaking perfectly fine existing setups for no benefits.
Well, I think the benefit is in the maintenance. The EOL of Python 2 was 2020/1/1 [1] and we are targeting this release (v6.13) in 2025. So
AFAIK it's still widely used, and supported by third parties. And even if not it's not that the python usage in perf needs any external support.
In Linux deprecation is generally tied to nobody using something anymore, and that is clearly not the case here.
Quoted 9 lines
Quoted 1 line
I think it's reasonable to consider removing Python 2 support now.
That's code that practically never changes, so I don't see any maintenance benefit. I mean it needs to be compile tested / perf tested, but Arnaldo's container collection will do that practically for free.
-Andi
630af16 was quite painful to do and was related to supporting both python versions, so there is some ongoing cost. If we do this removal we could remove that one too. Plus Arnaldo could drop the python2 containers and get a faster iteration time.
I think I'm neutral to in favor of removing python2 support. People on ancient systems would more likely be using an old branch anyway.
James
Ian Rogers
reviewerRe: [PATCH v1 1/2] perf python: Remove python 2 scripting support
In reply to Andi KleenQuoted 22 lines · Andi Kleen
Quoted 6 lines · Namhyung Kim
Quoted 5 lines · Ian Rogers
Quoted 4 lines · Andi Kleen
Quoted 1 line · Ian Rogers
Python2 was deprecated 4 years ago, remove support and workarounds.
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Nacked-by: Andi Kleen
I don't see any advantages of breaking perfectly fine existing setups for no benefits.
Well, I think the benefit is in the maintenance. The EOL of Python 2 was 2020/1/1 [1] and we are targeting this release (v6.13) in 2025. So
AFAIK it's still widely used, and supported by third parties. And even if not it's not that the python usage in perf needs any external support.
In Linux deprecation is generally tied to nobody using something anymore, and that is clearly not the case here.
Quoted 6 lines
Quoted 1 line
I think it's reasonable to consider removing Python 2 support now.
That's code that practically never changes, so I don't see any maintenance benefit. I mean it needs to be compile tested / perf tested, but Arnaldo's container collection will do that practically for free.
So of the Linux distributions that supported Python 2, the versions that did stopped being supported in June this year.
The hypothetical person who cares about python 2 support needs to be building their own kernel tree, they've had to upgrade GCC, etc. but GCC isn't particularly relevant here.
The hypothetical person wants to build on their unsupported distribution the latest and greatest perf tool. Now the perf build has required python 3.6 for json events for 2.5 years. So this hypothetical person who wants the latest perf tool on their unsupported system must not care about json events and metrics but does care about python 2 integration for scripting.
I really don't see such a person existing and if they did they can:
1) install python3
2) use an older perf tool
There is a constant cost in the code base trying to know whether python means 2 or 3. Keeping dead code around at the very least creates poor code coverage numbers. We want to add to the python entry points into the code with parse_events. We want to make python a dlopen dependency (as done in uftrace) rather than something that's linked against. In other words python development is somewhat active and trying to carry around python 2 support when no one we can name wants it is just burdening us down, costing us in time and code coverage for no gain.
Thanks,
Ian
Namhyung Kim
maintainerRe: [PATCH v1 1/2] perf python: Remove python 2 scripting support
Quoted 45 lines · Ian Rogers
Quoted 22 lines · Andi Kleen
Quoted 6 lines · Namhyung Kim
Quoted 5 lines · Ian Rogers
Quoted 4 lines · Andi Kleen
Quoted 1 line · Ian Rogers
Python2 was deprecated 4 years ago, remove support and workarounds.
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Nacked-by: Andi Kleen
I don't see any advantages of breaking perfectly fine existing setups for no benefits.
Well, I think the benefit is in the maintenance. The EOL of Python 2 was 2020/1/1 [1] and we are targeting this release (v6.13) in 2025. So
AFAIK it's still widely used, and supported by third parties. And even if not it's not that the python usage in perf needs any external support.
In Linux deprecation is generally tied to nobody using something anymore, and that is clearly not the case here.
Quoted 6 lines
Quoted 1 line
I think it's reasonable to consider removing Python 2 support now.
That's code that practically never changes, so I don't see any maintenance benefit. I mean it needs to be compile tested / perf tested, but Arnaldo's container collection will do that practically for free.
So of the Linux distributions that supported Python 2, the versions that did stopped being supported in June this year.
The hypothetical person who cares about python 2 support needs to be building their own kernel tree, they've had to upgrade GCC, etc. but GCC isn't particularly relevant here.
The hypothetical person wants to build on their unsupported distribution the latest and greatest perf tool. Now the perf build has required python 3.6 for json events for 2.5 years. So this hypothetical person who wants the latest perf tool on their unsupported system must not care about json events and metrics but does care about python 2 integration for scripting.
I really don't see such a person existing and if they did they can:
1) install python3
2) use an older perf tool
Quoted 9 lines
There is a constant cost in the code base trying to know whether python means 2 or 3. Keeping dead code around at the very least creates poor code coverage numbers. We want to add to the python entry points into the code with
parse_events. We want to make python a dlopen dependency (as done in uftrace) rather than something that's linked against. In other words python development is somewhat active and trying to carry around python 2 support when no one we can name wants it is just burdening us down, costing us in time and code coverage for no gain.
Yeah I think it's time to consider sunsetting Python 2. As Ian and James said, it was bothering some development.
Andi, do you still use it with Python 2? Or do you know anybody who might suffer from this change? Is it hard to upgrade the system?
I'm inclined to pick up this change unless there's a specific reason.
Thanks,
Namhyung
James Clark
reviewerRe: [PATCH v1 1/2] perf python: Remove python 2 scripting support
In reply to Ian RogersQuoted 15 lines · Ian Rogers
Python2 was deprecated 4 years ago, remove support and workarounds.
Signed-off-by Ian Rogers <[email protected]>--- .../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(-)tools/perf/scripts/python/Perf-Trace-Util/Context.c +0
-0@@ -23,16 +23,6 @@#include "../../../util/srcline.h"
tools/perf/scripts/python/Perf-Trace-Util/Context.c line 33
Quoted 10 lines
tools/perf/scripts/python/Perf-Trace-Util/Context.c +0
-8#include "../../../util/srccode.h" -#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) -
If we know the workarounds were required should we add an error to prevent hard to debug build issues?
#if PY_MAJOR_VERSION < 3
#error "Python 2 not supported"
#endifOr maybe something in the top level makefile?
Ian Rogers
reviewerPATCH 2/2 perf python: Constify variables and parameters
In reply to Ian RogersOpportunistically constify variables and parameters when possible.
--- tools/perf/util/python.c | 55 +++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 26 deletions(-)
tools/perf/util/python.c +29 -26
@@ -62,7 +62,7 @@ struct pyrf_event {sample_member_def (sample_period, period,T_ULONGLONG ,"event period" ), \sample_member_def (sample_cpu, cpu,T_UINT ,"event cpu" ), -static char pyrf_mmap_event__doc[] = PyDoc_STR("perf mmap event object."); +static const char pyrf_mmap_event__doc[] = PyDoc_STR("perf mmap event object.");static PyMemberDef pyrf_mmap_event__members[] = { sample_members
@@ -77,7 +77,7 @@ static PyMemberDef pyrf_mmap_event__members[] = { { .name = NULL, }, }; -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;
@@ -106,7 +106,7 @@ static PyTypeObject pyrf_mmap_event__type = { .tp_repr = (reprfunc)pyrf_mmap_event__repr, }; -static char pyrf_task_event__doc[] =PyDoc_STR ("perf task (fork/exit) event object." ); +static const char pyrf_task_event__doc[] =PyDoc_STR ("perf task (fork/exit) event object." );static PyMemberDef pyrf_task_event__members[] = { sample_members
@@ -119,7 +119,7 @@ static PyMemberDef pyrf_task_event__members[] = { { .name = NULL, }, }; -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 "}",
@@ -141,7 +141,7 @@ static PyTypeObject pyrf_task_event__type = { .tp_repr = (reprfunc)pyrf_task_event__repr, }; -static char pyrf_comm_event__doc[] =PyDoc_STR ("perf comm event object." ); +static const char pyrf_comm_event__doc[] =PyDoc_STR ("perf comm event object." );static PyMemberDef pyrf_comm_event__members[] = { sample_members
@@ -152,7 +152,7 @@ static PyMemberDef pyrf_comm_event__members[] = { { .name = NULL, }, }; -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,
@@ -170,7 +170,7 @@ static PyTypeObject pyrf_comm_event__type = { .tp_repr = (reprfunc)pyrf_comm_event__repr, }; -static char pyrf_throttle_event__doc[] =PyDoc_STR ("perf throttle event object." ); +static const char pyrf_throttle_event__doc[] =PyDoc_STR ("perf throttle event object." );static PyMemberDef pyrf_throttle_event__members[] = { sample_members
@@ -181,9 +181,10 @@ static PyMemberDef pyrf_throttle_event__members[] = { { .name = NULL, }, }; -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 = (struct perf_record_throttle *)(&pevent->event.header +1 ); +const struct perf_record_throttle *te = (const struct perf_record_throttle *) + (&pevent->event.header +1 ); return PyUnicode_FromFormat("{ type: %sthrottle, time: %" PRI_lu64 ", id: %" PRI_lu64 ", stream_id: %" PRI_lu64 " }",
@@ -201,7 +202,7 @@ static PyTypeObject pyrf_throttle_event__type = { .tp_repr = (reprfunc)pyrf_throttle_event__repr, }; -static char pyrf_lost_event__doc[] =PyDoc_STR ("perf lost event object." ); +static const char pyrf_lost_event__doc[] =PyDoc_STR ("perf lost event object." );static PyMemberDef pyrf_lost_event__members[] = { sample_members
@@ -210,7 +211,7 @@ static PyMemberDef pyrf_lost_event__members[] = { { .name = NULL, }, }; -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;
@@ -236,7 +237,7 @@ static PyTypeObject pyrf_lost_event__type = { .tp_repr = (reprfunc)pyrf_lost_event__repr, }; -static char pyrf_read_event__doc[] =PyDoc_STR ("perf read event object." ); +static const char pyrf_read_event__doc[] =PyDoc_STR ("perf read event object." );static PyMemberDef pyrf_read_event__members[] = { sample_members
@@ -245,7 +246,7 @@ static PyMemberDef pyrf_read_event__members[] = { { .name = NULL, }, }; -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,
@@ -266,7 +267,7 @@ static PyTypeObject pyrf_read_event__type = { .tp_repr = (reprfunc)pyrf_read_event__repr, }; -static char pyrf_sample_event__doc[] =PyDoc_STR ("perf sample event object." ); +static const char pyrf_sample_event__doc[] =PyDoc_STR ("perf sample event object." );static PyMemberDef pyrf_sample_event__members[] = { sample_members
@@ -274,7 +275,7 @@ static PyMemberDef pyrf_sample_event__members[] = { { .name = NULL, }, }; -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;
@@ -289,13 +290,13 @@ static PyObject *pyrf_sample_event__repr(struct pyrf_event *pevent) }#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 ==PERF_TYPE_TRACEPOINT ; }static PyObject * -tracepoint_field (struct pyrf_event *pe,struct tep_format_field *field) +tracepoint_field (const struct pyrf_event *pe,struct tep_format_field *field) {struct tep_handle *pevent = field->event->tep;void *data = pe->sample.raw_data;
@@ -384,7 +385,7 @@ static PyTypeObject pyrf_sample_event__type = { .tp_getattro = (getattrofunc) pyrf_sample_event__getattro, }; -static char pyrf_context_switch_event__doc[] =PyDoc_STR ("perf context_switch event object." ); +static const char pyrf_context_switch_event__doc[] =PyDoc_STR ("perf context_switch event object." );static PyMemberDef pyrf_context_switch_event__members[] = { sample_members
@@ -394,7 +395,7 @@ static PyMemberDef pyrf_context_switch_event__members[] = { { .name = NULL, }, }; -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;
@@ -474,7 +475,7 @@ static PyTypeObject *pyrf_event__type[] = { [PERF_RECORD_SWITCH_CPU_WIDE] = &pyrf_context_switch_event__type, }; -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;
@@ -542,7 +543,7 @@ static PySequenceMethods pyrf_cpu_map__sequence_methods = { .sq_item = pyrf_cpu_map__item, }; -static char pyrf_cpu_map__doc[] =PyDoc_STR ("cpu map object." ); +static const char pyrf_cpu_map__doc[] =PyDoc_STR ("cpu map object." );static PyTypeObject pyrf_cpu_map__type = {PyVarObject_HEAD_INIT (NULL ,0 )
@@ -611,7 +612,7 @@ static PySequenceMethods pyrf_thread_map__sequence_methods = { .sq_item = pyrf_thread_map__item, }; -static char pyrf_thread_map__doc[] =PyDoc_STR ("thread map object." ); +static const char pyrf_thread_map__doc[] =PyDoc_STR ("thread map object." );static PyTypeObject pyrf_thread_map__type = {PyVarObject_HEAD_INIT (NULL ,0 )
@@ -795,7 +796,7 @@ static PyMethodDef pyrf_evsel__methods[] = { { .ml_name = NULL, } }; -static char pyrf_evsel__doc[] =PyDoc_STR ("perf event selector list object." ); +static const char pyrf_evsel__doc[] =PyDoc_STR ("perf event selector list object." );static PyTypeObject pyrf_evsel__type = {PyVarObject_HEAD_INIT (NULL ,0 )
@@ -1078,7 +1079,7 @@ static PySequenceMethods pyrf_evlist__sequence_methods = { .sq_item = pyrf_evlist__item, }; -static char pyrf_evlist__doc[] =PyDoc_STR ("perf event selector list object." ); +static const char pyrf_evlist__doc[] =PyDoc_STR ("perf event selector list object." );static PyTypeObject pyrf_evlist__type = {PyVarObject_HEAD_INIT (NULL ,0 )
@@ -1100,10 +1101,12 @@ static int pyrf_evlist__setup_types(void)#define PERF_CONST (name) { #name, PERF_##name } -static struct { +struct perf_constant {const char *name;int value; -} perf__constants[] = { +}; + +static const struct perf_constant perf__constants[] = {PERF_CONST (TYPE_HARDWARE ),PERF_CONST (TYPE_SOFTWARE ),PERF_CONST (TYPE_TRACEPOINT ),
Signature · 1 line
2.46.0.662.g92d0881bb0-goog
Re: [PATCH v1 2/2] perf python: Constify variables and parameters
Quoted 3 lines · Ian Rogers
Opportunistically constify variables and parameters when possible.
Signed-off-by Ian Rogers <[email protected]>
Quoted 232 lines
--- tools/perf/util/python.c | 55 +++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 26 deletions(-)tools/perf/util/python.c +29
-26@@ -62,7 +62,7 @@ struct pyrf_event {sample_member_def (sample_period, period,T_ULONGLONG ,"event period" ), \sample_member_def (sample_cpu, cpu,T_UINT ,"event cpu" ), -static char pyrf_mmap_event__doc[] = PyDoc_STR("perf mmap event object."); +static const char pyrf_mmap_event__doc[] = PyDoc_STR("perf mmap event object.");static PyMemberDef pyrf_mmap_event__members[] = { sample_members@@ -77,7 +77,7 @@ static PyMemberDef pyrf_mmap_event__members[] = { { .name = NULL, }, }; -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;@@ -106,7 +106,7 @@ static PyTypeObject pyrf_mmap_event__type = { .tp_repr = (reprfunc)pyrf_mmap_event__repr, }; -static char pyrf_task_event__doc[] =PyDoc_STR ("perf task (fork/exit) event object." ); +static const char pyrf_task_event__doc[] =PyDoc_STR ("perf task (fork/exit) event object." );static PyMemberDef pyrf_task_event__members[] = { sample_members@@ -119,7 +119,7 @@ static PyMemberDef pyrf_task_event__members[] = { { .name = NULL, }, }; -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 "}",@@ -141,7 +141,7 @@ static PyTypeObject pyrf_task_event__type = { .tp_repr = (reprfunc)pyrf_task_event__repr, }; -static char pyrf_comm_event__doc[] =PyDoc_STR ("perf comm event object." ); +static const char pyrf_comm_event__doc[] =PyDoc_STR ("perf comm event object." );static PyMemberDef pyrf_comm_event__members[] = { sample_members@@ -152,7 +152,7 @@ static PyMemberDef pyrf_comm_event__members[] = { { .name = NULL, }, }; -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,@@ -170,7 +170,7 @@ static PyTypeObject pyrf_comm_event__type = { .tp_repr = (reprfunc)pyrf_comm_event__repr, }; -static char pyrf_throttle_event__doc[] =PyDoc_STR ("perf throttle event object." ); +static const char pyrf_throttle_event__doc[] =PyDoc_STR ("perf throttle event object." );static PyMemberDef pyrf_throttle_event__members[] = { sample_members@@ -181,9 +181,10 @@ static PyMemberDef pyrf_throttle_event__members[] = { { .name = NULL, }, }; -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 = (struct perf_record_throttle *)(&pevent->event.header +1 ); +const struct perf_record_throttle *te = (const struct perf_record_throttle *) + (&pevent->event.header +1 ); return PyUnicode_FromFormat("{ type: %sthrottle, time: %" PRI_lu64 ", id: %" PRI_lu64 ", stream_id: %" PRI_lu64 " }",@@ -201,7 +202,7 @@ static PyTypeObject pyrf_throttle_event__type = { .tp_repr = (reprfunc)pyrf_throttle_event__repr, }; -static char pyrf_lost_event__doc[] =PyDoc_STR ("perf lost event object." ); +static const char pyrf_lost_event__doc[] =PyDoc_STR ("perf lost event object." );static PyMemberDef pyrf_lost_event__members[] = { sample_members@@ -210,7 +211,7 @@ static PyMemberDef pyrf_lost_event__members[] = { { .name = NULL, }, }; -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;@@ -236,7 +237,7 @@ static PyTypeObject pyrf_lost_event__type = { .tp_repr = (reprfunc)pyrf_lost_event__repr, }; -static char pyrf_read_event__doc[] =PyDoc_STR ("perf read event object." ); +static const char pyrf_read_event__doc[] =PyDoc_STR ("perf read event object." );static PyMemberDef pyrf_read_event__members[] = { sample_members@@ -245,7 +246,7 @@ static PyMemberDef pyrf_read_event__members[] = { { .name = NULL, }, }; -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,@@ -266,7 +267,7 @@ static PyTypeObject pyrf_read_event__type = { .tp_repr = (reprfunc)pyrf_read_event__repr, }; -static char pyrf_sample_event__doc[] =PyDoc_STR ("perf sample event object." ); +static const char pyrf_sample_event__doc[] =PyDoc_STR ("perf sample event object." );static PyMemberDef pyrf_sample_event__members[] = { sample_members@@ -274,7 +275,7 @@ static PyMemberDef pyrf_sample_event__members[] = { { .name = NULL, }, }; -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;@@ -289,13 +290,13 @@ static PyObject *pyrf_sample_event__repr(struct pyrf_event *pevent) }#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 ==PERF_TYPE_TRACEPOINT ; }static PyObject * -tracepoint_field (struct pyrf_event *pe,struct tep_format_field *field) +tracepoint_field (const struct pyrf_event *pe,struct tep_format_field *field) {struct tep_handle *pevent = field->event->tep;void *data = pe->sample.raw_data;@@ -384,7 +385,7 @@ static PyTypeObject pyrf_sample_event__type = { .tp_getattro = (getattrofunc) pyrf_sample_event__getattro, }; -static char pyrf_context_switch_event__doc[] =PyDoc_STR ("perf context_switch event object." ); +static const char pyrf_context_switch_event__doc[] =PyDoc_STR ("perf context_switch event object." );static PyMemberDef pyrf_context_switch_event__members[] = { sample_members@@ -394,7 +395,7 @@ static PyMemberDef pyrf_context_switch_event__members[] = { { .name = NULL, }, }; -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;@@ -474,7 +475,7 @@ static PyTypeObject *pyrf_event__type[] = { [PERF_RECORD_SWITCH_CPU_WIDE] = &pyrf_context_switch_event__type, }; -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;@@ -542,7 +543,7 @@ static PySequenceMethods pyrf_cpu_map__sequence_methods = { .sq_item = pyrf_cpu_map__item, }; -static char pyrf_cpu_map__doc[] =PyDoc_STR ("cpu map object." ); +static const char pyrf_cpu_map__doc[] =PyDoc_STR ("cpu map object." );static PyTypeObject pyrf_cpu_map__type = {PyVarObject_HEAD_INIT (NULL ,0 )@@ -611,7 +612,7 @@ static PySequenceMethods pyrf_thread_map__sequence_methods = { .sq_item = pyrf_thread_map__item, }; -static char pyrf_thread_map__doc[] =PyDoc_STR ("thread map object." ); +static const char pyrf_thread_map__doc[] =PyDoc_STR ("thread map object." );static PyTypeObject pyrf_thread_map__type = {PyVarObject_HEAD_INIT (NULL ,0 )@@ -795,7 +796,7 @@ static PyMethodDef pyrf_evsel__methods[] = { { .ml_name = NULL, } }; -static char pyrf_evsel__doc[] =PyDoc_STR ("perf event selector list object." ); +static const char pyrf_evsel__doc[] =PyDoc_STR ("perf event selector list object." );static PyTypeObject pyrf_evsel__type = {PyVarObject_HEAD_INIT (NULL ,0 )@@ -1078,7 +1079,7 @@ static PySequenceMethods pyrf_evlist__sequence_methods = { .sq_item = pyrf_evlist__item, }; -static char pyrf_evlist__doc[] =PyDoc_STR ("perf event selector list object." ); +static const char pyrf_evlist__doc[] =PyDoc_STR ("perf event selector list object." );static PyTypeObject pyrf_evlist__type = {PyVarObject_HEAD_INIT (NULL ,0 )@@ -1100,10 +1101,12 @@ static int pyrf_evlist__setup_types(void)#define PERF_CONST (name) { #name, PERF_##name } -static struct { +struct perf_constant {const char *name;int value; -} perf__constants[] = { +}; + +static const struct perf_constant perf__constants[] = {PERF_CONST (TYPE_HARDWARE ),PERF_CONST (TYPE_SOFTWARE ),PERF_CONST (TYPE_TRACEPOINT ),