bin/phytronFilterIpPortLog.pl: Tool to beautify and filter IP-Port data to debug phyMotion motors
Annotate for file bin/phytronFilterIpPortLog.pl
2022-02-23 Bernhard.Kun 1 #!/usr/bin/env perl
11:45:57 ' 2
' 3 # EXAMPLE Data from phyMotion IP-Port log
' 4 #
' 5 # asynSetTraceMask connMOU1YU5L -1 9
' 6 # SIOC2S5L>
' 7 # 2022/02/22 16:05:47.956 mou1s05l.blc05.bessy.de:22222 write 14
' 8 # 0M1.1P20R:XX
' 9 # 2022/02/22 16:05:47.966 mou1s05l.blc05.bessy.de:22222 read 12
' 10 # -50188:25
' 11 # 2022/02/22 16:05:47.966 mou1s05l.blc05.bessy.de:22222 write 14
' 12 # 0M1.1P22R:XX
' 13 # 2022/02/22 16:05:47.975 mou1s05l.blc05.bessy.de:22222 read 7
' 14 # 0:0C
' 15
' 16 use strict;
' 17 use Getopt::Long;
' 18
' 19 my $usage = "phytronFilterLog.pl [OPTIONS] phytronIpPortLogFile\n\t-h: help\n\t-f: filter e.g. M1.1 for motor 1\n";
' 20 my $filter = ".*"; #default: get all
' 21 my $ignore = "___";
' 22 our($opt_h,$opt_f,$opt_i) = (undef,undef,undef);
' 23
' 24 Getopt::Long::config(qw(no_ignore_case));
' 25 die unless GetOptions("h","f=s","i=s");
' 26 die $usage unless scalar(@ARGV) > 0;
' 27 die $usage if( $opt_h);
' 28
' 29 $filter = $opt_f if( $opt_f);
' 30 $ignore = $opt_i if( $opt_i);
' 31 my $inFileName = @ARGV[0];
' 32
' 33 open(IN_FILE, "<$inFileName") or die "can't open input file: '$inFileName'";
' 34
' 35 my $command;
' 36 my $reply;
' 37 my $timeWrite;
' 38 my $timeRead;
' 39 my $line;
' 40 my $lineNr = 0;
' 41 while( <IN_FILE> )
' 42 {
' 43 my $matchFilter = undef;
' 44 $line = $_;
' 45 $lineNr++;
' 46 $timeWrite = $1;
' 47 # check write
' 48 if($line =~ /^.*?\s(.*?)\s.*?\s(\w+)/ && $2 eq 'write') {
' 49 $line = <IN_FILE>;
' 50 $lineNr++;
' 51 if($line=~/\d(M.*):../) { # Axis command
' 52 $command=$1;
' 53 }
' 54 elsif($line=~/(.*):../) { # other command
' 55 $command=$1;
' 56 }
' 57 else {
' 58 $command = "ILLEGAL COMMAND: '$line'\n";
' 59 }
' 60 if( not ($command =~/$ignore/) ) {
' 61 print "$lineNr\t$timeWrite\twr\t$command\n";
' 62 $matchFilter = 1;
' 63 if( $command =~/$filter/) {
' 64 print "$lineNr\t$timeWrite\twr\t$command\n";
' 65 $matchFilter = 1;
' 66 }
' 67 }
' 68 }
' 69 else {
' 70 chomp($line);
' 71 print "$lineNr\t$timeWrite\terr\tWRITE EXPECTED:\t'$line'\n";
' 72 }
' 73
' 74 # next should be 'read'
' 75 $line = <IN_FILE>;
' 76 $lineNr++;
' 77 $timeRead = $1;
' 78 if($line =~ /^.*?\s(.*?)\s.*?\s(\w+)/ && $2 eq 'read') {
' 79 $line = <IN_FILE>;
' 80 $lineNr++;
' 81 if($line=~/(.*):../) {
' 82 $reply = $1;
' 83 }
' 84 else {
' 85 chomp($line);
' 86 $reply = "ILLEGAL REPLY: '$line'";
' 87 }
' 88 print "$lineNr\t$timeRead\trd\t$reply\n" if($matchFilter);
' 89 }
' 90 else {
' 91 chomp($line);
' 92 print "$lineNr\t$timeRead\terr\tMISS READ\t'$line'\n";
' 93 }
' 94 }
' 95 close IN_FILE;