Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
the borland project file for stub_generator
[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 # Read the messages and do the job
70 while (<>) {
71     $orgline = $thisline = $_;
72
73     if ( $thisline =~ /^\[([^:]+):([^:]+):\((\d+)\) ([\d\.]*)\] ([^\[]*) \[([^\[]*)\] (.*)$/ ) {
74         $host=$1;
75         $procname=$2;
76         $pid=$3;
77         $date=$4;
78         $location=$5;
79         $xbt_channel=$6;
80         $message=$7;
81
82         $location =~ s/:$//;
83
84         print $col_norm;
85         printf "[% 10.3f]",$date;
86
87         print pidcolor($pid);
88         if($opt_print_location) {
89             printf "[%10s:%-10s %s ]",$host,$procname,$location;
90         } else {
91             printf "[%10s:%-10s]",$host,$procname;
92         }
93         print " $message";
94         print $col_norm."\n";
95     } elsif ( $thisline =~ /^==(\d+)== (.*)$/) {
96         # take care of valgrind outputs
97         print pidcolor($1)."$2\n";
98
99     } else {
100         print $col_default. $orgline;
101     }
102 }
103
104 print $col_norm;