Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] configuration option tracing/platform renamed to tracing/categorized
[simgrid.git] / tools / simgrid_update_xml.pl
1 #! /usr/bin/perl
2
3 # This script updates the simgrid XML file passed as argument (modification in place)
4 # It is built to do the conversion incrementally.
5
6 # Copyright (C) 2006-2010. The SimGrid team. All rights reserved.
7 #
8 # This file is part of the SimGrid project. This is free software:
9 # You can redistribute and/or modify it under the terms of the
10 # GNU LGPL (v2.1) licence.
11
12 use strict;
13
14 my $fromversion=-1;
15 my $toversion=3;
16
17 my($output_string);
18
19 $ARGV[0] or die "simgrid_update_xml.pl <platform.xml>\n";
20 open INPUT, "$ARGV[0]" or die "Cannot open input file $ARGV[0]: $!\n";
21
22 $output_string .=  "<?xml version='1.0'?>\n";
23 $output_string .=  "<!DOCTYPE platform SYSTEM \"simgrid.dtd\">\n";
24 $output_string .=  "<platform version=\"$toversion\">\n";
25 $output_string .=  " <AS  id=\"AS0\"  routing=\"Full\">\n";
26
27 my $line;
28 while (defined($line = <INPUT>)) {
29     chomp $line;
30     # eat the header, whatever form it has
31     next if ($line =~ s/<\?xml[^>]*>//           && ! $line =~ /\S/); # just in case several tags are on the same line
32     next if ($line =~ s/<!DOCTYPE[^>]*>//        && ! $line =~ /\S/);
33     
34     if ($line =~ s/<platform(_description)? *>//) {
35         $fromversion = 0;
36         print "version 0\n";
37         next if !$line =~ /\S/;
38     } elsif ($line =~ s/<platform.*version=["]*([0-9.])["]*>//) {
39         $fromversion = $1;
40         print "version $fromversion\n";
41         if ($fromversion == $toversion) {
42             die "Input platform file version is already $fromversion. This should be a no-op.\n";
43         }
44         if ($fromversion > $toversion) {
45             die "Input platform file version is more recent than this script (file version: $fromversion; script version: $toversion)\n";
46         }
47         next if !$line =~ /\S/;
48     }
49     
50     if ($fromversion == 0) {
51         while ($line =~ m|^(.*?)<cpu(.*?)power="([^"]*)"(.*)$|) {
52             $line = "$1TOTOTUTUTATA${2}TOTOTUTUTATA".($3*1000000)."TOTOTUTUTATA${4}";
53         }
54         while ($line =~ /^(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*)$/) {
55             $line = "$1<cpu${2}power=\"$3\"$4";
56         }
57         while ($line =~ m|^(.*?)<network_link(.*?)bandwidth="([^"]*)"(.*?)$|) {
58             $line = "$1TOTOTUTUTATA${2}TOTOTUTUTATA".($3*1000000)."TOTOTUTUTATA${4}";
59         }
60         while ($line =~ /^(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*?)$/) {
61             $line = "$1<network_link${2}bandwidth=\"$3\"$4";
62         }
63     }
64
65     if ($fromversion < 2)  {
66         # The renamings (\b=zero-width word boundary check)
67         $line =~ s/\bplatform_description\b/platform/g;
68         $line =~ s/\bname\b/id/g;
69         $line =~ s/\bcpu\b/host/g;
70         $line =~ s/\bnetwork_link\b/link/g;
71         $line =~ s/\broute_element\b/link:ctn/g;
72     }
73     
74     if ($fromversion < 3)  {
75         $line =~ s/\blink:ctn\b/link_ctn/g;
76         $line =~ s/\btrace:connect\b/trace_connect/g;
77         $line =~ s/^(.*)<\/platform>(.*)$/ <\/AS>\n<\/platform>/;
78     }
79
80     $output_string .= "$line\n";
81 }
82
83 close INPUT;
84
85 if ($fromversion == -1) {
86     die "Cannot retrieve the platform version\n";
87 }
88
89 open OUTPUT, "> $ARGV[0]";
90 print OUTPUT $output_string;
91 close OUTPUT;