1 /* Copyright (c) 2010, 2012-2017. 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.hpp"
9 #include "src/msg/msg_private.hpp"
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 container_t process_container = simgrid::instr::Container::byName(instr_process_id(MSG_process_self()));
53 simgrid::instr::Type* state = process_container->type_->byName("MSG_PROCESS_STATE");
54 simgrid::instr::Value* val = state->getEntityValue("task_execute");
55 new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, state, val);
59 void TRACE_msg_task_execute_end(msg_task_t task)
61 XBT_DEBUG("EXEC,out %p, %lld, %s", task, task->counter, task->category);
63 if (TRACE_msg_process_is_enabled()){
64 container_t process_container = simgrid::instr::Container::byName(instr_process_id(MSG_process_self()));
65 simgrid::instr::Type* type = process_container->type_->byName("MSG_PROCESS_STATE");
66 new simgrid::instr::PopStateEvent(MSG_get_clock(), process_container, type);
70 /* MSG_task_destroy related functions */
71 void TRACE_msg_task_destroy(msg_task_t task)
73 XBT_DEBUG("DESTROY %p, %lld, %s", task, task->counter, task->category);
76 xbt_free(task->category);
77 task->category = nullptr;
80 /* MSG_task_get related functions */
81 void TRACE_msg_task_get_start()
85 if (TRACE_msg_process_is_enabled()){
86 container_t process_container = simgrid::instr::Container::byName(instr_process_id(MSG_process_self()));
87 simgrid::instr::Type* state = process_container->type_->byName("MSG_PROCESS_STATE");
88 simgrid::instr::Value* val = state->getEntityValue("receive");
89 new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, state, val);
93 void TRACE_msg_task_get_end(double start_time, msg_task_t task)
95 XBT_DEBUG("GET,out %p, %lld, %s", task, task->counter, task->category);
97 if (TRACE_msg_process_is_enabled()){
98 container_t process_container = simgrid::instr::Container::byName(instr_process_id(MSG_process_self()));
99 simgrid::instr::Type* type = process_container->type_->byName("MSG_PROCESS_STATE");
100 new simgrid::instr::PopStateEvent(MSG_get_clock(), process_container, type);
102 std::string key = std::string("p") + std::to_string(task->counter);
103 type = simgrid::instr::Type::getRootType()->byName("MSG_PROCESS_TASK_LINK");
104 new simgrid::instr::EndLinkEvent(MSG_get_clock(), simgrid::instr::Container::getRootContainer(), type,
105 process_container, "SR", key);
109 /* MSG_task_put related functions */
110 int TRACE_msg_task_put_start(msg_task_t task)
112 XBT_DEBUG("PUT,in %p, %lld, %s", task, task->counter, task->category);
114 if (TRACE_msg_process_is_enabled()){
115 container_t process_container = simgrid::instr::Container::byName(instr_process_id(MSG_process_self()));
116 simgrid::instr::Type* type = process_container->type_->byName("MSG_PROCESS_STATE");
117 simgrid::instr::Value* val = type->getEntityValue("send");
118 new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, type, val);
120 std::string key = std::string("p") + std::to_string(task->counter);
121 type = simgrid::instr::Type::getRootType()->byName("MSG_PROCESS_TASK_LINK");
122 new simgrid::instr::StartLinkEvent(MSG_get_clock(), simgrid::instr::Container::getRootContainer(), type,
123 process_container, "SR", key);
129 void TRACE_msg_task_put_end()
131 XBT_DEBUG("PUT,out");
133 if (TRACE_msg_process_is_enabled()){
134 container_t process_container = simgrid::instr::Container::byName(instr_process_id(MSG_process_self()));
135 simgrid::instr::Type* type = process_container->type_->byName("MSG_PROCESS_STATE");
136 new simgrid::instr::PopStateEvent(MSG_get_clock(), process_container, type);