Logo AND Algorithmique Numérique Distribuée

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