Linux Perf
trace-event-python.c File Reference
#include <Python.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <errno.h>
#include <linux/bitmap.h>
#include <linux/compiler.h>
#include <linux/time64.h>
#include "../../perf.h"
#include "../debug.h"
#include "../callchain.h"
#include "../evsel.h"
#include "../util.h"
#include "../event.h"
#include "../thread.h"
#include "../comm.h"
#include "../machine.h"
#include "../db-export.h"
#include "../thread-stack.h"
#include "../trace-event.h"
#include "../call-path.h"
#include "thread_map.h"
#include "cpumap.h"
#include "print_binary.h"
#include "stat.h"
#include "mem-events.h"
Include dependency graph for trace-event-python.c:

Go to the source code of this file.

Classes

struct  tables
 

Macros

#define _PyUnicode_FromString(arg)   PyString_FromString(arg)
 
#define _PyUnicode_FromStringAndSize(arg1, arg2)   PyString_FromStringAndSize((arg1), (arg2))
 
#define _PyBytes_FromStringAndSize(arg1, arg2)   PyString_FromStringAndSize((arg1), (arg2))
 
#define _PyLong_FromLong(arg)   PyInt_FromLong(arg)
 
#define _PyLong_AsLong(arg)   PyInt_AsLong(arg)
 
#define _PyCapsule_New(arg1, arg2, arg3)   PyCObject_FromVoidPtr((arg1), (arg2))
 
#define TRACE_EVENT_TYPE_MAX   ((1 << (sizeof(unsigned short) * 8)) - 1)
 
#define MAX_FIELDS   64
 
#define N_COMMON_FIELDS   7
 
#define SET_TABLE_HANDLER_(name, handler_name, table_name)
 
#define SET_TABLE_HANDLER(name)   SET_TABLE_HANDLER_(name, name ## _handler, name ## _table)
 

Functions

PyMODINIT_FUNC initperf_trace_context (void)
 
static DECLARE_BITMAP (events_defined, TRACE_EVENT_TYPE_MAX)
 
static void handler_call_die (const char *handler_name) __noreturn
 
static void pydict_set_item_string_decref (PyObject *dict, const char *key, PyObject *val)
 
static PyObject * get_handler (const char *handler_name)
 
static int get_argument_count (PyObject *handler)
 
static void call_object (PyObject *handler, PyObject *args, const char *die_msg)
 
static void try_call_object (const char *handler_name, PyObject *args)
 
static void define_value (enum print_arg_type field_type, const char *ev_name, const char *field_name, const char *field_value, const char *field_str)
 
static void define_values (enum print_arg_type field_type, struct print_flag_sym *field, const char *ev_name, const char *field_name)
 
static void define_field (enum print_arg_type field_type, const char *ev_name, const char *field_name, const char *delim)
 
static void define_event_symbols (struct event_format *event, const char *ev_name, struct print_arg *args)
 
static PyObject * get_field_numeric_entry (struct event_format *event, struct format_field *field, void *data)
 
static const char * get_dsoname (struct map *map)
 
static PyObject * python_process_callchain (struct perf_sample *sample, struct perf_evsel *evsel, struct addr_location *al)
 
static PyObject * python_process_brstack (struct perf_sample *sample, struct thread *thread)
 
static unsigned long get_offset (struct symbol *sym, struct addr_location *al)
 
static int get_symoff (struct symbol *sym, struct addr_location *al, bool print_off, char *bf, int size)
 
static int get_br_mspred (struct branch_flags *flags, char *bf, int size)
 
static PyObject * python_process_brstacksym (struct perf_sample *sample, struct thread *thread)
 
static PyObject * get_sample_value_as_tuple (struct sample_read_value *value)
 
static void set_sample_read_in_dict (PyObject *dict_sample, struct perf_sample *sample, struct perf_evsel *evsel)
 
static void set_sample_datasrc_in_dict (PyObject *dict, struct perf_sample *sample)
 
static int regs_map (struct regs_dump *regs, uint64_t mask, char *bf, int size)
 
static void set_regs_in_dict (PyObject *dict, struct perf_sample *sample, struct perf_evsel *evsel)
 
static PyObject * get_perf_sample_dict (struct perf_sample *sample, struct perf_evsel *evsel, struct addr_location *al, PyObject *callchain)
 
static void python_process_tracepoint (struct perf_sample *sample, struct perf_evsel *evsel, struct addr_location *al)
 
static PyObject * tuple_new (unsigned int sz)
 
static int tuple_set_u64 (PyObject *t, unsigned int pos, u64 val)
 
static int tuple_set_s32 (PyObject *t, unsigned int pos, s32 val)
 
static int tuple_set_string (PyObject *t, unsigned int pos, const char *s)
 
static int python_export_evsel (struct db_export *dbe, struct perf_evsel *evsel)
 
static int python_export_machine (struct db_export *dbe, struct machine *machine)
 
static int python_export_thread (struct db_export *dbe, struct thread *thread, u64 main_thread_db_id, struct machine *machine)
 
static int python_export_comm (struct db_export *dbe, struct comm *comm)
 
static int python_export_comm_thread (struct db_export *dbe, u64 db_id, struct comm *comm, struct thread *thread)
 
static int python_export_dso (struct db_export *dbe, struct dso *dso, struct machine *machine)
 
static int python_export_symbol (struct db_export *dbe, struct symbol *sym, struct dso *dso)
 
static int python_export_branch_type (struct db_export *dbe, u32 branch_type, const char *name)
 
static int python_export_sample (struct db_export *dbe, struct export_sample *es)
 
static int python_export_call_path (struct db_export *dbe, struct call_path *cp)
 
static int python_export_call_return (struct db_export *dbe, struct call_return *cr)
 
static int python_process_call_return (struct call_return *cr, void *data)
 
static void python_process_general_event (struct perf_sample *sample, struct perf_evsel *evsel, struct addr_location *al)
 
static void python_process_event (union perf_event *event, struct perf_sample *sample, struct perf_evsel *evsel, struct addr_location *al)
 
static void get_handler_name (char *str, size_t size, struct perf_evsel *evsel)
 
static void process_stat (struct perf_evsel *counter, int cpu, int thread, u64 tstamp, struct perf_counts_values *count)
 
static void python_process_stat (struct perf_stat_config *config, struct perf_evsel *counter, u64 tstamp)
 
static void python_process_stat_interval (u64 tstamp)
 
static int run_start_sub (void)
 
static void set_table_handlers (struct tables *tables)
 
static void _free_command_line (const char **command_line, int num)
 
static int python_start_script (const char *script, int argc, const char **argv)
 
static int python_flush_script (void)
 
static int python_stop_script (void)
 
static int python_generate_script (struct pevent *pevent, const char *outfile)
 

Variables

struct scripting_contextscripting_context
 
static char * cur_field_name
 
static int zero_flag_atom
 
static PyObject * main_module
 
static PyObject * main_dict
 
static struct tables tables_global
 
struct scripting_ops python_scripting_ops
 

Macro Definition Documentation

◆ _PyBytes_FromStringAndSize

#define _PyBytes_FromStringAndSize (   arg1,
  arg2 
)    PyString_FromStringAndSize((arg1), (arg2))

Definition at line 58 of file trace-event-python.c.

◆ _PyCapsule_New

#define _PyCapsule_New (   arg1,
  arg2,
  arg3 
)    PyCObject_FromVoidPtr((arg1), (arg2))

Definition at line 64 of file trace-event-python.c.

◆ _PyLong_AsLong

#define _PyLong_AsLong (   arg)    PyInt_AsLong(arg)

Definition at line 62 of file trace-event-python.c.

◆ _PyLong_FromLong

#define _PyLong_FromLong (   arg)    PyInt_FromLong(arg)

Definition at line 60 of file trace-event-python.c.

◆ _PyUnicode_FromString

#define _PyUnicode_FromString (   arg)    PyString_FromString(arg)

Definition at line 54 of file trace-event-python.c.

◆ _PyUnicode_FromStringAndSize

#define _PyUnicode_FromStringAndSize (   arg1,
  arg2 
)    PyString_FromStringAndSize((arg1), (arg2))

Definition at line 56 of file trace-event-python.c.

◆ MAX_FIELDS

#define MAX_FIELDS   64

Definition at line 90 of file trace-event-python.c.

◆ N_COMMON_FIELDS

#define N_COMMON_FIELDS   7

Definition at line 91 of file trace-event-python.c.

◆ SET_TABLE_HANDLER

#define SET_TABLE_HANDLER (   name)    SET_TABLE_HANDLER_(name, name ## _handler, name ## _table)

Definition at line 1388 of file trace-event-python.c.

◆ SET_TABLE_HANDLER_

#define SET_TABLE_HANDLER_ (   name,
  handler_name,
  table_name 
)
Value:
do { \
tables->handler_name = get_handler(#table_name); \
if (tables->handler_name) \
tables->dbe.export_ ## name = python_export_ ## name; \
} while (0)
static PyObject * get_handler(const char *handler_name)
const char * name

Definition at line 1382 of file trace-event-python.c.

◆ TRACE_EVENT_TYPE_MAX

#define TRACE_EVENT_TYPE_MAX   ((1 << (sizeof(unsigned short) * 8)) - 1)

Definition at line 85 of file trace-event-python.c.

Function Documentation

◆ _free_command_line()

static void _free_command_line ( const char **  command_line,
int  num 
)
static

Definition at line 1480 of file trace-event-python.c.

Here is the call graph for this function:

◆ call_object()

static void call_object ( PyObject *  handler,
PyObject *  args,
const char *  die_msg 
)
static

Definition at line 177 of file trace-event-python.c.

Here is the call graph for this function:

◆ DECLARE_BITMAP()

static DECLARE_BITMAP ( events_defined  ,
TRACE_EVENT_TYPE_MAX   
)
static

◆ define_event_symbols()

static void define_event_symbols ( struct event_format *  event,
const char *  ev_name,
struct print_arg *  args 
)
static

Definition at line 267 of file trace-event-python.c.

Here is the call graph for this function:

◆ define_field()

static void define_field ( enum print_arg_type  field_type,
const char *  ev_name,
const char *  field_name,
const char *  delim 
)
static

Definition at line 238 of file trace-event-python.c.

Here is the call graph for this function:

◆ define_value()

static void define_value ( enum print_arg_type  field_type,
const char *  ev_name,
const char *  field_name,
const char *  field_value,
const char *  field_str 
)
static

Definition at line 196 of file trace-event-python.c.

Here is the call graph for this function:

◆ define_values()

static void define_values ( enum print_arg_type  field_type,
struct print_flag_sym *  field,
const char *  ev_name,
const char *  field_name 
)
static

Definition at line 226 of file trace-event-python.c.

Here is the call graph for this function:

◆ get_argument_count()

static int get_argument_count ( PyObject *  handler)
static

Definition at line 149 of file trace-event-python.c.

◆ get_br_mspred()

static int get_br_mspred ( struct branch_flags flags,
char *  bf,
int  size 
)
static

Definition at line 545 of file trace-event-python.c.

◆ get_dsoname()

static const char* get_dsoname ( struct map map)
static

Definition at line 376 of file trace-event-python.c.

◆ get_field_numeric_entry()

static PyObject* get_field_numeric_entry ( struct event_format *  event,
struct format_field *  field,
void *  data 
)
static

Definition at line 335 of file trace-event-python.c.

Here is the call graph for this function:

◆ get_handler()

static PyObject* get_handler ( const char *  handler_name)
static

Definition at line 139 of file trace-event-python.c.

◆ get_handler_name()

static void get_handler_name ( char *  str,
size_t  size,
struct perf_evsel evsel 
)
static

Definition at line 1262 of file trace-event-python.c.

Here is the call graph for this function:

◆ get_offset()

static unsigned long get_offset ( struct symbol sym,
struct addr_location al 
)
static

Definition at line 517 of file trace-event-python.c.

◆ get_perf_sample_dict()

static PyObject* get_perf_sample_dict ( struct perf_sample sample,
struct perf_evsel evsel,
struct addr_location al,
PyObject *  callchain 
)
static

Definition at line 720 of file trace-event-python.c.

Here is the call graph for this function:

◆ get_sample_value_as_tuple()

static PyObject* get_sample_value_as_tuple ( struct sample_read_value value)
static

Definition at line 619 of file trace-event-python.c.

◆ get_symoff()

static int get_symoff ( struct symbol sym,
struct addr_location al,
bool  print_off,
char *  bf,
int  size 
)
static

Definition at line 529 of file trace-event-python.c.

Here is the call graph for this function:

◆ handler_call_die()

static void handler_call_die ( const char *  handler_name)
static

Definition at line 119 of file trace-event-python.c.

◆ initperf_trace_context()

PyMODINIT_FUNC initperf_trace_context ( void  )

Definition at line 96 of file Context.c.

◆ process_stat()

static void process_stat ( struct perf_evsel counter,
int  cpu,
int  thread,
u64  tstamp,
struct perf_counts_values count 
)
static

Definition at line 1276 of file trace-event-python.c.

Here is the call graph for this function:

◆ pydict_set_item_string_decref()

static void pydict_set_item_string_decref ( PyObject *  dict,
const char *  key,
PyObject *  val 
)
static

Definition at line 133 of file trace-event-python.c.

◆ python_export_branch_type()

static int python_export_branch_type ( struct db_export dbe,
u32  branch_type,
const char *  name 
)
static

Definition at line 1092 of file trace-event-python.c.

Here is the call graph for this function:

◆ python_export_call_path()

static int python_export_call_path ( struct db_export dbe,
struct call_path cp 
)
static

Definition at line 1148 of file trace-event-python.c.

Here is the call graph for this function:

◆ python_export_call_return()

static int python_export_call_return ( struct db_export dbe,
struct call_return cr 
)
static

Definition at line 1171 of file trace-event-python.c.

Here is the call graph for this function:

◆ python_export_comm()

static int python_export_comm ( struct db_export dbe,
struct comm comm 
)
static

Definition at line 1009 of file trace-event-python.c.

Here is the call graph for this function:

◆ python_export_comm_thread()

static int python_export_comm_thread ( struct db_export dbe,
u64  db_id,
struct comm comm,
struct thread thread 
)
static

Definition at line 1026 of file trace-event-python.c.

Here is the call graph for this function:

◆ python_export_dso()

static int python_export_dso ( struct db_export dbe,
struct dso dso,
struct machine machine 
)
static

Definition at line 1045 of file trace-event-python.c.

Here is the call graph for this function:

◆ python_export_evsel()

static int python_export_evsel ( struct db_export dbe,
struct perf_evsel evsel 
)
static

Definition at line 952 of file trace-event-python.c.

Here is the call graph for this function:

◆ python_export_machine()

static int python_export_machine ( struct db_export dbe,
struct machine machine 
)
static

Definition at line 969 of file trace-event-python.c.

Here is the call graph for this function:

◆ python_export_sample()

static int python_export_sample ( struct db_export dbe,
struct export_sample es 
)
static

Definition at line 1110 of file trace-event-python.c.

Here is the call graph for this function:

◆ python_export_symbol()

static int python_export_symbol ( struct db_export dbe,
struct symbol sym,
struct dso dso 
)
static

Definition at line 1069 of file trace-event-python.c.

Here is the call graph for this function:

◆ python_export_thread()

static int python_export_thread ( struct db_export dbe,
struct thread thread,
u64  main_thread_db_id,
struct machine machine 
)
static

Definition at line 988 of file trace-event-python.c.

Here is the call graph for this function:

◆ python_flush_script()

static int python_flush_script ( void  )
static

Definition at line 1570 of file trace-event-python.c.

Here is the call graph for this function:

◆ python_generate_script()

static int python_generate_script ( struct pevent *  pevent,
const char *  outfile 
)
static

Definition at line 1595 of file trace-event-python.c.

Here is the call graph for this function:

◆ python_process_brstack()

static PyObject* python_process_brstack ( struct perf_sample sample,
struct thread thread 
)
static

Definition at line 459 of file trace-event-python.c.

Here is the call graph for this function:

◆ python_process_brstacksym()

static PyObject* python_process_brstacksym ( struct perf_sample sample,
struct thread thread 
)
static

Definition at line 556 of file trace-event-python.c.

Here is the call graph for this function:

◆ python_process_call_return()

static int python_process_call_return ( struct call_return cr,
void *  data 
)
static

Definition at line 1199 of file trace-event-python.c.

Here is the call graph for this function:

◆ python_process_callchain()

static PyObject* python_process_callchain ( struct perf_sample sample,
struct perf_evsel evsel,
struct addr_location al 
)
static

Definition at line 390 of file trace-event-python.c.

Here is the call graph for this function:

◆ python_process_event()

static void python_process_event ( union perf_event event,
struct perf_sample sample,
struct perf_evsel evsel,
struct addr_location al 
)
static

Definition at line 1242 of file trace-event-python.c.

Here is the call graph for this function:

◆ python_process_general_event()

static void python_process_general_event ( struct perf_sample sample,
struct perf_evsel evsel,
struct addr_location al 
)
static

Definition at line 1206 of file trace-event-python.c.

Here is the call graph for this function:

◆ python_process_stat()

static void python_process_stat ( struct perf_stat_config config,
struct perf_evsel counter,
u64  tstamp 
)
static

Definition at line 1312 of file trace-event-python.c.

Here is the call graph for this function:

◆ python_process_stat_interval()

static void python_process_stat_interval ( u64  tstamp)
static

Definition at line 1334 of file trace-event-python.c.

Here is the call graph for this function:

◆ python_process_tracepoint()

static void python_process_tracepoint ( struct perf_sample sample,
struct perf_evsel evsel,
struct addr_location al 
)
static

Definition at line 789 of file trace-event-python.c.

Here is the call graph for this function:

◆ python_start_script()

static int python_start_script ( const char *  script,
int  argc,
const char **  argv 
)
static

Definition at line 1498 of file trace-event-python.c.

Here is the call graph for this function:

◆ python_stop_script()

static int python_stop_script ( void  )
static

Definition at line 1580 of file trace-event-python.c.

Here is the call graph for this function:

◆ regs_map()

static int regs_map ( struct regs_dump regs,
uint64_t  mask,
char *  bf,
int  size 
)
static

Definition at line 684 of file trace-event-python.c.

Here is the call graph for this function:

◆ run_start_sub()

static int run_start_sub ( void  )
static

Definition at line 1360 of file trace-event-python.c.

Here is the call graph for this function:

◆ set_regs_in_dict()

static void set_regs_in_dict ( PyObject *  dict,
struct perf_sample sample,
struct perf_evsel evsel 
)
static

Definition at line 702 of file trace-event-python.c.

Here is the call graph for this function:

◆ set_sample_datasrc_in_dict()

static void set_sample_datasrc_in_dict ( PyObject *  dict,
struct perf_sample sample 
)
static

Definition at line 669 of file trace-event-python.c.

Here is the call graph for this function:

◆ set_sample_read_in_dict()

static void set_sample_read_in_dict ( PyObject *  dict_sample,
struct perf_sample sample,
struct perf_evsel evsel 
)
static

Definition at line 631 of file trace-event-python.c.

Here is the call graph for this function:

◆ set_table_handlers()

static void set_table_handlers ( struct tables tables)
static

Definition at line 1391 of file trace-event-python.c.

Here is the call graph for this function:

◆ try_call_object()

static void try_call_object ( const char *  handler_name,
PyObject *  args 
)
static

Definition at line 187 of file trace-event-python.c.

Here is the call graph for this function:

◆ tuple_new()

static PyObject* tuple_new ( unsigned int  sz)
static

Definition at line 922 of file trace-event-python.c.

◆ tuple_set_s32()

static int tuple_set_s32 ( PyObject *  t,
unsigned int  pos,
s32  val 
)
static

Definition at line 942 of file trace-event-python.c.

◆ tuple_set_string()

static int tuple_set_string ( PyObject *  t,
unsigned int  pos,
const char *  s 
)
static

Definition at line 947 of file trace-event-python.c.

◆ tuple_set_u64()

static int tuple_set_u64 ( PyObject *  t,
unsigned int  pos,
u64  val 
)
static

Definition at line 932 of file trace-event-python.c.

Variable Documentation

◆ cur_field_name

char* cur_field_name
static

Definition at line 95 of file trace-event-python.c.

◆ main_dict

PyObject * main_dict
static

Definition at line 98 of file trace-event-python.c.

◆ main_module

PyObject* main_module
static

Definition at line 98 of file trace-event-python.c.

◆ python_scripting_ops

struct scripting_ops python_scripting_ops
Initial value:
= {
.name = "Python",
.start_script = python_start_script,
.flush_script = python_flush_script,
.stop_script = python_stop_script,
.process_event = python_process_event,
.process_stat = python_process_stat,
.process_stat_interval = python_process_stat_interval,
.generate_script = python_generate_script,
}
static void python_process_stat(struct perf_stat_config *config, struct perf_evsel *counter, u64 tstamp)
static int python_stop_script(void)
static void python_process_stat_interval(u64 tstamp)
static int python_generate_script(struct pevent *pevent, const char *outfile)
static int python_flush_script(void)
static int python_start_script(const char *script, int argc, const char **argv)
static void python_process_event(union perf_event *event, struct perf_sample *sample, struct perf_evsel *evsel, struct addr_location *al)

Definition at line 1776 of file trace-event-python.c.

◆ scripting_context

Definition at line 32 of file trace-event-scripting.c.

◆ tables_global

struct tables tables_global
static

Definition at line 116 of file trace-event-python.c.

◆ zero_flag_atom

int zero_flag_atom
static

Definition at line 96 of file trace-event-python.c.