Logo AND Algorithmique Numérique Distribuée

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