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"
14 #include "instr/config.h"
18 static xbt_dict_t current_task_category = NULL;
20 void __TRACE_msg_init (void)
22 current_task_category = xbt_dict_new();
25 void __TRACE_current_category_set (m_task_t task)
28 snprintf (processid, 100, "%p", SIMIX_process_self());
29 xbt_dict_set (current_task_category, processid, xbt_strdup (task->category), xbt_free);
32 void __TRACE_current_category_unset ()
35 snprintf (processid, 100, "%p", SIMIX_process_self());
36 xbt_dict_remove (current_task_category, processid);
39 char *__TRACE_current_category_get (smx_process_t proc)
42 snprintf (processid, 100, "%p", proc);
43 return xbt_dict_get_or_null (current_task_category, processid);
46 void __TRACE_task_location (m_task_t task)
49 m_process_t process = MSG_process_self();
50 m_host_t host = MSG_process_get_host (process);
51 if (IS_TRACING_PROCESSES){
52 //container is a process
53 TRACE_process_alias_container (process, host, container, 200);
54 __TRACE_msg_process_location (process);
57 TRACE_host_container (host, container, 200);
60 char name[200], alias[200];
61 TRACE_task_container (task, name, 200);
62 TRACE_task_alias_container (task, process, host, alias, 200);
63 if (IS_TRACING_TASKS) pajeCreateContainer (MSG_get_clock(), alias, "TASK", container, name);
67 * TRACE_msg_set_task_category: tracing interface function
69 void TRACE_msg_set_task_category(m_task_t task, const char *category)
71 if (!IS_TRACING) return;
74 task->category = xbt_new (char, strlen (category)+1);
75 strncpy(task->category, category, strlen(category)+1);
77 char name[200];//, alias[200], process_alias[200];
78 TRACE_task_container (task, name, 200);
79 //create container of type "task" to indicate behavior
80 if (IS_TRACING_TASKS) pajeCreateContainer (MSG_get_clock(), name, "task", category, name);
81 if (IS_TRACING_TASKS) pajePushState (MSG_get_clock(), "task-state", name, "created");
83 //tracing task location based on process/host
84 __TRACE_task_location (task);
87 /* MSG_task_create related function*/
88 void TRACE_msg_task_create (m_task_t task)
90 static long long counter = 0;
91 task->counter = counter++;
92 task->category = NULL;
95 /* MSG_task_execute related functions */
96 void TRACE_msg_task_execute_start (m_task_t task)
98 if (!IS_TRACING || !IS_TRACED(task)) return;
101 TRACE_task_container (task, name, 200);
102 if (IS_TRACING_TASKS) pajePushState (MSG_get_clock(), "task-state", name, "execute");
104 __TRACE_current_category_set (task);
107 void TRACE_msg_task_execute_end (m_task_t task)
109 if (!IS_TRACING || !IS_TRACED(task)) return;
112 TRACE_task_container (task, name, 200);
113 if (IS_TRACING_TASKS) pajePopState (MSG_get_clock(), "task-state", name);
115 __TRACE_current_category_unset();
118 /* MSG_task_destroy related functions */
119 void TRACE_msg_task_destroy (m_task_t task)
121 if (!IS_TRACING || !IS_TRACED(task)) return;
124 TRACE_task_container (task, name, 200);
125 if (IS_TRACING_TASKS) pajeDestroyContainer (MSG_get_clock(), "task", name);
128 xbt_free (task->category);
132 /* MSG_task_get related functions */
133 void TRACE_msg_task_get_start (void)
135 if (!IS_TRACING) return;
138 void TRACE_msg_task_get_end (double start_time, m_task_t task)
140 if (!IS_TRACING || !IS_TRACED(task)) return;
143 TRACE_task_container (task, name, 200);
144 if (IS_TRACING_TASKS) pajePopState (MSG_get_clock(), "task-state", name);
146 //tracing task location based on process/host
147 __TRACE_task_location (task);
150 /* MSG_task_put related functions */
151 int TRACE_msg_task_put_start (m_task_t task)
153 if (!IS_TRACING || !IS_TRACED(task)) return 0;
156 TRACE_task_container (task, name, 200);
157 if (IS_TRACING_TASKS) pajePopState (MSG_get_clock(), "task-state", name);
158 if (IS_TRACING_TASKS) pajePushState (MSG_get_clock(), "task-state", name, "communicate");
160 __TRACE_current_category_set (task);
164 void TRACE_msg_task_put_end (void)
166 if (!IS_TRACING) return;
168 __TRACE_current_category_unset ();