Logo AND Algorithmique Numérique Distribuée

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