1 /* Copyright (c) 2010. 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. */
7 #include "instr/instr_private.h"
8 #include "msg_private.h"
9 #include "msg/datatypes.h"
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_msg, instr, "MSG");
17 void TRACE_msg_set_task_category(msg_task_t task, const char *category)
19 xbt_assert(task->category == NULL, "Task %p(%s) already has a category (%s).",
20 task, task->name, task->category);
22 //if user provides a NULL category, task is no longer traced
23 if (category == NULL) {
24 xbt_free (task->category);
25 task->category = NULL;
26 XBT_DEBUG("MSG task %p(%s), category removed", task, task->name);
31 task->category = xbt_strdup (category);
32 XBT_DEBUG("MSG task %p(%s), category %s", task, task->name, task->category);
35 /* MSG_task_create related function*/
36 void TRACE_msg_task_create(msg_task_t task)
38 static long long counter = 0;
39 task->counter = counter++;
40 task->category = NULL;
43 MC_ignore_data_bss(&counter, sizeof(counter));
44 MC_ignore_heap(&(task->counter), sizeof(task->counter));
47 XBT_DEBUG("CREATE %p, %lld", task, task->counter);
50 /* MSG_task_execute related functions */
51 void TRACE_msg_task_execute_start(msg_task_t task)
53 XBT_DEBUG("EXEC,in %p, %lld, %s", task, task->counter, task->category);
55 if (TRACE_msg_process_is_enabled()){
56 int len = INSTR_DEFAULT_STR_SIZE;
57 char str[INSTR_DEFAULT_STR_SIZE];
59 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
60 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
61 val_t value = PJ_value_get ("task_execute", type);
62 new_pajePushState (MSG_get_clock(), process_container, type, value);
66 void TRACE_msg_task_execute_end(msg_task_t task)
68 XBT_DEBUG("EXEC,out %p, %lld, %s", task, task->counter, task->category);
70 if (TRACE_msg_process_is_enabled()){
71 int len = INSTR_DEFAULT_STR_SIZE;
72 char str[INSTR_DEFAULT_STR_SIZE];
74 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
75 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
76 new_pajePopState (MSG_get_clock(), process_container, type);
80 /* MSG_task_destroy related functions */
81 void TRACE_msg_task_destroy(msg_task_t task)
83 XBT_DEBUG("DESTROY %p, %lld, %s", task, task->counter, task->category);
86 xbt_free(task->category);
87 task->category = NULL;
91 /* MSG_task_get related functions */
92 void TRACE_msg_task_get_start(void)
96 if (TRACE_msg_process_is_enabled()){
97 int len = INSTR_DEFAULT_STR_SIZE;
98 char str[INSTR_DEFAULT_STR_SIZE];
100 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
101 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
102 val_t value = PJ_value_get ("receive", type);
103 new_pajePushState (MSG_get_clock(), process_container, type, value);
107 void TRACE_msg_task_get_end(double start_time, msg_task_t task)
109 XBT_DEBUG("GET,out %p, %lld, %s", task, task->counter, task->category);
111 if (TRACE_msg_process_is_enabled()){
112 int len = INSTR_DEFAULT_STR_SIZE;
113 char str[INSTR_DEFAULT_STR_SIZE];
115 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
116 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
117 new_pajePopState (MSG_get_clock(), process_container, type);
119 char key[INSTR_DEFAULT_STR_SIZE];
120 snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter);
121 type = PJ_type_get ("MSG_PROCESS_TASK_LINK", PJ_type_get_root());
122 new_pajeEndLink(MSG_get_clock(), PJ_container_get_root(), type, process_container, "SR", key);
126 /* MSG_task_put related functions */
127 int TRACE_msg_task_put_start(msg_task_t task)
129 XBT_DEBUG("PUT,in %p, %lld, %s", task, task->counter, task->category);
131 if (TRACE_msg_process_is_enabled()){
132 int len = INSTR_DEFAULT_STR_SIZE;
133 char str[INSTR_DEFAULT_STR_SIZE];
135 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
136 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
137 val_t value = PJ_value_get ("send", type);
138 new_pajePushState (MSG_get_clock(), process_container, type, value);
140 char key[INSTR_DEFAULT_STR_SIZE];
141 snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter);
142 type = PJ_type_get ("MSG_PROCESS_TASK_LINK", PJ_type_get_root());
143 new_pajeStartLink(MSG_get_clock(), PJ_container_get_root(), type, process_container, "SR", key);
149 void TRACE_msg_task_put_end(void)
151 XBT_DEBUG("PUT,out");
153 if (TRACE_msg_process_is_enabled()){
154 int len = INSTR_DEFAULT_STR_SIZE;
155 char str[INSTR_DEFAULT_STR_SIZE];
157 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
158 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
159 new_pajePopState (MSG_get_clock(), process_container, type);
163 #endif /* HAVE_TRACING */