Back to home page

OSCL-LXR

 
 

    


0001 #!/usr/bin/perl -w
0002 # SPDX-License-Identifier: GPL-2.0-only
0003 # (c) 2009, Tom Zanussi <tzanussi@gmail.com>
0004 
0005 # Display avg/min/max wakeup latency
0006 
0007 # The common_* event handler fields are the most useful fields common to
0008 # all events.  They don't necessarily correspond to the 'common_*' fields
0009 # in the status files.  Those fields not available as handler params can
0010 # be retrieved via script functions of the form get_common_*().
0011 
0012 use 5.010000;
0013 use strict;
0014 use warnings;
0015 
0016 use lib "$ENV{'PERF_EXEC_PATH'}/scripts/perl/Perf-Trace-Util/lib";
0017 use lib "./Perf-Trace-Util/lib";
0018 use Perf::Trace::Core;
0019 use Perf::Trace::Util;
0020 
0021 my %last_wakeup;
0022 
0023 my $max_wakeup_latency;
0024 my $min_wakeup_latency;
0025 my $total_wakeup_latency = 0;
0026 my $total_wakeups = 0;
0027 
0028 sub sched::sched_switch
0029 {
0030     my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
0031     $common_pid, $common_comm, $common_callchain,
0032     $prev_comm, $prev_pid, $prev_prio, $prev_state, $next_comm, $next_pid,
0033     $next_prio) = @_;
0034 
0035     my $wakeup_ts = $last_wakeup{$common_cpu}{ts};
0036     if ($wakeup_ts) {
0037     my $switch_ts = nsecs($common_secs, $common_nsecs);
0038     my $wakeup_latency = $switch_ts - $wakeup_ts;
0039     if ($wakeup_latency > $max_wakeup_latency) {
0040         $max_wakeup_latency = $wakeup_latency;
0041     }
0042     if ($wakeup_latency < $min_wakeup_latency) {
0043         $min_wakeup_latency = $wakeup_latency;
0044     }
0045     $total_wakeup_latency += $wakeup_latency;
0046     $total_wakeups++;
0047     }
0048     $last_wakeup{$common_cpu}{ts} = 0;
0049 }
0050 
0051 sub sched::sched_wakeup
0052 {
0053     my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
0054     $common_pid, $common_comm, $common_callchain,
0055     $comm, $pid, $prio, $success, $target_cpu) = @_;
0056 
0057     $last_wakeup{$target_cpu}{ts} = nsecs($common_secs, $common_nsecs);
0058 }
0059 
0060 sub trace_begin
0061 {
0062     $min_wakeup_latency = 1000000000;
0063     $max_wakeup_latency = 0;
0064 }
0065 
0066 sub trace_end
0067 {
0068     printf("wakeup_latency stats:\n\n");
0069     print "total_wakeups: $total_wakeups\n";
0070     if ($total_wakeups) {
0071     printf("avg_wakeup_latency (ns): %u\n",
0072            avg($total_wakeup_latency, $total_wakeups));
0073     } else {
0074     printf("avg_wakeup_latency (ns): N/A\n");
0075     }
0076     printf("min_wakeup_latency (ns): %u\n", $min_wakeup_latency);
0077     printf("max_wakeup_latency (ns): %u\n", $max_wakeup_latency);
0078 
0079     print_unhandled();
0080 }
0081 
0082 my %unhandled;
0083 
0084 sub print_unhandled
0085 {
0086     if ((scalar keys %unhandled) == 0) {
0087     return;
0088     }
0089 
0090     print "\nunhandled events:\n\n";
0091 
0092     printf("%-40s  %10s\n", "event", "count");
0093     printf("%-40s  %10s\n", "----------------------------------------",
0094        "-----------");
0095 
0096     foreach my $event_name (keys %unhandled) {
0097     printf("%-40s  %10d\n", $event_name, $unhandled{$event_name});
0098     }
0099 }
0100 
0101 sub trace_unhandled
0102 {
0103     my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
0104     $common_pid, $common_comm, $common_callchain) = @_;
0105 
0106     $unhandled{$event_name}++;
0107 }