Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
f5f22138d4045d9dd1d82d18e8661c3fb20961fc
[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 = getVariableType(category, 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   static long long int counter = 0;
65   char key[INSTR_DEFAULT_STR_SIZE];
66   snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", counter++);
67
68   //start link
69   container_t msg = getContainer(process->name);
70   type_t type = getType ("MSG_PROCESS_LINK");
71   pajeStartLink (MSG_get_clock(), type->id, "0", "M", msg->id, key);
72
73   //destroy existing container of this process
74   destroyContainer(getContainer(process->name));
75
76   //create new container on the new_host location
77   msg = newContainer(process->name, INSTR_MSG_PROCESS, getContainer(new_host->name));
78   type = getType (process->category);
79   pajeSetVariable(SIMIX_get_clock(), type->id, msg->id, "1");
80
81   //end link
82   msg = getContainer(process->name);
83   type = getType ("MSG_PROCESS_LINK");
84   pajeEndLink (MSG_get_clock(), type->id, "0", "M", msg->id, key);
85 }
86
87 void TRACE_msg_process_kill(m_process_t process)
88 {
89   if (!(TRACE_is_enabled() &&
90       TRACE_msg_process_is_enabled() &&
91       process->category)) return;
92
93   //kill means that this process no longer exists, let's destroy it
94   destroyContainer (getContainer(process->name));
95 }
96
97 void TRACE_msg_process_suspend(m_process_t process)
98 {
99   if (!(TRACE_is_enabled() &&
100       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   pajePushState (MSG_get_clock(), type->id, process_container->id, "suspend");
106 }
107
108 void TRACE_msg_process_resume(m_process_t process)
109 {
110   if (!(TRACE_is_enabled() &&
111       TRACE_msg_process_is_enabled() &&
112       process->category)) return;
113
114   container_t process_container = getContainer (process->name);
115   type_t type = getType ("MSG_PROCESS_STATE");
116   pajePopState (MSG_get_clock(), type->id, process_container->id);
117 }
118
119 void TRACE_msg_process_sleep_in(m_process_t process)
120 {
121   if (!(TRACE_is_enabled() &&
122       TRACE_msg_process_is_enabled() &&
123       process->category)) return;
124
125   container_t process_container = getContainer (process->name);
126   type_t type = getType ("MSG_PROCESS_STATE");
127   pajePushState (MSG_get_clock(), type->id, process_container->id, "sleep");
128 }
129
130 void TRACE_msg_process_sleep_out(m_process_t process)
131 {
132   if (!(TRACE_is_enabled() &&
133       TRACE_msg_process_is_enabled() &&
134       process->category)) return;
135
136   container_t process_container = getContainer (process->name);
137   type_t type = getType ("MSG_PROCESS_STATE");
138   pajePopState (MSG_get_clock(), type->id, process_container->id);
139 }
140
141 void TRACE_msg_process_end(m_process_t process)
142 {
143   if (!(TRACE_is_enabled() &&
144       TRACE_msg_process_is_enabled() &&
145       process->category)) return;
146
147   //that's the end, let's destroy it
148   destroyContainer (getContainer(process->name));
149 }
150
151 #endif /* HAVE_TRACING */