^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #include <Python.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #include <structmember.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <inttypes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <poll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <perf/cpumap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <traceevent/event-parse.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <perf/mmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "evlist.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "callchain.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "evsel.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "event.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "print_binary.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "thread_map.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "trace-event.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "mmap.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "stat.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include "metricgroup.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include "util/env.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <internal/lib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include "util.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #if PY_MAJOR_VERSION < 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define _PyUnicode_FromString(arg) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) PyString_FromString(arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define _PyUnicode_AsString(arg) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) PyString_AsString(arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define _PyUnicode_FromFormat(...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) PyString_FromFormat(__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define _PyLong_FromLong(arg) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) PyInt_FromLong(arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define _PyUnicode_FromString(arg) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) PyUnicode_FromString(arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define _PyUnicode_FromFormat(...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) PyUnicode_FromFormat(__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define _PyLong_FromLong(arg) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) PyLong_FromLong(arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #ifndef Py_TYPE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * Provide these two so that we don't have to link against callchain.c and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * start dragging hist.c, etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct callchain_param callchain_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) int parse_callchain_record(const char *arg __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct callchain_param *param __maybe_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * Add this one here not to drag util/env.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct perf_env perf_env;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * Add this one here not to drag util/stat-shadow.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) void perf_stat__collect_metric_expr(struct evlist *evsel_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * Add this one here not to drag util/metricgroup.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) int metricgroup__copy_metric_events(struct evlist *evlist, struct cgroup *cgrp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct rblist *new_metric_events,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct rblist *old_metric_events)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * Support debug printing even though util/debug.c is not linked. That means
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * implementing 'verbose' and 'eprintf'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) int verbose;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) int debug_peo_args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) int eprintf(int level, int var, const char *fmt, ...);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) int eprintf(int level, int var, const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if (var >= level) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) ret = vfprintf(stderr, fmt, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /* Define PyVarObject_HEAD_INIT for python 2.5 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #ifndef PyVarObject_HEAD_INIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) # define PyVarObject_HEAD_INIT(type, size) PyObject_HEAD_INIT(type) size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) #if PY_MAJOR_VERSION < 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) PyMODINIT_FUNC initperf(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) PyMODINIT_FUNC PyInit_perf(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #define member_def(type, member, ptype, help) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) { #member, ptype, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) offsetof(struct pyrf_event, event) + offsetof(struct type, member), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 0, help }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) #define sample_member_def(name, member, ptype, help) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) { #name, ptype, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) offsetof(struct pyrf_event, sample) + offsetof(struct perf_sample, member), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 0, help }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct pyrf_event {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) PyObject_HEAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct evsel *evsel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) struct perf_sample sample;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) union perf_event event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) #define sample_members \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) sample_member_def(sample_ip, ip, T_ULONGLONG, "event type"), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) sample_member_def(sample_pid, pid, T_INT, "event pid"), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) sample_member_def(sample_tid, tid, T_INT, "event tid"), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) sample_member_def(sample_time, time, T_ULONGLONG, "event timestamp"), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) sample_member_def(sample_addr, addr, T_ULONGLONG, "event addr"), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) sample_member_def(sample_id, id, T_ULONGLONG, "event id"), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) sample_member_def(sample_stream_id, stream_id, T_ULONGLONG, "event stream id"), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) sample_member_def(sample_period, period, T_ULONGLONG, "event period"), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) sample_member_def(sample_cpu, cpu, T_UINT, "event cpu"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static char pyrf_mmap_event__doc[] = PyDoc_STR("perf mmap event object.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static PyMemberDef pyrf_mmap_event__members[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) sample_members
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) member_def(perf_event_header, type, T_UINT, "event type"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) member_def(perf_event_header, misc, T_UINT, "event misc"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) member_def(perf_record_mmap, pid, T_UINT, "event pid"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) member_def(perf_record_mmap, tid, T_UINT, "event tid"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) member_def(perf_record_mmap, start, T_ULONGLONG, "start of the map"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) member_def(perf_record_mmap, len, T_ULONGLONG, "map length"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) member_def(perf_record_mmap, pgoff, T_ULONGLONG, "page offset"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) member_def(perf_record_mmap, filename, T_STRING_INPLACE, "backing store"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) { .name = NULL, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static PyObject *pyrf_mmap_event__repr(struct pyrf_event *pevent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) PyObject *ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) char *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) if (asprintf(&s, "{ type: mmap, pid: %u, tid: %u, start: %#" PRI_lx64 ", "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) "length: %#" PRI_lx64 ", offset: %#" PRI_lx64 ", "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) "filename: %s }",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) pevent->event.mmap.pid, pevent->event.mmap.tid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) pevent->event.mmap.start, pevent->event.mmap.len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) pevent->event.mmap.pgoff, pevent->event.mmap.filename) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) ret = PyErr_NoMemory();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) ret = _PyUnicode_FromString(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) free(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static PyTypeObject pyrf_mmap_event__type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) PyVarObject_HEAD_INIT(NULL, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) .tp_name = "perf.mmap_event",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) .tp_basicsize = sizeof(struct pyrf_event),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) .tp_doc = pyrf_mmap_event__doc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) .tp_members = pyrf_mmap_event__members,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) .tp_repr = (reprfunc)pyrf_mmap_event__repr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) static char pyrf_task_event__doc[] = PyDoc_STR("perf task (fork/exit) event object.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static PyMemberDef pyrf_task_event__members[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) sample_members
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) member_def(perf_event_header, type, T_UINT, "event type"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) member_def(perf_record_fork, pid, T_UINT, "event pid"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) member_def(perf_record_fork, ppid, T_UINT, "event ppid"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) member_def(perf_record_fork, tid, T_UINT, "event tid"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) member_def(perf_record_fork, ptid, T_UINT, "event ptid"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) member_def(perf_record_fork, time, T_ULONGLONG, "timestamp"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) { .name = NULL, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) static PyObject *pyrf_task_event__repr(struct pyrf_event *pevent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return _PyUnicode_FromFormat("{ type: %s, pid: %u, ppid: %u, tid: %u, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) "ptid: %u, time: %" PRI_lu64 "}",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) pevent->event.header.type == PERF_RECORD_FORK ? "fork" : "exit",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) pevent->event.fork.pid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) pevent->event.fork.ppid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) pevent->event.fork.tid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) pevent->event.fork.ptid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) pevent->event.fork.time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) static PyTypeObject pyrf_task_event__type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) PyVarObject_HEAD_INIT(NULL, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) .tp_name = "perf.task_event",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) .tp_basicsize = sizeof(struct pyrf_event),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) .tp_doc = pyrf_task_event__doc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) .tp_members = pyrf_task_event__members,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) .tp_repr = (reprfunc)pyrf_task_event__repr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) static char pyrf_comm_event__doc[] = PyDoc_STR("perf comm event object.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) static PyMemberDef pyrf_comm_event__members[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) sample_members
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) member_def(perf_event_header, type, T_UINT, "event type"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) member_def(perf_record_comm, pid, T_UINT, "event pid"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) member_def(perf_record_comm, tid, T_UINT, "event tid"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) member_def(perf_record_comm, comm, T_STRING_INPLACE, "process name"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) { .name = NULL, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) static PyObject *pyrf_comm_event__repr(struct pyrf_event *pevent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) return _PyUnicode_FromFormat("{ type: comm, pid: %u, tid: %u, comm: %s }",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) pevent->event.comm.pid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) pevent->event.comm.tid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) pevent->event.comm.comm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static PyTypeObject pyrf_comm_event__type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) PyVarObject_HEAD_INIT(NULL, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) .tp_name = "perf.comm_event",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) .tp_basicsize = sizeof(struct pyrf_event),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) .tp_doc = pyrf_comm_event__doc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) .tp_members = pyrf_comm_event__members,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) .tp_repr = (reprfunc)pyrf_comm_event__repr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) static char pyrf_throttle_event__doc[] = PyDoc_STR("perf throttle event object.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static PyMemberDef pyrf_throttle_event__members[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) sample_members
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) member_def(perf_event_header, type, T_UINT, "event type"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) member_def(perf_record_throttle, time, T_ULONGLONG, "timestamp"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) member_def(perf_record_throttle, id, T_ULONGLONG, "event id"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) member_def(perf_record_throttle, stream_id, T_ULONGLONG, "event stream id"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) { .name = NULL, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static PyObject *pyrf_throttle_event__repr(struct pyrf_event *pevent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) struct perf_record_throttle *te = (struct perf_record_throttle *)(&pevent->event.header + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) return _PyUnicode_FromFormat("{ type: %sthrottle, time: %" PRI_lu64 ", id: %" PRI_lu64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) ", stream_id: %" PRI_lu64 " }",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) pevent->event.header.type == PERF_RECORD_THROTTLE ? "" : "un",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) te->time, te->id, te->stream_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) static PyTypeObject pyrf_throttle_event__type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) PyVarObject_HEAD_INIT(NULL, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) .tp_name = "perf.throttle_event",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) .tp_basicsize = sizeof(struct pyrf_event),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) .tp_doc = pyrf_throttle_event__doc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) .tp_members = pyrf_throttle_event__members,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) .tp_repr = (reprfunc)pyrf_throttle_event__repr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static char pyrf_lost_event__doc[] = PyDoc_STR("perf lost event object.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) static PyMemberDef pyrf_lost_event__members[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) sample_members
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) member_def(perf_record_lost, id, T_ULONGLONG, "event id"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) member_def(perf_record_lost, lost, T_ULONGLONG, "number of lost events"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) { .name = NULL, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) static PyObject *pyrf_lost_event__repr(struct pyrf_event *pevent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) PyObject *ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) char *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (asprintf(&s, "{ type: lost, id: %#" PRI_lx64 ", "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) "lost: %#" PRI_lx64 " }",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) pevent->event.lost.id, pevent->event.lost.lost) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) ret = PyErr_NoMemory();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) ret = _PyUnicode_FromString(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) free(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) static PyTypeObject pyrf_lost_event__type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) PyVarObject_HEAD_INIT(NULL, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) .tp_name = "perf.lost_event",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) .tp_basicsize = sizeof(struct pyrf_event),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) .tp_doc = pyrf_lost_event__doc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) .tp_members = pyrf_lost_event__members,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) .tp_repr = (reprfunc)pyrf_lost_event__repr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) static char pyrf_read_event__doc[] = PyDoc_STR("perf read event object.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) static PyMemberDef pyrf_read_event__members[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) sample_members
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) member_def(perf_record_read, pid, T_UINT, "event pid"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) member_def(perf_record_read, tid, T_UINT, "event tid"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) { .name = NULL, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) static PyObject *pyrf_read_event__repr(struct pyrf_event *pevent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) return _PyUnicode_FromFormat("{ type: read, pid: %u, tid: %u }",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) pevent->event.read.pid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) pevent->event.read.tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) * FIXME: return the array of read values,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) * making this method useful ;-)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) static PyTypeObject pyrf_read_event__type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) PyVarObject_HEAD_INIT(NULL, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) .tp_name = "perf.read_event",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) .tp_basicsize = sizeof(struct pyrf_event),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) .tp_doc = pyrf_read_event__doc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) .tp_members = pyrf_read_event__members,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) .tp_repr = (reprfunc)pyrf_read_event__repr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) static char pyrf_sample_event__doc[] = PyDoc_STR("perf sample event object.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) static PyMemberDef pyrf_sample_event__members[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) sample_members
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) member_def(perf_event_header, type, T_UINT, "event type"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) { .name = NULL, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) static PyObject *pyrf_sample_event__repr(struct pyrf_event *pevent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) PyObject *ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) char *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) if (asprintf(&s, "{ type: sample }") < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) ret = PyErr_NoMemory();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) ret = _PyUnicode_FromString(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) free(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) static bool is_tracepoint(struct pyrf_event *pevent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) return pevent->evsel->core.attr.type == PERF_TYPE_TRACEPOINT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) static PyObject*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) tracepoint_field(struct pyrf_event *pe, struct tep_format_field *field)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) struct tep_handle *pevent = field->event->tep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) void *data = pe->sample.raw_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) PyObject *ret = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) unsigned long long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) unsigned int offset, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) if (field->flags & TEP_FIELD_IS_ARRAY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) offset = field->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) len = field->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) if (field->flags & TEP_FIELD_IS_DYNAMIC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) val = tep_read_number(pevent, data + offset, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) offset = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) len = offset >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) offset &= 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) if (field->flags & TEP_FIELD_IS_STRING &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) is_printable_array(data + offset, len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) ret = _PyUnicode_FromString((char *)data + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) ret = PyByteArray_FromStringAndSize((const char *) data + offset, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) field->flags &= ~TEP_FIELD_IS_STRING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) val = tep_read_number(pevent, data + field->offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) field->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) if (field->flags & TEP_FIELD_IS_POINTER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) ret = PyLong_FromUnsignedLong((unsigned long) val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) else if (field->flags & TEP_FIELD_IS_SIGNED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) ret = PyLong_FromLong((long) val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) ret = PyLong_FromUnsignedLong((unsigned long) val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) static PyObject*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) get_tracepoint_field(struct pyrf_event *pevent, PyObject *attr_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) const char *str = _PyUnicode_AsString(PyObject_Str(attr_name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) struct evsel *evsel = pevent->evsel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) struct tep_format_field *field;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) if (!evsel->tp_format) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) struct tep_event *tp_format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) tp_format = trace_event__tp_format_id(evsel->core.attr.config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) if (!tp_format)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) evsel->tp_format = tp_format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) field = tep_find_any_field(evsel->tp_format, str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) if (!field)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) return tracepoint_field(pevent, field);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) static PyObject*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) pyrf_sample_event__getattro(struct pyrf_event *pevent, PyObject *attr_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) PyObject *obj = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) if (is_tracepoint(pevent))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) obj = get_tracepoint_field(pevent, attr_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) return obj ?: PyObject_GenericGetAttr((PyObject *) pevent, attr_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) static PyTypeObject pyrf_sample_event__type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) PyVarObject_HEAD_INIT(NULL, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) .tp_name = "perf.sample_event",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) .tp_basicsize = sizeof(struct pyrf_event),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) .tp_doc = pyrf_sample_event__doc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) .tp_members = pyrf_sample_event__members,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) .tp_repr = (reprfunc)pyrf_sample_event__repr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) .tp_getattro = (getattrofunc) pyrf_sample_event__getattro,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) static char pyrf_context_switch_event__doc[] = PyDoc_STR("perf context_switch event object.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) static PyMemberDef pyrf_context_switch_event__members[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) sample_members
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) member_def(perf_event_header, type, T_UINT, "event type"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) member_def(perf_record_switch, next_prev_pid, T_UINT, "next/prev pid"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) member_def(perf_record_switch, next_prev_tid, T_UINT, "next/prev tid"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) { .name = NULL, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) static PyObject *pyrf_context_switch_event__repr(struct pyrf_event *pevent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) PyObject *ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) char *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) if (asprintf(&s, "{ type: context_switch, next_prev_pid: %u, next_prev_tid: %u, switch_out: %u }",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) pevent->event.context_switch.next_prev_pid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) pevent->event.context_switch.next_prev_tid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) !!(pevent->event.header.misc & PERF_RECORD_MISC_SWITCH_OUT)) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) ret = PyErr_NoMemory();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) ret = _PyUnicode_FromString(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) free(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) static PyTypeObject pyrf_context_switch_event__type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) PyVarObject_HEAD_INIT(NULL, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) .tp_name = "perf.context_switch_event",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) .tp_basicsize = sizeof(struct pyrf_event),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) .tp_doc = pyrf_context_switch_event__doc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) .tp_members = pyrf_context_switch_event__members,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) .tp_repr = (reprfunc)pyrf_context_switch_event__repr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) static int pyrf_event__setup_types(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) pyrf_mmap_event__type.tp_new =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) pyrf_task_event__type.tp_new =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) pyrf_comm_event__type.tp_new =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) pyrf_lost_event__type.tp_new =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) pyrf_read_event__type.tp_new =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) pyrf_sample_event__type.tp_new =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) pyrf_context_switch_event__type.tp_new =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) pyrf_throttle_event__type.tp_new = PyType_GenericNew;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) err = PyType_Ready(&pyrf_mmap_event__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) err = PyType_Ready(&pyrf_lost_event__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) err = PyType_Ready(&pyrf_task_event__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) err = PyType_Ready(&pyrf_comm_event__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) err = PyType_Ready(&pyrf_throttle_event__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) err = PyType_Ready(&pyrf_read_event__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) err = PyType_Ready(&pyrf_sample_event__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) err = PyType_Ready(&pyrf_context_switch_event__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) static PyTypeObject *pyrf_event__type[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) [PERF_RECORD_MMAP] = &pyrf_mmap_event__type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) [PERF_RECORD_LOST] = &pyrf_lost_event__type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) [PERF_RECORD_COMM] = &pyrf_comm_event__type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) [PERF_RECORD_EXIT] = &pyrf_task_event__type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) [PERF_RECORD_THROTTLE] = &pyrf_throttle_event__type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) [PERF_RECORD_UNTHROTTLE] = &pyrf_throttle_event__type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) [PERF_RECORD_FORK] = &pyrf_task_event__type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) [PERF_RECORD_READ] = &pyrf_read_event__type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) [PERF_RECORD_SAMPLE] = &pyrf_sample_event__type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) [PERF_RECORD_SWITCH] = &pyrf_context_switch_event__type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) [PERF_RECORD_SWITCH_CPU_WIDE] = &pyrf_context_switch_event__type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) static PyObject *pyrf_event__new(union perf_event *event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) struct pyrf_event *pevent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) PyTypeObject *ptype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) if ((event->header.type < PERF_RECORD_MMAP ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) event->header.type > PERF_RECORD_SAMPLE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) !(event->header.type == PERF_RECORD_SWITCH ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) event->header.type == PERF_RECORD_SWITCH_CPU_WIDE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) ptype = pyrf_event__type[event->header.type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) pevent = PyObject_New(struct pyrf_event, ptype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) if (pevent != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) memcpy(&pevent->event, event, event->header.size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) return (PyObject *)pevent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) struct pyrf_cpu_map {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) PyObject_HEAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) struct perf_cpu_map *cpus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) static int pyrf_cpu_map__init(struct pyrf_cpu_map *pcpus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) PyObject *args, PyObject *kwargs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) static char *kwlist[] = { "cpustr", NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) char *cpustr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) kwlist, &cpustr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) pcpus->cpus = perf_cpu_map__new(cpustr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) if (pcpus->cpus == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) static void pyrf_cpu_map__delete(struct pyrf_cpu_map *pcpus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) perf_cpu_map__put(pcpus->cpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) Py_TYPE(pcpus)->tp_free((PyObject*)pcpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) static Py_ssize_t pyrf_cpu_map__length(PyObject *obj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) struct pyrf_cpu_map *pcpus = (void *)obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) return pcpus->cpus->nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) static PyObject *pyrf_cpu_map__item(PyObject *obj, Py_ssize_t i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) struct pyrf_cpu_map *pcpus = (void *)obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) if (i >= pcpus->cpus->nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) return Py_BuildValue("i", pcpus->cpus->map[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) static PySequenceMethods pyrf_cpu_map__sequence_methods = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) .sq_length = pyrf_cpu_map__length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) .sq_item = pyrf_cpu_map__item,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) static char pyrf_cpu_map__doc[] = PyDoc_STR("cpu map object.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) static PyTypeObject pyrf_cpu_map__type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) PyVarObject_HEAD_INIT(NULL, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) .tp_name = "perf.cpu_map",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) .tp_basicsize = sizeof(struct pyrf_cpu_map),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) .tp_dealloc = (destructor)pyrf_cpu_map__delete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) .tp_doc = pyrf_cpu_map__doc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) .tp_as_sequence = &pyrf_cpu_map__sequence_methods,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) .tp_init = (initproc)pyrf_cpu_map__init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) static int pyrf_cpu_map__setup_types(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) pyrf_cpu_map__type.tp_new = PyType_GenericNew;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) return PyType_Ready(&pyrf_cpu_map__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) struct pyrf_thread_map {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) PyObject_HEAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) struct perf_thread_map *threads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) static int pyrf_thread_map__init(struct pyrf_thread_map *pthreads,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) PyObject *args, PyObject *kwargs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) static char *kwlist[] = { "pid", "tid", "uid", NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) int pid = -1, tid = -1, uid = UINT_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|iii",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) kwlist, &pid, &tid, &uid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) pthreads->threads = thread_map__new(pid, tid, uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) if (pthreads->threads == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) static void pyrf_thread_map__delete(struct pyrf_thread_map *pthreads)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) perf_thread_map__put(pthreads->threads);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) Py_TYPE(pthreads)->tp_free((PyObject*)pthreads);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) static Py_ssize_t pyrf_thread_map__length(PyObject *obj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) struct pyrf_thread_map *pthreads = (void *)obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) return pthreads->threads->nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) static PyObject *pyrf_thread_map__item(PyObject *obj, Py_ssize_t i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) struct pyrf_thread_map *pthreads = (void *)obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) if (i >= pthreads->threads->nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) return Py_BuildValue("i", pthreads->threads->map[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) static PySequenceMethods pyrf_thread_map__sequence_methods = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) .sq_length = pyrf_thread_map__length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) .sq_item = pyrf_thread_map__item,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) static char pyrf_thread_map__doc[] = PyDoc_STR("thread map object.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) static PyTypeObject pyrf_thread_map__type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) PyVarObject_HEAD_INIT(NULL, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) .tp_name = "perf.thread_map",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) .tp_basicsize = sizeof(struct pyrf_thread_map),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) .tp_dealloc = (destructor)pyrf_thread_map__delete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) .tp_doc = pyrf_thread_map__doc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) .tp_as_sequence = &pyrf_thread_map__sequence_methods,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) .tp_init = (initproc)pyrf_thread_map__init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) static int pyrf_thread_map__setup_types(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) pyrf_thread_map__type.tp_new = PyType_GenericNew;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) return PyType_Ready(&pyrf_thread_map__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) struct pyrf_evsel {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) PyObject_HEAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) struct evsel evsel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) static int pyrf_evsel__init(struct pyrf_evsel *pevsel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) PyObject *args, PyObject *kwargs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) struct perf_event_attr attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) .type = PERF_TYPE_HARDWARE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) .config = PERF_COUNT_HW_CPU_CYCLES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) .sample_type = PERF_SAMPLE_PERIOD | PERF_SAMPLE_TID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) static char *kwlist[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) "type",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) "config",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) "sample_freq",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) "sample_period",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) "sample_type",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) "read_format",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) "disabled",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) "inherit",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) "pinned",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) "exclusive",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) "exclude_user",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) "exclude_kernel",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) "exclude_hv",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) "exclude_idle",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) "mmap",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) "context_switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) "comm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) "freq",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) "inherit_stat",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) "enable_on_exec",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) "task",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) "watermark",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) "precise_ip",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) "mmap_data",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) "sample_id_all",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) "wakeup_events",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) "bp_type",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) "bp_addr",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) "bp_len",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) u64 sample_period = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) u32 disabled = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) inherit = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) pinned = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) exclusive = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) exclude_user = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) exclude_kernel = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) exclude_hv = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) exclude_idle = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) mmap = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) context_switch = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) comm = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) freq = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) inherit_stat = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) enable_on_exec = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) task = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) watermark = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) precise_ip = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) mmap_data = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) sample_id_all = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) int idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) if (!PyArg_ParseTupleAndKeywords(args, kwargs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) "|iKiKKiiiiiiiiiiiiiiiiiiiiiiKK", kwlist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) &attr.type, &attr.config, &attr.sample_freq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) &sample_period, &attr.sample_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) &attr.read_format, &disabled, &inherit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) &pinned, &exclusive, &exclude_user,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) &exclude_kernel, &exclude_hv, &exclude_idle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) &mmap, &context_switch, &comm, &freq, &inherit_stat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) &enable_on_exec, &task, &watermark,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) &precise_ip, &mmap_data, &sample_id_all,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) &attr.wakeup_events, &attr.bp_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) &attr.bp_addr, &attr.bp_len, &idx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) /* union... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) if (sample_period != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) if (attr.sample_freq != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) return -1; /* FIXME: throw right exception */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) attr.sample_period = sample_period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) /* Bitfields */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) attr.disabled = disabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) attr.inherit = inherit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) attr.pinned = pinned;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) attr.exclusive = exclusive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) attr.exclude_user = exclude_user;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) attr.exclude_kernel = exclude_kernel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) attr.exclude_hv = exclude_hv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) attr.exclude_idle = exclude_idle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) attr.mmap = mmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) attr.context_switch = context_switch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) attr.comm = comm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) attr.freq = freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) attr.inherit_stat = inherit_stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) attr.enable_on_exec = enable_on_exec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) attr.task = task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) attr.watermark = watermark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) attr.precise_ip = precise_ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) attr.mmap_data = mmap_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) attr.sample_id_all = sample_id_all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) attr.size = sizeof(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) evsel__init(&pevsel->evsel, &attr, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) static void pyrf_evsel__delete(struct pyrf_evsel *pevsel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) evsel__exit(&pevsel->evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) Py_TYPE(pevsel)->tp_free((PyObject*)pevsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) static PyObject *pyrf_evsel__open(struct pyrf_evsel *pevsel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) PyObject *args, PyObject *kwargs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) struct evsel *evsel = &pevsel->evsel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) struct perf_cpu_map *cpus = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) struct perf_thread_map *threads = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) PyObject *pcpus = NULL, *pthreads = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) int group = 0, inherit = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) static char *kwlist[] = { "cpus", "threads", "group", "inherit", NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OOii", kwlist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) &pcpus, &pthreads, &group, &inherit))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) if (pthreads != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) threads = ((struct pyrf_thread_map *)pthreads)->threads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) if (pcpus != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) cpus = ((struct pyrf_cpu_map *)pcpus)->cpus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) evsel->core.attr.inherit = inherit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) * This will group just the fds for this single evsel, to group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) * multiple events, use evlist.open().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) if (evsel__open(evsel, cpus, threads) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) PyErr_SetFromErrno(PyExc_OSError);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) Py_INCREF(Py_None);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) return Py_None;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) static PyMethodDef pyrf_evsel__methods[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) .ml_name = "open",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) .ml_meth = (PyCFunction)pyrf_evsel__open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) .ml_flags = METH_VARARGS | METH_KEYWORDS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) .ml_doc = PyDoc_STR("open the event selector file descriptor table.")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) { .ml_name = NULL, }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) static char pyrf_evsel__doc[] = PyDoc_STR("perf event selector list object.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) static PyTypeObject pyrf_evsel__type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) PyVarObject_HEAD_INIT(NULL, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) .tp_name = "perf.evsel",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) .tp_basicsize = sizeof(struct pyrf_evsel),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) .tp_dealloc = (destructor)pyrf_evsel__delete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) .tp_doc = pyrf_evsel__doc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) .tp_methods = pyrf_evsel__methods,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) .tp_init = (initproc)pyrf_evsel__init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) static int pyrf_evsel__setup_types(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) pyrf_evsel__type.tp_new = PyType_GenericNew;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) return PyType_Ready(&pyrf_evsel__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) struct pyrf_evlist {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) PyObject_HEAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) struct evlist evlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) static int pyrf_evlist__init(struct pyrf_evlist *pevlist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) PyObject *args, PyObject *kwargs __maybe_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) PyObject *pcpus = NULL, *pthreads = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) struct perf_cpu_map *cpus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) struct perf_thread_map *threads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) if (!PyArg_ParseTuple(args, "OO", &pcpus, &pthreads))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) threads = ((struct pyrf_thread_map *)pthreads)->threads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) cpus = ((struct pyrf_cpu_map *)pcpus)->cpus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) evlist__init(&pevlist->evlist, cpus, threads);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) static void pyrf_evlist__delete(struct pyrf_evlist *pevlist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) evlist__exit(&pevlist->evlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) Py_TYPE(pevlist)->tp_free((PyObject*)pevlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) static PyObject *pyrf_evlist__mmap(struct pyrf_evlist *pevlist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) PyObject *args, PyObject *kwargs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) struct evlist *evlist = &pevlist->evlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) static char *kwlist[] = { "pages", "overwrite", NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) int pages = 128, overwrite = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ii", kwlist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) &pages, &overwrite))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) if (evlist__mmap(evlist, pages) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) PyErr_SetFromErrno(PyExc_OSError);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) Py_INCREF(Py_None);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) return Py_None;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) static PyObject *pyrf_evlist__poll(struct pyrf_evlist *pevlist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) PyObject *args, PyObject *kwargs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) struct evlist *evlist = &pevlist->evlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) static char *kwlist[] = { "timeout", NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) int timeout = -1, n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i", kwlist, &timeout))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) n = evlist__poll(evlist, timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) if (n < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) PyErr_SetFromErrno(PyExc_OSError);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) return Py_BuildValue("i", n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) static PyObject *pyrf_evlist__get_pollfd(struct pyrf_evlist *pevlist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) PyObject *args __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) PyObject *kwargs __maybe_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) struct evlist *evlist = &pevlist->evlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) PyObject *list = PyList_New(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) for (i = 0; i < evlist->core.pollfd.nr; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) PyObject *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) #if PY_MAJOR_VERSION < 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) FILE *fp = fdopen(evlist->core.pollfd.entries[i].fd, "r");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) if (fp == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) goto free_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) file = PyFile_FromFile(fp, "perf", "r", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) file = PyFile_FromFd(evlist->core.pollfd.entries[i].fd, "perf", "r", -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) NULL, NULL, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) if (file == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) goto free_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) if (PyList_Append(list, file) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) Py_DECREF(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) goto free_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) Py_DECREF(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) return list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) free_list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) return PyErr_NoMemory();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) static PyObject *pyrf_evlist__add(struct pyrf_evlist *pevlist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) PyObject *args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) PyObject *kwargs __maybe_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) struct evlist *evlist = &pevlist->evlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) PyObject *pevsel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) struct evsel *evsel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) if (!PyArg_ParseTuple(args, "O", &pevsel))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) Py_INCREF(pevsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) evsel = &((struct pyrf_evsel *)pevsel)->evsel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) evsel->idx = evlist->core.nr_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) evlist__add(evlist, evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) return Py_BuildValue("i", evlist->core.nr_entries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) static struct mmap *get_md(struct evlist *evlist, int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) for (i = 0; i < evlist->core.nr_mmaps; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) struct mmap *md = &evlist->mmap[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) if (md->core.cpu == cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) return md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) PyObject *args, PyObject *kwargs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) struct evlist *evlist = &pevlist->evlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) union perf_event *event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) int sample_id_all = 1, cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) static char *kwlist[] = { "cpu", "sample_id_all", NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) struct mmap *md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i|i", kwlist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) &cpu, &sample_id_all))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) md = get_md(evlist, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) if (!md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) if (perf_mmap__read_init(&md->core) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) event = perf_mmap__read_event(&md->core);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) if (event != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) PyObject *pyevent = pyrf_event__new(event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) struct pyrf_event *pevent = (struct pyrf_event *)pyevent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) struct evsel *evsel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) if (pyevent == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) return PyErr_NoMemory();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) evsel = perf_evlist__event2evsel(evlist, event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) if (!evsel) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) Py_INCREF(Py_None);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) return Py_None;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) pevent->evsel = evsel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) err = evsel__parse_sample(evsel, event, &pevent->sample);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) /* Consume the even only after we parsed it out. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) perf_mmap__consume(&md->core);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) return PyErr_Format(PyExc_OSError,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) "perf: can't parse sample, err=%d", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) return pyevent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) Py_INCREF(Py_None);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) return Py_None;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) static PyObject *pyrf_evlist__open(struct pyrf_evlist *pevlist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) PyObject *args, PyObject *kwargs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) struct evlist *evlist = &pevlist->evlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) int group = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) static char *kwlist[] = { "group", NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OOii", kwlist, &group))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) if (group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) perf_evlist__set_leader(evlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) if (evlist__open(evlist) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) PyErr_SetFromErrno(PyExc_OSError);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) Py_INCREF(Py_None);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) return Py_None;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) static PyMethodDef pyrf_evlist__methods[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) .ml_name = "mmap",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) .ml_meth = (PyCFunction)pyrf_evlist__mmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) .ml_flags = METH_VARARGS | METH_KEYWORDS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) .ml_doc = PyDoc_STR("mmap the file descriptor table.")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) .ml_name = "open",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) .ml_meth = (PyCFunction)pyrf_evlist__open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) .ml_flags = METH_VARARGS | METH_KEYWORDS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) .ml_doc = PyDoc_STR("open the file descriptors.")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) .ml_name = "poll",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) .ml_meth = (PyCFunction)pyrf_evlist__poll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) .ml_flags = METH_VARARGS | METH_KEYWORDS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) .ml_doc = PyDoc_STR("poll the file descriptor table.")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) .ml_name = "get_pollfd",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) .ml_meth = (PyCFunction)pyrf_evlist__get_pollfd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) .ml_flags = METH_VARARGS | METH_KEYWORDS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) .ml_doc = PyDoc_STR("get the poll file descriptor table.")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) .ml_name = "add",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) .ml_meth = (PyCFunction)pyrf_evlist__add,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) .ml_flags = METH_VARARGS | METH_KEYWORDS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) .ml_doc = PyDoc_STR("adds an event selector to the list.")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) .ml_name = "read_on_cpu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) .ml_meth = (PyCFunction)pyrf_evlist__read_on_cpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) .ml_flags = METH_VARARGS | METH_KEYWORDS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) .ml_doc = PyDoc_STR("reads an event.")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) { .ml_name = NULL, }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) static Py_ssize_t pyrf_evlist__length(PyObject *obj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) struct pyrf_evlist *pevlist = (void *)obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) return pevlist->evlist.core.nr_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) static PyObject *pyrf_evlist__item(PyObject *obj, Py_ssize_t i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) struct pyrf_evlist *pevlist = (void *)obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) struct evsel *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) if (i >= pevlist->evlist.core.nr_entries)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) evlist__for_each_entry(&pevlist->evlist, pos) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) if (i-- == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) return Py_BuildValue("O", container_of(pos, struct pyrf_evsel, evsel));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) static PySequenceMethods pyrf_evlist__sequence_methods = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) .sq_length = pyrf_evlist__length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) .sq_item = pyrf_evlist__item,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) static char pyrf_evlist__doc[] = PyDoc_STR("perf event selector list object.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) static PyTypeObject pyrf_evlist__type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) PyVarObject_HEAD_INIT(NULL, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) .tp_name = "perf.evlist",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) .tp_basicsize = sizeof(struct pyrf_evlist),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) .tp_dealloc = (destructor)pyrf_evlist__delete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) .tp_as_sequence = &pyrf_evlist__sequence_methods,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) .tp_doc = pyrf_evlist__doc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) .tp_methods = pyrf_evlist__methods,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) .tp_init = (initproc)pyrf_evlist__init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) static int pyrf_evlist__setup_types(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) pyrf_evlist__type.tp_new = PyType_GenericNew;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) return PyType_Ready(&pyrf_evlist__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) #define PERF_CONST(name) { #name, PERF_##name }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) static struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) int value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) } perf__constants[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) PERF_CONST(TYPE_HARDWARE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) PERF_CONST(TYPE_SOFTWARE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) PERF_CONST(TYPE_TRACEPOINT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) PERF_CONST(TYPE_HW_CACHE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) PERF_CONST(TYPE_RAW),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) PERF_CONST(TYPE_BREAKPOINT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) PERF_CONST(COUNT_HW_CPU_CYCLES),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) PERF_CONST(COUNT_HW_INSTRUCTIONS),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) PERF_CONST(COUNT_HW_CACHE_REFERENCES),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) PERF_CONST(COUNT_HW_CACHE_MISSES),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) PERF_CONST(COUNT_HW_BRANCH_INSTRUCTIONS),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) PERF_CONST(COUNT_HW_BRANCH_MISSES),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) PERF_CONST(COUNT_HW_BUS_CYCLES),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) PERF_CONST(COUNT_HW_CACHE_L1D),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) PERF_CONST(COUNT_HW_CACHE_L1I),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) PERF_CONST(COUNT_HW_CACHE_LL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) PERF_CONST(COUNT_HW_CACHE_DTLB),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) PERF_CONST(COUNT_HW_CACHE_ITLB),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) PERF_CONST(COUNT_HW_CACHE_BPU),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) PERF_CONST(COUNT_HW_CACHE_OP_READ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) PERF_CONST(COUNT_HW_CACHE_OP_WRITE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) PERF_CONST(COUNT_HW_CACHE_OP_PREFETCH),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) PERF_CONST(COUNT_HW_CACHE_RESULT_ACCESS),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) PERF_CONST(COUNT_HW_CACHE_RESULT_MISS),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) PERF_CONST(COUNT_HW_STALLED_CYCLES_FRONTEND),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) PERF_CONST(COUNT_HW_STALLED_CYCLES_BACKEND),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) PERF_CONST(COUNT_SW_CPU_CLOCK),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) PERF_CONST(COUNT_SW_TASK_CLOCK),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) PERF_CONST(COUNT_SW_PAGE_FAULTS),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) PERF_CONST(COUNT_SW_CONTEXT_SWITCHES),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) PERF_CONST(COUNT_SW_CPU_MIGRATIONS),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) PERF_CONST(COUNT_SW_PAGE_FAULTS_MIN),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) PERF_CONST(COUNT_SW_PAGE_FAULTS_MAJ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) PERF_CONST(COUNT_SW_ALIGNMENT_FAULTS),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) PERF_CONST(COUNT_SW_EMULATION_FAULTS),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) PERF_CONST(COUNT_SW_DUMMY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) PERF_CONST(SAMPLE_IP),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) PERF_CONST(SAMPLE_TID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) PERF_CONST(SAMPLE_TIME),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) PERF_CONST(SAMPLE_ADDR),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) PERF_CONST(SAMPLE_READ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) PERF_CONST(SAMPLE_CALLCHAIN),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) PERF_CONST(SAMPLE_ID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) PERF_CONST(SAMPLE_CPU),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) PERF_CONST(SAMPLE_PERIOD),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) PERF_CONST(SAMPLE_STREAM_ID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) PERF_CONST(SAMPLE_RAW),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) PERF_CONST(FORMAT_TOTAL_TIME_ENABLED),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) PERF_CONST(FORMAT_TOTAL_TIME_RUNNING),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) PERF_CONST(FORMAT_ID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) PERF_CONST(FORMAT_GROUP),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) PERF_CONST(RECORD_MMAP),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) PERF_CONST(RECORD_LOST),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) PERF_CONST(RECORD_COMM),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) PERF_CONST(RECORD_EXIT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) PERF_CONST(RECORD_THROTTLE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) PERF_CONST(RECORD_UNTHROTTLE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) PERF_CONST(RECORD_FORK),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) PERF_CONST(RECORD_READ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) PERF_CONST(RECORD_SAMPLE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) PERF_CONST(RECORD_MMAP2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) PERF_CONST(RECORD_AUX),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) PERF_CONST(RECORD_ITRACE_START),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) PERF_CONST(RECORD_LOST_SAMPLES),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) PERF_CONST(RECORD_SWITCH),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) PERF_CONST(RECORD_SWITCH_CPU_WIDE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) PERF_CONST(RECORD_MISC_SWITCH_OUT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) { .name = NULL, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) static PyObject *pyrf__tracepoint(struct pyrf_evsel *pevsel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) PyObject *args, PyObject *kwargs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) struct tep_event *tp_format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) static char *kwlist[] = { "sys", "name", NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) char *sys = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) char *name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ss", kwlist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) &sys, &name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) tp_format = trace_event__tp_format(sys, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) if (IS_ERR(tp_format))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) return _PyLong_FromLong(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) return _PyLong_FromLong(tp_format->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) static PyMethodDef perf__methods[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) .ml_name = "tracepoint",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) .ml_meth = (PyCFunction) pyrf__tracepoint,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) .ml_flags = METH_VARARGS | METH_KEYWORDS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) .ml_doc = PyDoc_STR("Get tracepoint config.")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) { .ml_name = NULL, }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) #if PY_MAJOR_VERSION < 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) PyMODINIT_FUNC initperf(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) PyMODINIT_FUNC PyInit_perf(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) PyObject *obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) PyObject *dict;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) #if PY_MAJOR_VERSION < 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) PyObject *module = Py_InitModule("perf", perf__methods);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) static struct PyModuleDef moduledef = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) PyModuleDef_HEAD_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) "perf", /* m_name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) "", /* m_doc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) -1, /* m_size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) perf__methods, /* m_methods */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) NULL, /* m_reload */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) NULL, /* m_traverse */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) NULL, /* m_clear */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) NULL, /* m_free */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) PyObject *module = PyModule_Create(&moduledef);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) if (module == NULL ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) pyrf_event__setup_types() < 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) pyrf_evlist__setup_types() < 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) pyrf_evsel__setup_types() < 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) pyrf_thread_map__setup_types() < 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) pyrf_cpu_map__setup_types() < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) #if PY_MAJOR_VERSION < 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) return module;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) /* The page_size is placed in util object. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) page_size = sysconf(_SC_PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) Py_INCREF(&pyrf_evlist__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) PyModule_AddObject(module, "evlist", (PyObject*)&pyrf_evlist__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) Py_INCREF(&pyrf_evsel__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) PyModule_AddObject(module, "evsel", (PyObject*)&pyrf_evsel__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) Py_INCREF(&pyrf_mmap_event__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) PyModule_AddObject(module, "mmap_event", (PyObject *)&pyrf_mmap_event__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) Py_INCREF(&pyrf_lost_event__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) PyModule_AddObject(module, "lost_event", (PyObject *)&pyrf_lost_event__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) Py_INCREF(&pyrf_comm_event__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) PyModule_AddObject(module, "comm_event", (PyObject *)&pyrf_comm_event__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) Py_INCREF(&pyrf_task_event__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) PyModule_AddObject(module, "task_event", (PyObject *)&pyrf_task_event__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) Py_INCREF(&pyrf_throttle_event__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) PyModule_AddObject(module, "throttle_event", (PyObject *)&pyrf_throttle_event__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) Py_INCREF(&pyrf_task_event__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) PyModule_AddObject(module, "task_event", (PyObject *)&pyrf_task_event__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) Py_INCREF(&pyrf_read_event__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) PyModule_AddObject(module, "read_event", (PyObject *)&pyrf_read_event__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) Py_INCREF(&pyrf_sample_event__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) PyModule_AddObject(module, "sample_event", (PyObject *)&pyrf_sample_event__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) Py_INCREF(&pyrf_context_switch_event__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) PyModule_AddObject(module, "switch_event", (PyObject *)&pyrf_context_switch_event__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) Py_INCREF(&pyrf_thread_map__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) PyModule_AddObject(module, "thread_map", (PyObject*)&pyrf_thread_map__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) Py_INCREF(&pyrf_cpu_map__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) PyModule_AddObject(module, "cpu_map", (PyObject*)&pyrf_cpu_map__type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) dict = PyModule_GetDict(module);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) if (dict == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) for (i = 0; perf__constants[i].name != NULL; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) obj = _PyLong_FromLong(perf__constants[i].value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) if (obj == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) PyDict_SetItemString(dict, perf__constants[i].name, obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) Py_DECREF(obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) if (PyErr_Occurred())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) PyErr_SetString(PyExc_ImportError, "perf: Init failed!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) #if PY_MAJOR_VERSION >= 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) return module;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) * Dummy, to avoid dragging all the test_attr infrastructure in the python
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) * binding.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) int fd, int group_fd, unsigned long flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) }