tools/perf/util/scripting-engines/trace-event-python.c
Source file repositories/reference/linux-study-clean/tools/perf/util/scripting-engines/trace-event-python.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/scripting-engines/trace-event-python.c- Extension
.c- Size
- 59770 bytes
- Lines
- 2210
- 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.hinttypes.hstdio.hstdlib.hstring.hstdbool.herrno.hlinux/bitmap.hlinux/compiler.hlinux/time64.hevent-parse.h../build-id.h../counts.h../debug.h../dso.h../callchain.h../env.h../evsel.h../event.h../thread.h../comm.h../machine.h../mem-info.h../db-export.h../thread-stack.h../trace-event.h../call-path.hdwarf-regs.hmap.hsymbol.hthread_map.hprint_binary.h
Detected Declarations
struct tablesfunction handler_call_diefunction PyDict_SetItemStringfunction call_objectfunction try_call_objectfunction get_argument_countfunction define_valuefunction define_valuesfunction define_fieldfunction define_event_symbolsfunction get_offsetfunction get_symofffunction get_br_mspredfunction set_sample_read_in_dictfunction sample_read_group__for_eachfunction set_sample_datasrc_in_dictfunction regs_mapfunction for_each_set_bitfunction set_regs_in_dictfunction set_sym_in_dictfunction set_sample_flagsfunction python_process_sample_flagsfunction python_process_tracepointfunction python_process_tracepointfunction tuple_set_s64function tuple_set_u64function tuple_set_u32function tuple_set_s32function tuple_set_boolfunction tuple_set_stringfunction tuple_set_bytesfunction python_export_evselfunction python_export_machinefunction python_export_threadfunction python_export_commfunction python_export_comm_threadfunction python_export_dsofunction python_export_symbolfunction python_export_branch_typefunction python_export_sample_tablefunction python_export_synthfunction python_export_samplefunction python_export_call_pathfunction python_export_call_returnfunction python_export_context_switchfunction python_process_call_returnfunction python_process_general_eventfunction python_process_event
Annotated Snippet
call_object(tables->context_switch_handler, t, "context_switch");
Py_DECREF(t);
return 0;
}
static int python_process_call_return(struct call_return *cr, u64 *parent_db_id,
void *data)
{
struct db_export *dbe = data;
return db_export__call_return(dbe, cr, parent_db_id);
}
static void python_process_general_event(struct perf_sample *sample,
struct evsel *evsel,
struct addr_location *al,
struct addr_location *addr_al)
{
PyObject *handler, *t, *dict, *callchain;
static char handler_name[64];
unsigned n = 0;
snprintf(handler_name, sizeof(handler_name), "%s", "process_event");
handler = get_handler(handler_name);
if (!handler)
return;
/*
* Use the MAX_FIELDS to make the function expandable, though
* currently there is only one item for the tuple.
*/
t = PyTuple_New(MAX_FIELDS);
if (!t)
Py_FatalError("couldn't create Python tuple");
/* ip unwinding */
callchain = python_process_callchain(sample, evsel, al);
dict = get_perf_sample_dict(sample, evsel, al, addr_al, callchain);
PyTuple_SetItem(t, n++, dict);
if (_PyTuple_Resize(&t, n) == -1)
Py_FatalError("error resizing Python tuple");
call_object(handler, t, handler_name);
Py_DECREF(t);
}
static void python_process_event(union perf_event *event,
struct perf_sample *sample,
struct evsel *evsel,
struct addr_location *al,
struct addr_location *addr_al)
{
struct tables *tables = &tables_global;
scripting_context__update(scripting_context, event, sample, evsel, al, addr_al);
switch (evsel->core.attr.type) {
case PERF_TYPE_TRACEPOINT:
python_process_tracepoint(sample, evsel, al, addr_al);
break;
/* Reserve for future process_hw/sw/raw APIs */
default:
if (tables->db_export_mode)
db_export__sample(&tables->dbe, event, sample, evsel, al, addr_al);
else
python_process_general_event(sample, evsel, al, addr_al);
}
}
static void python_process_throttle(union perf_event *event,
struct perf_sample *sample,
struct machine *machine)
{
const char *handler_name;
PyObject *handler, *t;
if (event->header.type == PERF_RECORD_THROTTLE)
handler_name = "throttle";
else
handler_name = "unthrottle";
handler = get_handler(handler_name);
if (!handler)
return;
t = tuple_new(6);
Annotation
- Immediate include surface: `Python.h`, `inttypes.h`, `stdio.h`, `stdlib.h`, `string.h`, `stdbool.h`, `errno.h`, `linux/bitmap.h`.
- Detected declarations: `struct tables`, `function handler_call_die`, `function PyDict_SetItemString`, `function call_object`, `function try_call_object`, `function get_argument_count`, `function define_value`, `function define_values`, `function define_field`, `function define_event_symbols`.
- 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.