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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




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@xxxxxxxxx>
---
  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;
  	}

_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux