[Intel-gfx] [PATCH i-g-t 1/8] trace.pl: Improve time axis labels

Tvrtko Ursulin tursulin at ursulin.net
Wed Jul 18 09:45:07 UTC 2018


From: Tvrtko Ursulin <tvrtko.ursulin at intel.com>

It is possible to customize the axis display so change it to display
timestamps in seconds on the major axis (with six decimal spaces) and
millisecond offsets on the minor axis.

v2:
 * Give up on broken relative timestamps.

v3:
 * Drop all date complications and just use micro seconds throughout.
   (John Harrison)

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
Suggested-by: Chris Wilson <chris at chris-wilson.co.uk>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
Cc: John Harrison <John.C.Harrison at Intel.com>
Reviewed-by: John Harrison <John.C.Harrison at Intel.com> # v2
---
 scripts/trace.pl | 72 ++++++++++++++++++++++++++++++++----------------
 1 file changed, 48 insertions(+), 24 deletions(-)

diff --git a/scripts/trace.pl b/scripts/trace.pl
index fc1713e4f9a7..3ad5effafd0a 100755
--- a/scripts/trace.pl
+++ b/scripts/trace.pl
@@ -329,20 +329,6 @@ sub sanitize_ctx
 	}
 }
 
-sub ts
-{
-	my ($us) = @_;
-	my ($y, $mo, $d, $h, $m, $s);
-
-	$s = int($us / 1000000);
-	$us = $us % 1000000;
-
-	($s, $m, $h, $d, $mo, $y) = gmtime($s);
-
-	return sprintf('%04u-%02u-%02u %02u:%02u:%02u.%06u',
-		        $y, 1 + $mo, $d, $h, $m, $s, int($us));
-}
-
 # Main input loop - parse lines and build the internal representation of the
 # trace using a hash of requests and some auxilliary data structures.
 my $prev_freq = 0;
@@ -912,7 +898,7 @@ foreach my $key (sort sortQueue keys %db) {
 		$style = 'color: black; background-color: ' .
 			 ctx_colour($ctx, 'queue');
 		$content = "$name<br>$db{$key}->{'submit-delay'}us <small>($db{$key}->{'execute-delay'}us)</small>";
-		$startend = 'start: \'' . ts($queue) . '\', end: \'' . ts($submit) . '\'';
+		$startend = 'start: ' . $queue . ', end: ' . $submit;
 		print "\t{id: $i, key: $skey, $type group: $group, subgroup: $subgroup, subgroupOrder: $subgroup, content: '$content', $startend, style: \'$style\'},\n";
 		$i++;
 	}
@@ -923,7 +909,7 @@ foreach my $key (sort sortQueue keys %db) {
 		$style = 'color: black; background-color: ' .
 			 ctx_colour($ctx, 'ready');
 		$content = "<small>$name<br>$db{$key}->{'execute-delay'}us</small>";
-		$startend = 'start: \'' . ts($submit) . '\', end: \'' . ts($start) . '\'';
+		$startend = 'start: ' . $submit . ', end: ' . $start;
 		print "\t{id: $i, key: $skey, $type group: $group, subgroup: $subgroup, subgroupOrder: $subgroup, content: '$content', $startend, style: \'$style\'},\n";
 		$i++;
 	}
@@ -942,7 +928,7 @@ foreach my $key (sort sortQueue keys %db) {
 		$content .= ' <small><i>++</i></small> ' if exists $db{$key}->{'no-end'};
 		$content .= ' <small><i>+</i></small> ' if exists $db{$key}->{'no-notify'};
 		$content .= "<br>$db{$key}->{'duration'}us <small>($db{$key}->{'context-complete-delay'}us)</small>";
-		$startend = 'start: \'' . ts($start) . '\', end: \'' . ts($notify) . '\'';
+		$startend = 'start: ' . $start . ', end: ' . $notify;
 		print "\t{id: $i, key: $skey, $type group: $group, subgroup: $subgroup, subgroupOrder: $subgroup, content: '$content', $startend, style: \'$style\'},\n";
 		$i++;
 	}
@@ -956,7 +942,7 @@ foreach my $key (sort sortQueue keys %db) {
 		$content .= ' <small><i>???</i></small> ' if exists $db{$key}->{'incomplete'};
 		$content .= ' <small><i>++</i></small> ' if exists $db{$key}->{'no-end'};
 		$content .= ' <small><i>+</i></small> ' if exists $db{$key}->{'no-notify'};
-		$startend = 'start: \'' . ts($notify) . '\', end: \'' . ts($end) . '\'';
+		$startend = 'start: ' . $notify . ', end: ' . $end;
 		print "\t{id: $i, key: $skey, $type group: $group, subgroup: $subgroup, subgroupOrder: $subgroup, content: '$content', $startend, style: \'$style\'},\n";
 		$i++;
 	}
@@ -974,7 +960,7 @@ foreach my $item (@freqs) {
 
 	$start = $first_ts if $start < $first_ts;
 	$end = $last_ts if $end > $last_ts;
-	$startend = 'start: \'' . ts($start) . '\', end: \'' . ts($end) . '\'';
+	$startend = 'start: ' . $start . ', end: ' . $end;
 	print "\t{id: $i, type: 'range', group: 0, content: '$freq', $startend},\n";
 	$i++;
 }
@@ -988,18 +974,55 @@ if ($gpu_timeline) {
 
 		$start = $first_ts if $start < $first_ts;
 		$end = $last_ts if $end > $last_ts;
-		$startend = 'start: \'' . ts($start) . '\', end: \'' . ts($end) . '\'';
+		$startend = 'start: ' . $start . ', end: ' . $end;
 		print "\t{id: $i, type: 'range', group: 1, $startend},\n";
 		$i++;
 	}
 }
 
-my $end_ts = ts($first_ts + $width_us);
-$first_ts = ts($first_ts);
+my $end_ts = $first_ts + $width_us;
+$first_ts = $first_ts;
 
 print <<ENDHTML;
   ]);
 
+  function majorAxis(date, scale, step) {
+	var s = date / 1000000;
+	var precision;
+
+	if (scale == 'millisecond')
+		precision = 6;
+	else if (scale == 'second')
+		precision = 3;
+	else
+		precision = 0;
+
+	return s.toFixed(precision) + "s";
+  }
+
+  function minorAxis(date, scale, step) {
+	var t = date;
+	var precision;
+	var unit;
+
+	if (scale == 'millisecond') {
+		t %= 1000;
+		precision = 0;
+		unit = 'us';
+	} else if (scale == 'second') {
+		t /= 1000;
+		t %= 1000;
+		precision = 0;
+		unit = 'ms';
+	} else {
+		t /= 1000000;
+		precision = 1;
+		unit = 's';
+	}
+
+	return t.toFixed(precision) + unit;
+  }
+
   // Configuration for the Timeline
   var options = { groupOrder: 'content',
 		  horizontalScroll: true,
@@ -1007,8 +1030,9 @@ print <<ENDHTML;
 		  stackSubgroups: false,
 		  zoomKey: 'ctrlKey',
 		  orientation: 'top',
-		  start: '$first_ts',
-		  end: '$end_ts'};
+		  format: { majorLabels: majorAxis, minorLabels: minorAxis },
+		  start: $first_ts,
+		  end: $end_ts};
 
   // Create a Timeline
   var timeline = new vis.Timeline(container, items, groups, options);
-- 
2.17.1



More information about the Intel-gfx mailing list