Logo AND Algorithmique Numérique Distribuée

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