1 /* Copyright (c) 2010. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #include "instr/private.h"
11 static xbt_dict_t task_containers = NULL;
12 static xbt_dict_t current_task_category = NULL;
14 void __TRACE_msg_init (void)
16 current_task_category = xbt_dict_new();
17 task_containers = xbt_dict_new();
20 void __TRACE_current_category_set (m_task_t task)
23 snprintf (processid, 100, "%p", SIMIX_process_self());
24 xbt_dict_set (current_task_category, processid, xbt_strdup (task->category), xbt_free);
27 void __TRACE_current_category_unset ()
30 snprintf (processid, 100, "%p", SIMIX_process_self());
31 xbt_dict_remove (current_task_category, processid);
34 char *__TRACE_current_category_get (smx_process_t proc)
37 snprintf (processid, 100, "%p", proc);
38 return xbt_dict_get_or_null (current_task_category, processid);
41 void __TRACE_task_location (m_task_t task)
43 if (!IS_TRACING_TASKS) return;
45 m_process_t process = MSG_process_self();
46 m_host_t host = MSG_process_get_host (process);
48 //tasks are grouped by host
49 TRACE_host_container (host, container, 200);
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);
62 void __TRACE_task_location_present (m_task_t task)
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);
70 TRACE_task_alias_container (task, process, host, alias, 200);
71 pajePushState (MSG_get_clock(), "presence", alias, "presence");
74 void __TRACE_task_location_not_present (m_task_t task)
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);
82 TRACE_task_alias_container (task, process, host, alias, 200);
83 pajePopState (MSG_get_clock(), "presence", alias);
87 * TRACE_msg_set_task_category: tracing interface function
89 void TRACE_msg_set_task_category(m_task_t task, const char *category)
91 if (!IS_TRACING) return;
94 task->category = xbt_new (char, strlen (category)+1);
95 strncpy(task->category, category, strlen(category)+1);
97 //tracing task location based on host
98 __TRACE_task_location (task);
99 __TRACE_task_location_present (task);
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");
108 /* MSG_task_create related function*/
109 void TRACE_msg_task_create (m_task_t task)
111 static long long counter = 0;
112 task->counter = counter++;
113 task->category = NULL;
116 /* MSG_task_execute related functions */
117 void TRACE_msg_task_execute_start (m_task_t task)
119 if (!IS_TRACING || !IS_TRACED(task)) return;
122 TRACE_task_container (task, name, 200);
123 if (IS_TRACING_TASKS) pajePushState (MSG_get_clock(), "task-state", name, "execute");
125 __TRACE_current_category_set (task);
128 void TRACE_msg_task_execute_end (m_task_t task)
130 if (!IS_TRACING || !IS_TRACED(task)) return;
133 TRACE_task_container (task, name, 200);
134 if (IS_TRACING_TASKS) pajePopState (MSG_get_clock(), "task-state", name);
136 __TRACE_current_category_unset();
139 /* MSG_task_destroy related functions */
140 void TRACE_msg_task_destroy (m_task_t task)
142 if (!IS_TRACING || !IS_TRACED(task)) return;
145 TRACE_task_container (task, name, 200);
146 if (IS_TRACING_TASKS) pajeDestroyContainer (MSG_get_clock(), "task", name);
148 //finish the location of this task
149 __TRACE_task_location_not_present (task);
152 xbt_free (task->category);
156 /* MSG_task_get related functions */
157 void TRACE_msg_task_get_start (void)
159 if (!IS_TRACING) return;
162 void TRACE_msg_task_get_end (double start_time, m_task_t task)
164 if (!IS_TRACING || !IS_TRACED(task)) return;
167 TRACE_task_container (task, name, 200);
168 if (IS_TRACING_TASKS) pajePopState (MSG_get_clock(), "task-state", name);
170 __TRACE_msg_volume_finish (task);
172 __TRACE_task_location (task);
173 __TRACE_task_location_present (task);
176 /* MSG_task_put related functions */
177 int TRACE_msg_task_put_start (m_task_t task)
179 if (!IS_TRACING || !IS_TRACED(task)) return 0;
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");
186 __TRACE_msg_volume_start (task);
188 //trace task location grouped by host
189 __TRACE_task_location_not_present (task);
191 //set current category
192 __TRACE_current_category_set (task);
196 void TRACE_msg_task_put_end (void)
198 if (!IS_TRACING) return;
200 __TRACE_current_category_unset ();