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 current_task_category = NULL;
19 void __TRACE_msg_init (void)
21 current_task_category = xbt_dict_new();
24 void __TRACE_current_category_set (m_task_t task)
27 snprintf (processid, 100, "%p", SIMIX_process_self());
28 xbt_dict_set (current_task_category, processid, xbt_strdup (task->category), xbt_free);
31 void __TRACE_current_category_unset ()
34 snprintf (processid, 100, "%p", SIMIX_process_self());
35 xbt_dict_remove (current_task_category, processid);
38 char *__TRACE_current_category_get (smx_process_t proc)
41 snprintf (processid, 100, "%p", proc);
42 return xbt_dict_get_or_null (current_task_category, processid);
45 void __TRACE_task_location (m_task_t task)
48 m_process_t process = MSG_process_self();
49 m_host_t host = MSG_process_get_host (process);
50 if (IS_TRACING_PROCESSES){
51 //container is a process
52 TRACE_process_alias_container (process, host, container, 200);
53 __TRACE_msg_process_location (process);
56 TRACE_host_container (host, container, 200);
59 char name[200], alias[200];
60 TRACE_task_container (task, name, 200);
61 TRACE_task_alias_container (task, process, host, alias, 200);
62 if (IS_TRACING_TASKS) pajeCreateContainer (MSG_get_clock(), alias, "TASK", container, name);
66 * TRACE_msg_set_task_category: tracing interface function
68 void TRACE_msg_set_task_category(m_task_t task, const char *category)
70 if (!IS_TRACING) return;
73 task->category = xbt_new (char, strlen (category)+1);
74 strncpy(task->category, category, strlen(category)+1);
76 char name[200];//, alias[200], process_alias[200];
77 TRACE_task_container (task, name, 200);
78 //create container of type "task" to indicate behavior
79 if (IS_TRACING_TASKS) pajeCreateContainer (MSG_get_clock(), name, "task", category, name);
80 if (IS_TRACING_TASKS) pajePushState (MSG_get_clock(), "task-state", name, "created");
82 //tracing task location based on process/host
83 __TRACE_task_location (task);
86 /* MSG_task_create related function*/
87 void TRACE_msg_task_create (m_task_t task)
89 static long long counter = 0;
90 task->counter = counter++;
91 task->category = NULL;
94 /* MSG_task_execute related functions */
95 void TRACE_msg_task_execute_start (m_task_t task)
97 if (!IS_TRACING || !IS_TRACED(task)) return;
100 TRACE_task_container (task, name, 200);
101 if (IS_TRACING_TASKS) pajePushState (MSG_get_clock(), "task-state", name, "execute");
103 __TRACE_current_category_set (task);
106 void TRACE_msg_task_execute_end (m_task_t task)
108 if (!IS_TRACING || !IS_TRACED(task)) return;
111 TRACE_task_container (task, name, 200);
112 if (IS_TRACING_TASKS) pajePopState (MSG_get_clock(), "task-state", name);
114 __TRACE_current_category_unset();
117 /* MSG_task_destroy related functions */
118 void TRACE_msg_task_destroy (m_task_t task)
120 if (!IS_TRACING || !IS_TRACED(task)) return;
123 TRACE_task_container (task, name, 200);
124 if (IS_TRACING_TASKS) pajeDestroyContainer (MSG_get_clock(), "task", name);
127 xbt_free (task->category);
131 /* MSG_task_get related functions */
132 void TRACE_msg_task_get_start (void)
134 if (!IS_TRACING) return;
137 void TRACE_msg_task_get_end (double start_time, m_task_t task)
139 if (!IS_TRACING || !IS_TRACED(task)) return;
142 TRACE_task_container (task, name, 200);
143 if (IS_TRACING_TASKS) pajePopState (MSG_get_clock(), "task-state", name);
145 //tracing task location based on process/host
146 __TRACE_task_location (task);
149 /* MSG_task_put related functions */
150 int TRACE_msg_task_put_start (m_task_t task)
152 if (!IS_TRACING || !IS_TRACED(task)) return 0;
155 TRACE_task_container (task, name, 200);
156 if (IS_TRACING_TASKS) pajePopState (MSG_get_clock(), "task-state", name);
157 if (IS_TRACING_TASKS) pajePushState (MSG_get_clock(), "task-state", name, "communicate");
159 __TRACE_current_category_set (task);
163 void TRACE_msg_task_put_end (void)
165 if (!IS_TRACING) return;
167 __TRACE_current_category_unset ();