Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] setting the process state to "executing" after migration
[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   if (!TRACE_msg_process_is_enabled()) return;
19
20   xbt_assert3(process->category == NULL,
21       "Process %p(%s) already has a category (%s).",
22       process, process->name, process->category);
23   xbt_assert2(process->name != NULL,
24       "Process %p(%s) must have a unique name in order to be traced.",
25       process, process->name);
26   xbt_assert3(getContainer(process->name)==NULL,
27       "Process %p(%s). Tracing already knows a process with name %s."
28       "The name of each process must be unique.", process, process->name, process->name);
29
30   if (category == NULL) {
31     //if user provides a NULL category, process is no longer traced
32     xbt_free (process->category);
33     process->category = NULL;
34     return;
35   }
36
37   //set process category
38   process->category = xbt_strdup(category);
39   DEBUG3("MSG process %p(%s), category %s", process, process->name, process->category);
40
41   m_host_t host = MSG_process_get_host(process);
42   container_t host_container = getContainer(host->name);
43   container_t msg = newContainer(process->name, INSTR_MSG_PROCESS, host_container);
44   type_t type = getType (category);
45   if (!type){
46     type = getVariableType(category, color, msg->type);
47   }
48   new_pajeSetVariable (SIMIX_get_clock(), msg, type, 1);
49
50   type = getType ("MSG_PROCESS_STATE");
51   new_pajeSetState (MSG_get_clock(), msg, type, "executing");
52 }
53
54 /*
55  * Instrumentation functions to trace MSG processes (m_process_t)
56  */
57 void TRACE_msg_process_change_host(m_process_t process, m_host_t old_host, m_host_t new_host)
58 {
59   if (!(TRACE_msg_process_is_enabled() &&
60         process->category)) return;
61
62   static long long int counter = 0;
63   char key[INSTR_DEFAULT_STR_SIZE];
64   snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", counter++);
65
66   //start link
67   container_t msg = getContainer(process->name);
68   type_t type = getType ("MSG_PROCESS_LINK");
69   new_pajeStartLink (MSG_get_clock(), getRootContainer(), type, msg, "M", key);
70
71   //destroy existing container of this process
72   destroyContainer(getContainer(process->name));
73
74   //create new container on the new_host location
75   msg = newContainer(process->name, INSTR_MSG_PROCESS, getContainer(new_host->name));
76   type = getType (process->category);
77   new_pajeSetVariable (MSG_get_clock(), msg, type, 1);
78
79   //set the state of this new container
80   type = getType ("MSG_PROCESS_STATE");
81   new_pajeSetState (MSG_get_clock(), msg, type, "executing");
82
83   //end link
84   msg = getContainer(process->name);
85   type = getType ("MSG_PROCESS_LINK");
86   new_pajeEndLink (MSG_get_clock(), getRootContainer(), type, msg, "M", key);
87 }
88
89 void TRACE_msg_process_kill(m_process_t process)
90 {
91   if (!(TRACE_msg_process_is_enabled() &&
92         process->category)) return;
93
94   //kill means that this process no longer exists, let's destroy it
95   destroyContainer (getContainer(process->name));
96 }
97
98 void TRACE_msg_process_suspend(m_process_t process)
99 {
100   if (!(TRACE_msg_process_is_enabled() &&
101       process->category)) return;
102
103   container_t process_container = getContainer (process->name);
104   type_t type = getType ("MSG_PROCESS_STATE");
105   new_pajePushState (MSG_get_clock(), process_container, type, "suspend");
106 }
107
108 void TRACE_msg_process_resume(m_process_t process)
109 {
110   if (!(TRACE_msg_process_is_enabled() &&
111         process->category)) return;
112
113   container_t process_container = getContainer (process->name);
114   type_t type = getType ("MSG_PROCESS_STATE");
115   new_pajePopState (MSG_get_clock(), process_container, type);
116 }
117
118 void TRACE_msg_process_sleep_in(m_process_t process)
119 {
120   if (!(TRACE_msg_process_is_enabled() &&
121         process->category)) return;
122
123   container_t process_container = getContainer (process->name);
124   type_t type = getType ("MSG_PROCESS_STATE");
125   new_pajePushState (MSG_get_clock(), process_container, type, "sleep");
126 }
127
128 void TRACE_msg_process_sleep_out(m_process_t process)
129 {
130   if (!(TRACE_msg_process_is_enabled() &&
131         process->category)) return;
132
133   container_t process_container = getContainer (process->name);
134   type_t type = getType ("MSG_PROCESS_STATE");
135   new_pajePopState (MSG_get_clock(), process_container, type);
136 }
137
138 void TRACE_msg_process_end(m_process_t process)
139 {
140   if (!(TRACE_msg_process_is_enabled() &&
141         process->category)) return;
142
143   //that's the end, let's destroy it
144   destroyContainer (getContainer(process->name));
145 }
146
147 #endif /* HAVE_TRACING */