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: Constify variables and parameters

Opportunistically constify variables and parameters when possible.

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-3-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
b8816289 e7e9943c

+29 -26
+29 -26
tools/perf/util/python.c
··· 63 63 sample_member_def(sample_period, period, T_ULONGLONG, "event period"), \ 64 64 sample_member_def(sample_cpu, cpu, T_UINT, "event cpu"), 65 65 66 - static char pyrf_mmap_event__doc[] = PyDoc_STR("perf mmap event object."); 66 + static const char pyrf_mmap_event__doc[] = PyDoc_STR("perf mmap event object."); 67 67 68 68 static PyMemberDef pyrf_mmap_event__members[] = { 69 69 sample_members ··· 78 78 { .name = NULL, }, 79 79 }; 80 80 81 - static PyObject *pyrf_mmap_event__repr(struct pyrf_event *pevent) 81 + static PyObject *pyrf_mmap_event__repr(const struct pyrf_event *pevent) 82 82 { 83 83 PyObject *ret; 84 84 char *s; ··· 107 107 .tp_repr = (reprfunc)pyrf_mmap_event__repr, 108 108 }; 109 109 110 - static char pyrf_task_event__doc[] = PyDoc_STR("perf task (fork/exit) event object."); 110 + static const char pyrf_task_event__doc[] = PyDoc_STR("perf task (fork/exit) event object."); 111 111 112 112 static PyMemberDef pyrf_task_event__members[] = { 113 113 sample_members ··· 120 120 { .name = NULL, }, 121 121 }; 122 122 123 - static PyObject *pyrf_task_event__repr(struct pyrf_event *pevent) 123 + static PyObject *pyrf_task_event__repr(const struct pyrf_event *pevent) 124 124 { 125 125 return PyUnicode_FromFormat("{ type: %s, pid: %u, ppid: %u, tid: %u, " 126 126 "ptid: %u, time: %" PRI_lu64 "}", ··· 142 142 .tp_repr = (reprfunc)pyrf_task_event__repr, 143 143 }; 144 144 145 - static char pyrf_comm_event__doc[] = PyDoc_STR("perf comm event object."); 145 + static const char pyrf_comm_event__doc[] = PyDoc_STR("perf comm event object."); 146 146 147 147 static PyMemberDef pyrf_comm_event__members[] = { 148 148 sample_members ··· 153 153 { .name = NULL, }, 154 154 }; 155 155 156 - static PyObject *pyrf_comm_event__repr(struct pyrf_event *pevent) 156 + static PyObject *pyrf_comm_event__repr(const struct pyrf_event *pevent) 157 157 { 158 158 return PyUnicode_FromFormat("{ type: comm, pid: %u, tid: %u, comm: %s }", 159 159 pevent->event.comm.pid, ··· 171 171 .tp_repr = (reprfunc)pyrf_comm_event__repr, 172 172 }; 173 173 174 - static char pyrf_throttle_event__doc[] = PyDoc_STR("perf throttle event object."); 174 + static const char pyrf_throttle_event__doc[] = PyDoc_STR("perf throttle event object."); 175 175 176 176 static PyMemberDef pyrf_throttle_event__members[] = { 177 177 sample_members ··· 182 182 { .name = NULL, }, 183 183 }; 184 184 185 - static PyObject *pyrf_throttle_event__repr(struct pyrf_event *pevent) 185 + static PyObject *pyrf_throttle_event__repr(const struct pyrf_event *pevent) 186 186 { 187 - struct perf_record_throttle *te = (struct perf_record_throttle *)(&pevent->event.header + 1); 187 + const struct perf_record_throttle *te = (const struct perf_record_throttle *) 188 + (&pevent->event.header + 1); 188 189 189 190 return PyUnicode_FromFormat("{ type: %sthrottle, time: %" PRI_lu64 ", id: %" PRI_lu64 190 191 ", stream_id: %" PRI_lu64 " }", ··· 203 202 .tp_repr = (reprfunc)pyrf_throttle_event__repr, 204 203 }; 205 204 206 - static char pyrf_lost_event__doc[] = PyDoc_STR("perf lost event object."); 205 + static const char pyrf_lost_event__doc[] = PyDoc_STR("perf lost event object."); 207 206 208 207 static PyMemberDef pyrf_lost_event__members[] = { 209 208 sample_members ··· 212 211 { .name = NULL, }, 213 212 }; 214 213 215 - static PyObject *pyrf_lost_event__repr(struct pyrf_event *pevent) 214 + static PyObject *pyrf_lost_event__repr(const struct pyrf_event *pevent) 216 215 { 217 216 PyObject *ret; 218 217 char *s; ··· 238 237 .tp_repr = (reprfunc)pyrf_lost_event__repr, 239 238 }; 240 239 241 - static char pyrf_read_event__doc[] = PyDoc_STR("perf read event object."); 240 + static const char pyrf_read_event__doc[] = PyDoc_STR("perf read event object."); 242 241 243 242 static PyMemberDef pyrf_read_event__members[] = { 244 243 sample_members ··· 247 246 { .name = NULL, }, 248 247 }; 249 248 250 - static PyObject *pyrf_read_event__repr(struct pyrf_event *pevent) 249 + static PyObject *pyrf_read_event__repr(const struct pyrf_event *pevent) 251 250 { 252 251 return PyUnicode_FromFormat("{ type: read, pid: %u, tid: %u }", 253 252 pevent->event.read.pid, ··· 268 267 .tp_repr = (reprfunc)pyrf_read_event__repr, 269 268 }; 270 269 271 - static char pyrf_sample_event__doc[] = PyDoc_STR("perf sample event object."); 270 + static const char pyrf_sample_event__doc[] = PyDoc_STR("perf sample event object."); 272 271 273 272 static PyMemberDef pyrf_sample_event__members[] = { 274 273 sample_members ··· 276 275 { .name = NULL, }, 277 276 }; 278 277 279 - static PyObject *pyrf_sample_event__repr(struct pyrf_event *pevent) 278 + static PyObject *pyrf_sample_event__repr(const struct pyrf_event *pevent) 280 279 { 281 280 PyObject *ret; 282 281 char *s; ··· 291 290 } 292 291 293 292 #ifdef HAVE_LIBTRACEEVENT 294 - static bool is_tracepoint(struct pyrf_event *pevent) 293 + static bool is_tracepoint(const struct pyrf_event *pevent) 295 294 { 296 295 return pevent->evsel->core.attr.type == PERF_TYPE_TRACEPOINT; 297 296 } 298 297 299 298 static PyObject* 300 - tracepoint_field(struct pyrf_event *pe, struct tep_format_field *field) 299 + tracepoint_field(const struct pyrf_event *pe, struct tep_format_field *field) 301 300 { 302 301 struct tep_handle *pevent = field->event->tep; 303 302 void *data = pe->sample.raw_data; ··· 386 385 .tp_getattro = (getattrofunc) pyrf_sample_event__getattro, 387 386 }; 388 387 389 - static char pyrf_context_switch_event__doc[] = PyDoc_STR("perf context_switch event object."); 388 + static const char pyrf_context_switch_event__doc[] = PyDoc_STR("perf context_switch event object."); 390 389 391 390 static PyMemberDef pyrf_context_switch_event__members[] = { 392 391 sample_members ··· 396 395 { .name = NULL, }, 397 396 }; 398 397 399 - static PyObject *pyrf_context_switch_event__repr(struct pyrf_event *pevent) 398 + static PyObject *pyrf_context_switch_event__repr(const struct pyrf_event *pevent) 400 399 { 401 400 PyObject *ret; 402 401 char *s; ··· 476 475 [PERF_RECORD_SWITCH_CPU_WIDE] = &pyrf_context_switch_event__type, 477 476 }; 478 477 479 - static PyObject *pyrf_event__new(union perf_event *event) 478 + static PyObject *pyrf_event__new(const union perf_event *event) 480 479 { 481 480 struct pyrf_event *pevent; 482 481 PyTypeObject *ptype; ··· 544 543 .sq_item = pyrf_cpu_map__item, 545 544 }; 546 545 547 - static char pyrf_cpu_map__doc[] = PyDoc_STR("cpu map object."); 546 + static const char pyrf_cpu_map__doc[] = PyDoc_STR("cpu map object."); 548 547 549 548 static PyTypeObject pyrf_cpu_map__type = { 550 549 PyVarObject_HEAD_INIT(NULL, 0) ··· 613 612 .sq_item = pyrf_thread_map__item, 614 613 }; 615 614 616 - static char pyrf_thread_map__doc[] = PyDoc_STR("thread map object."); 615 + static const char pyrf_thread_map__doc[] = PyDoc_STR("thread map object."); 617 616 618 617 static PyTypeObject pyrf_thread_map__type = { 619 618 PyVarObject_HEAD_INIT(NULL, 0) ··· 797 796 { .ml_name = NULL, } 798 797 }; 799 798 800 - static char pyrf_evsel__doc[] = PyDoc_STR("perf event selector list object."); 799 + static const char pyrf_evsel__doc[] = PyDoc_STR("perf event selector list object."); 801 800 802 801 static PyTypeObject pyrf_evsel__type = { 803 802 PyVarObject_HEAD_INIT(NULL, 0) ··· 1080 1079 .sq_item = pyrf_evlist__item, 1081 1080 }; 1082 1081 1083 - static char pyrf_evlist__doc[] = PyDoc_STR("perf event selector list object."); 1082 + static const char pyrf_evlist__doc[] = PyDoc_STR("perf event selector list object."); 1084 1083 1085 1084 static PyTypeObject pyrf_evlist__type = { 1086 1085 PyVarObject_HEAD_INIT(NULL, 0) ··· 1102 1101 1103 1102 #define PERF_CONST(name) { #name, PERF_##name } 1104 1103 1105 - static struct { 1104 + struct perf_constant { 1106 1105 const char *name; 1107 1106 int value; 1108 - } perf__constants[] = { 1107 + }; 1108 + 1109 + static const struct perf_constant perf__constants[] = { 1109 1110 PERF_CONST(TYPE_HARDWARE), 1110 1111 PERF_CONST(TYPE_SOFTWARE), 1111 1112 PERF_CONST(TYPE_TRACEPOINT),