[igt-dev] [PATCH i-g-t v2 1/4] scripts/trace.pl: More hash key optimisations

Tvrtko Ursulin tvrtko.ursulin at linux.intel.com
Wed Jan 24 10:07:00 UTC 2018


On 23/01/2018 06:32, John.C.Harrison at Intel.com wrote:
> From: John Harrison <John.C.Harrison at Intel.com>
> 
> Cache the key count value rather than querying the hash every time.
> Also assert that the database does not magically change size after the
> fixups.
> 
> v2: Rename variable according to style guide [Tvrtko]
> 
> Signed-off-by: John Harrison <John.C.Harrison at intel.com>
> Cc: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
> ---
>   scripts/trace.pl | 8 +++++---
>   1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/scripts/trace.pl b/scripts/trace.pl
> index cb93900d..a73fcf38 100755
> --- a/scripts/trace.pl
> +++ b/scripts/trace.pl
> @@ -508,7 +508,8 @@ foreach my $key (keys %db) {
>   }
>   
>   # Fix up incompletes
> -foreach my $key (keys %db) {
> +my $key_count = scalar(keys(%db));
> +foreach my $key (keys(%db)) {

Could have not changed formatting on this line.

>   	next unless exists $db{$key}->{'incomplete'};
>   
>   	# End the incomplete batch at the time next one starts
> @@ -522,7 +523,7 @@ foreach my $key (keys %db) {
>   		$next_key = db_key($ring, $ctx, $seqno + $i);
>   		$i++;
>   	} until ((exists $db{$next_key} and not exists $db{$next_key}->{'incomplete'})
> -		 or $i > scalar(keys(%db)));  # ugly stop hack
> +		 or $i > $key_count);  # ugly stop hack
>   
>   	if (exists $db{$next_key}) {
>   		$db{$key}->{'notify'} = $db{$next_key}->{'end'};
> @@ -540,6 +541,7 @@ my $first_ts;
>   
>   my @sorted_keys = sort {$db{$a}->{'start'} <=> $db{$b}->{'start'}} keys %db;
>   my $re_sort = 0;

A blank line between declarations and code would be better.

> +die "Database changed size?!" unless scalar(@sorted_keys) == $key_count;
>   
>   foreach my $key (@sorted_keys) {
>   	my $ring = $db{$key}->{'ring'};
> @@ -565,7 +567,7 @@ foreach my $key (@sorted_keys) {
>   		do {
>   			$next_key = db_key($ring, $ctx, $seqno + $i);
>   			$i++;
> -		} until (exists $db{$next_key} or $i > scalar(keys(%db)));  # ugly stop hack
> +		} until (exists $db{$next_key} or $i > $key_count);  # ugly stop hack
>   
>   		# 20us tolerance
>   		if (exists $db{$next_key} and $db{$next_key}->{'start'} < $start + 20) {
> 

With the two tiny tweaks,

Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin at intel.com>

Regards,

Tvrtko


More information about the igt-dev mailing list