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 xbt_dict_set (task_containers, xbt_strdup(alias), xbt_strdup("1"), xbt_free);
67 void __TRACE_task_location_present (m_task_t task)
69 if (!IS_TRACING_TASKS) return;
70 //updating presence state of this task location
71 m_process_t process = MSG_process_self();
72 m_host_t host = MSG_process_get_host (process);
75 TRACE_task_alias_container (task, process, host, alias, 200);
76 pajePushState (MSG_get_clock(), "presence", alias, "presence");
79 void __TRACE_task_location_not_present (m_task_t task)
81 if (!IS_TRACING_TASKS) return;
82 //updating presence state of this task location
83 m_process_t process = MSG_process_self();
84 m_host_t host = MSG_process_get_host (process);
87 TRACE_task_alias_container (task, process, host, alias, 200);
88 pajePopState (MSG_get_clock(), "presence", alias);
92 * TRACE_msg_set_task_category: tracing interface function
94 void TRACE_msg_set_task_category(m_task_t task, const char *category)
96 if (!IS_TRACING) return;
99 task->category = xbt_new (char, strlen (category)+1);
100 strncpy(task->category, category, strlen(category)+1);
102 //tracing task location based on host
103 __TRACE_task_location (task);
104 __TRACE_task_location_present (task);
107 TRACE_task_container (task, name, 200);
108 //create container of type "task" to indicate behavior
109 if (IS_TRACING_TASKS) pajeCreateContainer (MSG_get_clock(), name, "task", category, name);
110 if (IS_TRACING_TASKS) pajePushState (MSG_get_clock(), "task-state", name, "created");
113 /* MSG_task_create related function*/
114 void TRACE_msg_task_create (m_task_t task)
116 static long long counter = 0;
117 task->counter = counter++;
118 task->category = NULL;
121 /* MSG_task_execute related functions */
122 void TRACE_msg_task_execute_start (m_task_t task)
124 if (!IS_TRACING || !IS_TRACED(task)) return;
127 TRACE_task_container (task, name, 200);
128 if (IS_TRACING_TASKS) pajePushState (MSG_get_clock(), "task-state", name, "execute");
130 __TRACE_current_category_set (task);
133 void TRACE_msg_task_execute_end (m_task_t task)
135 if (!IS_TRACING || !IS_TRACED(task)) return;
138 TRACE_task_container (task, name, 200);
139 if (IS_TRACING_TASKS) pajePopState (MSG_get_clock(), "task-state", name);
141 __TRACE_current_category_unset();
144 /* MSG_task_destroy related functions */
145 void TRACE_msg_task_destroy (m_task_t task)
147 if (!IS_TRACING || !IS_TRACED(task)) return;
150 TRACE_task_container (task, name, 200);
151 if (IS_TRACING_TASKS) pajeDestroyContainer (MSG_get_clock(), "task", name);
153 //finish the location of this task
154 __TRACE_task_location_not_present (task);
157 xbt_free (task->category);
161 /* MSG_task_get related functions */
162 void TRACE_msg_task_get_start (void)
164 if (!IS_TRACING) return;
167 void TRACE_msg_task_get_end (double start_time, m_task_t task)
169 if (!IS_TRACING || !IS_TRACED(task)) return;
172 TRACE_task_container (task, name, 200);
173 if (IS_TRACING_TASKS) pajePopState (MSG_get_clock(), "task-state", name);
175 __TRACE_task_location (task);
176 __TRACE_task_location_present (task);
179 /* MSG_task_put related functions */
180 int TRACE_msg_task_put_start (m_task_t task)
182 if (!IS_TRACING || !IS_TRACED(task)) return 0;
185 TRACE_task_container (task, name, 200);
186 if (IS_TRACING_TASKS) pajePopState (MSG_get_clock(), "task-state", name);
187 if (IS_TRACING_TASKS) pajePushState (MSG_get_clock(), "task-state", name, "communicate");
189 //trace task location grouped by host
190 __TRACE_task_location_not_present (task);
192 //set current category
193 __TRACE_current_category_set (task);
197 void TRACE_msg_task_put_end (void)
199 if (!IS_TRACING) return;
201 __TRACE_current_category_unset ();