Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
873025f35cac1b7b8dd335417636edc35ca6410e
[simgrid.git] / src / msg / instr_msg_task.cpp
1 /* Copyright (c) 2010, 2012-2017. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "mc/mc.h"
8 #include "src/instr/instr_private.hpp"
9 #include "src/msg/msg_private.hpp"
10
11 #include <atomic>
12
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_msg, instr, "MSG instrumentation");
14
15 void TRACE_msg_set_task_category(msg_task_t task, const char *category)
16 {
17   xbt_assert(task->category == nullptr, "Task %p(%s) already has a category (%s).",
18       task, task->name, task->category);
19
20   //if user provides a nullptr category, task is no longer traced
21   if (category == nullptr) {
22     xbt_free (task->category);
23     task->category = nullptr;
24     XBT_DEBUG("MSG task %p(%s), category removed", task, task->name);
25     return;
26   }
27
28   //set task category
29   task->category = xbt_strdup (category);
30   XBT_DEBUG("MSG task %p(%s), category %s", task, task->name, task->category);
31 }
32
33 /* MSG_task_create related function*/
34 void TRACE_msg_task_create(msg_task_t task)
35 {
36   static std::atomic_ullong counter{0};
37   task->counter = counter++;
38   task->category = nullptr;
39
40   if(MC_is_active())
41     MC_ignore_heap(&(task->counter), sizeof(task->counter));
42
43   XBT_DEBUG("CREATE %p, %lld", task, task->counter);
44 }
45
46 /* MSG_task_execute related functions */
47 void TRACE_msg_task_execute_start(msg_task_t task)
48 {
49   XBT_DEBUG("EXEC,in %p, %lld, %s", task, task->counter, task->category);
50
51   if (TRACE_msg_process_is_enabled())
52     simgrid::instr::Container::byName(instr_pid(MSG_process_self()))
53         ->getState("MSG_PROCESS_STATE")
54         ->pushEvent("task_execute");
55 }
56
57 void TRACE_msg_task_execute_end(msg_task_t task)
58 {
59   XBT_DEBUG("EXEC,out %p, %lld, %s", task, task->counter, task->category);
60
61   if (TRACE_msg_process_is_enabled())
62     simgrid::instr::Container::byName(instr_pid(MSG_process_self()))->getState("MSG_PROCESS_STATE")->popEvent();
63 }
64
65 /* MSG_task_destroy related functions */
66 void TRACE_msg_task_destroy(msg_task_t task)
67 {
68   XBT_DEBUG("DESTROY %p, %lld, %s", task, task->counter, task->category);
69
70   //free category
71   xbt_free(task->category);
72   task->category = nullptr;
73 }
74
75 /* MSG_task_get related functions */
76 void TRACE_msg_task_get_start()
77 {
78   XBT_DEBUG("GET,in");
79
80   if (TRACE_msg_process_is_enabled())
81     simgrid::instr::Container::byName(instr_pid(MSG_process_self()))
82         ->getState("MSG_PROCESS_STATE")
83         ->pushEvent("receive");
84 }
85
86 void TRACE_msg_task_get_end(double start_time, msg_task_t task)
87 {
88   XBT_DEBUG("GET,out %p, %lld, %s", task, task->counter, task->category);
89
90   if (TRACE_msg_process_is_enabled()){
91     container_t process_container = simgrid::instr::Container::byName(instr_pid(MSG_process_self()));
92     process_container->getState("MSG_PROCESS_STATE")->popEvent();
93
94     std::string key = std::string("p") + std::to_string(task->counter);
95     container_t root               = simgrid::instr::Container::getRootContainer();
96     simgrid::instr::LinkType* link = root->getLink("MSG_PROCESS_TASK_LINK");
97     link->endEvent(root, process_container, "SR", key);
98   }
99 }
100
101 /* MSG_task_put related functions */
102 int TRACE_msg_task_put_start(msg_task_t task)
103 {
104   XBT_DEBUG("PUT,in %p, %lld, %s", task, task->counter, task->category);
105
106   if (TRACE_msg_process_is_enabled()){
107     container_t process_container = simgrid::instr::Container::byName(instr_pid(MSG_process_self()));
108     process_container->getState("MSG_PROCESS_STATE")->pushEvent("send");
109
110     std::string key = std::string("p") + std::to_string(task->counter);
111     container_t root               = simgrid::instr::Container::getRootContainer();
112     simgrid::instr::LinkType* link = root->getLink("MSG_PROCESS_TASK_LINK");
113     link->startEvent(root, process_container, "SR", key);
114   }
115
116   return 1;
117 }
118
119 void TRACE_msg_task_put_end()
120 {
121   XBT_DEBUG("PUT,out");
122
123   if (TRACE_msg_process_is_enabled())
124     simgrid::instr::Container::byName(instr_pid(MSG_process_self()))->getState("MSG_PROCESS_STATE")->popEvent();
125 }