Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] fix on link type creation (was indexed by type name, but should consider...
[simgrid.git] / src / instr / instr_msg_task.c
1 /* Copyright (c) 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include "instr/instr_private.h"
8
9 #ifdef HAVE_TRACING
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_msg, instr, "MSG");
12
13 xbt_dict_t tasks_created = NULL;
14
15 /*
16  * TRACE_msg_set_task_category: tracing interface function
17  */
18 void TRACE_msg_set_task_category(m_task_t task, const char *category)
19 {
20   if (!tasks_created) tasks_created = xbt_dict_new();
21   if (!TRACE_is_active())
22     return;
23
24   xbt_assert3(task->category == NULL, "Task %p(%s) already has a category (%s).",
25       task, task->name, task->category);
26   if (TRACE_msg_task_is_enabled()){
27     xbt_assert2(task->name != NULL,
28         "Task %p(%s) must have a unique name in order to be traced, if --cfg=tracing/msg/task:1 is used.",
29         task, task->name);
30     xbt_assert3(getContainer(task->name)==NULL,
31         "Task %p(%s). Tracing already knows a task with name %s."
32         "The name of each task must be unique, if --cfg=tracing/msg/task:1 is used.", task, task->name, task->name);
33   }
34
35   if (category == NULL) {
36     //if user provides a NULL category, task is no longer traced
37     xbt_free (task->category);
38     task->category = NULL;
39     return;
40   }
41
42   //set task category
43   task->category = xbt_strdup (category);
44   DEBUG3("MSG task %p(%s), category %s", task, task->name, task->category);
45
46   if (TRACE_msg_task_is_enabled()){
47     m_host_t host = MSG_host_self();
48     container_t host_container = getContainer(host->name);
49     //check to see if there is a container with the task->name
50     container_t msg = getContainer(task->name);
51     xbt_assert3(xbt_dict_get_or_null (tasks_created, task->name) == NULL,
52         "Task %p(%s). Tracing already knows a task with name %s."
53         "The name of each task must be unique, if --cfg=tracing/msg/task:1 is used.", task, task->name, task->name);
54     msg = newContainer(task->name, INSTR_MSG_TASK, host_container);
55     type_t type = getType (task->category);
56     if (!type){
57       type = getVariableType(task->category, NULL, msg->type);
58     }
59     pajeSetVariable(SIMIX_get_clock(), type->id, msg->id, "1");
60
61     type = getType ("MSG_TASK_STATE");
62     pajePushState (MSG_get_clock(), type->id, msg->id, "created");
63
64     xbt_dict_set (tasks_created, task->name, xbt_strdup("1"), xbt_free);
65   }
66 }
67
68 /* MSG_task_create related function*/
69 void TRACE_msg_task_create(m_task_t task)
70 {
71   static long long counter = 0;
72   task->counter = counter++;
73   task->category = NULL;
74   DEBUG2("CREATE %p, %lld", task, task->counter);
75 }
76
77 /* MSG_task_execute related functions */
78 void TRACE_msg_task_execute_start(m_task_t task)
79 {
80   if (!(TRACE_is_enabled() &&
81       TRACE_msg_task_is_enabled() &&
82       task->category)) return;
83
84   DEBUG3("EXEC,in %p, %lld, %s", task, task->counter, task->category);
85
86   container_t task_container = getContainer (task->name);
87   type_t type = getType ("MSG_TASK_STATE");
88   pajePushState (MSG_get_clock(), type->id, task_container->id, "MSG_task_execute");
89 }
90
91 void TRACE_msg_task_execute_end(m_task_t task)
92 {
93   if (!(TRACE_is_enabled() &&
94       TRACE_msg_task_is_enabled() &&
95       task->category)) return;
96
97   DEBUG3("EXEC,out %p, %lld, %s", task, task->counter, task->category);
98
99   container_t task_container = getContainer (task->name);
100   type_t type = getType ("MSG_TASK_STATE");
101   pajePopState (MSG_get_clock(), type->id, task_container->id);
102 }
103
104 /* MSG_task_destroy related functions */
105 void TRACE_msg_task_destroy(m_task_t task)
106 {
107   if (!tasks_created) tasks_created = xbt_dict_new();
108   if (!(TRACE_is_enabled() &&
109       TRACE_msg_task_is_enabled() &&
110       task->category)) return;
111
112   //that's the end, let's destroy it
113   destroyContainer (getContainer(task->name));
114
115   DEBUG3("DESTROY %p, %lld, %s", task, task->counter, task->category);
116
117   //free category
118   xbt_free(task->category);
119   task->category = NULL;
120
121   xbt_dict_remove (tasks_created, task->name);
122   return;
123 }
124
125 /* MSG_task_get related functions */
126 void TRACE_msg_task_get_start(void)
127 {
128   if (!(TRACE_is_enabled() &&
129       TRACE_msg_task_is_enabled())) return;
130
131   DEBUG0("GET,in");
132 }
133
134 void TRACE_msg_task_get_end(double start_time, m_task_t task)
135 {
136   if (!(TRACE_is_enabled() &&
137       TRACE_msg_task_is_enabled() &&
138       task->category)) return;
139
140   DEBUG3("GET,out %p, %lld, %s", task, task->counter, task->category);
141
142   //FIXME
143   //if (TRACE_msg_volume_is_enabled()){
144   //  TRACE_msg_volume_end(task);
145   //}
146
147   m_host_t host = MSG_host_self();
148   container_t host_container = getContainer(host->name);
149   container_t msg = newContainer(task->name, INSTR_MSG_TASK, host_container);
150   type_t type = getType (task->category);
151   pajeSetVariable(SIMIX_get_clock(), type->id, msg->id, "1");
152
153   type = getType ("MSG_TASK_STATE");
154   pajePushState (MSG_get_clock(), type->id, msg->id, "created");
155
156   type = getType ("MSG_TASK_LINK");
157   char key[INSTR_DEFAULT_STR_SIZE];
158   snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", task->counter);
159   pajeEndLink(MSG_get_clock(), type->id, "0", "SR", msg->id, key);
160 }
161
162 /* MSG_task_put related functions */
163 int TRACE_msg_task_put_start(m_task_t task)
164 {
165   if (!(TRACE_is_enabled() &&
166       TRACE_msg_task_is_enabled() &&
167       task->category)) return 0;
168
169   DEBUG3("PUT,in %p, %lld, %s", task, task->counter, task->category);
170
171   container_t msg = getContainer (task->name);
172   type_t type = getType ("MSG_TASK_STATE");
173   pajePopState (MSG_get_clock(), type->id, msg->id);
174
175   type = getType ("MSG_TASK_LINK");
176   char key[INSTR_DEFAULT_STR_SIZE];
177   snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", task->counter);
178   pajeStartLink(MSG_get_clock(), type->id, "0", "SR", msg->id, key);
179
180   destroyContainer (msg);
181
182   //FIXME
183   //if (TRACE_msg_volume_is_enabled()){
184   //  TRACE_msg_volume_start(task);
185   //}
186
187   return 1;
188 }
189
190 void TRACE_msg_task_put_end(void)
191 {
192   if (!(TRACE_is_enabled() &&
193       TRACE_msg_task_is_enabled())) return;
194
195   DEBUG0("PUT,out");
196 }
197
198 #endif /* HAVE_TRACING */