Logo AND Algorithmique Numérique Distribuée

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