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;
13 void TRACE_msg_task_alloc (void)
15 task_containers = xbt_dict_new();
18 void TRACE_msg_task_release (void)
20 xbt_dict_free (&task_containers);
23 static void TRACE_task_location (m_task_t task)
26 char name[200], alias[200];
28 m_process_t process = NULL;
30 if (!IS_TRACING_TASKS) return;
31 process = MSG_process_self();
32 host = MSG_process_get_host (process);
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);
47 static void TRACE_task_location_present (m_task_t task)
50 m_process_t process = 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);
57 TRACE_task_alias_container (task, process, host, alias, 200);
58 pajePushState (MSG_get_clock(), "presence", alias, "presence");
61 static void TRACE_task_location_not_present (m_task_t task)
64 m_process_t process = 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);
71 TRACE_task_alias_container (task, process, host, alias, 200);
72 pajePopState (MSG_get_clock(), "presence", alias);
76 * TRACE_msg_set_task_category: tracing interface function
78 void TRACE_msg_set_task_category(m_task_t task, const char *category)
81 if (!IS_TRACING) return;
84 task->category = xbt_new (char, strlen (category)+1);
85 strncpy(task->category, category, strlen(category)+1);
87 //tracing task location based on host
88 TRACE_task_location (task);
89 TRACE_task_location_present (task);
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");
97 /* MSG_task_create related function*/
98 void TRACE_msg_task_create (m_task_t task)
100 static long long counter = 0;
101 task->counter = counter++;
102 task->category = NULL;
105 /* MSG_task_execute related functions */
106 void TRACE_msg_task_execute_start (m_task_t task)
109 if (!IS_TRACING || !IS_TRACED(task)) return;
111 TRACE_task_container (task, name, 200);
112 if (IS_TRACING_TASKS) pajePushState (MSG_get_clock(), "task-state", name, "execute");
114 TRACE_msg_category_set (SIMIX_process_self(), task);
117 void TRACE_msg_task_execute_end (m_task_t task)
120 if (!IS_TRACING || !IS_TRACED(task)) return;
122 TRACE_task_container (task, name, 200);
123 if (IS_TRACING_TASKS) pajePopState (MSG_get_clock(), "task-state", name);
125 TRACE_category_unset(SIMIX_process_self());
128 /* MSG_task_destroy related functions */
129 void TRACE_msg_task_destroy (m_task_t task)
132 if (!IS_TRACING || !IS_TRACED(task)) return;
134 TRACE_task_container (task, name, 200);
135 if (IS_TRACING_TASKS) pajeDestroyContainer (MSG_get_clock(), "task", name);
137 //finish the location of this task
138 TRACE_task_location_not_present (task);
141 xbt_free (task->category);
145 /* MSG_task_get related functions */
146 void TRACE_msg_task_get_start (void)
148 if (!IS_TRACING) return;
151 void TRACE_msg_task_get_end (double start_time, m_task_t task)
154 if (!IS_TRACING || !IS_TRACED(task)) return;
156 TRACE_task_container (task, name, 200);
157 if (IS_TRACING_TASKS) pajePopState (MSG_get_clock(), "task-state", name);
159 TRACE_msg_volume_finish (task);
161 TRACE_task_location (task);
162 TRACE_task_location_present (task);
165 /* MSG_task_put related functions */
166 int TRACE_msg_task_put_start (m_task_t task)
169 if (!IS_TRACING || !IS_TRACED(task)) return 0;
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");
175 TRACE_msg_volume_start (task);
177 //trace task location grouped by host
178 TRACE_task_location_not_present (task);
180 //set current category
181 TRACE_msg_category_set (SIMIX_process_self(), task);
185 void TRACE_msg_task_put_end (void)
187 if (!IS_TRACING) return;
189 TRACE_category_unset (SIMIX_process_self());