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"
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_msg, instr, "MSG instrumentation");
13 void TRACE_msg_set_task_category(msg_task_t task, const char *category)
15 xbt_assert(task->category == nullptr, "Task %p(%s) already has a category (%s).",
16 task, task->name, task->category);
18 //if user provides a nullptr category, task is no longer traced
19 if (category == nullptr) {
20 xbt_free (task->category);
21 task->category = nullptr;
22 XBT_DEBUG("MSG task %p(%s), category removed", task, task->name);
27 task->category = xbt_strdup (category);
28 XBT_DEBUG("MSG task %p(%s), category %s", task, task->name, task->category);
31 /* MSG_task_create related function*/
32 void TRACE_msg_task_create(msg_task_t task)
34 static long long counter = 0;
35 task->counter = counter++;
36 task->category = nullptr;
39 MC_ignore_heap(&(task->counter), sizeof(task->counter));
41 XBT_DEBUG("CREATE %p, %lld", task, task->counter);
44 /* MSG_task_execute related functions */
45 void TRACE_msg_task_execute_start(msg_task_t task)
47 XBT_DEBUG("EXEC,in %p, %lld, %s", task, task->counter, task->category);
49 if (TRACE_msg_process_is_enabled()){
50 int len = INSTR_DEFAULT_STR_SIZE;
51 char str[INSTR_DEFAULT_STR_SIZE];
53 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
54 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
55 val_t value = PJ_value_get ("task_execute", type);
56 new PushStateEvent (MSG_get_clock(), process_container, type, value);
60 void TRACE_msg_task_execute_end(msg_task_t task)
62 XBT_DEBUG("EXEC,out %p, %lld, %s", task, task->counter, task->category);
64 if (TRACE_msg_process_is_enabled()){
65 int len = INSTR_DEFAULT_STR_SIZE;
66 char str[INSTR_DEFAULT_STR_SIZE];
68 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
69 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
70 new PopStateEvent (MSG_get_clock(), process_container, type);
74 /* MSG_task_destroy related functions */
75 void TRACE_msg_task_destroy(msg_task_t task)
77 XBT_DEBUG("DESTROY %p, %lld, %s", task, task->counter, task->category);
80 xbt_free(task->category);
81 task->category = nullptr;
84 /* MSG_task_get related functions */
85 void TRACE_msg_task_get_start()
89 if (TRACE_msg_process_is_enabled()){
90 int len = INSTR_DEFAULT_STR_SIZE;
91 char str[INSTR_DEFAULT_STR_SIZE];
93 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
94 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
95 val_t value = PJ_value_get ("receive", type);
96 new PushStateEvent (MSG_get_clock(), process_container, type, value);
100 void TRACE_msg_task_get_end(double start_time, msg_task_t task)
102 XBT_DEBUG("GET,out %p, %lld, %s", task, task->counter, task->category);
104 if (TRACE_msg_process_is_enabled()){
105 int len = INSTR_DEFAULT_STR_SIZE;
106 char str[INSTR_DEFAULT_STR_SIZE];
108 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
109 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
110 new PopStateEvent (MSG_get_clock(), process_container, type);
112 char key[INSTR_DEFAULT_STR_SIZE];
113 snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter);
114 type = PJ_type_get ("MSG_PROCESS_TASK_LINK", PJ_type_get_root());
115 new EndLinkEvent(MSG_get_clock(), PJ_container_get_root(), type, process_container, "SR", key);
119 /* MSG_task_put related functions */
120 int TRACE_msg_task_put_start(msg_task_t task)
122 XBT_DEBUG("PUT,in %p, %lld, %s", task, task->counter, task->category);
124 if (TRACE_msg_process_is_enabled()){
125 int len = INSTR_DEFAULT_STR_SIZE;
126 char str[INSTR_DEFAULT_STR_SIZE];
128 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
129 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
130 val_t value = PJ_value_get ("send", type);
131 new PushStateEvent (MSG_get_clock(), process_container, type, value);
133 char key[INSTR_DEFAULT_STR_SIZE];
134 snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter);
135 type = PJ_type_get ("MSG_PROCESS_TASK_LINK", PJ_type_get_root());
136 new StartLinkEvent(MSG_get_clock(), PJ_container_get_root(), type, process_container, "SR", key);
142 void TRACE_msg_task_put_end()
144 XBT_DEBUG("PUT,out");
146 if (TRACE_msg_process_is_enabled()){
147 int len = INSTR_DEFAULT_STR_SIZE;
148 char str[INSTR_DEFAULT_STR_SIZE];
150 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
151 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
152 new PopStateEvent (MSG_get_clock(), process_container, type);