From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f72.google.com (mail-dl1-f72.google.com [74.125.82.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 047BC56B85B for ; Wed, 23 Sep 2026 18:15:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.72 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790187365; cv=none; b=o5OEB9U9fkgQuuk3kp9WQk/9GMPc9yginynwT6ZSI+yTyv7x1l8xPojpko1hFq3ya3OfY2jUoCAi0r9MXZL1yeZPIJa/9ZxOKde2MKWiEMIi/UI+PfeyJGaNrLN8ys2J2q9/jK9ZzTtyII5fYAqzsb4hRNUnCKEuuYFQ5U6a28U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790187365; c=relaxed/simple; bh=4Ve56TaFlf4REdqw08b9nK4Po+K3xxqKcdzPWgwNk/E=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=NDUxU6QZsRN8mQwgfc7s5XGi4l6rcGJzppB2mnpFBrTRyEKSFrPEx/YRQ/qn6Ac2Fp9ZD+TLHAj5SHGxm57wLln6MiTnsdS8HVcSz5X868Njb+CCk0WWI/YyR7a2Xm7ym9XaPOcOIGtagXZZCbgZqZBAMH0PL5dmQIn2Qn1S9aw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=l5Nmq+0R; arc=none smtp.client-ip=74.125.82.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="l5Nmq+0R" Received: by mail-dl1-f72.google.com with SMTP id a92af1059eb24-1438492fb40so1874359c88.1 for ; Wed, 23 Sep 2026 11:15:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1790187349; x=1790792149; darn=vger.kernel.org; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date:from:to:cc :subject:date:message-id:reply-to:content-type; bh=19YL//2Bkf0fMj94KZ0aw0fSFEZLxJJzRQeGTwp1WB8=; b=l5Nmq+0Rjuo/tlaidrN/Ld6wwukZccQVA8X3m+VPwHoeEx0GlL28hjgDVt6ZfUf8Be Qlacu+5pfHbGVqRSbFneol9Dn48QJTRHratUiBKTvAvfcgrL/OYlYCPKXkubhU7/TE1Q y0/rg10fQMtmgmvQ6ac3Jy8PHPC6x4VlB2fY/fo77BpWwKHI93t4GcpGi4eH6xqhYLDM dd87e6/Jt/Mqfms9Tf0p+xgyWutvmWNGvzp++CL27y8j80wL4j3mr1BwfsIch6SYTOap N+rdRMDNf/CobUBUPehstk/y+Os3hOyNIRJMf5dgApEG5Ez1xIwKMSzc5Zp5JplminYU qBOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790187349; x=1790792149; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=19YL//2Bkf0fMj94KZ0aw0fSFEZLxJJzRQeGTwp1WB8=; b=Tb/jbZ5ld0wjYIhLvzsphbr5+E79/h4OaCKsYIuM/UR9HzXZFBUnAdzYxvvCZN4Gej aci0uvRA7SmFq38xIjNiiFzsq/buYHbD4PGF2+KRm/XSzPwcY/TE9ESQdqRInfRrg0Xm eizeirla3CFglp4NlMmwtFnLwCzeEQjQPtqCEq0EpFiYOEZicrrJLTo68ha+CFbko8vb LjmLkTxZfrVV1VzRE+/IAtGJQ8/iMhBs60i1QXdBTtVMrUP3CbGcubyhP6w5AlyV4HAF 2zcJXUnRTIZDBLgq90iNEwwL1O7OIWejBLKF+IKER7phh3RtwNEagSZCkZnHegDrDVd+ CRpg== X-Forwarded-Encrypted: i=1; AKwUvBzi1NlU9eC3gi1JTJ8UsLXatdGn2K6REX2COTdOlNROwYKfXO1xsqVn5f2KdLwPI0dBDNxVumvFeuOx2UY=@vger.kernel.org X-Gm-Message-State: AFuF++mmUll5/2wV9uj3/RBFU/XXNUYXGqNjGEXMwcbM/gin2T0uWkRi Wpb0ktGhxylBNV4aHcvM0WGj4xwMcTQQsE6LM35j+o5ibq1VKND/YqeHcrbmYI/7KEdZLgOYcNh 6s53qyArjOA== X-Received: from dldyq18-n2.prod.google.com ([2002:a05:701b:4552:20b0:144:cdc4:f2cb]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:b882:b0:144:de98:ef10 with SMTP id a92af1059eb24-144f91214famr3290039c88.21.1790187348161; Wed, 23 Sep 2026 11:15:48 -0700 (PDT) Date: Wed, 23 Sep 2026 11:12:12 -0700 In-Reply-To: <20260923181213.3032038-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260923181213.3032038-1-irogers@google.com> X-Mailer: git-send-email 2.56.0.rc1.310.g51773c2048-goog Message-ID: <20260923181213.3032038-50-irogers@google.com> Subject: [PATCH v3 49/49] perf Documentation: Update for standalone Python scripts From: Ian Rogers To: irogers@google.com, acme@kernel.org, alice.mei.rogers@gmail.com, namhyung@kernel.org Cc: adrian.hunter@intel.com, dapeng1.mi@linux.intel.com, james.clark@linaro.org, leo.yan@linux.dev, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, mingo@redhat.com, peterz@infradead.org, tmricht@linux.ibm.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Update perf-script documentation to reflect standalone Python script execution and the removal of embedded Python and Perl scripting: - Remove documentation for the removed -g and -s options and legacy record/report script wrapper modes in perf-script.txt. - Remove references to perf-script-perl and delete obsolete perf-script-perl.txt. - Rewrite perf-script-python.txt to document writing and running standalone Python scripts using the perf module. Assisted-by: Antigravity:gemini-3.1-pro Signed-off-by: Ian Rogers --- tools/perf/Documentation/db-export.txt | 16 +- tools/perf/Documentation/perf-script-perl.txt | 216 ----- .../perf/Documentation/perf-script-python.txt | 797 ++++-------------- tools/perf/Documentation/perf-script.txt | 82 +- tools/perf/Documentation/tips.txt | 1 - 5 files changed, 162 insertions(+), 950 deletions(-) delete mode 100644 tools/perf/Documentation/perf-script-perl.txt diff --git a/tools/perf/Documentation/db-export.txt b/tools/perf/Documentat= ion/db-export.txt index 20024e1f9164..a736be3b6e84 100644 --- a/tools/perf/Documentation/db-export.txt +++ b/tools/perf/Documentation/db-export.txt @@ -1,11 +1,11 @@ Database Export =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 -perf tool's python scripting engine: +perf tool's python module: =20 - tools/perf/util/scripting-engines/trace-event-python.c + tools/perf/util/python.c =20 -supports scripts: +supports standalone scripts: =20 tools/perf/python/export-to-sqlite.py tools/perf/python/export-to-postgresql.py @@ -31,11 +31,5 @@ backward compatibility by testing for the presence of ne= w tables and columns before using them. e.g. function IsSelectable() in exported-sql-viewer.py =20 4. The export scripts themselves maintain forward compatibility (i.e. an e= xisting -script will continue to work with new versions of perf) by accepting a var= iable -number of arguments (e.g. def call_return_table(*x)) i.e. perf can pass mo= re -arguments which old scripts will ignore. - -5. The scripting engine tests for the existence of script handler function= s -before calling them. The scripting engine can also test for the support o= f new -or optional features by checking for the existence and value of script glo= bal -variables. +script will continue to work with new versions of perf) by querying event = and +sample attributes dynamically from the perf Python module. diff --git a/tools/perf/Documentation/perf-script-perl.txt b/tools/perf/Doc= umentation/perf-script-perl.txt deleted file mode 100644 index 5b479f5e62ff..000000000000 --- a/tools/perf/Documentation/perf-script-perl.txt +++ /dev/null @@ -1,216 +0,0 @@ -perf-script-perl(1) -=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D - -NAME ----- -perf-script-perl - Process trace data with a Perl script - -SYNOPSIS --------- -[verse] -'perf script' [-s [Perl]:script[.pl] ] - -DESCRIPTION ------------ - -This perf script option is used to process perf script data using perf's -built-in Perl interpreter. It reads and processes the input file and -displays the results of the trace analysis implemented in the given -Perl script, if any. - -STARTER SCRIPTS ---------------- - -You can avoid reading the rest of this document by running 'perf script --g perl' in the same directory as an existing perf.data trace file. -That will generate a starter script containing a handler for each of -the event types in the trace file; it simply prints every available -field for each event in the trace file. - -You can also look at the existing scripts in -~/libexec/perf-core/scripts/perl for typical examples showing how to -do basic things like aggregate event data, print results, etc. Also, -the check-perf-script.pl script, while not interesting for its results, -attempts to exercise all of the main scripting features. - -EVENT HANDLERS --------------- - -When perf script is invoked using a trace script, a user-defined -'handler function' is called for each event in the trace. If there's -no handler function defined for a given event type, the event is -ignored (or passed to a 'trace_unhandled' function, see below) and the -next event is processed. - -Most of the event's field values are passed as arguments to the -handler function; some of the less common ones aren't - those are -available as calls back into the perf executable (see below). - -As an example, the following perf record command can be used to record -all sched_wakeup events in the system: - - # perf record -a -e sched:sched_wakeup - -Traces meant to be processed using a script should be recorded with -the above option: -a to enable system-wide collection. - -The format file for the sched_wakeup event defines the following fields -(see /sys/kernel/tracing/events/sched/sched_wakeup/format): - ----- - format: - field:unsigned short common_type; - field:unsigned char common_flags; - field:unsigned char common_preempt_count; - field:int common_pid; - - field:char comm[TASK_COMM_LEN]; - field:pid_t pid; - field:int prio; - field:int success; - field:int target_cpu; ----- - -The handler function for this event would be defined as: - ----- -sub sched::sched_wakeup -{ - my ($event_name, $context, $common_cpu, $common_secs, - $common_nsecs, $common_pid, $common_comm, - $comm, $pid, $prio, $success, $target_cpu) =3D @_; -} ----- - -The handler function takes the form subsystem::event_name. - -The $common_* arguments in the handler's argument list are the set of -arguments passed to all event handlers; some of the fields correspond -to the common_* fields in the format file, but some are synthesized, -and some of the common_* fields aren't common enough to to be passed -to every event as arguments but are available as library functions. - -Here's a brief description of each of the invariant event args: - - $event_name the name of the event as text - $context an opaque 'cookie' used in calls back into perf - $common_cpu the cpu the event occurred on - $common_secs the secs portion of the event timestamp - $common_nsecs the nsecs portion of the event timestamp - $common_pid the pid of the current task - $common_comm the name of the current process - -All of the remaining fields in the event's format file have -counterparts as handler function arguments of the same name, as can be -seen in the example above. - -The above provides the basics needed to directly access every field of -every event in a trace, which covers 90% of what you need to know to -write a useful trace script. The sections below cover the rest. - -SCRIPT LAYOUT -------------- - -Every perf script Perl script should start by setting up a Perl module -search path and 'use'ing a few support modules (see module -descriptions below): - ----- - use lib "$ENV{'PERF_EXEC_PATH'}/scripts/perl/Perf-Trace-Util/lib"; - use lib "./Perf-Trace-Util/lib"; - use Perf::Trace::Core; - use Perf::Trace::Context; - use Perf::Trace::Util; ----- - -The rest of the script can contain handler functions and support -functions in any order. - -Aside from the event handler functions discussed above, every script -can implement a set of optional functions: - -*trace_begin*, if defined, is called before any event is processed and -gives scripts a chance to do setup tasks: - ----- - sub trace_begin - { - } ----- - -*trace_end*, if defined, is called after all events have been - processed and gives scripts a chance to do end-of-script tasks, such - as display results: - ----- -sub trace_end -{ -} ----- - -*trace_unhandled*, if defined, is called after for any event that - doesn't have a handler explicitly defined for it. The standard set - of common arguments are passed into it: - ----- -sub trace_unhandled -{ - my ($event_name, $context, $common_cpu, $common_secs, - $common_nsecs, $common_pid, $common_comm) =3D @_; -} ----- - -The remaining sections provide descriptions of each of the available -built-in perf script Perl modules and their associated functions. - -AVAILABLE MODULES AND FUNCTIONS -------------------------------- - -The following sections describe the functions and variables available -via the various Perf::Trace::* Perl modules. To use the functions and -variables from the given module, add the corresponding 'use -Perf::Trace::XXX' line to your perf script script. - -Perf::Trace::Core 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 re= presentation corresponding to $field_value for the flag field $field_name o= f 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 - -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 event handler as the second -argument. - - 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 e= vent - -Perf::Trace::Util Module -~~~~~~~~~~~~~~~~~~~~~~~~ - -Various utility functions for use with perf script: - - nsecs($secs, $nsecs) - returns total nsecs given secs/nsecs pair - nsecs_secs($nsecs) - returns whole secs portion given nsecs - nsecs_nsecs($nsecs) - returns nsecs remainder given nsecs - nsecs_str($nsecs) - returns printable string in the form secs.nsecs - avg($total, $n) - returns average given a sum and a total number of valu= es - -SEE ALSO --------- -linkperf:perf-script[1] diff --git a/tools/perf/Documentation/perf-script-python.txt b/tools/perf/D= ocumentation/perf-script-python.txt index 27a1cac6fe76..bd1809b07543 100644 --- a/tools/perf/Documentation/perf-script-python.txt +++ b/tools/perf/Documentation/perf-script-python.txt @@ -3,676 +3,181 @@ perf-script-python(1) =20 NAME ---- -perf-script-python - Process trace data with a Python script +perf-script-python - Process trace data with a Python script using perf mo= dule =20 SYNOPSIS -------- [verse] -'perf script' [-s [Python]:script[.py] ] +'perf script'