Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines.
[simgrid.git] / examples / s4u / trace-categories / s4u-trace-categories.cpp
1 /* Copyright (c) 2010-2021. 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   for (int i = 0; i < 10; i++) {
25     Task task;
26     if (i % 2)
27       task = {"task_compute", "compute", 10000000, 0};
28     else if (i % 3)
29       task = {"task_request", "request", 10, 10};
30     else
31       task = {"task_data", "data", 10, 10000000};
32     mbox->put(new Task(task), task.bytes);
33   }
34   Task finalize = {"finalize", "finalize", 0, 1000};
35   mbox->put(new Task(finalize), finalize.bytes);
36 }
37
38 static void worker()
39 {
40   auto mbox = simgrid::s4u::Mailbox::by_name("master_mailbox");
41   while (true) {
42     auto task = mbox->get_unique<Task>();
43     if (task->name == "finalize") {
44       break;
45     }
46     // creating task and setting its category
47     simgrid::s4u::this_actor::exec_init(task->flops)
48         ->set_name(task->name)
49         ->set_tracing_category(task->category)
50         ->wait();
51   }
52 }
53
54 int main(int argc, char* argv[])
55 {
56   simgrid::s4u::Engine e(&argc, argv);
57   xbt_assert(argc > 1, "Usage: %s platform_file\n \tExample: %s small_platform.xml\n", argv[0], argv[0]);
58
59   e.load_platform(argv[1]);
60
61   // declaring user categories with RGB colors
62   TRACE_category_with_color("compute", "1 0 0");  // red
63   TRACE_category_with_color("request", "0 1 0");  // green
64   TRACE_category_with_color("data", "0 0 1");     // blue
65   TRACE_category_with_color("finalize", "0 0 0"); // black
66
67   simgrid::s4u::Actor::create("master", simgrid::s4u::Host::by_name("Tremblay"), master);
68   simgrid::s4u::Actor::create("worker", simgrid::s4u::Host::by_name("Fafard"), worker);
69
70   e.run();
71   return 0;
72 }