diff mbox

[i-g-t,06/11] trace.pl: Improve context colouring for large context id's

Message ID 20180709132004.14468-7-tvrtko.ursulin@linux.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Tvrtko Ursulin July 9, 2018, 1:19 p.m. UTC
From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

John reports that on a long runnning systems the huge disparity between
kernel context and user context id's causes all interesting colours to be
clustered too close together.

Fix this by assigning colours to seen contexts instead of basing purely
on context id's.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Suggested-by: John Harrison <John.C.Harrison@Intel.com>
Cc: John Harrison <John.C.Harrison@Intel.com>
---
 scripts/trace.pl | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

Comments

John Harrison July 11, 2018, 10:16 p.m. UTC | #1
On 7/9/2018 6:19 AM, Tvrtko Ursulin wrote:
> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
>
> John reports that on a long runnning systems the huge disparity between
> kernel context and user context id's causes all interesting colours to be
> clustered too close together.
>
> Fix this by assigning colours to seen contexts instead of basing purely
> on context id's.
>
> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> Suggested-by: John Harrison <John.C.Harrison@Intel.com>
> Cc: John Harrison <John.C.Harrison@Intel.com>
> ---
>   scripts/trace.pl | 25 ++++++++++++++++++++-----
>   1 file changed, 20 insertions(+), 5 deletions(-)
>
> diff --git a/scripts/trace.pl b/scripts/trace.pl
> index aeaf2392162e..60a8e441c1d9 100755
> --- a/scripts/trace.pl
> +++ b/scripts/trace.pl
> @@ -336,7 +336,7 @@ sub sanitize_ctx
>   {
>   	my ($ctx, $ring) = @_;
>   
> -	if (exists $ctxdb{$ctx}) {
> +	if (exists $ctxdb{$ctx} and $ctxdb{$ctx} > 1) {
>   		return $ctx . '.' . $ctxdb{$ctx};
>   	} else {
>   		return $ctx;
> @@ -425,6 +425,8 @@ while (<>) {
>   			$ctxdb{$orig_ctx}++;
>   			$ctx = sanitize_ctx($orig_ctx, $ring);
>   			$key = db_key($ring, $ctx, $seqno);
> +		} else {
> +			$ctxdb{$orig_ctx} = 1;
>   		}
>   
>   		$queue{$key} = $time;
> @@ -592,7 +594,7 @@ foreach my $key (@sorted_keys) {
>   
>   my $last_ts = 0;
>   my $first_ts;
> -my ($min_ctx, $max_ctx);
> +my $min_ctx;
>   
>   foreach my $key (@sorted_keys) {
>   	my $ring = $db{$key}->{'ring'};
> @@ -604,8 +606,6 @@ foreach my $key (@sorted_keys) {
>   	$last_ts = $end if $end > $last_ts;
>   	$min_ctx = $db{$key}->{'ctx'} if not defined $min_ctx or
>   					 $db{$key}->{'ctx'} < $min_ctx;
> -	$max_ctx = $db{$key}->{'ctx'} if not defined $max_ctx or
> -					 $db{$key}->{'ctx'} > $max_ctx;
>   
>   	$db{$key}->{'context-complete-delay'} = $end - $notify;
>   	$db{$key}->{'execute-delay'} = $start - $db{$key}->{'submit'};
> @@ -739,6 +739,21 @@ say sprintf('GPU: %.2f%% idle, %.2f%% busy',
>   my $timeline_text = $colour_contexts ?
>   		    'Per context coloured shading like:' : 'Box shading like:';
>   
> +my %ctx_colours;
> +
> +sub generate_ctx_colours
> +{
> +	my $num_ctx = keys %ctxdb;
> +	my $i = 0;
> +
> +	foreach my $ctx (sort keys %ctxdb) {
> +		$ctx_colours{$ctx} = int(360 / $num_ctx * $i++);
> +	}
> +}
> +
> +
> +generate_ctx_colours() if $html and $colour_contexts;
> +
>   my $queued_style = box_style($min_ctx, 'queue');
>   my $ready_style = box_style($min_ctx, 'ready');
>   my $execute_style = box_style($min_ctx, 'execute');
> @@ -947,7 +962,7 @@ sub ctx_colour
>   			$l = 25;
>   		}
>   
> -		$val = int(360 / ($max_ctx - $min_ctx + 1)) * ($ctx - $min_ctx);
> +		$val = $ctx_colours{$ctx};
>   	}
>   
>   	$l = int($l * $lfac);

Oops, I think I had already squashed this patch into patch #2 in my 
brain. So some of my comments (and certainly the legend tweak patch) 
probably apply to here instead. So I guess you might need to either 
split my comments/tweaks up across the two patches or possibly just 
squash this one into the other for real :).
diff mbox

Patch

diff --git a/scripts/trace.pl b/scripts/trace.pl
index aeaf2392162e..60a8e441c1d9 100755
--- a/scripts/trace.pl
+++ b/scripts/trace.pl
@@ -336,7 +336,7 @@  sub sanitize_ctx
 {
 	my ($ctx, $ring) = @_;
 
-	if (exists $ctxdb{$ctx}) {
+	if (exists $ctxdb{$ctx} and $ctxdb{$ctx} > 1) {
 		return $ctx . '.' . $ctxdb{$ctx};
 	} else {
 		return $ctx;
@@ -425,6 +425,8 @@  while (<>) {
 			$ctxdb{$orig_ctx}++;
 			$ctx = sanitize_ctx($orig_ctx, $ring);
 			$key = db_key($ring, $ctx, $seqno);
+		} else {
+			$ctxdb{$orig_ctx} = 1;
 		}
 
 		$queue{$key} = $time;
@@ -592,7 +594,7 @@  foreach my $key (@sorted_keys) {
 
 my $last_ts = 0;
 my $first_ts;
-my ($min_ctx, $max_ctx);
+my $min_ctx;
 
 foreach my $key (@sorted_keys) {
 	my $ring = $db{$key}->{'ring'};
@@ -604,8 +606,6 @@  foreach my $key (@sorted_keys) {
 	$last_ts = $end if $end > $last_ts;
 	$min_ctx = $db{$key}->{'ctx'} if not defined $min_ctx or
 					 $db{$key}->{'ctx'} < $min_ctx;
-	$max_ctx = $db{$key}->{'ctx'} if not defined $max_ctx or
-					 $db{$key}->{'ctx'} > $max_ctx;
 
 	$db{$key}->{'context-complete-delay'} = $end - $notify;
 	$db{$key}->{'execute-delay'} = $start - $db{$key}->{'submit'};
@@ -739,6 +739,21 @@  say sprintf('GPU: %.2f%% idle, %.2f%% busy',
 my $timeline_text = $colour_contexts ?
 		    'Per context coloured shading like:' : 'Box shading like:';
 
+my %ctx_colours;
+
+sub generate_ctx_colours
+{
+	my $num_ctx = keys %ctxdb;
+	my $i = 0;
+
+	foreach my $ctx (sort keys %ctxdb) {
+		$ctx_colours{$ctx} = int(360 / $num_ctx * $i++);
+	}
+}
+
+
+generate_ctx_colours() if $html and $colour_contexts;
+
 my $queued_style = box_style($min_ctx, 'queue');
 my $ready_style = box_style($min_ctx, 'ready');
 my $execute_style = box_style($min_ctx, 'execute');
@@ -947,7 +962,7 @@  sub ctx_colour
 			$l = 25;
 		}
 
-		$val = int(360 / ($max_ctx - $min_ctx + 1)) * ($ctx - $min_ctx);
+		$val = $ctx_colours{$ctx};
 	}
 
 	$l = int($l * $lfac);