Logo AND Algorithmique Numérique Distribuée

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