Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] replace IS_TRACING by TRACE_is_active() function
[simgrid.git] / src / instr / instr_msg_process.c
1 /* Copyright (c) 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5   * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "instr/instr_private.h"
8
9 #ifdef HAVE_TRACING
10
11 static xbt_dict_t process_containers = NULL;
12
13 char *TRACE_process_alias_container(m_process_t process, m_host_t host,
14                                     char *output, int len)
15 {
16   if (output) {
17     snprintf(output, len, "%p-%p", process, host);
18     return output;
19   } else {
20     return NULL;
21   }
22 }
23
24 char *TRACE_process_container(m_process_t process, char *output, int len)
25 {
26   if (output) {
27     snprintf(output, len, "%s-%p", MSG_process_get_name(process), process);
28     return output;
29   } else {
30     return NULL;
31   }
32 }
33
34 void TRACE_msg_process_alloc(void)
35 {
36   process_containers = xbt_dict_new();
37 }
38
39 void TRACE_msg_process_release(void)
40 {
41   xbt_dict_free(&process_containers);
42 }
43
44 static void TRACE_msg_process_location(m_process_t process)
45 {
46   char name[200], alias[200];
47   m_host_t host = NULL;
48   if (!(IS_TRACING_PROCESSES || IS_TRACING_VOLUME))
49     return;
50
51   host = MSG_process_get_host(process);
52   TRACE_process_container(process, name, 200);
53   TRACE_process_alias_container(process, host, alias, 200);
54
55   //check if process_alias container is already created
56   if (!xbt_dict_get_or_null(process_containers, alias)) {
57     pajeCreateContainer(MSG_get_clock(), alias, "PROCESS",
58                         MSG_host_get_name(host), name);
59     if (IS_TRACING_PROCESSES)
60       pajeSetState(MSG_get_clock(), "category", alias, process->category);
61     xbt_dict_set(process_containers, xbt_strdup(alias), xbt_strdup("1"),
62                  xbt_free);
63   }
64 }
65
66 static void TRACE_msg_process_present(m_process_t process)
67 {
68   char alias[200];
69   m_host_t host = NULL;
70   if (!IS_TRACING_PROCESSES)
71     return;
72
73   //updating presence state of this process location
74   host = MSG_process_get_host(process);
75   TRACE_process_alias_container(process, host, alias, 200);
76   pajePushState(MSG_get_clock(), "presence", alias, "presence");
77 }
78
79 /*
80  * TRACE_msg_set_process_category: tracing interface function
81  */
82 void TRACE_msg_set_process_category(m_process_t process,
83                                     const char *category)
84 {
85   char name[200];
86   if (!TRACE_is_active())
87     return;
88
89   //set process category
90   process->category = xbt_strdup(category);
91
92   //create container of type "PROCESS" to indicate location
93   TRACE_msg_process_location(process);
94   TRACE_msg_process_present(process);
95
96   //create container of type "process" to indicate behavior
97   TRACE_process_container(process, name, 200);
98   if (IS_TRACING_PROCESSES)
99     pajeCreateContainer(MSG_get_clock(), name, "process", category, name);
100   if (IS_TRACING_PROCESSES)
101     pajeSetState(MSG_get_clock(), "process-state", name, "executing");
102 }
103
104 /*
105  * Instrumentation functions to trace MSG processes (m_process_t)
106  */
107 void TRACE_msg_process_change_host(m_process_t process, m_host_t old_host,
108                                    m_host_t new_host)
109 {
110   char alias[200];
111   if (!(IS_TRACING_PROCESSES || IS_TRACING_VOLUME) || !IS_TRACED(process))
112     return;
113
114   //disabling presence in old_host (__TRACE_msg_process_not_present)
115   TRACE_process_alias_container(process, old_host, alias, 200);
116   if (IS_TRACING_PROCESSES)
117     pajePopState(MSG_get_clock(), "presence", alias);
118
119   TRACE_msg_process_location(process);
120   TRACE_msg_process_present(process);
121 }
122
123 void TRACE_msg_process_kill(m_process_t process)
124 {
125   char name[200];
126   if (!IS_TRACING_PROCESSES || !IS_TRACED(process))
127     return;
128
129   TRACE_process_container(process, name, 200);
130   pajeDestroyContainer(MSG_get_clock(), "process", name);
131 }
132
133 void TRACE_msg_process_suspend(m_process_t process)
134 {
135   char name[200];
136   if (!IS_TRACING_PROCESSES || !IS_TRACED(process))
137     return;
138
139   TRACE_process_container(process, name, 200);
140   pajeSetState(MSG_get_clock(), "process-state", name, "suspend");
141 }
142
143 void TRACE_msg_process_resume(m_process_t process)
144 {
145   char name[200];
146   if (!IS_TRACING_PROCESSES || !IS_TRACED(process))
147     return;
148
149   TRACE_process_container(process, name, 200);
150   pajeSetState(MSG_get_clock(), "process-state", name, "executing");
151 }
152
153 void TRACE_msg_process_sleep_in(m_process_t process)
154 {
155   char name[200];
156   if (!IS_TRACING_PROCESSES || !IS_TRACED(process))
157     return;
158
159   TRACE_process_container(process, name, 200);
160   pajeSetState(MSG_get_clock(), "process-state", name, "sleep");
161 }
162
163 void TRACE_msg_process_sleep_out(m_process_t process)
164 {
165   char name[200];
166   if (!IS_TRACING_PROCESSES || !IS_TRACED(process))
167     return;
168
169   TRACE_process_container(process, name, 200);
170   pajeSetState(MSG_get_clock(), "process-state", name, "executing");
171 }
172
173 void TRACE_msg_process_end(m_process_t process)
174 {
175   char name[200], alias[200];
176   m_host_t host = NULL;
177   if (!IS_TRACED(process))
178     return;
179
180   host = MSG_process_get_host(process);
181   TRACE_process_container(process, name, 200);
182   TRACE_process_alias_container(process, host, alias, 200);
183   if (IS_TRACING_PROCESSES)
184     pajeDestroyContainer(MSG_get_clock(), "process", name);
185   if (IS_TRACING_PROCESSES)
186     pajeDestroyContainer(MSG_get_clock(), "PROCESS", alias);
187 }
188
189 #endif /* HAVE_TRACING */