Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
498bab6472216f2adbfe64a8810ccd90bfa51898
[simgrid.git] / tools / MSG_visualization / colorize.pl
1 #!/usr/bin/perl
2
3 $col_white    = "\033[00m";
4 $col_black    = "\033[30m";
5 $col_red      = "\033[31m";
6 $col_green    = "\033[32m";
7 $col_yellow   = "\033[33m";
8 $col_blue     = "\033[34m";
9 $col_purple   = "\033[35m";
10 $col_cyan     = "\033[36m";
11 $col_ltgray   = "\033[37m";
12 $col_darkgray = "\033[30m";
13
14 $col_norm       = $col_white;
15 $col_background = "\033[07m";
16 $col_brighten   = "\033[01m";
17 $col_underline  = "\033[04m";
18 $col_blink      = "\033[05m";
19
20 # Customize colors here...
21 #
22 $col_default = $col_ltgray;
23 my (@coltab) = (
24     $col_green,                    $col_yellow,
25     $col_purple,                   $col_cyan,
26     $col_red,                      $col_blue,
27     $col_background . $col_green,
28     $col_background . $col_yellow, $col_background . $col_purple,
29     $col_background . $col_cyan,   $col_background . $col_red,
30     $col_background . $col_blue,   $col_background . $col_magenta,
31 );
32
33 my %pid;
34
35 # Get options
36 #
37 while (($_ = $ARGV[0]) =~ /^-/) {
38     shift;
39     if (/-location/i) {
40         $opt_print_location = 1;  shift;
41     } elsif (/-h(elp)?$|-u(sage)?$/i) {
42         print<<EOH
43 colorize.pl - Log colorizer for SimGrid
44 Syntax:
45
46     colorize.pl [options] <file>
47
48     where <file> is a text file of values or '-' for STDIN
49
50 Options: () denote short version
51
52     -location          Print the location in the code of the message.
53 EOH
54 ;
55         exit;
56     }
57 }
58
59 sub pidcolor {
60     my $pid = shift;
61
62     unless (defined($pid{$pid})) {
63         # first time we see this pid. Affect it a color
64         $pid{$pid}=(scalar keys %pid) % (scalar @coltab);
65     }
66     return $coltab[$pid{$pid}];
67 }
68
69 sub print_line {
70     my($host,$procname,$pid,$date,$location,$xbt_channel,$message)=@_;
71
72     print $col_norm;
73     printf "[% 10.3f]",$date;
74
75     print pidcolor($pid);
76
77     if(defined($location)) {
78         printf "[%10s:%-10s %s ]",$host,$procname,$location;
79     } else {
80         printf "[%10s:%-10s]",$host,$procname;
81     }
82     print " $message";
83     print $col_norm."\n";
84 }
85
86 # Read the messages and do the job
87 while (<>) {
88     $orgline = $thisline = $_;
89
90     # Typical line  [Gatien:slave:(9) 11.243148] msg/gos.c:137: [msg_gos/DEBUG] Action terminated
91     if ($thisline =~ /^\[(.+):([^:]+):\((\d+)\) ([\d\.]*)\] ([^\[]*) \[([^\[]*)\] (.*)$/) {
92         $host=$1;
93         $procname=$2;
94         $pid=$3;
95         $date=$4;
96         if($opt_print_location) {
97             $location=$5;
98             $location =~ s/:$//;
99         } else {
100             $location = undef;
101         }
102         $xbt_channel=$6;
103         $message=$7;
104
105         print_line($host,$procname,$pid,$date,$location,$xbt_channel,$message);
106     # Typical line  [Boivin:slave:(2) 9.269357] [pmm/INFO] ROW: step(2)<>myrow(0). Receive data from TeX
107     } elsif ($thisline =~ /^\[([^:]+):([^:]+):\((\d+)\) ([\d\.]*)\] \[([^\[]*)\] (.*)$/) {
108         $host=$1;
109         $procname=$2;
110         $pid=$3;
111         $date=$4;
112         $xbt_channel=$5;
113         $message=$6;
114         print_line($host,$procname,$pid,$date,undef,$xbt_channel,$message);
115     } elsif ( $thisline =~ /^==(\d+)== (.*)$/) {
116         # take care of valgrind outputs
117         print pidcolor($1)."$2\n";
118
119     } else {
120         print $col_default. $orgline;
121     }
122 }
123
124 print $col_norm;