Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
allowing the user to set the three tracing masks
[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     xbt_dict_set (task_containers, xbt_strdup(alias), xbt_strdup("1"), xbt_free);
64   }
65 }
66
67 void __TRACE_task_location_present (m_task_t task)
68 {
69   if (!IS_TRACING_TASKS) return;
70   //updating presence state of this task location
71   m_process_t process = MSG_process_self();
72   m_host_t host = MSG_process_get_host (process);
73
74   char alias[200];
75   TRACE_task_alias_container (task, process, host, alias, 200);
76   pajePushState (MSG_get_clock(), "presence", alias, "presence");
77 }
78
79 void __TRACE_task_location_not_present (m_task_t task)
80 {
81   if (!IS_TRACING_TASKS) return;
82   //updating presence state of this task location
83   m_process_t process = MSG_process_self();
84   m_host_t host = MSG_process_get_host (process);
85
86   char alias[200];
87   TRACE_task_alias_container (task, process, host, alias, 200);
88   pajePopState (MSG_get_clock(), "presence", alias);
89 }
90
91 /*
92  * TRACE_msg_set_task_category: tracing interface function
93  */
94 void TRACE_msg_set_task_category(m_task_t task, const char *category)
95 {
96   if (!IS_TRACING) return;
97
98   //set task category
99   task->category = xbt_new (char, strlen (category)+1);
100   strncpy(task->category, category, strlen(category)+1);
101
102   //tracing task location based on host
103   __TRACE_task_location (task);
104   __TRACE_task_location_present (task);
105
106   char name[200];
107   TRACE_task_container (task, name, 200);
108   //create container of type "task" to indicate behavior
109   if (IS_TRACING_TASKS) pajeCreateContainer (MSG_get_clock(), name, "task", category, name);
110   if (IS_TRACING_TASKS) pajePushState (MSG_get_clock(), "task-state", name, "created");
111 }
112
113 /* MSG_task_create related function*/
114 void TRACE_msg_task_create (m_task_t task)
115 {
116   static long long counter = 0;
117   task->counter = counter++;
118   task->category = NULL;
119 }
120
121 /* MSG_task_execute related functions */
122 void TRACE_msg_task_execute_start (m_task_t task)
123 {
124   if (!IS_TRACING || !IS_TRACED(task)) return;
125
126   char name[200];
127   TRACE_task_container (task, name, 200);
128   if (IS_TRACING_TASKS) pajePushState (MSG_get_clock(), "task-state", name, "execute");
129
130   __TRACE_current_category_set (task);
131 }
132
133 void TRACE_msg_task_execute_end (m_task_t task)
134 {
135   if (!IS_TRACING || !IS_TRACED(task)) return;
136
137   char name[200];
138   TRACE_task_container (task, name, 200);
139   if (IS_TRACING_TASKS) pajePopState (MSG_get_clock(), "task-state", name);
140
141   __TRACE_current_category_unset();
142 }
143
144 /* MSG_task_destroy related functions */
145 void TRACE_msg_task_destroy (m_task_t task)
146 {
147   if (!IS_TRACING || !IS_TRACED(task)) return;
148
149   char name[200];
150   TRACE_task_container (task, name, 200);
151   if (IS_TRACING_TASKS) pajeDestroyContainer (MSG_get_clock(), "task", name);
152
153   //finish the location of this task
154   __TRACE_task_location_not_present (task);
155
156   //free category
157   xbt_free (task->category);
158   return;
159 }
160
161 /* MSG_task_get related functions */
162 void TRACE_msg_task_get_start (void)
163 {
164   if (!IS_TRACING) return;
165 }
166
167 void TRACE_msg_task_get_end (double start_time, m_task_t task)
168 {
169   if (!IS_TRACING || !IS_TRACED(task)) return;
170
171   char name[200];
172   TRACE_task_container (task, name, 200);
173   if (IS_TRACING_TASKS) pajePopState (MSG_get_clock(), "task-state", name);
174
175   __TRACE_task_location (task);
176   __TRACE_task_location_present (task);
177 }
178
179 /* MSG_task_put related functions */
180 int TRACE_msg_task_put_start (m_task_t task)
181 {
182   if (!IS_TRACING || !IS_TRACED(task)) return 0;
183
184   char name[200];
185   TRACE_task_container (task, name, 200);
186   if (IS_TRACING_TASKS) pajePopState (MSG_get_clock(), "task-state", name);
187   if (IS_TRACING_TASKS) pajePushState (MSG_get_clock(), "task-state", name, "communicate");
188
189   //trace task location grouped by host
190   __TRACE_task_location_not_present (task);
191
192   //set current category
193   __TRACE_current_category_set (task);
194   return 1;
195 }
196
197 void TRACE_msg_task_put_end (void)
198 {
199   if (!IS_TRACING) return;
200
201   __TRACE_current_category_unset ();
202 }
203
204 #endif