1 /* Copyright (c) 2010, 2012-2015. The SimGrid Team.
2 * All rights reserved. */
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. */
8 #include "src/instr/instr_private.h"
9 #include "src/msg/msg_private.h"
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_msg, instr, "MSG instrumentation");
15 void TRACE_msg_set_task_category(msg_task_t task, const char *category)
17 xbt_assert(task->category == nullptr, "Task %p(%s) already has a category (%s).",
18 task, task->name, task->category);
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);
29 task->category = xbt_strdup (category);
30 XBT_DEBUG("MSG task %p(%s), category %s", task, task->name, task->category);
33 /* MSG_task_create related function*/
34 void TRACE_msg_task_create(msg_task_t task)
36 static std::atomic_ullong counter{0};
37 task->counter = counter++;
38 task->category = nullptr;
41 MC_ignore_heap(&(task->counter), sizeof(task->counter));
43 XBT_DEBUG("CREATE %p, %lld", task, task->counter);
46 /* MSG_task_execute related functions */
47 void TRACE_msg_task_execute_start(msg_task_t task)
49 XBT_DEBUG("EXEC,in %p, %lld, %s", task, task->counter, task->category);
51 if (TRACE_msg_process_is_enabled()){
52 int len = INSTR_DEFAULT_STR_SIZE;
53 char str[INSTR_DEFAULT_STR_SIZE];
55 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
56 simgrid::instr::Type* type = process_container->type_->getChild("MSG_PROCESS_STATE");
57 simgrid::instr::Value* val = simgrid::instr::Value::get("task_execute", type);
58 new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, type, val);
62 void TRACE_msg_task_execute_end(msg_task_t task)
64 XBT_DEBUG("EXEC,out %p, %lld, %s", task, task->counter, task->category);
66 if (TRACE_msg_process_is_enabled()){
67 int len = INSTR_DEFAULT_STR_SIZE;
68 char str[INSTR_DEFAULT_STR_SIZE];
70 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
71 simgrid::instr::Type* type = process_container->type_->getChild("MSG_PROCESS_STATE");
72 new simgrid::instr::PopStateEvent(MSG_get_clock(), process_container, type);
76 /* MSG_task_destroy related functions */
77 void TRACE_msg_task_destroy(msg_task_t task)
79 XBT_DEBUG("DESTROY %p, %lld, %s", task, task->counter, task->category);
82 xbt_free(task->category);
83 task->category = nullptr;
86 /* MSG_task_get related functions */
87 void TRACE_msg_task_get_start()
91 if (TRACE_msg_process_is_enabled()){
92 int len = INSTR_DEFAULT_STR_SIZE;
93 char str[INSTR_DEFAULT_STR_SIZE];
95 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
96 simgrid::instr::Type* type = process_container->type_->getChild("MSG_PROCESS_STATE");
97 simgrid::instr::Value* val = simgrid::instr::Value::get("receive", type);
98 new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, type, val);
102 void TRACE_msg_task_get_end(double start_time, msg_task_t task)
104 XBT_DEBUG("GET,out %p, %lld, %s", task, task->counter, task->category);
106 if (TRACE_msg_process_is_enabled()){
107 int len = INSTR_DEFAULT_STR_SIZE;
108 char str[INSTR_DEFAULT_STR_SIZE];
110 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
111 simgrid::instr::Type* type = process_container->type_->getChild("MSG_PROCESS_STATE");
112 new simgrid::instr::PopStateEvent(MSG_get_clock(), process_container, type);
114 char key[INSTR_DEFAULT_STR_SIZE];
115 snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter);
116 type = PJ_type_get_root()->getChild("MSG_PROCESS_TASK_LINK");
117 new simgrid::instr::EndLinkEvent(MSG_get_clock(), PJ_container_get_root(), type, process_container, "SR", key);
121 /* MSG_task_put related functions */
122 int TRACE_msg_task_put_start(msg_task_t task)
124 XBT_DEBUG("PUT,in %p, %lld, %s", task, task->counter, task->category);
126 if (TRACE_msg_process_is_enabled()){
127 int len = INSTR_DEFAULT_STR_SIZE;
128 char str[INSTR_DEFAULT_STR_SIZE];
130 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
131 simgrid::instr::Type* type = process_container->type_->getChild("MSG_PROCESS_STATE");
132 simgrid::instr::Value* val = simgrid::instr::Value::get("send", type);
133 new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, type, val);
135 char key[INSTR_DEFAULT_STR_SIZE];
136 snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter);
137 type = PJ_type_get_root()->getChild("MSG_PROCESS_TASK_LINK");
138 new simgrid::instr::StartLinkEvent(MSG_get_clock(), PJ_container_get_root(), type, process_container, "SR", key);
144 void TRACE_msg_task_put_end()
146 XBT_DEBUG("PUT,out");
148 if (TRACE_msg_process_is_enabled()){
149 int len = INSTR_DEFAULT_STR_SIZE;
150 char str[INSTR_DEFAULT_STR_SIZE];
152 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
153 simgrid::instr::Type* type = process_container->type_->getChild("MSG_PROCESS_STATE");
154 new simgrid::instr::PopStateEvent(MSG_get_clock(), process_container, type);