Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
proper use of the HAVE_TRACING variable defined by Cmake through -Dtracing=on
[simgrid.git] / src / instr / msg_task_instr.c
1 /*
2  * msg.c
3  *
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.
9  *
10  *     Copyright (c) 2009 The SimGrid team.
11  */
12
13 #include "instr/private.h"
14
15 #ifdef HAVE_TRACING
16
17 static xbt_dict_t current_task_category = NULL;
18
19 void __TRACE_msg_init (void)
20 {
21   current_task_category = xbt_dict_new();
22 }
23
24 void __TRACE_current_category_set (m_task_t task)
25 {
26   char processid[100];
27   snprintf (processid, 100, "%p", SIMIX_process_self());
28   xbt_dict_set (current_task_category, processid, xbt_strdup (task->category), xbt_free);
29 }
30
31 void __TRACE_current_category_unset ()
32 {
33   char processid[100];
34   snprintf (processid, 100, "%p", SIMIX_process_self());
35   xbt_dict_remove (current_task_category, processid);
36 }
37
38 char *__TRACE_current_category_get (smx_process_t proc)
39 {
40   char processid[100];
41   snprintf (processid, 100, "%p", proc);
42   return xbt_dict_get_or_null (current_task_category, processid);
43 }
44
45 void __TRACE_task_location (m_task_t task)
46 {
47   char container[200];
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);
54   }else{
55         //container is a host
56         TRACE_host_container (host, container, 200);
57   }
58
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);
63 }
64
65 /*
66  * TRACE_msg_set_task_category: tracing interface function
67  */
68 void TRACE_msg_set_task_category(m_task_t task, const char *category)
69 {
70   if (!IS_TRACING) return;
71
72   //set task category
73   task->category = xbt_new (char, strlen (category)+1);
74   strncpy(task->category, category, strlen(category)+1);
75
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");
81
82   //tracing task location based on process/host
83   __TRACE_task_location (task);
84 }
85
86 /* MSG_task_create related function*/
87 void TRACE_msg_task_create (m_task_t task)
88 {
89   static long long counter = 0;
90   task->counter = counter++;
91   task->category = NULL;
92 }
93
94 /* MSG_task_execute related functions */
95 void TRACE_msg_task_execute_start (m_task_t task)
96 {
97   if (!IS_TRACING || !IS_TRACED(task)) return;
98
99   char name[200];
100   TRACE_task_container (task, name, 200);
101   if (IS_TRACING_TASKS) pajePushState (MSG_get_clock(), "task-state", name, "execute");
102
103   __TRACE_current_category_set (task);
104 }
105
106 void TRACE_msg_task_execute_end (m_task_t task)
107 {
108   if (!IS_TRACING || !IS_TRACED(task)) return;
109
110   char name[200];
111   TRACE_task_container (task, name, 200);
112   if (IS_TRACING_TASKS) pajePopState (MSG_get_clock(), "task-state", name);
113
114   __TRACE_current_category_unset();
115 }
116
117 /* MSG_task_destroy related functions */
118 void TRACE_msg_task_destroy (m_task_t task)
119 {
120   if (!IS_TRACING || !IS_TRACED(task)) return;
121
122   char name[200];
123   TRACE_task_container (task, name, 200);
124   if (IS_TRACING_TASKS) pajeDestroyContainer (MSG_get_clock(), "task", name);
125
126   //free category
127   xbt_free (task->category);
128   return;
129 }
130
131 /* MSG_task_get related functions */
132 void TRACE_msg_task_get_start (void)
133 {
134   if (!IS_TRACING) return;
135 }
136
137 void TRACE_msg_task_get_end (double start_time, m_task_t task)
138 {
139   if (!IS_TRACING || !IS_TRACED(task)) return;
140
141   char name[200];
142   TRACE_task_container (task, name, 200);
143   if (IS_TRACING_TASKS) pajePopState (MSG_get_clock(), "task-state", name);
144
145   //tracing task location based on process/host
146   __TRACE_task_location (task);
147 }
148
149 /* MSG_task_put related functions */
150 int TRACE_msg_task_put_start (m_task_t task)
151 {
152   if (!IS_TRACING || !IS_TRACED(task)) return 0;
153
154   char name[200];
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");
158
159   __TRACE_current_category_set (task);
160   return 1;
161 }
162
163 void TRACE_msg_task_put_end (void)
164 {
165   if (!IS_TRACING) return;
166
167   __TRACE_current_category_unset ();
168 }
169
170 #endif