Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] when a process migrates, we need to clean-up its container properly (includin...
[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 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_msg_process, instr, "MSG process");
12
13 /*
14  * TRACE_msg_set_process_category: tracing interface function
15  */
16 void TRACE_msg_set_process_category(m_process_t process, const char *category, const char *color)
17 {
18   xbt_die("deprecated");
19 }
20
21 char *instr_process_id (m_process_t proc, char *str, int len)
22 {
23   return instr_process_id_2 (MSG_process_get_name(proc), MSG_process_get_PID(proc), str, len);
24 }
25
26 char *instr_process_id_2 (const char *process_name, int process_pid, char *str, int len)
27 {
28   snprintf (str, len, "%s-%d", process_name, process_pid);
29   return str;
30 }
31
32 /*
33  * Instrumentation functions to trace MSG processes (m_process_t)
34  */
35 void TRACE_msg_process_change_host(m_process_t process, m_host_t old_host, m_host_t new_host)
36 {
37   if (TRACE_msg_process_is_enabled()){
38     static long long int counter = 0;
39     char key[INSTR_DEFAULT_STR_SIZE];
40     snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", counter++);
41
42     int len = INSTR_DEFAULT_STR_SIZE;
43     char str[INSTR_DEFAULT_STR_SIZE];
44
45     //start link
46     container_t msg = getContainer(instr_process_id(process, str, len));
47     type_t type = getType ("MSG_PROCESS_LINK", getRootType());
48     new_pajeStartLink (MSG_get_clock(), getRootContainer(), type, msg, "M", key);
49
50     //destroy existing container of this process
51     container_t existing_container = getContainer(instr_process_id(process, str, len));
52     removeContainerFromParent (existing_container);
53     destroyContainer(existing_container);
54
55     //create new container on the new_host location
56     msg = newContainer(instr_process_id(process, str, len), INSTR_MSG_PROCESS, getContainer(new_host->name));
57
58     //set the state of this new container
59     type = getType ("MSG_PROCESS_STATE", msg->type);
60     val_t value = getValueByName ("executing", type);
61     new_pajeSetState (MSG_get_clock(), msg, type, value);
62
63     //end link
64     msg = getContainer(instr_process_id(process, str, len));
65     type = getType ("MSG_PROCESS_LINK", getRootType());
66     new_pajeEndLink (MSG_get_clock(), getRootContainer(), type, msg, "M", key);
67   }
68 }
69
70 void TRACE_msg_process_create (const char *process_name, int process_pid, m_host_t host)
71 {
72   if (TRACE_msg_process_is_enabled()){
73     int len = INSTR_DEFAULT_STR_SIZE;
74     char str[INSTR_DEFAULT_STR_SIZE];
75
76     container_t host_container = getContainer(host->name);
77     container_t msg = newContainer(instr_process_id_2(process_name, process_pid, str, len), INSTR_MSG_PROCESS, host_container);
78
79     type_t type = getType ("MSG_PROCESS_STATE", msg->type);
80     val_t value = getValueByName ("executing", type);
81     new_pajeSetState (MSG_get_clock(), msg, type, value);
82   }
83 }
84
85 void TRACE_msg_process_kill(m_process_t process)
86 {
87   if (TRACE_msg_process_is_enabled()){
88     int len = INSTR_DEFAULT_STR_SIZE;
89     char str[INSTR_DEFAULT_STR_SIZE];
90
91     //kill means that this process no longer exists, let's destroy it
92     destroyContainer (getContainer(instr_process_id(process, str, len)));
93   }
94 }
95
96 void TRACE_msg_process_suspend(m_process_t process)
97 {
98   if (TRACE_msg_process_is_enabled()){
99     int len = INSTR_DEFAULT_STR_SIZE;
100     char str[INSTR_DEFAULT_STR_SIZE];
101
102     container_t process_container = getContainer (instr_process_id(process, str, len));
103     type_t type = getType ("MSG_PROCESS_STATE", process_container->type);
104     val_t value = getValueByName ("suspend", type);
105     new_pajePushState (MSG_get_clock(), process_container, type, value);
106   }
107 }
108
109 void TRACE_msg_process_resume(m_process_t process)
110 {
111   if (TRACE_msg_process_is_enabled()){
112     int len = INSTR_DEFAULT_STR_SIZE;
113     char str[INSTR_DEFAULT_STR_SIZE];
114
115     container_t process_container = getContainer (instr_process_id(process, str, len));
116     type_t type = getType ("MSG_PROCESS_STATE", process_container->type);
117     new_pajePopState (MSG_get_clock(), process_container, type);
118   }
119 }
120
121 void TRACE_msg_process_sleep_in(m_process_t process)
122 {
123   if (TRACE_msg_process_is_enabled()){
124     int len = INSTR_DEFAULT_STR_SIZE;
125     char str[INSTR_DEFAULT_STR_SIZE];
126
127     container_t process_container = getContainer (instr_process_id(process, str, len));
128     type_t type = getType ("MSG_PROCESS_STATE", process_container->type);
129     val_t value = getValueByName ("sleep", type);
130     new_pajePushState (MSG_get_clock(), process_container, type, value);
131   }
132 }
133
134 void TRACE_msg_process_sleep_out(m_process_t process)
135 {
136   if (TRACE_msg_process_is_enabled()){
137     int len = INSTR_DEFAULT_STR_SIZE;
138     char str[INSTR_DEFAULT_STR_SIZE];
139
140     container_t process_container = getContainer (instr_process_id(process, str, len));
141     type_t type = getType ("MSG_PROCESS_STATE", process_container->type);
142     new_pajePopState (MSG_get_clock(), process_container, type);
143   }
144 }
145
146 void TRACE_msg_process_end(m_process_t process)
147 {
148   if (TRACE_msg_process_is_enabled()) {
149     int len = INSTR_DEFAULT_STR_SIZE;
150     char str[INSTR_DEFAULT_STR_SIZE];
151
152     //that's the end, let's destroy it
153     container_t container = getContainer(instr_process_id(process, str, len));
154     removeContainerFromParent (container);
155     destroyContainer (container);
156   }
157 }
158
159 #endif /* HAVE_TRACING */