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.
10 * Copyright (c) 2009 The SimGrid team.
13 #include "instr/private.h"
17 static xbt_dict_t task_containers = NULL;
18 static xbt_dict_t current_task_category = NULL;
20 void __TRACE_msg_init (void)
22 current_task_category = xbt_dict_new();
23 task_containers = xbt_dict_new();
26 void __TRACE_current_category_set (m_task_t task)
29 snprintf (processid, 100, "%p", SIMIX_process_self());
30 xbt_dict_set (current_task_category, processid, xbt_strdup (task->category), xbt_free);
33 void __TRACE_current_category_unset ()
36 snprintf (processid, 100, "%p", SIMIX_process_self());
37 xbt_dict_remove (current_task_category, processid);
40 char *__TRACE_current_category_get (smx_process_t proc)
43 snprintf (processid, 100, "%p", proc);
44 return xbt_dict_get_or_null (current_task_category, processid);
47 void __TRACE_task_location (m_task_t task)
49 if (!IS_TRACING_TASKS) return;
51 m_process_t process = MSG_process_self();
52 m_host_t host = MSG_process_get_host (process);
54 //tasks are grouped by host
55 TRACE_host_container (host, container, 200);
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 pajeSetState (MSG_get_clock(), "category", alias, task->category);
64 xbt_dict_set (task_containers, xbt_strdup(alias), xbt_strdup("1"), xbt_free);
68 void __TRACE_task_location_present (m_task_t task)
70 if (!IS_TRACING_TASKS) return;
71 //updating presence state of this task location
72 m_process_t process = MSG_process_self();
73 m_host_t host = MSG_process_get_host (process);
76 TRACE_task_alias_container (task, process, host, alias, 200);
77 pajePushState (MSG_get_clock(), "presence", alias, "presence");
80 void __TRACE_task_location_not_present (m_task_t task)
82 if (!IS_TRACING_TASKS) return;
83 //updating presence state of this task location
84 m_process_t process = MSG_process_self();
85 m_host_t host = MSG_process_get_host (process);
88 TRACE_task_alias_container (task, process, host, alias, 200);
89 pajePopState (MSG_get_clock(), "presence", alias);
93 * TRACE_msg_set_task_category: tracing interface function
95 void TRACE_msg_set_task_category(m_task_t task, const char *category)
97 if (!IS_TRACING) return;
100 task->category = xbt_new (char, strlen (category)+1);
101 strncpy(task->category, category, strlen(category)+1);
103 //tracing task location based on host
104 __TRACE_task_location (task);
105 __TRACE_task_location_present (task);
108 TRACE_task_container (task, name, 200);
109 //create container of type "task" to indicate behavior
110 if (IS_TRACING_TASKS) pajeCreateContainer (MSG_get_clock(), name, "task", category, name);
111 if (IS_TRACING_TASKS) pajePushState (MSG_get_clock(), "task-state", name, "created");
114 /* MSG_task_create related function*/
115 void TRACE_msg_task_create (m_task_t task)
117 static long long counter = 0;
118 task->counter = counter++;
119 task->category = NULL;
122 /* MSG_task_execute related functions */
123 void TRACE_msg_task_execute_start (m_task_t task)
125 if (!IS_TRACING || !IS_TRACED(task)) return;
128 TRACE_task_container (task, name, 200);
129 if (IS_TRACING_TASKS) pajePushState (MSG_get_clock(), "task-state", name, "execute");
131 __TRACE_current_category_set (task);
134 void TRACE_msg_task_execute_end (m_task_t task)
136 if (!IS_TRACING || !IS_TRACED(task)) return;
139 TRACE_task_container (task, name, 200);
140 if (IS_TRACING_TASKS) pajePopState (MSG_get_clock(), "task-state", name);
142 __TRACE_current_category_unset();
145 /* MSG_task_destroy related functions */
146 void TRACE_msg_task_destroy (m_task_t task)
148 if (!IS_TRACING || !IS_TRACED(task)) return;
151 TRACE_task_container (task, name, 200);
152 if (IS_TRACING_TASKS) pajeDestroyContainer (MSG_get_clock(), "task", name);
154 //finish the location of this task
155 __TRACE_task_location_not_present (task);
158 xbt_free (task->category);
162 /* MSG_task_get related functions */
163 void TRACE_msg_task_get_start (void)
165 if (!IS_TRACING) return;
168 void TRACE_msg_task_get_end (double start_time, m_task_t task)
170 if (!IS_TRACING || !IS_TRACED(task)) return;
173 TRACE_task_container (task, name, 200);
174 if (IS_TRACING_TASKS) pajePopState (MSG_get_clock(), "task-state", name);
176 __TRACE_task_location (task);
177 __TRACE_task_location_present (task);
180 /* MSG_task_put related functions */
181 int TRACE_msg_task_put_start (m_task_t task)
183 if (!IS_TRACING || !IS_TRACED(task)) return 0;
186 TRACE_task_container (task, name, 200);
187 if (IS_TRACING_TASKS) pajePopState (MSG_get_clock(), "task-state", name);
188 if (IS_TRACING_TASKS) pajePushState (MSG_get_clock(), "task-state", name, "communicate");
190 //trace task location grouped by host
191 __TRACE_task_location_not_present (task);
193 //set current category
194 __TRACE_current_category_set (task);
198 void TRACE_msg_task_put_end (void)
200 if (!IS_TRACING) return;
202 __TRACE_current_category_unset ();