Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Drawing states...
authoralegrand <alegrand@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Sun, 18 Jun 2006 13:28:03 +0000 (13:28 +0000)
committeralegrand <alegrand@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Sun, 18 Jun 2006 13:28:03 +0000 (13:28 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@2388 48e7efb5-ca39-0410-a469-dd3cf9ba447f

tools/MSG_visualization/trace2fig.pl

index 839f3a7..55fa06e 100755 (executable)
@@ -3,8 +3,8 @@ use strict;
 use Data::Dumper;
 use XFig;
 
 use Data::Dumper;
 use XFig;
 
-my($grid_size)=225; # xfig 
-
+my($grid_Y_size)=225; # xfig 
+my($grid_X_size)=225; # xfig 
 
 sub read_cat {
     my(%Cat);
 
 sub read_cat {
     my(%Cat);
@@ -30,6 +30,27 @@ sub read_cat {
 }
 
 
 }
 
 
+sub read_event {
+    my($filename,$Cat)=@_;
+    my($line);
+
+    open INPUT, $filename;
+
+    while (defined($line=<INPUT>)) {
+       chomp $line;
+       if($line =~ /^11\s/) {
+           my($event,$date,$type,$id,$state) = split(/\s+/,$line);
+           push @{$$Cat{$id}{state}}, [$date,$state];
+       }
+       if($line =~ /^12\s/) {
+           my($event,$date,$type,$id) = split(/\s+/,$line);
+           push @{$$Cat{$id}{state}}, [$date];
+       }
+    }
+    close INPUT;
+}
+
+
 sub build_cat_tree {
     my($root,$Cat)=@_;
     my(@childs)=();
 sub build_cat_tree {
     my($root,$Cat)=@_;
     my(@childs)=();
@@ -64,8 +85,8 @@ sub set_cat_position {
     my($i)=0;
     my($cat);
     foreach $cat (@$cat_list) {
     my($i)=0;
     my($cat);
     foreach $cat (@$cat_list) {
-       $$Cat{$cat}{X_min} = $i;
-       $$Cat{$cat}{X_max} = $i+1;
+       $$Cat{$cat}{Y_min} = $i;
+       $$Cat{$cat}{Y_max} = $i+1;
        $i++;
     }
 }
        $i++;
     }
 }
@@ -89,10 +110,60 @@ sub create_fig {
     return $fig;
 }
 
     return $fig;
 }
 
+sub draw_cat {
+    my($fig,$Cat)=@_;
+    my($cat,$e);
+    foreach $cat (keys %$Cat) {
+       next unless (defined($$Cat{$cat}{Y_min}) && 
+                    defined($$Cat{$cat}{Y_max}));
+       my($text) = new XFig ('text');
+       $text->{'text'} = $cat;
+       $text->{'y'} = ($$Cat{$cat}{Y_min}+$$Cat{$cat}{Y_max})/2*$grid_Y_size+68;
+       $fig->add ($text);
+    }
+    foreach $cat (keys %$Cat) {
+       next unless (defined($$Cat{$cat}{Y_min}) && 
+                    defined($$Cat{$cat}{Y_max}));
+       my(@states)=();
+       my($e);
+       foreach $e (@{$$Cat{$cat}{state}}) {
+           my($new_date,$state) = ($$e[0],$$e[1]);
+           if(defined($state)) {
+               push @states, $e;
+           } else {
+               my($old_event) = pop @states;
+               my($old_date) = $$old_event[0];
+               $state = $$old_event[1];
+               
+               my($line) = new XFig ('polyline');
+
+               $line->{'subtype'} = 1;  # line
+               $line->{'points'} = [ [$old_date*$grid_X_size, $$Cat{$cat}{Y_min}*$grid_Y_size],
+                                     [$new_date*$grid_X_size, $$Cat{$cat}{Y_min}*$grid_Y_size],
+                                     [$new_date*$grid_X_size, $$Cat{$cat}{Y_max}*$grid_Y_size],
+                                     [$old_date*$grid_X_size, $$Cat{$cat}{Y_max}*$grid_Y_size] ];
+               $line->{'areafill'} = 20;
+               if($state eq "S") {
+                   $line->{'fillcolor'} = 1;
+               } elsif ($state eq "E") {
+                   $line->{'fillcolor'} = 2;
+               } elsif ($state eq "B") {
+                   $line->{'fillcolor'} = 3;
+               } elsif ($state eq "C") {
+                   $line->{'fillcolor'} = 4;
+               }
+               $fig->add ($line);
+           }
+       }
+    }
+}
+
 sub main {
     my($Cat) = read_cat($ARGV[0]);
     my($cat_tree)=build_cat_tree("0",$Cat);
 sub main {
     my($Cat) = read_cat($ARGV[0]);
     my($cat_tree)=build_cat_tree("0",$Cat);
+    read_event($ARGV[0],$Cat);
 #    print Dumper($cat_tree);
 #    print Dumper($cat_tree);
+#    print Dumper($Cat);
     my($cat_list)=[];
     build_cat_list($cat_tree,$cat_list);
     shift @$cat_list;
     my($cat_list)=[];
     build_cat_list($cat_tree,$cat_list);
     shift @$cat_list;
@@ -102,14 +173,9 @@ sub main {
     set_cat_position($Cat,$cat_list);
     
     my($fig)=create_fig("toto.fig");
     set_cat_position($Cat,$cat_list);
     
     my($fig)=create_fig("toto.fig");
-    my($cat);
-    foreach $cat (@$cat_list) {
-       my($text) = new XFig ('text');
-       $text->{'text'} = $cat;
-       $text->{'y'} = ($$Cat{$cat}{X_min}+$$Cat{$cat}{X_max})/2*$grid_size+68;
-       $fig->add ($text);
-    }
+    draw_cat($fig,$Cat);
     $fig->writefile ();
     $fig->writefile ();
+    system "fig2dev -L pdf toto.fig toto.pdf";
 }
 
 main;
 }
 
 main;