Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
8aabfcf2a18242b35476dcba40fe4d632ad4cdbc
[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 = newVariableType(task->category, TYPE_VARIABLE, NULL, msg->type);
58     }
59     pajeSetVariable(SIMIX_get_clock(), type->id, msg->id, "1");
60
61     //FIXME
62     //pajePushState(MSG_get_clock(), "task-state", name, "created");
63     xbt_dict_set (tasks_created, task->name, xbt_strdup("1"), xbt_free);
64   }
65 }
66
67 /* MSG_task_create related function*/
68 void TRACE_msg_task_create(m_task_t task)
69 {
70   static long long counter = 0;
71   task->counter = counter++;
72   task->category = NULL;
73   DEBUG2("CREATE %p, %lld", task, task->counter);
74 }
75
76 /* MSG_task_execute related functions */
77 void TRACE_msg_task_execute_start(m_task_t task)
78 {
79   if (!(TRACE_is_enabled() &&
80       TRACE_msg_task_is_enabled() &&
81       task->category)) return;
82
83   DEBUG3("EXEC,in %p, %lld, %s", task, task->counter, task->category);
84
85   //FIXME
86   //pajePushState(MSG_get_clock(), "task-state", name, "execute");
87 }
88
89 void TRACE_msg_task_execute_end(m_task_t task)
90 {
91   if (!(TRACE_is_enabled() &&
92       TRACE_msg_task_is_enabled() &&
93       task->category)) return;
94
95   DEBUG3("EXEC,out %p, %lld, %s", task, task->counter, task->category);
96
97   //FIXME
98   //pajePopState(MSG_get_clock(), "task-state", name);
99 }
100
101 /* MSG_task_destroy related functions */
102 void TRACE_msg_task_destroy(m_task_t task)
103 {
104   if (!tasks_created) tasks_created = xbt_dict_new();
105   if (!(TRACE_is_enabled() &&
106       TRACE_msg_task_is_enabled() &&
107       task->category)) return;
108
109   //that's the end, let's destroy it
110   destroyContainer (getContainer(task->name));
111
112   DEBUG3("DESTROY %p, %lld, %s", task, task->counter, task->category);
113
114   //free category
115   xbt_free(task->category);
116   task->category = NULL;
117
118   xbt_dict_remove (tasks_created, task->name);
119   return;
120 }
121
122 /* MSG_task_get related functions */
123 void TRACE_msg_task_get_start(void)
124 {
125   if (!(TRACE_is_enabled() &&
126       TRACE_msg_task_is_enabled())) return;
127
128   DEBUG0("GET,in");
129 }
130
131 void TRACE_msg_task_get_end(double start_time, m_task_t task)
132 {
133   if (!(TRACE_is_enabled() &&
134       TRACE_msg_task_is_enabled() &&
135       task->category)) return;
136
137   DEBUG3("GET,out %p, %lld, %s", task, task->counter, task->category);
138
139   //FIXME
140   //pajePopState(MSG_get_clock(), "task-state", name);
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
154 /* MSG_task_put related functions */
155 int TRACE_msg_task_put_start(m_task_t task)
156 {
157   if (!(TRACE_is_enabled() &&
158       TRACE_msg_task_is_enabled() &&
159       task->category)) return 0;
160
161   DEBUG3("PUT,in %p, %lld, %s", task, task->counter, task->category);
162
163   destroyContainer (getContainer(task->name));
164
165   //FIXME
166   //pajePopState(MSG_get_clock(), "task-state", name);
167   //pajePushState(MSG_get_clock(), "task-state", name, "communicate");
168
169   //FIXME
170   //if (TRACE_msg_volume_is_enabled()){
171   //  TRACE_msg_volume_start(task);
172   //}
173
174   return 1;
175 }
176
177 void TRACE_msg_task_put_end(void)
178 {
179   if (!(TRACE_is_enabled() &&
180       TRACE_msg_task_is_enabled())) return;
181
182   DEBUG0("PUT,out");
183 }
184
185 #endif /* HAVE_TRACING */