if (md->core.cpu == cpu) return md; } return NULL;} static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist, PyObject *args, PyObject *kwargs){ struct evlist *evlist = &pevlist->evlist; union perf_event *event; int sample_id_all = 1, cpu; static char *kwlist[] = { "cpu", "sample_id_all", NULL }; struct mmap *md; int err; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i|i", kwlist, &cpu, &sample_id_all)) return NULL; md = get_md(evlist, cpu); if (!md) return NULL; if (perf_mmap__read_init(&md->core) < 0) goto end; event = perf_mmap__read_event(&md->core); if (event != NULL) { PyObject *pyevent = pyrf_event__new(event); struct pyrf_event *pevent = (struct pyrf_event *)pyevent; struct evsel *evsel; if (pyevent == NULL) return PyErr_NoMemory(); evsel = perf_evlist__event2evsel(evlist, event); if (!evsel) { Py_INCREF(Py_None); return Py_None; } pevent->evsel = evsel; err = evsel__parse_sample(evsel, event, &pevent->sample); /* Consume the even only after we parsed it out. */ perf_mmap__consume(&md->core); if (err) return PyErr_Format(PyExc_OSError, "perf: can't parse sample, err=%d", err); return pyevent; }end: Py_INCREF(Py_None); return Py_None;} static PyObject *pyrf_evlist__open(struct pyrf_evlist *pevlist, PyObject *args, PyObject *kwargs){ struct evlist *evlist = &pevlist->evlist; int group = 0; static char *kwlist[] = { "group", NULL }; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OOii", kwlist, &group)) return NULL; if (group) perf_evlist__set_leader(evlist); if (evlist__open(evlist) < 0) { PyErr_SetFromErrno(PyExc_OSError); return NULL; } Py_INCREF(Py_None); return Py_None;} static PyMethodDef pyrf_evlist__methods[] = { { .ml_name = "mmap", .ml_meth = (PyCFunction)pyrf_evlist__mmap, .ml_flags = METH_VARARGS | METH_KEYWORDS, .ml_doc = PyDoc_STR("mmap the file descriptor table.") }, { .ml_name = "open", .ml_meth = (PyCFunction)pyrf_evlist__open, .ml_flags = METH_VARARGS | METH_KEYWORDS, .ml_doc = PyDoc_STR("open the file descriptors.") }, { .ml_name = "poll", .ml_meth = (PyCFunction)pyrf_evlist__poll, .ml_flags = METH_VARARGS | METH_KEYWORDS, .ml_doc = PyDoc_STR("poll the file descriptor table.") }, { .ml_name = "get_pollfd", .ml_meth = (PyCFunction)pyrf_evlist__get_pollfd, .ml_flags = METH_VARARGS | METH_KEYWORDS, .ml_doc = PyDoc_STR("get the poll file descriptor table.") }, { .ml_name = "add", .ml_meth = (PyCFunction)pyrf_evlist__add, .ml_flags = METH_VARARGS | METH_KEYWORDS, .ml_doc = PyDoc_STR("adds an event selector to the list.") }, { .ml_name = "read_on_cpu", .ml_meth = (PyCFunction)pyrf_evlist__read_on_cpu, .ml_flags = METH_VARARGS | METH_KEYWORDS, .ml_doc = PyDoc_STR("reads an event.") }, { .ml_name = NULL, }}; static Py_ssize_t pyrf_evlist__length(PyObject *obj){ struct pyrf_evlist *pevlist = (void *)obj; return pevlist->evlist.core.nr_entries;} static PyObject *pyrf_evlist__item(PyObject *obj, Py_ssize_t i){ struct pyrf_evlist *pevlist = (void *)obj; struct evsel *pos; if (i >= pevlist->evlist.core.nr_entries) return NULL; evlist__for_each_entry(&pevlist->evlist, pos) { if (i-- == 0) break; } return Py_BuildValue("O", container_of(pos, struct pyrf_evsel, evsel));} static PySequenceMethods pyrf_evlist__sequence_methods = { .sq_length = pyrf_evlist__length, .sq_item = pyrf_evlist__item,}; static char pyrf_evlist__doc[] = PyDoc_STR("perf event selector list object."); static PyTypeObject pyrf_evlist__type = { PyVarObject_HEAD_INIT(NULL, 0) .tp_name = "perf.evlist", .tp_basicsize = sizeof(struct pyrf_evlist), .tp_dealloc = (destructor)pyrf_evlist__delete, .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, .tp_as_sequence = &pyrf_evlist__sequence_methods, .tp_doc = pyrf_evlist__doc, .tp_methods = pyrf_evlist__methods, .tp_init = (initproc)pyrf_evlist__init,}; static int pyrf_evlist__setup_types(void){ pyrf_evlist__type.tp_new = PyType_GenericNew; return PyType_Ready(&pyrf_evlist__type);} #define PERF_CONST(name) { #name, PERF_##name } static struct { const char *name; int value;} perf__constants[] = { PERF_CONST(TYPE_HARDWARE), PERF_CONST(TYPE_SOFTWARE), PERF_CONST(TYPE_TRACEPOINT), PERF_CONST(TYPE_HW_CACHE), PERF_CONST(TYPE_RAW), PERF_CONST(TYPE_BREAKPOINT), PERF_CONST(COUNT_HW_CPU_CYCLES), PERF_CONST(COUNT_HW_INSTRUCTIONS), PERF_CONST(COUNT_HW_CACHE_REFERENCES), PERF_CONST(COUNT_HW_CACHE_MISSES), PERF_CONST(COUNT_HW_BRANCH_INSTRUCTIONS), PERF_CONST(COUNT_HW_BRANCH_MISSES), PERF_CONST(COUNT_HW_BUS_CYCLES), PERF_CONST(COUNT_HW_CACHE_L1D), PERF_CONST(COUNT_HW_CACHE_L1I), PERF_CONST(COUNT_HW_CACHE_LL), PERF_CONST(COUNT_HW_CACHE_DTLB), PERF_CONST(COUNT_HW_CACHE_ITLB), PERF_CONST(COUNT_HW_CACHE_BPU), PERF_CONST(COUNT_HW_CACHE_OP_READ), PERF_CONST(COUNT_HW_CACHE_OP_WRITE), PERF_CONST(COUNT_HW_CACHE_OP_PREFETCH), PERF_CONST(COUNT_HW_CACHE_RESULT_ACCESS), PERF_CONST(COUNT_HW_CACHE_RESULT_MISS), PERF_CONST(COUNT_HW_STALLED_CYCLES_FRONTEND), PERF_CONST(COUNT_HW_STALLED_CYCLES_BACKEND), PERF_CONST(COUNT_SW_CPU_CLOCK), PERF_CONST(COUNT_SW_TASK_CLOCK), PERF_CONST(COUNT_SW_PAGE_FAULTS), PERF_CONST(COUNT_SW_CONTEXT_SWITCHES), PERF_CONST(COUNT_SW_CPU_MIGRATIONS), PERF_CONST(COUNT_SW_PAGE_FAULTS_MIN), PERF_CONST(COUNT_SW_PAGE_FAULTS_MAJ), PERF_CONST(COUNT_SW_ALIGNMENT_FAULTS), PERF_CONST(COUNT_SW_EMULATION_FAULTS), PERF_CONST(COUNT_SW_DUMMY), PERF_CONST(SAMPLE_IP), PERF_CONST(SAMPLE_TID), PERF_CONST(SAMPLE_TIME), PERF_CONST(SAMPLE_ADDR), PERF_CONST(SAMPLE_READ), PERF_CONST(SAMPLE_CALLCHAIN), PERF_CONST(SAMPLE_ID), PERF_CONST(SAMPLE_CPU), PERF_CONST(SAMPLE_PERIOD), PERF_CONST(SAMPLE_STREAM_ID), PERF_CONST(SAMPLE_RAW), PERF_CONST(FORMAT_TOTAL_TIME_ENABLED), PERF_CONST(FORMAT_TOTAL_TIME_RUNNING), PERF_CONST(FORMAT_ID), PERF_CONST(FORMAT_GROUP), PERF_CONST(RECORD_MMAP), PERF_CONST(RECORD_LOST), PERF_CONST(RECORD_COMM), PERF_CONST(RECORD_EXIT), PERF_CONST(RECORD_THROTTLE), PERF_CONST(RECORD_UNTHROTTLE), PERF_CONST(RECORD_FORK), PERF_CONST(RECORD_READ), PERF_CONST(RECORD_SAMPLE), PERF_CONST(RECORD_MMAP2), PERF_CONST(RECORD_AUX), PERF_CONST(RECORD_ITRACE_START), PERF_CONST(RECORD_LOST_SAMPLES), PERF_CONST(RECORD_SWITCH), PERF_CONST(RECORD_SWITCH_CPU_WIDE), PERF_CONST(RECORD_MISC_SWITCH_OUT), { .name = NULL, },}; static PyObject *pyrf__tracepoint(struct pyrf_evsel *pevsel, PyObject *args, PyObject *kwargs){ struct tep_event *tp_format; static char *kwlist[] = { "sys", "name", NULL }; char *sys = NULL; char *name = NULL; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ss", kwlist, &sys, &name)) return NULL; tp_format = trace_event__tp_format(sys, name); if (IS_ERR(tp_format)) return _PyLong_FromLong(-1); return _PyLong_FromLong(tp_format->id);} static PyMethodDef perf__methods[] = { { .ml_name = "tracepoint", .ml_meth = (PyCFunction) pyrf__tracepoint, .ml_flags = METH_VARARGS | METH_KEYWORDS, .ml_doc = PyDoc_STR("Get tracepoint config.") }, { .ml_name = NULL, }}; #if PY_MAJOR_VERSION < 3PyMODINIT_FUNC initperf(void)#elsePyMODINIT_FUNC PyInit_perf(void)#endif{ PyObject *obj; int i; PyObject *dict;#if PY_MAJOR_VERSION < 3 PyObject *module = Py_InitModule("perf", perf__methods);#else static struct PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, "perf", /* m_name */ "", /* m_doc */ -1, /* m_size */ perf__methods, /* m_methods */ NULL, /* m_reload */ NULL, /* m_traverse */ NULL, /* m_clear */ NULL, /* m_free */ }; PyObject *module = PyModule_Create(&moduledef);#endif if (module == NULL || pyrf_event__setup_types() < 0 || pyrf_evlist__setup_types() < 0 || pyrf_evsel__setup_types() < 0 || pyrf_thread_map__setup_types() < 0 || pyrf_cpu_map__setup_types() < 0)#if PY_MAJOR_VERSION < 3 return;#else return module;#endif /* The page_size is placed in util object. */ page_size = sysconf(_SC_PAGE_SIZE); Py_INCREF(&pyrf_evlist__type); PyModule_AddObject(module, "evlist", (PyObject*)&pyrf_evlist__type); Py_INCREF(&pyrf_evsel__type); PyModule_AddObject(module, "evsel", (PyObject*)&pyrf_evsel__type); Py_INCREF(&pyrf_mmap_event__type); PyModule_AddObject(module, "mmap_event", (PyObject *)&pyrf_mmap_event__type); Py_INCREF(&pyrf_lost_event__type); PyModule_AddObject(module, "lost_event", (PyObject *)&pyrf_lost_event__type); Py_INCREF(&pyrf_comm_event__type); PyModule_AddObject(module, "comm_event", (PyObject *)&pyrf_comm_event__type); Py_INCREF(&pyrf_task_event__type); PyModule_AddObject(module, "task_event", (PyObject *)&pyrf_task_event__type); Py_INCREF(&pyrf_throttle_event__type); PyModule_AddObject(module, "throttle_event", (PyObject *)&pyrf_throttle_event__type); Py_INCREF(&pyrf_task_event__type); PyModule_AddObject(module, "task_event", (PyObject *)&pyrf_task_event__type); Py_INCREF(&pyrf_read_event__type); PyModule_AddObject(module, "read_event", (PyObject *)&pyrf_read_event__type); Py_INCREF(&pyrf_sample_event__type); PyModule_AddObject(module, "sample_event", (PyObject *)&pyrf_sample_event__type); Py_INCREF(&pyrf_context_switch_event__type); PyModule_AddObject(module, "switch_event", (PyObject *)&pyrf_context_switch_event__type); Py_INCREF(&pyrf_thread_map__type); PyModule_AddObject(module, "thread_map", (PyObject*)&pyrf_thread_map__type); Py_INCREF(&pyrf_cpu_map__type); PyModule_AddObject(module, "cpu_map", (PyObject*)&pyrf_cpu_map__type); dict = PyModule_GetDict(module); if (dict == NULL) goto error; for (i = 0; perf__constants[i].name != NULL; i++) { obj = _PyLong_FromLong(perf__constants[i].value); if (obj == NULL) goto error; PyDict_SetItemString(dict, perf__constants[i].name, obj); Py_DECREF(obj); } error: if (PyErr_Occurred()) PyErr_SetString(PyExc_ImportError, "perf: Init failed!");#if PY_MAJOR_VERSION >= 3 return module;#endif} /* * Dummy, to avoid dragging all the test_attr infrastructure in the python * binding. */void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu, int fd, int group_fd, unsigned long flags){}Lines 1001–1391 of 1391. Previous lines
if (md->core.cpu == cpu) return md; } return NULL; } static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist, PyObject *args, PyObject *kwargs) { struct evlist *evlist = &pevlist->evlist; union perf_event *event; int sample_id_all = 1, cpu; static char *kwlist[] = { "cpu", "sample_id_all", NULL }; struct mmap *md; int err; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i|i", kwlist, &cpu, &sample_id_all)) return NULL; md = get_md(evlist, cpu); if (!md) return NULL; if (perf_mmap__read_init(&md->core) < 0) goto end; event = perf_mmap__read_event(&md->core); if (event != NULL) { PyObject *pyevent = pyrf_event__new(event); struct pyrf_event *pevent = (struct pyrf_event *)pyevent; struct evsel *evsel; if (pyevent == NULL) return PyErr_NoMemory(); evsel = perf_evlist__event2evsel(evlist, event); if (!evsel) { Py_INCREF(Py_None); return Py_None; } pevent->evsel = evsel; err = evsel__parse_sample(evsel, event, &pevent->sample); /* Consume the even only after we parsed it out. */ perf_mmap__consume(&md->core); if (err) return PyErr_Format(PyExc_OSError, "perf: can't parse sample, err=%d", err); return pyevent; } end: Py_INCREF(Py_None); return Py_None; } static PyObject *pyrf_evlist__open(struct pyrf_evlist *pevlist, PyObject *args, PyObject *kwargs) { struct evlist *evlist = &pevlist->evlist; int group = 0; static char *kwlist[] = { "group", NULL }; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OOii", kwlist, &group)) return NULL; if (group) perf_evlist__set_leader(evlist); if (evlist__open(evlist) < 0) { PyErr_SetFromErrno(PyExc_OSError); return NULL; } Py_INCREF(Py_None); return Py_None; } static PyMethodDef pyrf_evlist__methods[] = { { .ml_name = "mmap", .ml_meth = (PyCFunction)pyrf_evlist__mmap, .ml_flags = METH_VARARGS | METH_KEYWORDS, .ml_doc = PyDoc_STR("mmap the file descriptor table.") }, { .ml_name = "open", .ml_meth = (PyCFunction)pyrf_evlist__open, .ml_flags = METH_VARARGS | METH_KEYWORDS, .ml_doc = PyDoc_STR("open the file descriptors.") }, { .ml_name = "poll", .ml_meth = (PyCFunction)pyrf_evlist__poll, .ml_flags = METH_VARARGS | METH_KEYWORDS, .ml_doc = PyDoc_STR("poll the file descriptor table.") }, { .ml_name = "get_pollfd", .ml_meth = (PyCFunction)pyrf_evlist__get_pollfd, .ml_flags = METH_VARARGS | METH_KEYWORDS, .ml_doc = PyDoc_STR("get the poll file descriptor table.") }, { .ml_name = "add", .ml_meth = (PyCFunction)pyrf_evlist__add, .ml_flags = METH_VARARGS | METH_KEYWORDS, .ml_doc = PyDoc_STR("adds an event selector to the list.") }, { .ml_name = "read_on_cpu", .ml_meth = (PyCFunction)pyrf_evlist__read_on_cpu, .ml_flags = METH_VARARGS | METH_KEYWORDS, .ml_doc = PyDoc_STR("reads an event.") }, { .ml_name = NULL, } }; static Py_ssize_t pyrf_evlist__length(PyObject *obj) { struct pyrf_evlist *pevlist = (void *)obj; return pevlist->evlist.core.nr_entries; } static PyObject *pyrf_evlist__item(PyObject *obj, Py_ssize_t i) { struct pyrf_evlist *pevlist = (void *)obj; struct evsel *pos; if (i >= pevlist->evlist.core.nr_entries) return NULL; evlist__for_each_entry(&pevlist->evlist, pos) { if (i-- == 0) break; } return Py_BuildValue("O", container_of(pos, struct pyrf_evsel, evsel)); } static PySequenceMethods pyrf_evlist__sequence_methods = { .sq_length = pyrf_evlist__length, .sq_item = pyrf_evlist__item, }; static char pyrf_evlist__doc[] = PyDoc_STR("perf event selector list object."); static PyTypeObject pyrf_evlist__type = { PyVarObject_HEAD_INIT(NULL, 0) .tp_name = "perf.evlist", .tp_basicsize = sizeof(struct pyrf_evlist), .tp_dealloc = (destructor)pyrf_evlist__delete, .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, .tp_as_sequence = &pyrf_evlist__sequence_methods, .tp_doc = pyrf_evlist__doc, .tp_methods = pyrf_evlist__methods, .tp_init = (initproc)pyrf_evlist__init, }; static int pyrf_evlist__setup_types(void) { pyrf_evlist__type.tp_new = PyType_GenericNew; return PyType_Ready(&pyrf_evlist__type); } #define PERF_CONST(name) { #name, PERF_##name } static struct { const char *name; int value; } perf__constants[] = { PERF_CONST(TYPE_HARDWARE), PERF_CONST(TYPE_SOFTWARE), PERF_CONST(TYPE_TRACEPOINT), PERF_CONST(TYPE_HW_CACHE), PERF_CONST(TYPE_RAW), PERF_CONST(TYPE_BREAKPOINT), PERF_CONST(COUNT_HW_CPU_CYCLES), PERF_CONST(COUNT_HW_INSTRUCTIONS), PERF_CONST(COUNT_HW_CACHE_REFERENCES), PERF_CONST(COUNT_HW_CACHE_MISSES), PERF_CONST(COUNT_HW_BRANCH_INSTRUCTIONS), PERF_CONST(COUNT_HW_BRANCH_MISSES), PERF_CONST(COUNT_HW_BUS_CYCLES), PERF_CONST(COUNT_HW_CACHE_L1D), PERF_CONST(COUNT_HW_CACHE_L1I), PERF_CONST(COUNT_HW_CACHE_LL), PERF_CONST(COUNT_HW_CACHE_DTLB), PERF_CONST(COUNT_HW_CACHE_ITLB), PERF_CONST(COUNT_HW_CACHE_BPU), PERF_CONST(COUNT_HW_CACHE_OP_READ), PERF_CONST(COUNT_HW_CACHE_OP_WRITE), PERF_CONST(COUNT_HW_CACHE_OP_PREFETCH), PERF_CONST(COUNT_HW_CACHE_RESULT_ACCESS), PERF_CONST(COUNT_HW_CACHE_RESULT_MISS), PERF_CONST(COUNT_HW_STALLED_CYCLES_FRONTEND), PERF_CONST(COUNT_HW_STALLED_CYCLES_BACKEND), PERF_CONST(COUNT_SW_CPU_CLOCK), PERF_CONST(COUNT_SW_TASK_CLOCK), PERF_CONST(COUNT_SW_PAGE_FAULTS), PERF_CONST(COUNT_SW_CONTEXT_SWITCHES), PERF_CONST(COUNT_SW_CPU_MIGRATIONS), PERF_CONST(COUNT_SW_PAGE_FAULTS_MIN), PERF_CONST(COUNT_SW_PAGE_FAULTS_MAJ), PERF_CONST(COUNT_SW_ALIGNMENT_FAULTS), PERF_CONST(COUNT_SW_EMULATION_FAULTS), PERF_CONST(COUNT_SW_DUMMY), PERF_CONST(SAMPLE_IP), PERF_CONST(SAMPLE_TID), PERF_CONST(SAMPLE_TIME), PERF_CONST(SAMPLE_ADDR), PERF_CONST(SAMPLE_READ), PERF_CONST(SAMPLE_CALLCHAIN), PERF_CONST(SAMPLE_ID), PERF_CONST(SAMPLE_CPU), PERF_CONST(SAMPLE_PERIOD), PERF_CONST(SAMPLE_STREAM_ID), PERF_CONST(SAMPLE_RAW), PERF_CONST(FORMAT_TOTAL_TIME_ENABLED), PERF_CONST(FORMAT_TOTAL_TIME_RUNNING), PERF_CONST(FORMAT_ID), PERF_CONST(FORMAT_GROUP), PERF_CONST(RECORD_MMAP), PERF_CONST(RECORD_LOST), PERF_CONST(RECORD_COMM), PERF_CONST(RECORD_EXIT), PERF_CONST(RECORD_THROTTLE), PERF_CONST(RECORD_UNTHROTTLE), PERF_CONST(RECORD_FORK), PERF_CONST(RECORD_READ), PERF_CONST(RECORD_SAMPLE), PERF_CONST(RECORD_MMAP2), PERF_CONST(RECORD_AUX), PERF_CONST(RECORD_ITRACE_START), PERF_CONST(RECORD_LOST_SAMPLES), PERF_CONST(RECORD_SWITCH), PERF_CONST(RECORD_SWITCH_CPU_WIDE), PERF_CONST(RECORD_MISC_SWITCH_OUT), { .name = NULL, }, }; static PyObject *pyrf__tracepoint(struct pyrf_evsel *pevsel, PyObject *args, PyObject *kwargs) { struct tep_event *tp_format; static char *kwlist[] = { "sys", "name", NULL }; char *sys = NULL; char *name = NULL; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ss", kwlist, &sys, &name)) return NULL; tp_format = trace_event__tp_format(sys, name); if (IS_ERR(tp_format)) return _PyLong_FromLong(-1); return _PyLong_FromLong(tp_format->id); } static PyMethodDef perf__methods[] = { { .ml_name = "tracepoint", .ml_meth = (PyCFunction) pyrf__tracepoint, .ml_flags = METH_VARARGS | METH_KEYWORDS, .ml_doc = PyDoc_STR("Get tracepoint config.") }, { .ml_name = NULL, } }; #if PY_MAJOR_VERSION < 3 PyMODINIT_FUNC initperf(void) #else PyMODINIT_FUNC PyInit_perf(void) #endif { PyObject *obj; int i; PyObject *dict; #if PY_MAJOR_VERSION < 3 PyObject *module = Py_InitModule("perf", perf__methods); #else static struct PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, "perf", /* m_name */ "", /* m_doc */ -1, /* m_size */ perf__methods, /* m_methods */ NULL, /* m_reload */ NULL, /* m_traverse */ NULL, /* m_clear */ NULL, /* m_free */ }; PyObject *module = PyModule_Create(&moduledef); #endif if (module == NULL || pyrf_event__setup_types() < 0 || pyrf_evlist__setup_types() < 0 || pyrf_evsel__setup_types() < 0 || pyrf_thread_map__setup_types() < 0 || pyrf_cpu_map__setup_types() < 0) #if PY_MAJOR_VERSION < 3 return; #else return module; #endif /* The page_size is placed in util object. */ page_size = sysconf(_SC_PAGE_SIZE); Py_INCREF(&pyrf_evlist__type); PyModule_AddObject(module, "evlist", (PyObject*)&pyrf_evlist__type); Py_INCREF(&pyrf_evsel__type); PyModule_AddObject(module, "evsel", (PyObject*)&pyrf_evsel__type); Py_INCREF(&pyrf_mmap_event__type); PyModule_AddObject(module, "mmap_event", (PyObject *)&pyrf_mmap_event__type); Py_INCREF(&pyrf_lost_event__type); PyModule_AddObject(module, "lost_event", (PyObject *)&pyrf_lost_event__type); Py_INCREF(&pyrf_comm_event__type); PyModule_AddObject(module, "comm_event", (PyObject *)&pyrf_comm_event__type); Py_INCREF(&pyrf_task_event__type); PyModule_AddObject(module, "task_event", (PyObject *)&pyrf_task_event__type); Py_INCREF(&pyrf_throttle_event__type); PyModule_AddObject(module, "throttle_event", (PyObject *)&pyrf_throttle_event__type); Py_INCREF(&pyrf_task_event__type); PyModule_AddObject(module, "task_event", (PyObject *)&pyrf_task_event__type); Py_INCREF(&pyrf_read_event__type); PyModule_AddObject(module, "read_event", (PyObject *)&pyrf_read_event__type); Py_INCREF(&pyrf_sample_event__type); PyModule_AddObject(module, "sample_event", (PyObject *)&pyrf_sample_event__type); Py_INCREF(&pyrf_context_switch_event__type); PyModule_AddObject(module, "switch_event", (PyObject *)&pyrf_context_switch_event__type); Py_INCREF(&pyrf_thread_map__type); PyModule_AddObject(module, "thread_map", (PyObject*)&pyrf_thread_map__type); Py_INCREF(&pyrf_cpu_map__type); PyModule_AddObject(module, "cpu_map", (PyObject*)&pyrf_cpu_map__type); dict = PyModule_GetDict(module); if (dict == NULL) goto error; for (i = 0; perf__constants[i].name != NULL; i++) { obj = _PyLong_FromLong(perf__constants[i].value); if (obj == NULL) goto error; PyDict_SetItemString(dict, perf__constants[i].name, obj); Py_DECREF(obj); } error: if (PyErr_Occurred()) PyErr_SetString(PyExc_ImportError, "perf: Init failed!"); #if PY_MAJOR_VERSION >= 3 return module; #endif } /* * Dummy, to avoid dragging all the test_attr infrastructure in the python * binding. */ void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu, int fd, int group_fd, unsigned long flags) { }