Logo AND Algorithmique Numérique Distribuée

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