Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
detecting if TRACE_start was called too soon (before TRACE_global_init)
[simgrid.git] / src / instr / msg_task_instr.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/private.h"
8
9 #ifdef HAVE_TRACING
10
11 static xbt_dict_t task_containers = NULL;
12 static xbt_dict_t current_task_category = NULL;
13
14 void __TRACE_msg_init (void)
15 {
16   current_task_category = xbt_dict_new();
17   task_containers = xbt_dict_new();
18 }
19
20 void __TRACE_current_category_set (m_task_t task)
21 {
22   char processid[100];
23   char *var_cpy = NULL;
24   snprintf (processid, 100, "%p", SIMIX_process_self());
25   var_cpy = xbt_strdup (task->category);
26   xbt_dict_set (current_task_category, processid, var_cpy, xbt_free);
27 }
28
29 void __TRACE_current_category_unset ()
30 {
31   char processid[100];
32   snprintf (processid, 100, "%p", SIMIX_process_self());
33   xbt_dict_remove (current_task_category, processid);
34 }
35
36 char *__TRACE_current_category_get (smx_process_t proc)
37 {
38   char processid[100];
39   snprintf (processid, 100, "%p", proc);
40   return xbt_dict_get_or_null (current_task_category, processid);
41 }
42
43 void __TRACE_task_location (m_task_t task)
44 {
45         char container[200];
46         char name[200], alias[200];
47         char *val_one = NULL;
48         m_process_t process = NULL;
49         m_host_t host = NULL;
50   if (!IS_TRACING_TASKS) return;
51   process = MSG_process_self();
52   host = MSG_process_get_host (process);
53
54   //tasks are grouped by host
55   TRACE_host_container (host, container, 200);
56   TRACE_task_container (task, name, 200);
57   TRACE_task_alias_container (task, process, host, alias, 200);
58   //check if task container is already created
59   if (!xbt_dict_get_or_null (task_containers, alias)){
60     pajeCreateContainer (MSG_get_clock(), alias, "TASK", container, name);
61     pajeSetState (MSG_get_clock(), "category", alias, task->category);
62     val_one = xbt_strdup ("1");
63     xbt_dict_set (task_containers, alias, val_one, xbt_free);
64   }
65 }
66
67 void __TRACE_task_location_present (m_task_t task)
68 {
69         char alias[200];
70         m_process_t process = NULL;
71         m_host_t host = NULL;
72   if (!IS_TRACING_TASKS) return;
73   //updating presence state of this task location
74   process = MSG_process_self();
75   host = MSG_process_get_host (process);
76
77   TRACE_task_alias_container (task, process, host, alias, 200);
78   pajePushState (MSG_get_clock(), "presence", alias, "presence");
79 }
80
81 void __TRACE_task_location_not_present (m_task_t task)
82 {
83         char alias[200];
84         m_process_t process = NULL;
85         m_host_t host = NULL;
86   if (!IS_TRACING_TASKS) return;
87   //updating presence state of this task location
88   process = MSG_process_self();
89   host = MSG_process_get_host (process);
90
91   TRACE_task_alias_container (task, process, host, alias, 200);
92   pajePopState (MSG_get_clock(), "presence", alias);
93 }
94
95 /*
96  * TRACE_msg_set_task_category: tracing interface function
97  */
98 void TRACE_msg_set_task_category(m_task_t task, const char *category)
99 {
100         char name[200];
101   if (!IS_TRACING) return;
102
103   //set task category
104   task->category = xbt_new (char, strlen (category)+1);
105   strncpy(task->category, category, strlen(category)+1);
106
107   //tracing task location based on host
108   __TRACE_task_location (task);
109   __TRACE_task_location_present (task);
110
111   TRACE_task_container (task, name, 200);
112   //create container of type "task" to indicate behavior
113   if (IS_TRACING_TASKS) pajeCreateContainer (MSG_get_clock(), name, "task", category, name);
114   if (IS_TRACING_TASKS) pajePushState (MSG_get_clock(), "task-state", name, "created");
115 }
116
117 /* MSG_task_create related function*/
118 void TRACE_msg_task_create (m_task_t task)
119 {
120   static long long counter = 0;
121   task->counter = counter++;
122   task->category = NULL;
123 }
124
125 /* MSG_task_execute related functions */
126 void TRACE_msg_task_execute_start (m_task_t task)
127 {
128         char name[200];
129   if (!IS_TRACING || !IS_TRACED(task)) return;
130
131   TRACE_task_container (task, name, 200);
132   if (IS_TRACING_TASKS) pajePushState (MSG_get_clock(), "task-state", name, "execute");
133
134   __TRACE_current_category_set (task);
135 }
136
137 void TRACE_msg_task_execute_end (m_task_t task)
138 {
139         char name[200];
140   if (!IS_TRACING || !IS_TRACED(task)) return;
141
142   TRACE_task_container (task, name, 200);
143   if (IS_TRACING_TASKS) pajePopState (MSG_get_clock(), "task-state", name);
144
145   __TRACE_current_category_unset();
146 }
147
148 /* MSG_task_destroy related functions */
149 void TRACE_msg_task_destroy (m_task_t task)
150 {
151         char name[200];
152   if (!IS_TRACING || !IS_TRACED(task)) return;
153
154   TRACE_task_container (task, name, 200);
155   if (IS_TRACING_TASKS) pajeDestroyContainer (MSG_get_clock(), "task", name);
156
157   //finish the location of this task
158   __TRACE_task_location_not_present (task);
159
160   //free category
161   xbt_free (task->category);
162   return;
163 }
164
165 /* MSG_task_get related functions */
166 void TRACE_msg_task_get_start (void)
167 {
168   if (!IS_TRACING) return;
169 }
170
171 void TRACE_msg_task_get_end (double start_time, m_task_t task)
172 {
173         char name[200];
174   if (!IS_TRACING || !IS_TRACED(task)) return;
175
176   TRACE_task_container (task, name, 200);
177   if (IS_TRACING_TASKS) pajePopState (MSG_get_clock(), "task-state", name);
178
179   __TRACE_msg_volume_finish (task);
180
181   __TRACE_task_location (task);
182   __TRACE_task_location_present (task);
183 }
184
185 /* MSG_task_put related functions */
186 int TRACE_msg_task_put_start (m_task_t task)
187 {
188         char name[200];
189   if (!IS_TRACING || !IS_TRACED(task)) return 0;
190
191   TRACE_task_container (task, name, 200);
192   if (IS_TRACING_TASKS) pajePopState (MSG_get_clock(), "task-state", name);
193   if (IS_TRACING_TASKS) pajePushState (MSG_get_clock(), "task-state", name, "communicate");
194
195   __TRACE_msg_volume_start (task);
196
197   //trace task location grouped by host
198   __TRACE_task_location_not_present (task);
199
200   //set current category
201   __TRACE_current_category_set (task);
202   return 1;
203 }
204
205 void TRACE_msg_task_put_end (void)
206 {
207   if (!IS_TRACING) return;
208
209   __TRACE_current_category_unset ();
210 }
211
212 #endif