Path: blob/master/tools/perf/scripts/perl/wakeup-latency.pl
10823 views
#!/usr/bin/perl -w1# (c) 2009, Tom Zanussi <[email protected]>2# Licensed under the terms of the GNU GPL License version 234# Display avg/min/max wakeup latency56# The common_* event handler fields are the most useful fields common to7# all events. They don't necessarily correspond to the 'common_*' fields8# in the status files. Those fields not available as handler params can9# be retrieved via script functions of the form get_common_*().1011use 5.010000;12use strict;13use warnings;1415use lib "$ENV{'PERF_EXEC_PATH'}/scripts/perl/Perf-Trace-Util/lib";16use lib "./Perf-Trace-Util/lib";17use Perf::Trace::Core;18use Perf::Trace::Util;1920my %last_wakeup;2122my $max_wakeup_latency;23my $min_wakeup_latency;24my $total_wakeup_latency = 0;25my $total_wakeups = 0;2627sub sched::sched_switch28{29my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,30$common_pid, $common_comm,31$prev_comm, $prev_pid, $prev_prio, $prev_state, $next_comm, $next_pid,32$next_prio) = @_;3334my $wakeup_ts = $last_wakeup{$common_cpu}{ts};35if ($wakeup_ts) {36my $switch_ts = nsecs($common_secs, $common_nsecs);37my $wakeup_latency = $switch_ts - $wakeup_ts;38if ($wakeup_latency > $max_wakeup_latency) {39$max_wakeup_latency = $wakeup_latency;40}41if ($wakeup_latency < $min_wakeup_latency) {42$min_wakeup_latency = $wakeup_latency;43}44$total_wakeup_latency += $wakeup_latency;45$total_wakeups++;46}47$last_wakeup{$common_cpu}{ts} = 0;48}4950sub sched::sched_wakeup51{52my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,53$common_pid, $common_comm,54$comm, $pid, $prio, $success, $target_cpu) = @_;5556$last_wakeup{$target_cpu}{ts} = nsecs($common_secs, $common_nsecs);57}5859sub trace_begin60{61$min_wakeup_latency = 1000000000;62$max_wakeup_latency = 0;63}6465sub trace_end66{67printf("wakeup_latency stats:\n\n");68print "total_wakeups: $total_wakeups\n";69if ($total_wakeups) {70printf("avg_wakeup_latency (ns): %u\n",71avg($total_wakeup_latency, $total_wakeups));72} else {73printf("avg_wakeup_latency (ns): N/A\n");74}75printf("min_wakeup_latency (ns): %u\n", $min_wakeup_latency);76printf("max_wakeup_latency (ns): %u\n", $max_wakeup_latency);7778print_unhandled();79}8081my %unhandled;8283sub print_unhandled84{85if ((scalar keys %unhandled) == 0) {86return;87}8889print "\nunhandled events:\n\n";9091printf("%-40s %10s\n", "event", "count");92printf("%-40s %10s\n", "----------------------------------------",93"-----------");9495foreach my $event_name (keys %unhandled) {96printf("%-40s %10d\n", $event_name, $unhandled{$event_name});97}98}99100sub trace_unhandled101{102my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,103$common_pid, $common_comm) = @_;104105$unhandled{$event_name}++;106}107108109