Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
839f3a72c48ea349ba0d48772f8809da62c3be4d
[simgrid.git] / tools / MSG_visualization / trace2fig.pl
1 #!/usr/bin/perl -w
2 use strict;
3 use Data::Dumper;
4 use XFig;
5
6 my($grid_size)=225; # xfig 
7
8
9 sub read_cat {
10     my(%Cat);
11     my($filename)=@_;
12     my($line);
13
14     open INPUT, $filename;
15
16     while (defined($line=<INPUT>)) {
17         chomp $line;
18         if($line =~ /^7\s/) {
19             my($event,$date,$id,$type,$father,@name) = split(/\s+/,$line);
20
21             $Cat{$id}{name}="@name ";
22             $Cat{$id}{name}=~s/\"//g;
23             $Cat{$id}{father}=$father;
24             $Cat{$id}{type}=$type;
25             $Cat{$id}{date}=$date;
26         }
27     }
28     close INPUT;
29     return \%Cat;
30 }
31
32
33 sub build_cat_tree {
34     my($root,$Cat)=@_;
35     my(@childs)=();
36     my($cat);
37
38     foreach $cat (keys %$Cat) {
39         if($$Cat{$cat}{father} eq $root) {
40             push @childs, build_cat_tree($cat,$Cat);
41         }
42 #       print "$$Cat{$cat}{name}\t\t $Cat{$cat}{father}\n";
43     }
44     
45     return [$root,@childs];
46 }
47
48 sub build_cat_list {
49     my($tree,$cat_list)=@_;
50     my($root) = shift @$tree;
51     my($u);
52     
53     push @$cat_list,$root;
54
55     foreach $u (@$tree) {
56         build_cat_list($u,$cat_list);
57     }
58     unshift @$tree, $root;
59 }
60
61
62 sub set_cat_position {
63     my($Cat,$cat_list)=@_;
64     my($i)=0;
65     my($cat);
66     foreach $cat (@$cat_list) {
67         $$Cat{$cat}{X_min} = $i;
68         $$Cat{$cat}{X_max} = $i+1;
69         $i++;
70     }
71 }
72
73 sub create_fig {
74     my($filename)=shift;
75     my($fig)=new XFig;
76     $fig->{object} = 'compound'; # Compound
77     $fig->{elements} = [];
78     $fig->{version} = 3.2;
79     $fig->{orientation}   = 'Landscape';
80     $fig->{justification} = 'Center';
81     $fig->{units}         = 'Metric';
82     $fig->{papersize}     = 'A4';
83     $fig->{magnification} = '100.00';
84     $fig->{multiplepage}  = 'Single';
85     $fig->{transparent}   = '-2';
86     $fig->{resolution}    = '1200';
87     $fig->{coordsystem}   = '2';
88     $fig->{filename}   = $filename;
89     return $fig;
90 }
91
92 sub main {
93     my($Cat) = read_cat($ARGV[0]);
94     my($cat_tree)=build_cat_tree("0",$Cat);
95 #    print Dumper($cat_tree);
96     my($cat_list)=[];
97     build_cat_list($cat_tree,$cat_list);
98     shift @$cat_list;
99     shift @$cat_list;
100     print "@$cat_list \n";
101
102     set_cat_position($Cat,$cat_list);
103     
104     my($fig)=create_fig("toto.fig");
105     my($cat);
106     foreach $cat (@$cat_list) {
107         my($text) = new XFig ('text');
108         $text->{'text'} = $cat;
109         $text->{'y'} = ($$Cat{$cat}{X_min}+$$Cat{$cat}{X_max})/2*$grid_size+68;
110         $fig->add ($text);
111     }
112     $fig->writefile ();
113 }
114
115 main;