Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
d09b8f2a90e54dc06464aa16e1ecebb93cce5a8b
[simgrid.git] / src / instr / msg_process_instr.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/private.h"
8
9 #ifdef HAVE_TRACING
10
11 static xbt_dict_t process_containers = NULL;
12
13 void TRACE_msg_process_alloc(void)
14 {
15   process_containers = xbt_dict_new();
16 }
17
18 void TRACE_msg_process_release(void)
19 {
20   xbt_dict_free(&process_containers);
21 }
22
23 static void TRACE_msg_process_location(m_process_t process)
24 {
25   char name[200], alias[200];
26   m_host_t host = NULL;
27   if (!(IS_TRACING_PROCESSES || IS_TRACING_VOLUME))
28     return;
29
30   host = MSG_process_get_host(process);
31   TRACE_process_container(process, name, 200);
32   TRACE_process_alias_container(process, host, alias, 200);
33
34   //check if process_alias container is already created
35   if (!xbt_dict_get_or_null(process_containers, alias)) {
36     pajeCreateContainer(MSG_get_clock(), alias, "PROCESS",
37                         MSG_host_get_name(host), name);
38     if (IS_TRACING_PROCESSES)
39       pajeSetState(MSG_get_clock(), "category", alias, process->category);
40     xbt_dict_set(process_containers, xbt_strdup(alias), xbt_strdup("1"),
41                  xbt_free);
42   }
43 }
44
45 static void TRACE_msg_process_present(m_process_t process)
46 {
47   char alias[200];
48   m_host_t host = NULL;
49   if (!IS_TRACING_PROCESSES)
50     return;
51
52   //updating presence state of this process location
53   host = MSG_process_get_host(process);
54   TRACE_process_alias_container(process, host, alias, 200);
55   pajePushState(MSG_get_clock(), "presence", alias, "presence");
56 }
57
58 /*
59  * TRACE_msg_set_process_category: tracing interface function
60  */
61 void TRACE_msg_set_process_category(m_process_t process,
62                                     const char *category)
63 {
64   char name[200];
65   if (!IS_TRACING)
66     return;
67
68   //set process category
69   process->category = xbt_strdup(category);
70
71   //create container of type "PROCESS" to indicate location
72   TRACE_msg_process_location(process);
73   TRACE_msg_process_present(process);
74
75   //create container of type "process" to indicate behavior
76   TRACE_process_container(process, name, 200);
77   if (IS_TRACING_PROCESSES)
78     pajeCreateContainer(MSG_get_clock(), name, "process", category, name);
79   if (IS_TRACING_PROCESSES)
80     pajeSetState(MSG_get_clock(), "process-state", name, "executing");
81 }
82
83 /*
84  * Instrumentation functions to trace MSG processes (m_process_t)
85  */
86 void TRACE_msg_process_change_host(m_process_t process, m_host_t old_host,
87                                    m_host_t new_host)
88 {
89   char alias[200];
90   if (!(IS_TRACING_PROCESSES || IS_TRACING_VOLUME) || !IS_TRACED(process))
91     return;
92
93   //disabling presence in old_host (__TRACE_msg_process_not_present)
94   TRACE_process_alias_container(process, old_host, alias, 200);
95   if (IS_TRACING_PROCESSES)
96     pajePopState(MSG_get_clock(), "presence", alias);
97
98   TRACE_msg_process_location(process);
99   TRACE_msg_process_present(process);
100 }
101
102 void TRACE_msg_process_kill(m_process_t process)
103 {
104   char name[200];
105   if (!IS_TRACING_PROCESSES || !IS_TRACED(process))
106     return;
107
108   TRACE_process_container(process, name, 200);
109   pajeDestroyContainer(MSG_get_clock(), "process", name);
110 }
111
112 void TRACE_msg_process_suspend(m_process_t process)
113 {
114   char name[200];
115   if (!IS_TRACING_PROCESSES || !IS_TRACED(process))
116     return;
117
118   TRACE_process_container(process, name, 200);
119   pajeSetState(MSG_get_clock(), "process-state", name, "suspend");
120 }
121
122 void TRACE_msg_process_resume(m_process_t process)
123 {
124   char name[200];
125   if (!IS_TRACING_PROCESSES || !IS_TRACED(process))
126     return;
127
128   TRACE_process_container(process, name, 200);
129   pajeSetState(MSG_get_clock(), "process-state", name, "executing");
130 }
131
132 void TRACE_msg_process_sleep_in(m_process_t process)
133 {
134   char name[200];
135   if (!IS_TRACING_PROCESSES || !IS_TRACED(process))
136     return;
137
138   TRACE_process_container(process, name, 200);
139   pajeSetState(MSG_get_clock(), "process-state", name, "sleep");
140 }
141
142 void TRACE_msg_process_sleep_out(m_process_t process)
143 {
144   char name[200];
145   if (!IS_TRACING_PROCESSES || !IS_TRACED(process))
146     return;
147
148   TRACE_process_container(process, name, 200);
149   pajeSetState(MSG_get_clock(), "process-state", name, "executing");
150 }
151
152 void TRACE_msg_process_end(m_process_t process)
153 {
154   char name[200], alias[200];
155   m_host_t host = NULL;
156   if (!IS_TRACED(process))
157     return;
158
159   host = MSG_process_get_host(process);
160   TRACE_process_container(process, name, 200);
161   TRACE_process_alias_container(process, host, alias, 200);
162   if (IS_TRACING_PROCESSES)
163     pajeDestroyContainer(MSG_get_clock(), "process", name);
164   if (IS_TRACING_PROCESSES)
165     pajeDestroyContainer(MSG_get_clock(), "PROCESS", alias);
166 }
167
168 #endif