tools/perf/Documentation/perf-script-python.txt

Source file repositories/reference/linux-study-clean/tools/perf/Documentation/perf-script-python.txt

File Facts

System
Linux kernel
Corpus path
tools/perf/Documentation/perf-script-python.txt
Extension
.txt
Size
25106 bytes
Lines
680
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: documentation
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

*context_switch*, if defined, is called for any context switch

----
def context_switch(ts, cpu, pid, tid, np_pid, np_tid, machine_pid, out, out_preempt, *x):
    pass
----

*auxtrace_error*, if defined, is called for any AUX area tracing error

----
def auxtrace_error(typ, code, cpu, pid, tid, ip, ts, msg, cpumode, *x):
    pass
----

The remaining sections provide descriptions of each of the available
built-in perf script Python modules and their associated functions.

AVAILABLE MODULES AND FUNCTIONS
-------------------------------

The following sections describe the functions and variables available
via the various perf script Python modules.  To use the functions and
variables from the given module, add the corresponding 'from XXXX
import' line to your perf script script.

Core.py Module
~~~~~~~~~~~~~~

These functions provide some essential functions to user scripts.

The *flag_str* and *symbol_str* functions provide human-readable
strings for flag and symbolic fields.  These correspond to the strings
and values parsed from the 'print fmt' fields of the event format
files:

  flag_str(event_name, field_name, field_value) - returns the string representation corresponding to field_value for the flag field field_name of event event_name
  symbol_str(event_name, field_name, field_value) - returns the string representation corresponding to field_value for the symbolic field field_name of event event_name

The *autodict* function returns a special kind of Python
dictionary that implements Perl's 'autovivifying' hashes in Python
i.e. with autovivifying hashes, you can assign nested hash values
without having to go to the trouble of creating intermediate levels if
they don't exist.

  autodict() - returns an autovivifying dictionary instance


perf_trace_context Module
~~~~~~~~~~~~~~~~~~~~~~~~~

Some of the 'common' fields in the event format file aren't all that
common, but need to be made accessible to user scripts nonetheless.

perf_trace_context defines a set of functions that can be used to
access this data in the context of the current event.  Each of these
functions expects a context variable, which is the same as the
context variable passed into every tracepoint event handler as the second
argument. For non-tracepoint events, the context variable is also present
as perf_trace_context.perf_script_context .

 common_pc(context) - returns common_preempt count for the current event
 common_flags(context) - returns common_flags for the current event
 common_lock_depth(context) - returns common_lock_depth for the current event
 perf_sample_insn(context) - returns the machine code instruction
 perf_set_itrace_options(context, itrace_options) - set --itrace options if they have not been set already
 perf_sample_srcline(context) - returns source_file_name, line_number
 perf_sample_srccode(context) - returns source_file_name, line_number, source_line
 perf_config_get(config_name) - returns the value of the named config item, or None if unset

Util.py Module

Annotation

Implementation Notes