Logo AND Algorithmique Numérique Distribuée

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