From 1af2ae74fa7418a689e479be3e6d406b089fa5e8 Mon Sep 17 00:00:00 2001 From: Tvrtko Ursulin Date: Tue, 23 May 2017 15:09:33 +0100 Subject: trace.pl: Add aggregate GPU idle/busy stat Merge and flatten all the engine timelines to produce an aggregate stat. Signed-off-by: Tvrtko Ursulin --- scripts/trace.pl | 84 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 67 insertions(+), 17 deletions(-) (limited to 'scripts/trace.pl') diff --git a/scripts/trace.pl b/scripts/trace.pl index 86a175db..3e737d13 100755 --- a/scripts/trace.pl +++ b/scripts/trace.pl @@ -726,7 +726,11 @@ foreach my $gid (sort keys %rings) { # Current entry overlaps with the previous one. We need # to merge end of the previous interval from the list # with the start of the current one. - splice @e_, $i - 1, 1; + if ($e_[$i] >= $e_[$i - 1]) { + splice @e_, $i - 1, 1; + } else { + splice @e_, $i, 1; + } splice @s_, $i, 1; # Continue with the same element when list got squashed. redo; @@ -744,11 +748,54 @@ foreach my $gid (sort keys %rings) { $flat_busy{$ring} = $total; } +# Calculate overall GPU idle time +my (@s_, @e_); + +# Extract all GPU busy intervals and sort them. +foreach my $key (sort {$db{$a}->{'start'} <=> $db{$b}->{'start'}} keys %db) { + push @s_, $db{$key}->{'start'}; + push @e_, $db{$key}->{'end'}; + die if $db{$key}->{'start'} > $db{$key}->{'end'}; +} + +die unless $#s_ == $#e_; + +# Flatten the intervals (copy & paste of the flattening loop above) +for my $i (1..$#s_) { + last if $i >= @s_; + die if $e_[$i] < $s_[$i]; + die if $s_[$i] < $s_[$i - 1]; + if ($s_[$i] <= $e_[$i - 1]) { + if ($e_[$i] >= $e_[$i - 1]) { + splice @e_, $i - 1, 1; + } else { + splice @e_, $i, 1; + } + splice @s_, $i, 1; + redo; + } +} + +# Add up all busy times. +my $total = 0; +for my $i (0..$#s_) { + die if $e_[$i] < $s_[$i]; + + $total = $total + ($e_[$i] - $s_[$i]); +} + +$flat_busy{'gpu-busy'} = $total / ($last_ts - $first_ts) * 100.0; +$flat_busy{'gpu-idle'} = (1.0 - $total / ($last_ts - $first_ts)) * 100.0; + +# Add up all request waits per engine my %reqw; foreach my $key (keys %reqwait) { $reqw{$reqwait{$key}->{'ring'}} += $reqwait{$key}->{'end'} - $reqwait{$key}->{'start'}; } +say sprintf('GPU: %.2f%% idle, %.2f%% busy', + $flat_busy{'gpu-idle'}, $flat_busy{'gpu-busy'}) unless $html; + print < @@ -779,7 +826,11 @@ Boxes are in format 'ctx-id/seqno'.

Use Ctrl+scroll-action to zoom-in/out and scroll-action or dragging to move around the timeline.

- +

+GPU idle: $flat_busy{'gpu-idle'}% +
+GPU busy: $flat_busy{'gpu-busy'}% +