Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
A Pull from simgrid/master and a subsequent merge
[simgrid.git] / examples / s4u / trace-categories / s4u-trace-categories.cpp
1 /* Copyright (c) 2010-2020. 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 struct Task {
15   std::string name;
16   std::string category;
17   double flops;
18   uint64_t bytes;
19 };
20
21 static void master()
22 {
23   auto mbox                     = simgrid::s4u::Mailbox::by_name("master_mailbox");
24
25   for (int i = 0; i < 10; i++) {
26     Task task;
27     if (i % 2)
28       task = {"task_compute", "compute", 10000000, 0};
29     else if (i % 3)
30       task = {"task_request", "request", 10, 10};
31     else
32       task = {"task_data", "data", 10, 10000000};
33     mbox->put(new Task(task), task.bytes);
34   }
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 = simgrid::s4u::Mailbox::by_name("master_mailbox");
43   while (true) {
44     const auto* task = static_cast<Task*>(mbox->get());
45     if (task->name == "finalize") {
46       delete task;
47       break;
48     }
49     // creating task and setting its category
50     simgrid::s4u::this_actor::exec_init(task->flops)
51         ->set_name(task->name)
52         ->set_tracing_category(task->category)
53         ->wait();
54     delete task;
55   }
56 }
57
58 int main(int argc, char* argv[])
59 {
60   simgrid::s4u::Engine e(&argc, argv);
61   xbt_assert(argc > 1, "Usage: %s platform_file\n \tExample: %s small_platform.xml\n", argv[0], argv[0]);
62
63   e.load_platform(argv[1]);
64
65   // declaring user categories with RGB colors
66   TRACE_category_with_color("compute", "1 0 0");  // red
67   TRACE_category_with_color("request", "0 1 0");  // green
68   TRACE_category_with_color("data", "0 0 1");     // blue
69   TRACE_category_with_color("finalize", "0 0 0"); // black
70
71   simgrid::s4u::Actor::create("master", simgrid::s4u::Host::by_name("Tremblay"), master);
72   simgrid::s4u::Actor::create("worker", simgrid::s4u::Host::by_name("Fafard"), worker);
73
74   e.run();
75   return 0;
76 }