[igt-dev] [PATCH i-g-t 05/11] trace.pl: Fix HTML timestamp generation

John Harrison John.C.Harrison at Intel.com
Wed Jul 11 18:01:44 UTC 2018


On 7/9/2018 6:19 AM, Tvrtko Ursulin wrote:
> From: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
>
> Now that we scale timestamps to get better timeline granularity, the hacky
> hand rolled micro-second time to HTML date conversion does no longer cut
> it.
>
> Use perl built-in gmtime to handle things properly.
>
> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
> Cc: John Harrison <John.C.Harrison at Intel.com>
> ---
>   scripts/trace.pl | 15 ++++-----------
>   1 file changed, 4 insertions(+), 11 deletions(-)
>
> diff --git a/scripts/trace.pl b/scripts/trace.pl
> index e2978e5382c2..aeaf2392162e 100755
> --- a/scripts/trace.pl
> +++ b/scripts/trace.pl
> @@ -346,24 +346,17 @@ sub sanitize_ctx
>   sub ts
>   {
>   	my ($us) = @_;
> -	my ($d, $h, $m, $s);
> +	my ($y, $mo, $d, $h, $m, $s);
>   
>   	$us *= 1000 unless $no_timeline_scaling;
>   
>   	$s = int($us / 1000000);
>   	$us = $us % 1000000;
>   
> -	$m = int($s / 60);
> -	$s = $s % 60;
> +	($s, $m, $h, $d, $mo, $y) = gmtime($s);
>   
> -	$h = int($m / 60);
> -	$m = $m % 60;
> -
> -	$d = 1 + int($h / 24);
> -	$h = $h % 24;
> -
> -	return sprintf('2017-01-%02u %02u:%02u:%02u.%06u',
> -		       int($d), int($h), int($m), int($s), int($us));
> +	return sprintf('%04u-%02u-%02u %02u:%02u:%02u.%06u',
> +		        1970 + $y, 1 + $mo, $d, $h, $m, $s, int($us));

Maybe not bother with the +1970 in the scaling case given that the whole 
date thing is meaningless when microseconds become milliseconds? 
Actually, even in the non-scaling case the epoch is actually whenever 
the traced system was last booted and not some specific calendar date. 
So maybe leaving out the offset regardless would make sense?

Again, a minor point so...

Reviewed-by: John Harrison <John.C.Harrison at Intel.com>


>   }
>   
>   # Main input loop - parse lines and build the internal representation of the



More information about the igt-dev mailing list