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_init (void)
15 task_containers = xbt_dict_new();
18 void __TRACE_task_location (m_task_t task)
21 char name[200], alias[200];
23 m_process_t process = NULL;
25 if (!IS_TRACING_TASKS) return;
26 process = MSG_process_self();
27 host = MSG_process_get_host (process);
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);
42 void __TRACE_task_location_present (m_task_t task)
45 m_process_t process = 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);
52 TRACE_task_alias_container (task, process, host, alias, 200);
53 pajePushState (MSG_get_clock(), "presence", alias, "presence");
56 void __TRACE_task_location_not_present (m_task_t task)
59 m_process_t process = 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);
66 TRACE_task_alias_container (task, process, host, alias, 200);
67 pajePopState (MSG_get_clock(), "presence", alias);
71 * TRACE_msg_set_task_category: tracing interface function
73 void TRACE_msg_set_task_category(m_task_t task, const char *category)
76 if (!IS_TRACING) return;
79 task->category = xbt_new (char, strlen (category)+1);
80 strncpy(task->category, category, strlen(category)+1);
82 //tracing task location based on host
83 __TRACE_task_location (task);
84 __TRACE_task_location_present (task);
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");
92 /* MSG_task_create related function*/
93 void TRACE_msg_task_create (m_task_t task)
95 static long long counter = 0;
96 task->counter = counter++;
97 task->category = NULL;
100 /* MSG_task_execute related functions */
101 void TRACE_msg_task_execute_start (m_task_t task)
104 if (!IS_TRACING || !IS_TRACED(task)) return;
106 TRACE_task_container (task, name, 200);
107 if (IS_TRACING_TASKS) pajePushState (MSG_get_clock(), "task-state", name, "execute");
109 __TRACE_msg_category_set (SIMIX_process_self(), task);
112 void TRACE_msg_task_execute_end (m_task_t task)
115 if (!IS_TRACING || !IS_TRACED(task)) return;
117 TRACE_task_container (task, name, 200);
118 if (IS_TRACING_TASKS) pajePopState (MSG_get_clock(), "task-state", name);
120 __TRACE_category_unset(SIMIX_process_self());
123 /* MSG_task_destroy related functions */
124 void TRACE_msg_task_destroy (m_task_t task)
127 if (!IS_TRACING || !IS_TRACED(task)) return;
129 TRACE_task_container (task, name, 200);
130 if (IS_TRACING_TASKS) pajeDestroyContainer (MSG_get_clock(), "task", name);
132 //finish the location of this task
133 __TRACE_task_location_not_present (task);
136 xbt_free (task->category);
140 /* MSG_task_get related functions */
141 void TRACE_msg_task_get_start (void)
143 if (!IS_TRACING) return;
146 void TRACE_msg_task_get_end (double start_time, m_task_t task)
149 if (!IS_TRACING || !IS_TRACED(task)) return;
151 TRACE_task_container (task, name, 200);
152 if (IS_TRACING_TASKS) pajePopState (MSG_get_clock(), "task-state", name);
154 __TRACE_msg_volume_finish (task);
156 __TRACE_task_location (task);
157 __TRACE_task_location_present (task);
160 /* MSG_task_put related functions */
161 int TRACE_msg_task_put_start (m_task_t task)
164 if (!IS_TRACING || !IS_TRACED(task)) return 0;
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");
170 __TRACE_msg_volume_start (task);
172 //trace task location grouped by host
173 __TRACE_task_location_not_present (task);
175 //set current category
176 __TRACE_msg_category_set (SIMIX_process_self(), task);
180 void TRACE_msg_task_put_end (void)
182 if (!IS_TRACING) return;
184 __TRACE_category_unset (SIMIX_process_self());