diff options
author | Charles Baylis <charles.baylis@linaro.org> | 2017-12-14 13:45:32 +0000 |
---|---|---|
committer | Charles Baylis <charles.baylis@linaro.org> | 2017-12-14 13:45:32 +0000 |
commit | 3ff839b9468ff9bc837464a7c96d922c4f34aff8 (patch) | |
tree | d68d81b030e464be44a97548bc4ef279a0ad7c76 | |
parent | d7986cbc3f0327aa18323b4c3a1310d32a083b1b (diff) |
Misc improvements
Use <details> tag to limit default size of profile display.
Automatically determine sample frequency.
Hide tasks with low CPU usage (controlled by --min-task-cpu) from
the menu at the top.
Change-Id: I14c2fed50b1e02d38f30c8ea240f67aca97dad92
-rw-r--r-- | perf-utilization.pl | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/perf-utilization.pl b/perf-utilization.pl index 9ddeb71..22f5fc5 100644 --- a/perf-utilization.pl +++ b/perf-utilization.pl @@ -3,8 +3,9 @@ use File::Temp qw/ tempfile tempdir /; use strict; -my $REPORT_INTERVAL=0.1; # default to 0.1s -my $PERF="perf"; # default perf binary +my $REPORT_INTERVAL=0.1; # default to 0.1s +my $PERF="perf"; # default perf binary +my $MIN_TASK_CPU=1; # hide tasks below 5% CPU usage in menu my ($SAMPLE_INTERVAL, $INPUT, $OUTPUT); while (@ARGV) @@ -13,13 +14,14 @@ while (@ARGV) if ($opt =~ /^--report[_-]?interval(=(.*))?$/) { $REPORT_INTERVAL = $2 // shift; } elsif ($opt =~ /^--sample[_-]?interval(=(.*))?$/) { $SAMPLE_INTERVAL = $2 // shift; } elsif ($opt =~ /^--sample[_-]?freq(?:uency)?(=(.*))?$/) { $SAMPLE_INTERVAL = 1 / ($2 // shift); } + elsif ($opt =~ /^--min[_-]task[_-]cpu(=(.*))?$/) { $MIN_TASK_CPU = $2 // shift; } elsif ($opt =~ /^--output(=(.*))?$/) { $OUTPUT = $2 // shift; } elsif ($opt =~ /^--input(=(.*))?$/) { $INPUT = $2 // shift; } elsif ($opt =~ /^--perf(=(.*))?$/) { $PERF = $2 // shift; } else { die "Unknown option: $opt"; } } -die "Must specify --sample-interval" unless defined $SAMPLE_INTERVAL; +#die "Must specify --sample-interval" unless defined $SAMPLE_INTERVAL; die "Must specify --input" unless defined $INPUT; my $tmpdir = tempdir( CLEANUP => 1 ); @@ -44,9 +46,15 @@ while (<INPUT>) if (/^# event : .*{ sample_period, sample_freq } = (\d+)/) { my $discovered_interval = 1/$1; - warn "Command line configured interval was $SAMPLE_INTERVAL, but perf.data header has $discovered_interval" if $SAMPLE_INTERVAL != $discovered_interval; + if (!defined $SAMPLE_INTERVAL) + { + $SAMPLE_INTERVAL = $discovered_interval; + } else { + warn "Command line configured interval was $SAMPLE_INTERVAL, but perf.data header has $discovered_interval" if $SAMPLE_INTERVAL != $discovered_interval; + } } next unless /\s*(\S+)\s+(\d+)\s+\[0*(\d+)\]\s+(\d+\.\d+):\s+(\d+)\s+(\S+)\s+(\S+)\s+(.*)/; + die "Sample interval/frequency not specified and couldn't discover it from perf output. Use --sample-frequency or --sample-interval" unless defined $SAMPLE_INTERVAL; my ($task, $pid, $cpu, $time, $where) = ($1, $2, $3, $4, $8); $max_cpu = $cpu if $cpu > $max_cpu; @@ -197,9 +205,11 @@ my $max_count=1+($time[$#time]-$time[0])/$SAMPLE_INTERVAL; print $fh qq(<div id="pidtaskwrapper">); foreach my $pid (sort keys %task) { - my $task_cpu=sprintf("%.1f%%",100*$pid_count{$pid}/$max_count); + my $task_cpu = $pid_count{$pid}/$max_count; + next if $task_cpu < ($MIN_TASK_CPU/100); + my $task_cpu_pct=sprintf("%.1f%%",100*$task_cpu); print $fh qq(<span class="pidtask pid$pid" onclick="do_click($pid)">); - print $fh qq($pid<br>$task{$pid}<br>$task_cpu); + print $fh qq($pid<br>$task{$pid}<br>$task_cpu_pct); print $fh qq(</span>); } print $fh qq(</div>); @@ -240,14 +250,27 @@ for (my $i=0;$i<$#cpu;$i++) $str .= qq(<span class="hoverprofile">); my $lochash=$locs{$c}; $str.="Time = ${row_time}s<p>"; - $str.="<pre>"; my @loc_list = sort { $lochash->{$b} <=> $lochash->{$a} } keys %{$lochash}; + my $top_part; + my $remainder; + my $count=0; foreach my $loc (@loc_list) { my $prof_pct = sprintf("%5.1f%%", 100 * $lochash->{$loc} / $n); - $str .= qq($prof_pct - $loc\n); + my $line = qq($prof_pct - $loc\n); + if ($count++ > 7) { + $remainder .= $line + } else { + $top_part .= $line + } } - $str .= "</pre><p>"; + if ($remainder) + { + $str .= "<p><details><summary>Profile contains $count entries<br><pre>$top_part</pre></summary><pre>$remainder</pre></details>"; + } else { + $str .= "<p><pre>$top_part</pre>"; + } + my $max_counts=$REPORT_INTERVAL/$SAMPLE_INTERVAL; $str .= "Threads active in this timeslot<p>"; $str .= "<table><tr><th>PID</th><th>Task name</th><th>CPU usage</th></tr>"; |