diff mbox

[i-g-t] trace.pl: handle request tracepoint fields regardless of their order

Message ID 20171215180447.17387-1-lionel.g.landwerlin@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Lionel Landwerlin Dec. 15, 2017, 6:04 p.m. UTC
It doesn't look like tracepoint have any guarantee to have always the
same ordering of their parameter. Instead of relying on a predefined
regexp, let's split the parameters on commas and access the values
through a map.

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
---
 scripts/trace.pl | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

Comments

Tvrtko Ursulin Dec. 18, 2017, 8:23 a.m. UTC | #1
On 15/12/2017 18:04, Lionel Landwerlin wrote:
> It doesn't look like tracepoint have any guarantee to have always the
> same ordering of their parameter. Instead of relying on a predefined
> regexp, let's split the parameters on commas and access the values
> through a map.
> 
> Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
> ---
>   scripts/trace.pl | 30 ++++++++++++++++++++----------
>   1 file changed, 20 insertions(+), 10 deletions(-)
> 
> diff --git a/scripts/trace.pl b/scripts/trace.pl
> index aed9b20d..41b1ae46 100755
> --- a/scripts/trace.pl
> +++ b/scripts/trace.pl
> @@ -302,15 +302,25 @@ die if scalar(@args);
>   
>   @ARGV = @args;
>   
> +sub params_to_map
> +{
> +    my @arr = split /,\s*/, $_;

shift @_ instead of $_ or unexpected things happen.

> +    my %keyvals = ();

No need to init to nothing.

> +    foreach my $el (@arr) {
> +        my @keyval = split /=/, $el;
> +        $keyvals{$keyval[0]} = $keyval[1];
> +    }
> +    return %keyvals;
> +}
> +
>   sub parse_req
>   {
>   	my ($line, $tp) = @_;
> -	state %cache;
> -
> -	$cache{$tp} = qr/(\d+)\.(\d+):.*$tp.*ring=(\d+), ctx=(\d+), seqno=(\d+), global(?:_seqno)?=(\d+)/ unless exists $cache{$tp}; >
> -	if ($line =~ $cache{$tp}) {
> -		return ($1, $2, $3, $4, $5, $6);

I was worried about regexp cache removal, since it was very important 
for performance. So I tried with this patch and indeed the script was 
~2.4x slower.

I'll see if I can do better.

Regards,

Tvrtko

> +	if ($line =~ /(\d+)\.(\d+):.*$tp:\s*(.*)/) {
> +		my %params = params_to_map($3);
> +		return ($1, $2, $params{"ring"}, $params{"ctx"}, $params{"seqno"},
> +			exists $params{"global"} ? $params{"global"} : $params{"global_seqno"});
>   	} else {
>   		return undef;
>   	}
> @@ -319,12 +329,12 @@ sub parse_req
>   sub parse_req_hw
>   {
>   	my ($line, $tp) = @_;
> -	state %cache;
> -
> -	$cache{$tp} = qr/(\d+)\.(\d+):.*$tp.*ring=(\d+), ctx=(\d+), seqno=(\d+), global(?:_seqno)?=(\d+), port=(\d+)/ unless exists $cache{$tp};
>   
> -	if ($line =~ $cache{$tp}) {
> -		return ($1, $2, $3, $4, $5, $6, $7);
> +	if ($line =~ /(\d+)\.(\d+):.*$tp:\s*(.*)/) {
> +		my %params = params_to_map($3);
> +		return ($1, $2, $params{"ring"}, $params{"ctx"}, $params{"seqno"},
> +			exists $params{"global"} ? $params{"global"} : $params{"global_seqno"},
> +			$params{"port"});
>   	} else {
>   		return undef;
>   	}
>
diff mbox

Patch

diff --git a/scripts/trace.pl b/scripts/trace.pl
index aed9b20d..41b1ae46 100755
--- a/scripts/trace.pl
+++ b/scripts/trace.pl
@@ -302,15 +302,25 @@  die if scalar(@args);
 
 @ARGV = @args;
 
+sub params_to_map
+{
+    my @arr = split /,\s*/, $_;
+    my %keyvals = ();
+    foreach my $el (@arr) {
+        my @keyval = split /=/, $el;
+        $keyvals{$keyval[0]} = $keyval[1];
+    }
+    return %keyvals;
+}
+
 sub parse_req
 {
 	my ($line, $tp) = @_;
-	state %cache;
-
-	$cache{$tp} = qr/(\d+)\.(\d+):.*$tp.*ring=(\d+), ctx=(\d+), seqno=(\d+), global(?:_seqno)?=(\d+)/ unless exists $cache{$tp};
 
-	if ($line =~ $cache{$tp}) {
-		return ($1, $2, $3, $4, $5, $6);
+	if ($line =~ /(\d+)\.(\d+):.*$tp:\s*(.*)/) {
+		my %params = params_to_map($3);
+		return ($1, $2, $params{"ring"}, $params{"ctx"}, $params{"seqno"},
+			exists $params{"global"} ? $params{"global"} : $params{"global_seqno"});
 	} else {
 		return undef;
 	}
@@ -319,12 +329,12 @@  sub parse_req
 sub parse_req_hw
 {
 	my ($line, $tp) = @_;
-	state %cache;
-
-	$cache{$tp} = qr/(\d+)\.(\d+):.*$tp.*ring=(\d+), ctx=(\d+), seqno=(\d+), global(?:_seqno)?=(\d+), port=(\d+)/ unless exists $cache{$tp};
 
-	if ($line =~ $cache{$tp}) {
-		return ($1, $2, $3, $4, $5, $6, $7);
+	if ($line =~ /(\d+)\.(\d+):.*$tp:\s*(.*)/) {
+		my %params = params_to_map($3);
+		return ($1, $2, $params{"ring"}, $params{"ctx"}, $params{"seqno"},
+			exists $params{"global"} ? $params{"global"} : $params{"global_seqno"},
+			$params{"port"});
 	} else {
 		return undef;
 	}