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);
80 msg = getContainer(process->name);
81 type = getType ("MSG_PROCESS_LINK");
82 new_pajeEndLink (MSG_get_clock(), getRootContainer(), type, msg, "M", key);
85 void TRACE_msg_process_kill(m_process_t process)
87 if (!(TRACE_msg_process_is_enabled() &&
88 process->category)) return;
90 //kill means that this process no longer exists, let's destroy it
91 destroyContainer (getContainer(process->name));
94 void TRACE_msg_process_suspend(m_process_t process)
96 if (!(TRACE_msg_process_is_enabled() &&
97 process->category)) return;
99 container_t process_container = getContainer (process->name);
100 type_t type = getType ("MSG_PROCESS_STATE");
101 new_pajePushState (MSG_get_clock(), process_container, type, "suspend");
104 void TRACE_msg_process_resume(m_process_t process)
106 if (!(TRACE_msg_process_is_enabled() &&
107 process->category)) return;
109 container_t process_container = getContainer (process->name);
110 type_t type = getType ("MSG_PROCESS_STATE");
111 new_pajePopState (MSG_get_clock(), process_container, type);
114 void TRACE_msg_process_sleep_in(m_process_t process)
116 if (!(TRACE_msg_process_is_enabled() &&
117 process->category)) return;
119 container_t process_container = getContainer (process->name);
120 type_t type = getType ("MSG_PROCESS_STATE");
121 new_pajePushState (MSG_get_clock(), process_container, type, "sleep");
124 void TRACE_msg_process_sleep_out(m_process_t process)
126 if (!(TRACE_msg_process_is_enabled() &&
127 process->category)) return;
129 container_t process_container = getContainer (process->name);
130 type_t type = getType ("MSG_PROCESS_STATE");
131 new_pajePopState (MSG_get_clock(), process_container, type);
134 void TRACE_msg_process_end(m_process_t process)
136 if (!(TRACE_msg_process_is_enabled() &&
137 process->category)) return;
139 //that's the end, let's destroy it
140 destroyContainer (getContainer(process->name));
143 #endif /* HAVE_TRACING */