1 // SPDX-License-Identifier: GPL-2.0
3 #include <structmember.h>
7 #include <perf/cpumap.h>
8 #include <traceevent/event-parse.h>
11 #include "callchain.h"
14 #include "print_binary.h"
15 #include "thread_map.h"
16 #include "trace-event.h"
19 #include "metricgroup.h"
21 #include <internal/lib.h>
24 #if PY_MAJOR_VERSION < 3
25 #define _PyUnicode_FromString(arg) \
26 PyString_FromString(arg)
27 #define _PyUnicode_AsString(arg) \
28 PyString_AsString(arg)
29 #define _PyUnicode_FromFormat(...) \
30 PyString_FromFormat(__VA_ARGS__)
31 #define _PyLong_FromLong(arg) \
36 #define _PyUnicode_FromString(arg) \
37 PyUnicode_FromString(arg)
38 #define _PyUnicode_FromFormat(...) \
39 PyUnicode_FromFormat(__VA_ARGS__)
40 #define _PyLong_FromLong(arg) \
45 #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
49 * Provide these two so that we don't have to link against callchain.c and
50 * start dragging hist.c, etc.
52 struct callchain_param callchain_param
;
54 int parse_callchain_record(const char *arg __maybe_unused
,
55 struct callchain_param
*param __maybe_unused
)
61 * Add this one here not to drag util/env.c
63 struct perf_env perf_env
;
66 * Add this one here not to drag util/stat-shadow.c
68 void perf_stat__collect_metric_expr(struct evlist
*evsel_list
)
73 * Add this one here not to drag util/metricgroup.c
75 int metricgroup__copy_metric_events(struct evlist
*evlist
, struct cgroup
*cgrp
,
76 struct rblist
*new_metric_events
,
77 struct rblist
*old_metric_events
)
83 * Support debug printing even though util/debug.c is not linked. That means
84 * implementing 'verbose' and 'eprintf'.
89 int eprintf(int level
, int var
, const char *fmt
, ...);
91 int eprintf(int level
, int var
, const char *fmt
, ...)
98 ret
= vfprintf(stderr
, fmt
, args
);
105 /* Define PyVarObject_HEAD_INIT for python 2.5 */
106 #ifndef PyVarObject_HEAD_INIT
107 # define PyVarObject_HEAD_INIT(type, size) PyObject_HEAD_INIT(type) size,
110 #if PY_MAJOR_VERSION < 3
111 PyMODINIT_FUNC
initperf(void);
113 PyMODINIT_FUNC
PyInit_perf(void);
116 #define member_def(type, member, ptype, help) \
118 offsetof(struct pyrf_event, event) + offsetof(struct type, member), \
121 #define sample_member_def(name, member, ptype, help) \
123 offsetof(struct pyrf_event, sample) + offsetof(struct perf_sample, member), \
129 struct perf_sample sample
;
130 union perf_event event
;
133 #define sample_members \
134 sample_member_def(sample_ip, ip, T_ULONGLONG, "event type"), \
135 sample_member_def(sample_pid, pid, T_INT, "event pid"), \
136 sample_member_def(sample_tid, tid, T_INT, "event tid"), \
137 sample_member_def(sample_time, time, T_ULONGLONG, "event timestamp"), \
138 sample_member_def(sample_addr, addr, T_ULONGLONG, "event addr"), \
139 sample_member_def(sample_id, id, T_ULONGLONG, "event id"), \
140 sample_member_def(sample_stream_id, stream_id, T_ULONGLONG, "event stream id"), \
141 sample_member_def(sample_period, period, T_ULONGLONG, "event period"), \
142 sample_member_def(sample_cpu, cpu, T_UINT, "event cpu"),
144 static char pyrf_mmap_event__doc
[] = PyDoc_STR("perf mmap event object.");
146 static PyMemberDef pyrf_mmap_event__members
[] = {
148 member_def(perf_event_header
, type
, T_UINT
, "event type"),
149 member_def(perf_event_header
, misc
, T_UINT
, "event misc"),
150 member_def(perf_record_mmap
, pid
, T_UINT
, "event pid"),
151 member_def(perf_record_mmap
, tid
, T_UINT
, "event tid"),
152 member_def(perf_record_mmap
, start
, T_ULONGLONG
, "start of the map"),
153 member_def(perf_record_mmap
, len
, T_ULONGLONG
, "map length"),
154 member_def(perf_record_mmap
, pgoff
, T_ULONGLONG
, "page offset"),
155 member_def(perf_record_mmap
, filename
, T_STRING_INPLACE
, "backing store"),
159 static PyObject
*pyrf_mmap_event__repr(struct pyrf_event
*pevent
)
164 if (asprintf(&s
, "{ type: mmap, pid: %u, tid: %u, start: %#" PRI_lx64
", "
165 "length: %#" PRI_lx64
", offset: %#" PRI_lx64
", "
167 pevent
->event
.mmap
.pid
, pevent
->event
.mmap
.tid
,
168 pevent
->event
.mmap
.start
, pevent
->event
.mmap
.len
,
169 pevent
->event
.mmap
.pgoff
, pevent
->event
.mmap
.filename
) < 0) {
170 ret
= PyErr_NoMemory();
172 ret
= _PyUnicode_FromString(s
);
178 static PyTypeObject pyrf_mmap_event__type
= {
179 PyVarObject_HEAD_INIT(NULL
, 0)
180 .tp_name
= "perf.mmap_event",
181 .tp_basicsize
= sizeof(struct pyrf_event
),
182 .tp_flags
= Py_TPFLAGS_DEFAULT
|Py_TPFLAGS_BASETYPE
,
183 .tp_doc
= pyrf_mmap_event__doc
,
184 .tp_members
= pyrf_mmap_event__members
,
185 .tp_repr
= (reprfunc
)pyrf_mmap_event__repr
,
188 static char pyrf_task_event__doc
[] = PyDoc_STR("perf task (fork/exit) event object.");
190 static PyMemberDef pyrf_task_event__members
[] = {
192 member_def(perf_event_header
, type
, T_UINT
, "event type"),
193 member_def(perf_record_fork
, pid
, T_UINT
, "event pid"),
194 member_def(perf_record_fork
, ppid
, T_UINT
, "event ppid"),
195 member_def(perf_record_fork
, tid
, T_UINT
, "event tid"),
196 member_def(perf_record_fork
, ptid
, T_UINT
, "event ptid"),
197 member_def(perf_record_fork
, time
, T_ULONGLONG
, "timestamp"),
201 static PyObject
*pyrf_task_event__repr(struct pyrf_event
*pevent
)
203 return _PyUnicode_FromFormat("{ type: %s, pid: %u, ppid: %u, tid: %u, "
204 "ptid: %u, time: %" PRI_lu64
"}",
205 pevent
->event
.header
.type
== PERF_RECORD_FORK
? "fork" : "exit",
206 pevent
->event
.fork
.pid
,
207 pevent
->event
.fork
.ppid
,
208 pevent
->event
.fork
.tid
,
209 pevent
->event
.fork
.ptid
,
210 pevent
->event
.fork
.time
);
213 static PyTypeObject pyrf_task_event__type
= {
214 PyVarObject_HEAD_INIT(NULL
, 0)
215 .tp_name
= "perf.task_event",
216 .tp_basicsize
= sizeof(struct pyrf_event
),
217 .tp_flags
= Py_TPFLAGS_DEFAULT
|Py_TPFLAGS_BASETYPE
,
218 .tp_doc
= pyrf_task_event__doc
,
219 .tp_members
= pyrf_task_event__members
,
220 .tp_repr
= (reprfunc
)pyrf_task_event__repr
,
223 static char pyrf_comm_event__doc
[] = PyDoc_STR("perf comm event object.");
225 static PyMemberDef pyrf_comm_event__members
[] = {
227 member_def(perf_event_header
, type
, T_UINT
, "event type"),
228 member_def(perf_record_comm
, pid
, T_UINT
, "event pid"),
229 member_def(perf_record_comm
, tid
, T_UINT
, "event tid"),
230 member_def(perf_record_comm
, comm
, T_STRING_INPLACE
, "process name"),
234 static PyObject
*pyrf_comm_event__repr(struct pyrf_event
*pevent
)
236 return _PyUnicode_FromFormat("{ type: comm, pid: %u, tid: %u, comm: %s }",
237 pevent
->event
.comm
.pid
,
238 pevent
->event
.comm
.tid
,
239 pevent
->event
.comm
.comm
);
242 static PyTypeObject pyrf_comm_event__type
= {
243 PyVarObject_HEAD_INIT(NULL
, 0)
244 .tp_name
= "perf.comm_event",
245 .tp_basicsize
= sizeof(struct pyrf_event
),
246 .tp_flags
= Py_TPFLAGS_DEFAULT
|Py_TPFLAGS_BASETYPE
,
247 .tp_doc
= pyrf_comm_event__doc
,
248 .tp_members
= pyrf_comm_event__members
,
249 .tp_repr
= (reprfunc
)pyrf_comm_event__repr
,
252 static char pyrf_throttle_event__doc
[] = PyDoc_STR("perf throttle event object.");
254 static PyMemberDef pyrf_throttle_event__members
[] = {
256 member_def(perf_event_header
, type
, T_UINT
, "event type"),
257 member_def(perf_record_throttle
, time
, T_ULONGLONG
, "timestamp"),
258 member_def(perf_record_throttle
, id
, T_ULONGLONG
, "event id"),
259 member_def(perf_record_throttle
, stream_id
, T_ULONGLONG
, "event stream id"),
263 static PyObject
*pyrf_throttle_event__repr(struct pyrf_event
*pevent
)
265 struct perf_record_throttle
*te
= (struct perf_record_throttle
*)(&pevent
->event
.header
+ 1);
267 return _PyUnicode_FromFormat("{ type: %sthrottle, time: %" PRI_lu64
", id: %" PRI_lu64
268 ", stream_id: %" PRI_lu64
" }",
269 pevent
->event
.header
.type
== PERF_RECORD_THROTTLE
? "" : "un",
270 te
->time
, te
->id
, te
->stream_id
);
273 static PyTypeObject pyrf_throttle_event__type
= {
274 PyVarObject_HEAD_INIT(NULL
, 0)
275 .tp_name
= "perf.throttle_event",
276 .tp_basicsize
= sizeof(struct pyrf_event
),
277 .tp_flags
= Py_TPFLAGS_DEFAULT
|Py_TPFLAGS_BASETYPE
,
278 .tp_doc
= pyrf_throttle_event__doc
,
279 .tp_members
= pyrf_throttle_event__members
,
280 .tp_repr
= (reprfunc
)pyrf_throttle_event__repr
,
283 static char pyrf_lost_event__doc
[] = PyDoc_STR("perf lost event object.");
285 static PyMemberDef pyrf_lost_event__members
[] = {
287 member_def(perf_record_lost
, id
, T_ULONGLONG
, "event id"),
288 member_def(perf_record_lost
, lost
, T_ULONGLONG
, "number of lost events"),
292 static PyObject
*pyrf_lost_event__repr(struct pyrf_event
*pevent
)
297 if (asprintf(&s
, "{ type: lost, id: %#" PRI_lx64
", "
298 "lost: %#" PRI_lx64
" }",
299 pevent
->event
.lost
.id
, pevent
->event
.lost
.lost
) < 0) {
300 ret
= PyErr_NoMemory();
302 ret
= _PyUnicode_FromString(s
);
308 static PyTypeObject pyrf_lost_event__type
= {
309 PyVarObject_HEAD_INIT(NULL
, 0)
310 .tp_name
= "perf.lost_event",
311 .tp_basicsize
= sizeof(struct pyrf_event
),
312 .tp_flags
= Py_TPFLAGS_DEFAULT
|Py_TPFLAGS_BASETYPE
,
313 .tp_doc
= pyrf_lost_event__doc
,
314 .tp_members
= pyrf_lost_event__members
,
315 .tp_repr
= (reprfunc
)pyrf_lost_event__repr
,
318 static char pyrf_read_event__doc
[] = PyDoc_STR("perf read event object.");
320 static PyMemberDef pyrf_read_event__members
[] = {
322 member_def(perf_record_read
, pid
, T_UINT
, "event pid"),
323 member_def(perf_record_read
, tid
, T_UINT
, "event tid"),
327 static PyObject
*pyrf_read_event__repr(struct pyrf_event
*pevent
)
329 return _PyUnicode_FromFormat("{ type: read, pid: %u, tid: %u }",
330 pevent
->event
.read
.pid
,
331 pevent
->event
.read
.tid
);
333 * FIXME: return the array of read values,
334 * making this method useful ;-)
338 static PyTypeObject pyrf_read_event__type
= {
339 PyVarObject_HEAD_INIT(NULL
, 0)
340 .tp_name
= "perf.read_event",
341 .tp_basicsize
= sizeof(struct pyrf_event
),
342 .tp_flags
= Py_TPFLAGS_DEFAULT
|Py_TPFLAGS_BASETYPE
,
343 .tp_doc
= pyrf_read_event__doc
,
344 .tp_members
= pyrf_read_event__members
,
345 .tp_repr
= (reprfunc
)pyrf_read_event__repr
,
348 static char pyrf_sample_event__doc
[] = PyDoc_STR("perf sample event object.");
350 static PyMemberDef pyrf_sample_event__members
[] = {
352 member_def(perf_event_header
, type
, T_UINT
, "event type"),
356 static PyObject
*pyrf_sample_event__repr(struct pyrf_event
*pevent
)
361 if (asprintf(&s
, "{ type: sample }") < 0) {
362 ret
= PyErr_NoMemory();
364 ret
= _PyUnicode_FromString(s
);
370 static bool is_tracepoint(struct pyrf_event
*pevent
)
372 return pevent
->evsel
->core
.attr
.type
== PERF_TYPE_TRACEPOINT
;
376 tracepoint_field(struct pyrf_event
*pe
, struct tep_format_field
*field
)
378 struct tep_handle
*pevent
= field
->event
->tep
;
379 void *data
= pe
->sample
.raw_data
;
380 PyObject
*ret
= NULL
;
381 unsigned long long val
;
382 unsigned int offset
, len
;
384 if (field
->flags
& TEP_FIELD_IS_ARRAY
) {
385 offset
= field
->offset
;
387 if (field
->flags
& TEP_FIELD_IS_DYNAMIC
) {
388 val
= tep_read_number(pevent
, data
+ offset
, len
);
393 if (field
->flags
& TEP_FIELD_IS_STRING
&&
394 is_printable_array(data
+ offset
, len
)) {
395 ret
= _PyUnicode_FromString((char *)data
+ offset
);
397 ret
= PyByteArray_FromStringAndSize((const char *) data
+ offset
, len
);
398 field
->flags
&= ~TEP_FIELD_IS_STRING
;
401 val
= tep_read_number(pevent
, data
+ field
->offset
,
403 if (field
->flags
& TEP_FIELD_IS_POINTER
)
404 ret
= PyLong_FromUnsignedLong((unsigned long) val
);
405 else if (field
->flags
& TEP_FIELD_IS_SIGNED
)
406 ret
= PyLong_FromLong((long) val
);
408 ret
= PyLong_FromUnsignedLong((unsigned long) val
);
415 get_tracepoint_field(struct pyrf_event
*pevent
, PyObject
*attr_name
)
417 const char *str
= _PyUnicode_AsString(PyObject_Str(attr_name
));
418 struct evsel
*evsel
= pevent
->evsel
;
419 struct tep_format_field
*field
;
421 if (!evsel
->tp_format
) {
422 struct tep_event
*tp_format
;
424 tp_format
= trace_event__tp_format_id(evsel
->core
.attr
.config
);
428 evsel
->tp_format
= tp_format
;
431 field
= tep_find_any_field(evsel
->tp_format
, str
);
435 return tracepoint_field(pevent
, field
);
439 pyrf_sample_event__getattro(struct pyrf_event
*pevent
, PyObject
*attr_name
)
441 PyObject
*obj
= NULL
;
443 if (is_tracepoint(pevent
))
444 obj
= get_tracepoint_field(pevent
, attr_name
);
446 return obj
?: PyObject_GenericGetAttr((PyObject
*) pevent
, attr_name
);
449 static PyTypeObject pyrf_sample_event__type
= {
450 PyVarObject_HEAD_INIT(NULL
, 0)
451 .tp_name
= "perf.sample_event",
452 .tp_basicsize
= sizeof(struct pyrf_event
),
453 .tp_flags
= Py_TPFLAGS_DEFAULT
|Py_TPFLAGS_BASETYPE
,
454 .tp_doc
= pyrf_sample_event__doc
,
455 .tp_members
= pyrf_sample_event__members
,
456 .tp_repr
= (reprfunc
)pyrf_sample_event__repr
,
457 .tp_getattro
= (getattrofunc
) pyrf_sample_event__getattro
,
460 static char pyrf_context_switch_event__doc
[] = PyDoc_STR("perf context_switch event object.");
462 static PyMemberDef pyrf_context_switch_event__members
[] = {
464 member_def(perf_event_header
, type
, T_UINT
, "event type"),
465 member_def(perf_record_switch
, next_prev_pid
, T_UINT
, "next/prev pid"),
466 member_def(perf_record_switch
, next_prev_tid
, T_UINT
, "next/prev tid"),
470 static PyObject
*pyrf_context_switch_event__repr(struct pyrf_event
*pevent
)
475 if (asprintf(&s
, "{ type: context_switch, next_prev_pid: %u, next_prev_tid: %u, switch_out: %u }",
476 pevent
->event
.context_switch
.next_prev_pid
,
477 pevent
->event
.context_switch
.next_prev_tid
,
478 !!(pevent
->event
.header
.misc
& PERF_RECORD_MISC_SWITCH_OUT
)) < 0) {
479 ret
= PyErr_NoMemory();
481 ret
= _PyUnicode_FromString(s
);
487 static PyTypeObject pyrf_context_switch_event__type
= {
488 PyVarObject_HEAD_INIT(NULL
, 0)
489 .tp_name
= "perf.context_switch_event",
490 .tp_basicsize
= sizeof(struct pyrf_event
),
491 .tp_flags
= Py_TPFLAGS_DEFAULT
|Py_TPFLAGS_BASETYPE
,
492 .tp_doc
= pyrf_context_switch_event__doc
,
493 .tp_members
= pyrf_context_switch_event__members
,
494 .tp_repr
= (reprfunc
)pyrf_context_switch_event__repr
,
497 static int pyrf_event__setup_types(void)
500 pyrf_mmap_event__type
.tp_new
=
501 pyrf_task_event__type
.tp_new
=
502 pyrf_comm_event__type
.tp_new
=
503 pyrf_lost_event__type
.tp_new
=
504 pyrf_read_event__type
.tp_new
=
505 pyrf_sample_event__type
.tp_new
=
506 pyrf_context_switch_event__type
.tp_new
=
507 pyrf_throttle_event__type
.tp_new
= PyType_GenericNew
;
508 err
= PyType_Ready(&pyrf_mmap_event__type
);
511 err
= PyType_Ready(&pyrf_lost_event__type
);
514 err
= PyType_Ready(&pyrf_task_event__type
);
517 err
= PyType_Ready(&pyrf_comm_event__type
);
520 err
= PyType_Ready(&pyrf_throttle_event__type
);
523 err
= PyType_Ready(&pyrf_read_event__type
);
526 err
= PyType_Ready(&pyrf_sample_event__type
);
529 err
= PyType_Ready(&pyrf_context_switch_event__type
);
536 static PyTypeObject
*pyrf_event__type
[] = {
537 [PERF_RECORD_MMAP
] = &pyrf_mmap_event__type
,
538 [PERF_RECORD_LOST
] = &pyrf_lost_event__type
,
539 [PERF_RECORD_COMM
] = &pyrf_comm_event__type
,
540 [PERF_RECORD_EXIT
] = &pyrf_task_event__type
,
541 [PERF_RECORD_THROTTLE
] = &pyrf_throttle_event__type
,
542 [PERF_RECORD_UNTHROTTLE
] = &pyrf_throttle_event__type
,
543 [PERF_RECORD_FORK
] = &pyrf_task_event__type
,
544 [PERF_RECORD_READ
] = &pyrf_read_event__type
,
545 [PERF_RECORD_SAMPLE
] = &pyrf_sample_event__type
,
546 [PERF_RECORD_SWITCH
] = &pyrf_context_switch_event__type
,
547 [PERF_RECORD_SWITCH_CPU_WIDE
] = &pyrf_context_switch_event__type
,
550 static PyObject
*pyrf_event__new(union perf_event
*event
)
552 struct pyrf_event
*pevent
;
555 if ((event
->header
.type
< PERF_RECORD_MMAP
||
556 event
->header
.type
> PERF_RECORD_SAMPLE
) &&
557 !(event
->header
.type
== PERF_RECORD_SWITCH
||
558 event
->header
.type
== PERF_RECORD_SWITCH_CPU_WIDE
))
561 ptype
= pyrf_event__type
[event
->header
.type
];
562 pevent
= PyObject_New(struct pyrf_event
, ptype
);
564 memcpy(&pevent
->event
, event
, event
->header
.size
);
565 return (PyObject
*)pevent
;
568 struct pyrf_cpu_map
{
571 struct perf_cpu_map
*cpus
;
574 static int pyrf_cpu_map__init(struct pyrf_cpu_map
*pcpus
,
575 PyObject
*args
, PyObject
*kwargs
)
577 static char *kwlist
[] = { "cpustr", NULL
};
580 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "|s",
584 pcpus
->cpus
= perf_cpu_map__new(cpustr
);
585 if (pcpus
->cpus
== NULL
)
590 static void pyrf_cpu_map__delete(struct pyrf_cpu_map
*pcpus
)
592 perf_cpu_map__put(pcpus
->cpus
);
593 Py_TYPE(pcpus
)->tp_free((PyObject
*)pcpus
);
596 static Py_ssize_t
pyrf_cpu_map__length(PyObject
*obj
)
598 struct pyrf_cpu_map
*pcpus
= (void *)obj
;
600 return pcpus
->cpus
->nr
;
603 static PyObject
*pyrf_cpu_map__item(PyObject
*obj
, Py_ssize_t i
)
605 struct pyrf_cpu_map
*pcpus
= (void *)obj
;
607 if (i
>= pcpus
->cpus
->nr
)
610 return Py_BuildValue("i", pcpus
->cpus
->map
[i
]);
613 static PySequenceMethods pyrf_cpu_map__sequence_methods
= {
614 .sq_length
= pyrf_cpu_map__length
,
615 .sq_item
= pyrf_cpu_map__item
,
618 static char pyrf_cpu_map__doc
[] = PyDoc_STR("cpu map object.");
620 static PyTypeObject pyrf_cpu_map__type
= {
621 PyVarObject_HEAD_INIT(NULL
, 0)
622 .tp_name
= "perf.cpu_map",
623 .tp_basicsize
= sizeof(struct pyrf_cpu_map
),
624 .tp_dealloc
= (destructor
)pyrf_cpu_map__delete
,
625 .tp_flags
= Py_TPFLAGS_DEFAULT
|Py_TPFLAGS_BASETYPE
,
626 .tp_doc
= pyrf_cpu_map__doc
,
627 .tp_as_sequence
= &pyrf_cpu_map__sequence_methods
,
628 .tp_init
= (initproc
)pyrf_cpu_map__init
,
631 static int pyrf_cpu_map__setup_types(void)
633 pyrf_cpu_map__type
.tp_new
= PyType_GenericNew
;
634 return PyType_Ready(&pyrf_cpu_map__type
);
637 struct pyrf_thread_map
{
640 struct perf_thread_map
*threads
;
643 static int pyrf_thread_map__init(struct pyrf_thread_map
*pthreads
,
644 PyObject
*args
, PyObject
*kwargs
)
646 static char *kwlist
[] = { "pid", "tid", "uid", NULL
};
647 int pid
= -1, tid
= -1, uid
= UINT_MAX
;
649 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "|iii",
650 kwlist
, &pid
, &tid
, &uid
))
653 pthreads
->threads
= thread_map__new(pid
, tid
, uid
);
654 if (pthreads
->threads
== NULL
)
659 static void pyrf_thread_map__delete(struct pyrf_thread_map
*pthreads
)
661 perf_thread_map__put(pthreads
->threads
);
662 Py_TYPE(pthreads
)->tp_free((PyObject
*)pthreads
);
665 static Py_ssize_t
pyrf_thread_map__length(PyObject
*obj
)
667 struct pyrf_thread_map
*pthreads
= (void *)obj
;
669 return pthreads
->threads
->nr
;
672 static PyObject
*pyrf_thread_map__item(PyObject
*obj
, Py_ssize_t i
)
674 struct pyrf_thread_map
*pthreads
= (void *)obj
;
676 if (i
>= pthreads
->threads
->nr
)
679 return Py_BuildValue("i", pthreads
->threads
->map
[i
]);
682 static PySequenceMethods pyrf_thread_map__sequence_methods
= {
683 .sq_length
= pyrf_thread_map__length
,
684 .sq_item
= pyrf_thread_map__item
,
687 static char pyrf_thread_map__doc
[] = PyDoc_STR("thread map object.");
689 static PyTypeObject pyrf_thread_map__type
= {
690 PyVarObject_HEAD_INIT(NULL
, 0)
691 .tp_name
= "perf.thread_map",
692 .tp_basicsize
= sizeof(struct pyrf_thread_map
),
693 .tp_dealloc
= (destructor
)pyrf_thread_map__delete
,
694 .tp_flags
= Py_TPFLAGS_DEFAULT
|Py_TPFLAGS_BASETYPE
,
695 .tp_doc
= pyrf_thread_map__doc
,
696 .tp_as_sequence
= &pyrf_thread_map__sequence_methods
,
697 .tp_init
= (initproc
)pyrf_thread_map__init
,
700 static int pyrf_thread_map__setup_types(void)
702 pyrf_thread_map__type
.tp_new
= PyType_GenericNew
;
703 return PyType_Ready(&pyrf_thread_map__type
);
712 static int pyrf_evsel__init(struct pyrf_evsel
*pevsel
,
713 PyObject
*args
, PyObject
*kwargs
)
715 struct perf_event_attr attr
= {
716 .type
= PERF_TYPE_HARDWARE
,
717 .config
= PERF_COUNT_HW_CPU_CYCLES
,
718 .sample_type
= PERF_SAMPLE_PERIOD
| PERF_SAMPLE_TID
,
720 static char *kwlist
[] = {
752 u64 sample_period
= 0;
774 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
,
775 "|iKiKKiiiiiiiiiiiiiiiiiiiiiiKK", kwlist
,
776 &attr
.type
, &attr
.config
, &attr
.sample_freq
,
777 &sample_period
, &attr
.sample_type
,
778 &attr
.read_format
, &disabled
, &inherit
,
779 &pinned
, &exclusive
, &exclude_user
,
780 &exclude_kernel
, &exclude_hv
, &exclude_idle
,
781 &mmap
, &context_switch
, &comm
, &freq
, &inherit_stat
,
782 &enable_on_exec
, &task
, &watermark
,
783 &precise_ip
, &mmap_data
, &sample_id_all
,
784 &attr
.wakeup_events
, &attr
.bp_type
,
785 &attr
.bp_addr
, &attr
.bp_len
, &idx
))
789 if (sample_period
!= 0) {
790 if (attr
.sample_freq
!= 0)
791 return -1; /* FIXME: throw right exception */
792 attr
.sample_period
= sample_period
;
796 attr
.disabled
= disabled
;
797 attr
.inherit
= inherit
;
798 attr
.pinned
= pinned
;
799 attr
.exclusive
= exclusive
;
800 attr
.exclude_user
= exclude_user
;
801 attr
.exclude_kernel
= exclude_kernel
;
802 attr
.exclude_hv
= exclude_hv
;
803 attr
.exclude_idle
= exclude_idle
;
805 attr
.context_switch
= context_switch
;
808 attr
.inherit_stat
= inherit_stat
;
809 attr
.enable_on_exec
= enable_on_exec
;
811 attr
.watermark
= watermark
;
812 attr
.precise_ip
= precise_ip
;
813 attr
.mmap_data
= mmap_data
;
814 attr
.sample_id_all
= sample_id_all
;
815 attr
.size
= sizeof(attr
);
817 evsel__init(&pevsel
->evsel
, &attr
, idx
);
821 static void pyrf_evsel__delete(struct pyrf_evsel
*pevsel
)
823 evsel__exit(&pevsel
->evsel
);
824 Py_TYPE(pevsel
)->tp_free((PyObject
*)pevsel
);
827 static PyObject
*pyrf_evsel__open(struct pyrf_evsel
*pevsel
,
828 PyObject
*args
, PyObject
*kwargs
)
830 struct evsel
*evsel
= &pevsel
->evsel
;
831 struct perf_cpu_map
*cpus
= NULL
;
832 struct perf_thread_map
*threads
= NULL
;
833 PyObject
*pcpus
= NULL
, *pthreads
= NULL
;
834 int group
= 0, inherit
= 0;
835 static char *kwlist
[] = { "cpus", "threads", "group", "inherit", NULL
};
837 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "|OOii", kwlist
,
838 &pcpus
, &pthreads
, &group
, &inherit
))
841 if (pthreads
!= NULL
)
842 threads
= ((struct pyrf_thread_map
*)pthreads
)->threads
;
845 cpus
= ((struct pyrf_cpu_map
*)pcpus
)->cpus
;
847 evsel
->core
.attr
.inherit
= inherit
;
849 * This will group just the fds for this single evsel, to group
850 * multiple events, use evlist.open().
852 if (evsel__open(evsel
, cpus
, threads
) < 0) {
853 PyErr_SetFromErrno(PyExc_OSError
);
861 static PyMethodDef pyrf_evsel__methods
[] = {
864 .ml_meth
= (PyCFunction
)pyrf_evsel__open
,
865 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
,
866 .ml_doc
= PyDoc_STR("open the event selector file descriptor table.")
871 static char pyrf_evsel__doc
[] = PyDoc_STR("perf event selector list object.");
873 static PyTypeObject pyrf_evsel__type
= {
874 PyVarObject_HEAD_INIT(NULL
, 0)
875 .tp_name
= "perf.evsel",
876 .tp_basicsize
= sizeof(struct pyrf_evsel
),
877 .tp_dealloc
= (destructor
)pyrf_evsel__delete
,
878 .tp_flags
= Py_TPFLAGS_DEFAULT
|Py_TPFLAGS_BASETYPE
,
879 .tp_doc
= pyrf_evsel__doc
,
880 .tp_methods
= pyrf_evsel__methods
,
881 .tp_init
= (initproc
)pyrf_evsel__init
,
884 static int pyrf_evsel__setup_types(void)
886 pyrf_evsel__type
.tp_new
= PyType_GenericNew
;
887 return PyType_Ready(&pyrf_evsel__type
);
893 struct evlist evlist
;
896 static int pyrf_evlist__init(struct pyrf_evlist
*pevlist
,
897 PyObject
*args
, PyObject
*kwargs __maybe_unused
)
899 PyObject
*pcpus
= NULL
, *pthreads
= NULL
;
900 struct perf_cpu_map
*cpus
;
901 struct perf_thread_map
*threads
;
903 if (!PyArg_ParseTuple(args
, "OO", &pcpus
, &pthreads
))
906 threads
= ((struct pyrf_thread_map
*)pthreads
)->threads
;
907 cpus
= ((struct pyrf_cpu_map
*)pcpus
)->cpus
;
908 evlist__init(&pevlist
->evlist
, cpus
, threads
);
912 static void pyrf_evlist__delete(struct pyrf_evlist
*pevlist
)
914 evlist__exit(&pevlist
->evlist
);
915 Py_TYPE(pevlist
)->tp_free((PyObject
*)pevlist
);
918 static PyObject
*pyrf_evlist__mmap(struct pyrf_evlist
*pevlist
,
919 PyObject
*args
, PyObject
*kwargs
)
921 struct evlist
*evlist
= &pevlist
->evlist
;
922 static char *kwlist
[] = { "pages", "overwrite", NULL
};
923 int pages
= 128, overwrite
= false;
925 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "|ii", kwlist
,
929 if (evlist__mmap(evlist
, pages
) < 0) {
930 PyErr_SetFromErrno(PyExc_OSError
);
938 static PyObject
*pyrf_evlist__poll(struct pyrf_evlist
*pevlist
,
939 PyObject
*args
, PyObject
*kwargs
)
941 struct evlist
*evlist
= &pevlist
->evlist
;
942 static char *kwlist
[] = { "timeout", NULL
};
945 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "|i", kwlist
, &timeout
))
948 n
= evlist__poll(evlist
, timeout
);
950 PyErr_SetFromErrno(PyExc_OSError
);
954 return Py_BuildValue("i", n
);
957 static PyObject
*pyrf_evlist__get_pollfd(struct pyrf_evlist
*pevlist
,
958 PyObject
*args __maybe_unused
,
959 PyObject
*kwargs __maybe_unused
)
961 struct evlist
*evlist
= &pevlist
->evlist
;
962 PyObject
*list
= PyList_New(0);
965 for (i
= 0; i
< evlist
->core
.pollfd
.nr
; ++i
) {
967 #if PY_MAJOR_VERSION < 3
968 FILE *fp
= fdopen(evlist
->core
.pollfd
.entries
[i
].fd
, "r");
973 file
= PyFile_FromFile(fp
, "perf", "r", NULL
);
975 file
= PyFile_FromFd(evlist
->core
.pollfd
.entries
[i
].fd
, "perf", "r", -1,
976 NULL
, NULL
, NULL
, 0);
981 if (PyList_Append(list
, file
) != 0) {
991 return PyErr_NoMemory();
995 static PyObject
*pyrf_evlist__add(struct pyrf_evlist
*pevlist
,
997 PyObject
*kwargs __maybe_unused
)
999 struct evlist
*evlist
= &pevlist
->evlist
;
1001 struct evsel
*evsel
;
1003 if (!PyArg_ParseTuple(args
, "O", &pevsel
))
1007 evsel
= &((struct pyrf_evsel
*)pevsel
)->evsel
;
1008 evsel
->idx
= evlist
->core
.nr_entries
;
1009 evlist__add(evlist
, evsel
);
1011 return Py_BuildValue("i", evlist
->core
.nr_entries
);
1014 static struct mmap
*get_md(struct evlist
*evlist
, int cpu
)
1018 for (i
= 0; i
< evlist
->core
.nr_mmaps
; i
++) {
1019 struct mmap
*md
= &evlist
->mmap
[i
];
1021 if (md
->core
.cpu
== cpu
)
1028 static PyObject
*pyrf_evlist__read_on_cpu(struct pyrf_evlist
*pevlist
,
1029 PyObject
*args
, PyObject
*kwargs
)
1031 struct evlist
*evlist
= &pevlist
->evlist
;
1032 union perf_event
*event
;
1033 int sample_id_all
= 1, cpu
;
1034 static char *kwlist
[] = { "cpu", "sample_id_all", NULL
};
1038 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "i|i", kwlist
,
1039 &cpu
, &sample_id_all
))
1042 md
= get_md(evlist
, cpu
);
1046 if (perf_mmap__read_init(&md
->core
) < 0)
1049 event
= perf_mmap__read_event(&md
->core
);
1050 if (event
!= NULL
) {
1051 PyObject
*pyevent
= pyrf_event__new(event
);
1052 struct pyrf_event
*pevent
= (struct pyrf_event
*)pyevent
;
1053 struct evsel
*evsel
;
1055 if (pyevent
== NULL
)
1056 return PyErr_NoMemory();
1058 evsel
= evlist__event2evsel(evlist
, event
);
1064 pevent
->evsel
= evsel
;
1066 err
= evsel__parse_sample(evsel
, event
, &pevent
->sample
);
1068 /* Consume the even only after we parsed it out. */
1069 perf_mmap__consume(&md
->core
);
1072 return PyErr_Format(PyExc_OSError
,
1073 "perf: can't parse sample, err=%d", err
);
1081 static PyObject
*pyrf_evlist__open(struct pyrf_evlist
*pevlist
,
1082 PyObject
*args
, PyObject
*kwargs
)
1084 struct evlist
*evlist
= &pevlist
->evlist
;
1086 static char *kwlist
[] = { "group", NULL
};
1088 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "|OOii", kwlist
, &group
))
1092 evlist__set_leader(evlist
);
1094 if (evlist__open(evlist
) < 0) {
1095 PyErr_SetFromErrno(PyExc_OSError
);
1103 static PyMethodDef pyrf_evlist__methods
[] = {
1106 .ml_meth
= (PyCFunction
)pyrf_evlist__mmap
,
1107 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
,
1108 .ml_doc
= PyDoc_STR("mmap the file descriptor table.")
1112 .ml_meth
= (PyCFunction
)pyrf_evlist__open
,
1113 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
,
1114 .ml_doc
= PyDoc_STR("open the file descriptors.")
1118 .ml_meth
= (PyCFunction
)pyrf_evlist__poll
,
1119 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
,
1120 .ml_doc
= PyDoc_STR("poll the file descriptor table.")
1123 .ml_name
= "get_pollfd",
1124 .ml_meth
= (PyCFunction
)pyrf_evlist__get_pollfd
,
1125 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
,
1126 .ml_doc
= PyDoc_STR("get the poll file descriptor table.")
1130 .ml_meth
= (PyCFunction
)pyrf_evlist__add
,
1131 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
,
1132 .ml_doc
= PyDoc_STR("adds an event selector to the list.")
1135 .ml_name
= "read_on_cpu",
1136 .ml_meth
= (PyCFunction
)pyrf_evlist__read_on_cpu
,
1137 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
,
1138 .ml_doc
= PyDoc_STR("reads an event.")
1140 { .ml_name
= NULL
, }
1143 static Py_ssize_t
pyrf_evlist__length(PyObject
*obj
)
1145 struct pyrf_evlist
*pevlist
= (void *)obj
;
1147 return pevlist
->evlist
.core
.nr_entries
;
1150 static PyObject
*pyrf_evlist__item(PyObject
*obj
, Py_ssize_t i
)
1152 struct pyrf_evlist
*pevlist
= (void *)obj
;
1155 if (i
>= pevlist
->evlist
.core
.nr_entries
)
1158 evlist__for_each_entry(&pevlist
->evlist
, pos
) {
1163 return Py_BuildValue("O", container_of(pos
, struct pyrf_evsel
, evsel
));
1166 static PySequenceMethods pyrf_evlist__sequence_methods
= {
1167 .sq_length
= pyrf_evlist__length
,
1168 .sq_item
= pyrf_evlist__item
,
1171 static char pyrf_evlist__doc
[] = PyDoc_STR("perf event selector list object.");
1173 static PyTypeObject pyrf_evlist__type
= {
1174 PyVarObject_HEAD_INIT(NULL
, 0)
1175 .tp_name
= "perf.evlist",
1176 .tp_basicsize
= sizeof(struct pyrf_evlist
),
1177 .tp_dealloc
= (destructor
)pyrf_evlist__delete
,
1178 .tp_flags
= Py_TPFLAGS_DEFAULT
|Py_TPFLAGS_BASETYPE
,
1179 .tp_as_sequence
= &pyrf_evlist__sequence_methods
,
1180 .tp_doc
= pyrf_evlist__doc
,
1181 .tp_methods
= pyrf_evlist__methods
,
1182 .tp_init
= (initproc
)pyrf_evlist__init
,
1185 static int pyrf_evlist__setup_types(void)
1187 pyrf_evlist__type
.tp_new
= PyType_GenericNew
;
1188 return PyType_Ready(&pyrf_evlist__type
);
1191 #define PERF_CONST(name) { #name, PERF_##name }
1196 } perf__constants
[] = {
1197 PERF_CONST(TYPE_HARDWARE
),
1198 PERF_CONST(TYPE_SOFTWARE
),
1199 PERF_CONST(TYPE_TRACEPOINT
),
1200 PERF_CONST(TYPE_HW_CACHE
),
1201 PERF_CONST(TYPE_RAW
),
1202 PERF_CONST(TYPE_BREAKPOINT
),
1204 PERF_CONST(COUNT_HW_CPU_CYCLES
),
1205 PERF_CONST(COUNT_HW_INSTRUCTIONS
),
1206 PERF_CONST(COUNT_HW_CACHE_REFERENCES
),
1207 PERF_CONST(COUNT_HW_CACHE_MISSES
),
1208 PERF_CONST(COUNT_HW_BRANCH_INSTRUCTIONS
),
1209 PERF_CONST(COUNT_HW_BRANCH_MISSES
),
1210 PERF_CONST(COUNT_HW_BUS_CYCLES
),
1211 PERF_CONST(COUNT_HW_CACHE_L1D
),
1212 PERF_CONST(COUNT_HW_CACHE_L1I
),
1213 PERF_CONST(COUNT_HW_CACHE_LL
),
1214 PERF_CONST(COUNT_HW_CACHE_DTLB
),
1215 PERF_CONST(COUNT_HW_CACHE_ITLB
),
1216 PERF_CONST(COUNT_HW_CACHE_BPU
),
1217 PERF_CONST(COUNT_HW_CACHE_OP_READ
),
1218 PERF_CONST(COUNT_HW_CACHE_OP_WRITE
),
1219 PERF_CONST(COUNT_HW_CACHE_OP_PREFETCH
),
1220 PERF_CONST(COUNT_HW_CACHE_RESULT_ACCESS
),
1221 PERF_CONST(COUNT_HW_CACHE_RESULT_MISS
),
1223 PERF_CONST(COUNT_HW_STALLED_CYCLES_FRONTEND
),
1224 PERF_CONST(COUNT_HW_STALLED_CYCLES_BACKEND
),
1226 PERF_CONST(COUNT_SW_CPU_CLOCK
),
1227 PERF_CONST(COUNT_SW_TASK_CLOCK
),
1228 PERF_CONST(COUNT_SW_PAGE_FAULTS
),
1229 PERF_CONST(COUNT_SW_CONTEXT_SWITCHES
),
1230 PERF_CONST(COUNT_SW_CPU_MIGRATIONS
),
1231 PERF_CONST(COUNT_SW_PAGE_FAULTS_MIN
),
1232 PERF_CONST(COUNT_SW_PAGE_FAULTS_MAJ
),
1233 PERF_CONST(COUNT_SW_ALIGNMENT_FAULTS
),
1234 PERF_CONST(COUNT_SW_EMULATION_FAULTS
),
1235 PERF_CONST(COUNT_SW_DUMMY
),
1237 PERF_CONST(SAMPLE_IP
),
1238 PERF_CONST(SAMPLE_TID
),
1239 PERF_CONST(SAMPLE_TIME
),
1240 PERF_CONST(SAMPLE_ADDR
),
1241 PERF_CONST(SAMPLE_READ
),
1242 PERF_CONST(SAMPLE_CALLCHAIN
),
1243 PERF_CONST(SAMPLE_ID
),
1244 PERF_CONST(SAMPLE_CPU
),
1245 PERF_CONST(SAMPLE_PERIOD
),
1246 PERF_CONST(SAMPLE_STREAM_ID
),
1247 PERF_CONST(SAMPLE_RAW
),
1249 PERF_CONST(FORMAT_TOTAL_TIME_ENABLED
),
1250 PERF_CONST(FORMAT_TOTAL_TIME_RUNNING
),
1251 PERF_CONST(FORMAT_ID
),
1252 PERF_CONST(FORMAT_GROUP
),
1254 PERF_CONST(RECORD_MMAP
),
1255 PERF_CONST(RECORD_LOST
),
1256 PERF_CONST(RECORD_COMM
),
1257 PERF_CONST(RECORD_EXIT
),
1258 PERF_CONST(RECORD_THROTTLE
),
1259 PERF_CONST(RECORD_UNTHROTTLE
),
1260 PERF_CONST(RECORD_FORK
),
1261 PERF_CONST(RECORD_READ
),
1262 PERF_CONST(RECORD_SAMPLE
),
1263 PERF_CONST(RECORD_MMAP2
),
1264 PERF_CONST(RECORD_AUX
),
1265 PERF_CONST(RECORD_ITRACE_START
),
1266 PERF_CONST(RECORD_LOST_SAMPLES
),
1267 PERF_CONST(RECORD_SWITCH
),
1268 PERF_CONST(RECORD_SWITCH_CPU_WIDE
),
1270 PERF_CONST(RECORD_MISC_SWITCH_OUT
),
1274 static PyObject
*pyrf__tracepoint(struct pyrf_evsel
*pevsel
,
1275 PyObject
*args
, PyObject
*kwargs
)
1277 struct tep_event
*tp_format
;
1278 static char *kwlist
[] = { "sys", "name", NULL
};
1282 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "|ss", kwlist
,
1286 tp_format
= trace_event__tp_format(sys
, name
);
1287 if (IS_ERR(tp_format
))
1288 return _PyLong_FromLong(-1);
1290 return _PyLong_FromLong(tp_format
->id
);
1293 static PyMethodDef perf__methods
[] = {
1295 .ml_name
= "tracepoint",
1296 .ml_meth
= (PyCFunction
) pyrf__tracepoint
,
1297 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
,
1298 .ml_doc
= PyDoc_STR("Get tracepoint config.")
1300 { .ml_name
= NULL
, }
1303 #if PY_MAJOR_VERSION < 3
1304 PyMODINIT_FUNC
initperf(void)
1306 PyMODINIT_FUNC
PyInit_perf(void)
1312 #if PY_MAJOR_VERSION < 3
1313 PyObject
*module
= Py_InitModule("perf", perf__methods
);
1315 static struct PyModuleDef moduledef
= {
1316 PyModuleDef_HEAD_INIT
,
1317 "perf", /* m_name */
1320 perf__methods
, /* m_methods */
1321 NULL
, /* m_reload */
1322 NULL
, /* m_traverse */
1326 PyObject
*module
= PyModule_Create(&moduledef
);
1329 if (module
== NULL
||
1330 pyrf_event__setup_types() < 0 ||
1331 pyrf_evlist__setup_types() < 0 ||
1332 pyrf_evsel__setup_types() < 0 ||
1333 pyrf_thread_map__setup_types() < 0 ||
1334 pyrf_cpu_map__setup_types() < 0)
1335 #if PY_MAJOR_VERSION < 3
1341 /* The page_size is placed in util object. */
1342 page_size
= sysconf(_SC_PAGE_SIZE
);
1344 Py_INCREF(&pyrf_evlist__type
);
1345 PyModule_AddObject(module
, "evlist", (PyObject
*)&pyrf_evlist__type
);
1347 Py_INCREF(&pyrf_evsel__type
);
1348 PyModule_AddObject(module
, "evsel", (PyObject
*)&pyrf_evsel__type
);
1350 Py_INCREF(&pyrf_mmap_event__type
);
1351 PyModule_AddObject(module
, "mmap_event", (PyObject
*)&pyrf_mmap_event__type
);
1353 Py_INCREF(&pyrf_lost_event__type
);
1354 PyModule_AddObject(module
, "lost_event", (PyObject
*)&pyrf_lost_event__type
);
1356 Py_INCREF(&pyrf_comm_event__type
);
1357 PyModule_AddObject(module
, "comm_event", (PyObject
*)&pyrf_comm_event__type
);
1359 Py_INCREF(&pyrf_task_event__type
);
1360 PyModule_AddObject(module
, "task_event", (PyObject
*)&pyrf_task_event__type
);
1362 Py_INCREF(&pyrf_throttle_event__type
);
1363 PyModule_AddObject(module
, "throttle_event", (PyObject
*)&pyrf_throttle_event__type
);
1365 Py_INCREF(&pyrf_task_event__type
);
1366 PyModule_AddObject(module
, "task_event", (PyObject
*)&pyrf_task_event__type
);
1368 Py_INCREF(&pyrf_read_event__type
);
1369 PyModule_AddObject(module
, "read_event", (PyObject
*)&pyrf_read_event__type
);
1371 Py_INCREF(&pyrf_sample_event__type
);
1372 PyModule_AddObject(module
, "sample_event", (PyObject
*)&pyrf_sample_event__type
);
1374 Py_INCREF(&pyrf_context_switch_event__type
);
1375 PyModule_AddObject(module
, "switch_event", (PyObject
*)&pyrf_context_switch_event__type
);
1377 Py_INCREF(&pyrf_thread_map__type
);
1378 PyModule_AddObject(module
, "thread_map", (PyObject
*)&pyrf_thread_map__type
);
1380 Py_INCREF(&pyrf_cpu_map__type
);
1381 PyModule_AddObject(module
, "cpu_map", (PyObject
*)&pyrf_cpu_map__type
);
1383 dict
= PyModule_GetDict(module
);
1387 for (i
= 0; perf__constants
[i
].name
!= NULL
; i
++) {
1388 obj
= _PyLong_FromLong(perf__constants
[i
].value
);
1391 PyDict_SetItemString(dict
, perf__constants
[i
].name
, obj
);
1396 if (PyErr_Occurred())
1397 PyErr_SetString(PyExc_ImportError
, "perf: Init failed!");
1398 #if PY_MAJOR_VERSION >= 3
1404 * Dummy, to avoid dragging all the test_attr infrastructure in the python
1407 void test_attr__open(struct perf_event_attr
*attr
, pid_t pid
, int cpu
,
1408 int fd
, int group_fd
, unsigned long flags
)