Logo AND Algorithmique Numérique Distribuée

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