1 /* Copyright (c) 2010. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #include "instr/instr_private.h"
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_msg_process, instr, "MSG process");
14 * TRACE_msg_set_process_category: tracing interface function
16 void TRACE_msg_set_process_category(m_process_t process, const char *category, const char *color)
18 if (!TRACE_msg_process_is_enabled()) return;
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);
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;
37 //set process category
38 process->category = xbt_strdup(category);
39 DEBUG3("MSG process %p(%s), category %s", process, process->name, process->category);
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);
46 type = getVariableType(category, color, msg->type);
48 new_pajeSetVariable (SIMIX_get_clock(), msg, type, 1);
50 type = getType ("MSG_PROCESS_STATE");
51 new_pajeSetState (MSG_get_clock(), msg, type, "executing");
55 * Instrumentation functions to trace MSG processes (m_process_t)
57 void TRACE_msg_process_change_host(m_process_t process, m_host_t old_host, m_host_t new_host)
59 if (!(TRACE_msg_process_is_enabled() &&
60 process->category)) return;
62 static long long int counter = 0;
63 char key[INSTR_DEFAULT_STR_SIZE];
64 snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", counter++);
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);
71 //destroy existing container of this process
72 destroyContainer(getContainer(process->name));
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);
79 //set the state of this new container
80 type = getType ("MSG_PROCESS_STATE");
81 new_pajeSetState (MSG_get_clock(), msg, type, "executing");
84 msg = getContainer(process->name);
85 type = getType ("MSG_PROCESS_LINK");
86 new_pajeEndLink (MSG_get_clock(), getRootContainer(), type, msg, "M", key);
89 void TRACE_msg_process_kill(m_process_t process)
91 if (!(TRACE_msg_process_is_enabled() &&
92 process->category)) return;
94 //kill means that this process no longer exists, let's destroy it
95 destroyContainer (getContainer(process->name));
98 void TRACE_msg_process_suspend(m_process_t process)
100 if (!(TRACE_msg_process_is_enabled() &&
101 process->category)) return;
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");
108 void TRACE_msg_process_resume(m_process_t process)
110 if (!(TRACE_msg_process_is_enabled() &&
111 process->category)) return;
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);
118 void TRACE_msg_process_sleep_in(m_process_t process)
120 if (!(TRACE_msg_process_is_enabled() &&
121 process->category)) return;
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");
128 void TRACE_msg_process_sleep_out(m_process_t process)
130 if (!(TRACE_msg_process_is_enabled() &&
131 process->category)) return;
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);
138 void TRACE_msg_process_end(m_process_t process)
140 if (!(TRACE_msg_process_is_enabled() &&
141 process->category)) return;
143 //that's the end, let's destroy it
144 destroyContainer (getContainer(process->name));
147 #endif /* HAVE_TRACING */