Logo AND Algorithmique Numérique Distribuée

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