Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Clang-tidy: readability-qualified-auto.
[simgrid.git] / examples / cpp / trace-categories / s4u-trace-categories.cpp
1 /* Copyright (c) 2010-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 /* This source code simply loads the platform. This is only useful to play
7  * with the tracing module. See the tesh file to see how to generate the
8  * traces.
9  */
10
11 #include "simgrid/instr.h"
12 #include "simgrid/s4u.hpp"
13
14 namespace sg4 = simgrid::s4u;
15
16 struct Task {
17   std::string name;
18   std::string category;
19   double flops;
20   uint64_t bytes;
21 };
22
23 static void master()
24 {
25   auto* mbox = sg4::Mailbox::by_name("master_mailbox");
26   for (int i = 0; i < 10; i++) {
27     Task task;
28     if (i % 2)
29       task = {"task_compute", "compute", 10000000, 0};
30     else if (i % 3)
31       task = {"task_request", "request", 10, 10};
32     else
33       task = {"task_data", "data", 10, 10000000};
34     mbox->put(new Task(task), task.bytes);
35   }
36   Task finalize = {"finalize", "finalize", 0, 1000};
37   mbox->put(new Task(finalize), finalize.bytes);
38 }
39
40 static void worker()
41 {
42   auto* mbox = sg4::Mailbox::by_name("master_mailbox");
43   while (true) {
44     auto task = mbox->get_unique<Task>();
45     if (task->name == "finalize") {
46       break;
47     }
48     // creating task and setting its category
49     sg4::this_actor::exec_init(task->flops)->set_name(task->name)->set_tracing_category(task->category)->wait();
50   }
51 }
52
53 int main(int argc, char* argv[])
54 {
55   sg4::Engine e(&argc, argv);
56   xbt_assert(argc > 1, "Usage: %s platform_file\n \tExample: %s small_platform.xml\n", argv[0], argv[0]);
57
58   e.load_platform(argv[1]);
59
60   // declaring user categories with RGB colors
61   simgrid::instr::declare_tracing_category("compute", "1 0 0");  // red
62   simgrid::instr::declare_tracing_category("request", "0 1 0");  // green
63   simgrid::instr::declare_tracing_category("data", "0 0 1");     // blue
64   simgrid::instr::declare_tracing_category("finalize", "0 0 0"); // black
65
66   sg4::Actor::create("master", e.host_by_name("Tremblay"), master);
67   sg4::Actor::create("worker", e.host_by_name("Fafard"), worker);
68
69   e.run();
70   return 0;
71 }