~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/perf/Documentation/perf-script-perl.txt

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /tools/perf/Documentation/perf-script-perl.txt (Architecture ppc) and /tools/perf/Documentation/perf-script-perl.txt (Architecture alpha)


  1 perf-script-perl(1)                                 1 perf-script-perl(1)
  2 ===================                                 2 ===================
  3                                                     3 
  4 NAME                                                4 NAME
  5 ----                                                5 ----
  6 perf-script-perl - Process trace data with a P      6 perf-script-perl - Process trace data with a Perl script
  7                                                     7 
  8 SYNOPSIS                                            8 SYNOPSIS
  9 --------                                            9 --------
 10 [verse]                                            10 [verse]
 11 'perf script' [-s [Perl]:script[.pl] ]             11 'perf script' [-s [Perl]:script[.pl] ]
 12                                                    12 
 13 DESCRIPTION                                        13 DESCRIPTION
 14 -----------                                        14 -----------
 15                                                    15 
 16 This perf script option is used to process per     16 This perf script option is used to process perf script data using perf's
 17 built-in Perl interpreter.  It reads and proce     17 built-in Perl interpreter.  It reads and processes the input file and
 18 displays the results of the trace analysis imp     18 displays the results of the trace analysis implemented in the given
 19 Perl script, if any.                               19 Perl script, if any.
 20                                                    20 
 21 STARTER SCRIPTS                                    21 STARTER SCRIPTS
 22 ---------------                                    22 ---------------
 23                                                    23 
 24 You can avoid reading the rest of this documen     24 You can avoid reading the rest of this document by running 'perf script
 25 -g perl' in the same directory as an existing      25 -g perl' in the same directory as an existing perf.data trace file.
 26 That will generate a starter script containing     26 That will generate a starter script containing a handler for each of
 27 the event types in the trace file; it simply p     27 the event types in the trace file; it simply prints every available
 28 field for each event in the trace file.            28 field for each event in the trace file.
 29                                                    29 
 30 You can also look at the existing scripts in       30 You can also look at the existing scripts in
 31 ~/libexec/perf-core/scripts/perl for typical e     31 ~/libexec/perf-core/scripts/perl for typical examples showing how to
 32 do basic things like aggregate event data, pri     32 do basic things like aggregate event data, print results, etc.  Also,
 33 the check-perf-script.pl script, while not int     33 the check-perf-script.pl script, while not interesting for its results,
 34 attempts to exercise all of the main scripting     34 attempts to exercise all of the main scripting features.
 35                                                    35 
 36 EVENT HANDLERS                                     36 EVENT HANDLERS
 37 --------------                                     37 --------------
 38                                                    38 
 39 When perf script is invoked using a trace scri     39 When perf script is invoked using a trace script, a user-defined
 40 'handler function' is called for each event in     40 'handler function' is called for each event in the trace.  If there's
 41 no handler function defined for a given event      41 no handler function defined for a given event type, the event is
 42 ignored (or passed to a 'trace_unhandled' func     42 ignored (or passed to a 'trace_unhandled' function, see below) and the
 43 next event is processed.                           43 next event is processed.
 44                                                    44 
 45 Most of the event's field values are passed as     45 Most of the event's field values are passed as arguments to the
 46 handler function; some of the less common ones     46 handler function; some of the less common ones aren't - those are
 47 available as calls back into the perf executab     47 available as calls back into the perf executable (see below).
 48                                                    48 
 49 As an example, the following perf record comma     49 As an example, the following perf record command can be used to record
 50 all sched_wakeup events in the system:             50 all sched_wakeup events in the system:
 51                                                    51 
 52  # perf record -a -e sched:sched_wakeup            52  # perf record -a -e sched:sched_wakeup
 53                                                    53 
 54 Traces meant to be processed using a script sh     54 Traces meant to be processed using a script should be recorded with
 55 the above option: -a to enable system-wide col     55 the above option: -a to enable system-wide collection.
 56                                                    56 
 57 The format file for the sched_wakeup event def     57 The format file for the sched_wakeup event defines the following fields
 58 (see /sys/kernel/tracing/events/sched/sched_wa     58 (see /sys/kernel/tracing/events/sched/sched_wakeup/format):
 59                                                    59 
 60 ----                                               60 ----
 61  format:                                           61  format:
 62         field:unsigned short common_type;          62         field:unsigned short common_type;
 63         field:unsigned char common_flags;          63         field:unsigned char common_flags;
 64         field:unsigned char common_preempt_cou     64         field:unsigned char common_preempt_count;
 65         field:int common_pid;                      65         field:int common_pid;
 66                                                    66 
 67         field:char comm[TASK_COMM_LEN];            67         field:char comm[TASK_COMM_LEN];
 68         field:pid_t pid;                           68         field:pid_t pid;
 69         field:int prio;                            69         field:int prio;
 70         field:int success;                         70         field:int success;
 71         field:int target_cpu;                      71         field:int target_cpu;
 72 ----                                               72 ----
 73                                                    73 
 74 The handler function for this event would be d     74 The handler function for this event would be defined as:
 75                                                    75 
 76 ----                                               76 ----
 77 sub sched::sched_wakeup                            77 sub sched::sched_wakeup
 78 {                                                  78 {
 79    my ($event_name, $context, $common_cpu, $co     79    my ($event_name, $context, $common_cpu, $common_secs,
 80        $common_nsecs, $common_pid, $common_com     80        $common_nsecs, $common_pid, $common_comm,
 81        $comm, $pid, $prio, $success, $target_c     81        $comm, $pid, $prio, $success, $target_cpu) = @_;
 82 }                                                  82 }
 83 ----                                               83 ----
 84                                                    84 
 85 The handler function takes the form subsystem:     85 The handler function takes the form subsystem::event_name.
 86                                                    86 
 87 The $common_* arguments in the handler's argum     87 The $common_* arguments in the handler's argument list are the set of
 88 arguments passed to all event handlers; some o     88 arguments passed to all event handlers; some of the fields correspond
 89 to the common_* fields in the format file, but     89 to the common_* fields in the format file, but some are synthesized,
 90 and some of the common_* fields aren't common      90 and some of the common_* fields aren't common enough to to be passed
 91 to every event as arguments but are available      91 to every event as arguments but are available as library functions.
 92                                                    92 
 93 Here's a brief description of each of the inva     93 Here's a brief description of each of the invariant event args:
 94                                                    94 
 95  $event_name                the name of the ev     95  $event_name                the name of the event as text
 96  $context                   an opaque 'cookie'     96  $context                   an opaque 'cookie' used in calls back into perf
 97  $common_cpu                the cpu the event      97  $common_cpu                the cpu the event occurred on
 98  $common_secs               the secs portion o     98  $common_secs               the secs portion of the event timestamp
 99  $common_nsecs              the nsecs portion      99  $common_nsecs              the nsecs portion of the event timestamp
100  $common_pid                the pid of the cur    100  $common_pid                the pid of the current task
101  $common_comm               the name of the cu    101  $common_comm               the name of the current process
102                                                   102 
103 All of the remaining fields in the event's for    103 All of the remaining fields in the event's format file have
104 counterparts as handler function arguments of     104 counterparts as handler function arguments of the same name, as can be
105 seen in the example above.                        105 seen in the example above.
106                                                   106 
107 The above provides the basics needed to direct    107 The above provides the basics needed to directly access every field of
108 every event in a trace, which covers 90% of wh    108 every event in a trace, which covers 90% of what you need to know to
109 write a useful trace script.  The sections bel    109 write a useful trace script.  The sections below cover the rest.
110                                                   110 
111 SCRIPT LAYOUT                                     111 SCRIPT LAYOUT
112 -------------                                     112 -------------
113                                                   113 
114 Every perf script Perl script should start by     114 Every perf script Perl script should start by setting up a Perl module
115 search path and 'use'ing a few support modules    115 search path and 'use'ing a few support modules (see module
116 descriptions below):                              116 descriptions below):
117                                                   117 
118 ----                                              118 ----
119  use lib "$ENV{'PERF_EXEC_PATH'}/scripts/perl/    119  use lib "$ENV{'PERF_EXEC_PATH'}/scripts/perl/Perf-Trace-Util/lib";
120  use lib "./Perf-Trace-Util/lib";                 120  use lib "./Perf-Trace-Util/lib";
121  use Perf::Trace::Core;                           121  use Perf::Trace::Core;
122  use Perf::Trace::Context;                        122  use Perf::Trace::Context;
123  use Perf::Trace::Util;                           123  use Perf::Trace::Util;
124 ----                                              124 ----
125                                                   125 
126 The rest of the script can contain handler fun    126 The rest of the script can contain handler functions and support
127 functions in any order.                           127 functions in any order.
128                                                   128 
129 Aside from the event handler functions discuss    129 Aside from the event handler functions discussed above, every script
130 can implement a set of optional functions:        130 can implement a set of optional functions:
131                                                   131 
132 *trace_begin*, if defined, is called before an    132 *trace_begin*, if defined, is called before any event is processed and
133 gives scripts a chance to do setup tasks:         133 gives scripts a chance to do setup tasks:
134                                                   134 
135 ----                                              135 ----
136  sub trace_begin                                  136  sub trace_begin
137  {                                                137  {
138  }                                                138  }
139 ----                                              139 ----
140                                                   140 
141 *trace_end*, if defined, is called after all e    141 *trace_end*, if defined, is called after all events have been
142  processed and gives scripts a chance to do en    142  processed and gives scripts a chance to do end-of-script tasks, such
143  as display results:                              143  as display results:
144                                                   144 
145 ----                                              145 ----
146 sub trace_end                                     146 sub trace_end
147 {                                                 147 {
148 }                                                 148 }
149 ----                                              149 ----
150                                                   150 
151 *trace_unhandled*, if defined, is called after    151 *trace_unhandled*, if defined, is called after for any event that
152  doesn't have a handler explicitly defined for    152  doesn't have a handler explicitly defined for it.  The standard set
153  of common arguments are passed into it:          153  of common arguments are passed into it:
154                                                   154 
155 ----                                              155 ----
156 sub trace_unhandled                               156 sub trace_unhandled
157 {                                                 157 {
158     my ($event_name, $context, $common_cpu, $c    158     my ($event_name, $context, $common_cpu, $common_secs,
159         $common_nsecs, $common_pid, $common_co    159         $common_nsecs, $common_pid, $common_comm) = @_;
160 }                                                 160 }
161 ----                                              161 ----
162                                                   162 
163 The remaining sections provide descriptions of    163 The remaining sections provide descriptions of each of the available
164 built-in perf script Perl modules and their as    164 built-in perf script Perl modules and their associated functions.
165                                                   165 
166 AVAILABLE MODULES AND FUNCTIONS                   166 AVAILABLE MODULES AND FUNCTIONS
167 -------------------------------                   167 -------------------------------
168                                                   168 
169 The following sections describe the functions     169 The following sections describe the functions and variables available
170 via the various Perf::Trace::* Perl modules.      170 via the various Perf::Trace::* Perl modules.  To use the functions and
171 variables from the given module, add the corre    171 variables from the given module, add the corresponding 'use
172 Perf::Trace::XXX' line to your perf script scr    172 Perf::Trace::XXX' line to your perf script script.
173                                                   173 
174 Perf::Trace::Core Module                          174 Perf::Trace::Core Module
175 ~~~~~~~~~~~~~~~~~~~~~~~~                          175 ~~~~~~~~~~~~~~~~~~~~~~~~
176                                                   176 
177 These functions provide some essential functio    177 These functions provide some essential functions to user scripts.
178                                                   178 
179 The *flag_str* and *symbol_str* functions prov    179 The *flag_str* and *symbol_str* functions provide human-readable
180 strings for flag and symbolic fields.  These c    180 strings for flag and symbolic fields.  These correspond to the strings
181 and values parsed from the 'print fmt' fields     181 and values parsed from the 'print fmt' fields of the event format
182 files:                                            182 files:
183                                                   183 
184   flag_str($event_name, $field_name, $field_va    184   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
185   symbol_str($event_name, $field_name, $field_    185   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
186                                                   186 
187 Perf::Trace::Context Module                       187 Perf::Trace::Context Module
188 ~~~~~~~~~~~~~~~~~~~~~~~~~~~                       188 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
189                                                   189 
190 Some of the 'common' fields in the event forma    190 Some of the 'common' fields in the event format file aren't all that
191 common, but need to be made accessible to user    191 common, but need to be made accessible to user scripts nonetheless.
192                                                   192 
193 Perf::Trace::Context defines a set of function    193 Perf::Trace::Context defines a set of functions that can be used to
194 access this data in the context of the current    194 access this data in the context of the current event.  Each of these
195 functions expects a $context variable, which i    195 functions expects a $context variable, which is the same as the
196 $context variable passed into every event hand    196 $context variable passed into every event handler as the second
197 argument.                                         197 argument.
198                                                   198 
199  common_pc($context) - returns common_preempt     199  common_pc($context) - returns common_preempt count for the current event
200  common_flags($context) - returns common_flags    200  common_flags($context) - returns common_flags for the current event
201  common_lock_depth($context) - returns common_    201  common_lock_depth($context) - returns common_lock_depth for the current event
202                                                   202 
203 Perf::Trace::Util Module                          203 Perf::Trace::Util Module
204 ~~~~~~~~~~~~~~~~~~~~~~~~                          204 ~~~~~~~~~~~~~~~~~~~~~~~~
205                                                   205 
206 Various utility functions for use with perf sc    206 Various utility functions for use with perf script:
207                                                   207 
208   nsecs($secs, $nsecs) - returns total nsecs g    208   nsecs($secs, $nsecs) - returns total nsecs given secs/nsecs pair
209   nsecs_secs($nsecs) - returns whole secs port    209   nsecs_secs($nsecs) - returns whole secs portion given nsecs
210   nsecs_nsecs($nsecs) - returns nsecs remainde    210   nsecs_nsecs($nsecs) - returns nsecs remainder given nsecs
211   nsecs_str($nsecs) - returns printable string    211   nsecs_str($nsecs) - returns printable string in the form secs.nsecs
212   avg($total, $n) - returns average given a su    212   avg($total, $n) - returns average given a sum and a total number of values
213                                                   213 
214 SEE ALSO                                          214 SEE ALSO
215 --------                                          215 --------
216 linkperf:perf-script[1]                           216 linkperf:perf-script[1]
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php