From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1E64EFF8863 for ; Sat, 25 Apr 2026 22:54:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=4nB2isuX/JhvQvkWDCfxi1bwLTo8ITgEAb1m1yloXvw=; b=DawthhMOE71hvFyM98Kr7MQQsA O1Vh2AEjydwpsA+tW6vefBtg+9W2VvNHDayXASJnqzoqBmR1OTSiKpLmbJLLdxxUJ4qpWv0gzpqw4 cCp2SqQGHV1TFjnoHilJTL7waCSE8bQn8iF1t7W+zsHRmQI7FbXPZCsae47GFQyoahqMZaMQfZTlA cLEsCUvsuAAduBhUPt30G+cXCfdbfFeke3D94aXncH2uWix5XPgL1/j2+5Y0PivZKDIZy9oTFRNXd 5psOgsA2Zlzp4vaPqkVzxPiM0Kggu+78j4qnOB3la73jEVm1hyLwCMDfeQGLZqcC9YDBAr3mts9a1 G7MU0/Vg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1wGlsp-0000000F1lG-2HTy; Sat, 25 Apr 2026 22:53:55 +0000 Received: from mail-dl1-f74.google.com ([74.125.82.74]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1wGlrD-0000000Ezv3-2xfe for linux-arm-kernel@lists.infradead.org; Sat, 25 Apr 2026 22:52:33 +0000 Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-12c21dbc9c1so33859328c88.0 for ; Sat, 25 Apr 2026 15:52:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777157533; x=1777762333; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=4nB2isuX/JhvQvkWDCfxi1bwLTo8ITgEAb1m1yloXvw=; b=RkDz5lYbiKbkjslMsQOP9iB8qnpq+8wUaX3rgC3p1V46Q6uf9uubEIneSZ93/1Ns70 miT0nKcHiW9dWw08eSjBC7DxpfDE62N0XQhUqbHZRiK74bD2cV8bmi19IwIsxVYRk7jn tjlJVjn9/80hcA9A925Fpkjv8ePzGuD3SZ17Gz1w6Dto9Q6Nldg/bmdabBXSLLt8BcKC TYXEvLD0kUspB/+yCvxqUzuiC4LiQh5T4dZASBtGFmXCPKMY5sDW1+XLRw6DuoDZ1bZc /ESKT+7GmhJ81Z+F5mxdnDUWO48CxnH4ikfZ4oUni2115LO+gU1u9lZd0oGFWZD384rk an5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777157533; x=1777762333; h=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; bh=4nB2isuX/JhvQvkWDCfxi1bwLTo8ITgEAb1m1yloXvw=; b=XXOI5A0LXoGkKaWlsSQiwl2y89Q9YDrD0IpNxLDOGAFLrw8Xq/OxRJ4NJf6sqZZHFd ZHbYGJ3UvcwqjiH8XKKMjPllk2ImRQ72RXt5T/WCP3QHhsc5rouV2XJBItpht7wHdMZW OX6XnZbgsAbyXDNnEHnN/ZleXQiv/PLF3prS7tETYOKjq9kLclL+a0bhO+fVh7HsTN8L 7Z7Eww4o6oh13aa4aK2n7FU9WK2+HvyGor6Ms2Ii4INpV5Uny429XEnLeS5mJZ4RC+X1 9jqN6W/z9R1+fRzpf1JLGtbemTVoNPZRCrZMxhf0mlhoFDoTpJ8mEBpDuzr5me/6TQNs QkJw== X-Forwarded-Encrypted: i=1; AFNElJ8CboVlgAgoxfg9+Ja+6UfP9Byj+AGMJ554gYyB0d0qA9ur5DKLQqbN/bl1ocvimeU7zmZvhYO8QhvTNCobjhTq@lists.infradead.org X-Gm-Message-State: AOJu0Yx/4l/qCAH0lsskmq5fd28huzHB2OLHhI+cJwEezshNxJi8H5Ek zWEnD/EtBJsqxVdYKY7oWVvhw2z12bCIDEXNI15xUUdQg5QVpnAad5cNMSow1okl04QKO+pFerp I1QPymFI1WQ== X-Received: from dlbts2-n2.prod.google.com ([2002:a05:7022:b042:20b0:128:cfd6:a3c6]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:6b96:b0:11b:bf3f:5240 with SMTP id a92af1059eb24-12c73f70cd0mr17624819c88.9.1777157532626; Sat, 25 Apr 2026 15:52:12 -0700 (PDT) Date: Sat, 25 Apr 2026 15:49:49 -0700 In-Reply-To: <20260425224951.174663-1-irogers@google.com> Mime-Version: 1.0 References: <20260425174858.3922152-1-irogers@google.com> <20260425224951.174663-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260425224951.174663-58-irogers@google.com> Subject: [PATCH v7 57/59] perf Documentation: Update for standalone Python scripts and remove obsolete data From: Ian Rogers To: acme@kernel.org, adrian.hunter@intel.com, james.clark@linaro.org, leo.yan@linux.dev, namhyung@kernel.org, tmricht@linux.ibm.com Cc: alice.mei.rogers@gmail.com, dapeng1.mi@linux.intel.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, mingo@redhat.com, peterz@infradead.org, Ian Rogers Content-Type: text/plain; charset="UTF-8" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260425_155216_343282_FA8F293B X-CRM114-Status: GOOD ( 33.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org - Remove documentation for -g and -s options in perf-script.txt. - Remove links to perf-script-perl in perf-script.txt. - Rewrite perf-script-python.txt to describe the new standalone script usage with perf module. - Remove obsolete perf-script-perl.txt. Assisted-by: Gemini:gemini-3.1-pro-preview Signed-off-by: Ian Rogers --- v6: - Updated `perf-script-python.txt` to use indented code blocks to fix man page formatting, and documented `find_thread` and `elf_machine`. --- tools/perf/Documentation/perf-script-perl.txt | 216 ------ .../perf/Documentation/perf-script-python.txt | 713 +++--------------- tools/perf/Documentation/perf-script.txt | 70 +- 3 files changed, 96 insertions(+), 903 deletions(-) delete mode 100644 tools/perf/Documentation/perf-script-perl.txt diff --git a/tools/perf/Documentation/perf-script-perl.txt b/tools/perf/Documentation/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) -=================== - -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) = @_; -} ----- - -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) = @_; -} ----- - -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 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 - -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 event - -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 values - -SEE ALSO --------- -linkperf:perf-script[1] diff --git a/tools/perf/Documentation/perf-script-python.txt b/tools/perf/Documentation/perf-script-python.txt index 27a1cac6fe76..6bcf98e4e6c6 100644 --- a/tools/perf/Documentation/perf-script-python.txt +++ b/tools/perf/Documentation/perf-script-python.txt @@ -3,676 +3,143 @@ perf-script-python(1) NAME ---- -perf-script-python - Process trace data with a Python script +perf-script-python - Process trace data with a Python script using perf module SYNOPSIS -------- [verse] -'perf script' [-s [Python]:script[.py] ] +'perf script'