tools/perf/util/python.c
Source file repositories/reference/linux-study-clean/tools/perf/util/python.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/python.c- Extension
.c- Size
- 63750 bytes
- Lines
- 2330
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
Python.hstructmember.hinttypes.hpoll.hlinux/err.hperf/cpumap.hevent-parse.hperf/mmap.hcallchain.hcounts.hevlist.hevsel.hevent.hexpr.hprint_binary.hrecord.hstrbuf.hthread_map.htp_pmu.htrace-event.hmetricgroup.hmmap.hutil/sample.hinternal/lib.h
Detected Declarations
struct pyrf_eventstruct pyrf_cpu_mapstruct pyrf_thread_mapstruct pyrf_pmustruct pyrf_pmu_iteratorstruct pyrf_counts_valuesstruct pyrf_evselstruct pyrf_evliststruct perf_constantfunction pyrf_sample_event__deletefunction is_tracepointfunction tracepoint_fieldfunction get_tracepoint_fieldfunction pyrf_sample_event__getattrofunction pyrf_event__setup_typesfunction pyrf_cpu_map__initfunction pyrf_cpu_map__deletefunction pyrf_cpu_map__lengthfunction pyrf_cpu_map__setup_typesfunction pyrf_thread_map__initfunction pyrf_thread_map__deletefunction pyrf_thread_map__lengthfunction pyrf_thread_map__setup_typesfunction pyrf_pmu__deletefunction add_to_dictfunction pyrf_pmu__events_cbfunction pyrf_pmu__setup_typesfunction pyrf_pmu_iterator__deallocfunction pyrf_pmu_iterator__setup_typesfunction pyrf_counts_values__deletefunction pyrf_counts_values_set_valuesfunction pyrf_counts_values__setup_typesfunction pyrf_evsel__initfunction pyrf_evsel__deletefunction evsel__ensure_countsfunction pyrf_evsel__setup_typesfunction pyrf_evlist__initfunction pyrf_evlist__deletefunction list_for_eachfunction prepare_metricfunction evlist__for_each_entryfunction list_for_eachfunction evlist__for_each_entryfunction pyrf_evlist__lengthfunction evlist__for_each_entryfunction pyrf_evlist__setup_typesfunction evlist__posfunction evlist__for_each_entry
Annotated Snippet
static const char pyrf_context_switch_event__doc[] = PyDoc_STR("perf context_switch event object.");
static PyMemberDef pyrf_context_switch_event__members[] = {
sample_members
member_def(perf_event_header, type, T_UINT, "event type"),
member_def(perf_record_switch, next_prev_pid, T_UINT, "next/prev pid"),
member_def(perf_record_switch, next_prev_tid, T_UINT, "next/prev tid"),
{ .name = NULL, },
};
static PyObject *pyrf_context_switch_event__repr(const struct pyrf_event *pevent)
{
PyObject *ret;
char *s;
if (asprintf(&s, "{ type: context_switch, next_prev_pid: %u, next_prev_tid: %u, switch_out: %u }",
pevent->event.context_switch.next_prev_pid,
pevent->event.context_switch.next_prev_tid,
!!(pevent->event.header.misc & PERF_RECORD_MISC_SWITCH_OUT)) < 0) {
ret = PyErr_NoMemory();
} else {
ret = PyUnicode_FromString(s);
free(s);
}
return ret;
}
static PyTypeObject pyrf_context_switch_event__type = {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "perf.context_switch_event",
.tp_basicsize = sizeof(struct pyrf_event),
.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
.tp_doc = pyrf_context_switch_event__doc,
.tp_members = pyrf_context_switch_event__members,
.tp_repr = (reprfunc)pyrf_context_switch_event__repr,
};
static int pyrf_event__setup_types(void)
{
int err;
pyrf_mmap_event__type.tp_new =
pyrf_task_event__type.tp_new =
pyrf_comm_event__type.tp_new =
pyrf_lost_event__type.tp_new =
pyrf_read_event__type.tp_new =
pyrf_sample_event__type.tp_new =
pyrf_context_switch_event__type.tp_new =
pyrf_throttle_event__type.tp_new = PyType_GenericNew;
pyrf_sample_event__type.tp_dealloc = (destructor)pyrf_sample_event__delete,
err = PyType_Ready(&pyrf_mmap_event__type);
if (err < 0)
goto out;
err = PyType_Ready(&pyrf_lost_event__type);
if (err < 0)
goto out;
err = PyType_Ready(&pyrf_task_event__type);
if (err < 0)
goto out;
err = PyType_Ready(&pyrf_comm_event__type);
if (err < 0)
goto out;
err = PyType_Ready(&pyrf_throttle_event__type);
if (err < 0)
goto out;
err = PyType_Ready(&pyrf_read_event__type);
if (err < 0)
goto out;
err = PyType_Ready(&pyrf_sample_event__type);
if (err < 0)
goto out;
err = PyType_Ready(&pyrf_context_switch_event__type);
if (err < 0)
goto out;
out:
return err;
}
static PyTypeObject *pyrf_event__type[] = {
[PERF_RECORD_MMAP] = &pyrf_mmap_event__type,
[PERF_RECORD_LOST] = &pyrf_lost_event__type,
[PERF_RECORD_COMM] = &pyrf_comm_event__type,
[PERF_RECORD_EXIT] = &pyrf_task_event__type,
[PERF_RECORD_THROTTLE] = &pyrf_throttle_event__type,
[PERF_RECORD_UNTHROTTLE] = &pyrf_throttle_event__type,
[PERF_RECORD_FORK] = &pyrf_task_event__type,
[PERF_RECORD_READ] = &pyrf_read_event__type,
[PERF_RECORD_SAMPLE] = &pyrf_sample_event__type,
[PERF_RECORD_SWITCH] = &pyrf_context_switch_event__type,
Annotation
- Immediate include surface: `Python.h`, `structmember.h`, `inttypes.h`, `poll.h`, `linux/err.h`, `perf/cpumap.h`, `event-parse.h`, `perf/mmap.h`.
- Detected declarations: `struct pyrf_event`, `struct pyrf_cpu_map`, `struct pyrf_thread_map`, `struct pyrf_pmu`, `struct pyrf_pmu_iterator`, `struct pyrf_counts_values`, `struct pyrf_evsel`, `struct pyrf_evlist`, `struct perf_constant`, `function pyrf_sample_event__delete`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.