1 /* Copyright (c) 2010, 2012-2013. 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_heap(&(task->counter), sizeof(task->counter));
45 XBT_DEBUG("CREATE %p, %lld", task, task->counter);
48 /* MSG_task_execute related functions */
49 void TRACE_msg_task_execute_start(msg_task_t task)
51 XBT_DEBUG("EXEC,in %p, %lld, %s", task, task->counter, task->category);
53 if (TRACE_msg_process_is_enabled()){
54 int len = INSTR_DEFAULT_STR_SIZE;
55 char str[INSTR_DEFAULT_STR_SIZE];
57 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
58 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
59 val_t value = PJ_value_get ("task_execute", type);
60 new_pajePushState (MSG_get_clock(), process_container, type, value);
64 void TRACE_msg_task_execute_end(msg_task_t task)
66 XBT_DEBUG("EXEC,out %p, %lld, %s", task, task->counter, task->category);
68 if (TRACE_msg_process_is_enabled()){
69 int len = INSTR_DEFAULT_STR_SIZE;
70 char str[INSTR_DEFAULT_STR_SIZE];
72 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
73 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
74 new_pajePopState (MSG_get_clock(), process_container, type);
78 /* MSG_task_destroy related functions */
79 void TRACE_msg_task_destroy(msg_task_t task)
81 XBT_DEBUG("DESTROY %p, %lld, %s", task, task->counter, task->category);
84 xbt_free(task->category);
85 task->category = NULL;
89 /* MSG_task_get related functions */
90 void TRACE_msg_task_get_start(void)
94 if (TRACE_msg_process_is_enabled()){
95 int len = INSTR_DEFAULT_STR_SIZE;
96 char str[INSTR_DEFAULT_STR_SIZE];
98 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
99 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
100 val_t value = PJ_value_get ("receive", type);
101 new_pajePushState (MSG_get_clock(), process_container, type, value);
105 void TRACE_msg_task_get_end(double start_time, msg_task_t task)
107 XBT_DEBUG("GET,out %p, %lld, %s", task, task->counter, task->category);
109 if (TRACE_msg_process_is_enabled()){
110 int len = INSTR_DEFAULT_STR_SIZE;
111 char str[INSTR_DEFAULT_STR_SIZE];
113 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
114 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
115 new_pajePopState (MSG_get_clock(), process_container, type);
117 char key[INSTR_DEFAULT_STR_SIZE];
118 snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter);
119 type = PJ_type_get ("MSG_PROCESS_TASK_LINK", PJ_type_get_root());
120 new_pajeEndLink(MSG_get_clock(), PJ_container_get_root(), type, process_container, "SR", key);
124 /* MSG_task_put related functions */
125 int TRACE_msg_task_put_start(msg_task_t task)
127 XBT_DEBUG("PUT,in %p, %lld, %s", task, task->counter, task->category);
129 if (TRACE_msg_process_is_enabled()){
130 int len = INSTR_DEFAULT_STR_SIZE;
131 char str[INSTR_DEFAULT_STR_SIZE];
133 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
134 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
135 val_t value = PJ_value_get ("send", type);
136 new_pajePushState (MSG_get_clock(), process_container, type, value);
138 char key[INSTR_DEFAULT_STR_SIZE];
139 snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter);
140 type = PJ_type_get ("MSG_PROCESS_TASK_LINK", PJ_type_get_root());
141 new_pajeStartLink(MSG_get_clock(), PJ_container_get_root(), type, process_container, "SR", key);
147 void TRACE_msg_task_put_end(void)
149 XBT_DEBUG("PUT,out");
151 if (TRACE_msg_process_is_enabled()){
152 int len = INSTR_DEFAULT_STR_SIZE;
153 char str[INSTR_DEFAULT_STR_SIZE];
155 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
156 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
157 new_pajePopState (MSG_get_clock(), process_container, type);
161 #endif /* HAVE_TRACING */