Logo AND Algorithmique Numérique Distribuée

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