Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / teshsuite / platforms / flatifier.cpp
1 /* Copyright (c) 2008-2023. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include <xbt/xbt_os_time.h>
7
8 #include "simgrid/kernel/routing/NetPoint.hpp"
9 #include "simgrid/s4u/Engine.hpp"
10 #include "simgrid/s4u/Host.hpp"
11 #include "simgrid/s4u/Link.hpp"
12 #include "src/kernel/resource/StandardLinkImpl.hpp"
13
14 #include <algorithm>
15 #include <cstring>
16 #include <sstream>
17
18 XBT_LOG_NEW_DEFAULT_CATEGORY(flatifier, "Logging specific to this platform parsing tool");
19
20 namespace sg4 = simgrid::s4u;
21
22 static bool parse_cmdline(bool* timings, char** platformFile, int argc, char** argv)
23 {
24   bool parse_ok = true;
25   for (int i = 1; i < argc; i++) {
26     if (std::strlen(argv[i]) > 1 && argv[i][0] == '-' && argv[i][1] == '-') {
27       if (not std::strcmp(argv[i], "--timings")) {
28         *timings = true;
29       } else {
30         parse_ok = false;
31         break;
32       }
33     } else {
34       *platformFile = argv[i];
35     }
36   }
37   return parse_ok && platformFile != nullptr;
38 }
39
40 int main(int argc, char** argv)
41 {
42   char* platformFile = nullptr;
43   bool timings       = false;
44
45   xbt_os_timer_t parse_time = xbt_os_timer_new();
46
47   sg4::Engine e(&argc, argv);
48
49   xbt_assert(parse_cmdline(&timings, &platformFile, argc, argv),
50              "Invalid command line arguments: expected [--timings] platformFile");
51
52   xbt_os_cputimer_start(parse_time);
53   e.load_platform(platformFile);
54   e.seal_platform();
55   xbt_os_cputimer_stop(parse_time);
56
57   if (timings) {
58     XBT_INFO("Parsing time: %fs (%zu hosts, %zu links)", xbt_os_timer_elapsed(parse_time), e.get_host_count(),
59              e.get_link_count());
60   } else {
61     std::printf("%s", e.flatify_platform().c_str());
62   }
63
64   xbt_os_timer_free(parse_time);
65
66   return 0;
67 }