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 xbt_die("deprecated");
21 char *instr_process_id (m_process_t proc, char *str, int len)
23 return instr_process_id_2 (proc->name, proc->pid, str, len);//MSG_process_get_name(proc), MSG_process_get_PID(proc), str, len);
26 char *instr_process_id_2 (const char *process_name, int process_pid, char *str, int len)
28 snprintf (str, len, "%s-%d", process_name, process_pid);
33 * Instrumentation functions to trace MSG processes (m_process_t)
35 void TRACE_msg_process_change_host(m_process_t process, m_host_t old_host, m_host_t new_host)
37 if (TRACE_msg_process_is_enabled()){
38 static long long int counter = 0;
39 char key[INSTR_DEFAULT_STR_SIZE];
40 snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", counter++);
42 int len = INSTR_DEFAULT_STR_SIZE;
43 char str[INSTR_DEFAULT_STR_SIZE];
46 container_t msg = PJ_container_get (instr_process_id(process, str, len));
47 type_t type = PJ_type_get ("MSG_PROCESS_LINK", PJ_type_get_root());
48 new_pajeStartLink (MSG_get_clock(), PJ_container_get_root(), type, msg, "M", key);
50 //destroy existing container of this process
51 container_t existing_container = PJ_container_get(instr_process_id(process, str, len));
52 PJ_container_remove_from_parent (existing_container);
53 PJ_container_free(existing_container);
55 //create new container on the new_host location
56 msg = PJ_container_new(instr_process_id(process, str, len), INSTR_MSG_PROCESS, PJ_container_get(new_host->name));
58 //set the state of this new container
59 type = PJ_type_get ("MSG_PROCESS_STATE", msg->type);
60 val_t value = PJ_value_get ("executing", type);
61 new_pajeSetState (MSG_get_clock(), msg, type, value);
64 msg = PJ_container_get(instr_process_id(process, str, len));
65 type = PJ_type_get ("MSG_PROCESS_LINK", PJ_type_get_root());
66 new_pajeEndLink (MSG_get_clock(), PJ_container_get_root(), type, msg, "M", key);
70 void TRACE_msg_process_create (const char *process_name, int process_pid, m_host_t host)
72 if (TRACE_msg_process_is_enabled()){
73 int len = INSTR_DEFAULT_STR_SIZE;
74 char str[INSTR_DEFAULT_STR_SIZE];
76 container_t host_container = PJ_container_get (host->name);
77 container_t msg = PJ_container_new(instr_process_id_2(process_name, process_pid, str, len), INSTR_MSG_PROCESS, host_container);
79 type_t type = PJ_type_get ("MSG_PROCESS_STATE", msg->type);
80 val_t value = PJ_value_get ("executing", type);
81 new_pajeSetState (MSG_get_clock(), msg, type, value);
85 void TRACE_msg_process_kill(m_process_t process)
87 if (TRACE_msg_process_is_enabled()){
88 int len = INSTR_DEFAULT_STR_SIZE;
89 char str[INSTR_DEFAULT_STR_SIZE];
91 //kill means that this process no longer exists, let's destroy it
92 PJ_container_free (PJ_container_get (instr_process_id(process, str, len)));
96 void TRACE_msg_process_suspend(m_process_t process)
98 if (TRACE_msg_process_is_enabled()){
99 int len = INSTR_DEFAULT_STR_SIZE;
100 char str[INSTR_DEFAULT_STR_SIZE];
102 container_t process_container = PJ_container_get (instr_process_id(process, str, len));
103 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
104 val_t value = PJ_value_get ("suspend", type);
105 new_pajePushState (MSG_get_clock(), process_container, type, value);
109 void TRACE_msg_process_resume(m_process_t process)
111 if (TRACE_msg_process_is_enabled()){
112 int len = INSTR_DEFAULT_STR_SIZE;
113 char str[INSTR_DEFAULT_STR_SIZE];
115 container_t process_container = PJ_container_get (instr_process_id(process, str, len));
116 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
117 new_pajePopState (MSG_get_clock(), process_container, type);
121 void TRACE_msg_process_sleep_in(m_process_t process)
123 if (TRACE_msg_process_is_enabled()){
124 int len = INSTR_DEFAULT_STR_SIZE;
125 char str[INSTR_DEFAULT_STR_SIZE];
127 container_t process_container = PJ_container_get (instr_process_id(process, str, len));
128 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
129 val_t value = PJ_value_get ("sleep", type);
130 new_pajePushState (MSG_get_clock(), process_container, type, value);
134 void TRACE_msg_process_sleep_out(m_process_t process)
136 if (TRACE_msg_process_is_enabled()){
137 int len = INSTR_DEFAULT_STR_SIZE;
138 char str[INSTR_DEFAULT_STR_SIZE];
140 container_t process_container = PJ_container_get (instr_process_id(process, str, len));
141 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
142 new_pajePopState (MSG_get_clock(), process_container, type);
146 void TRACE_msg_process_end(m_process_t process)
148 if (TRACE_msg_process_is_enabled()) {
149 int len = INSTR_DEFAULT_STR_SIZE;
150 char str[INSTR_DEFAULT_STR_SIZE];
152 //that's the end, let's destroy it
153 container_t container = PJ_container_get (instr_process_id(process, str, len));
154 PJ_container_remove_from_parent (container);
155 PJ_container_free (container);
159 #endif /* HAVE_TRACING */