1 /* Copyright (c) 2010, 2012-2013. 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 "msg_private.h"
9 #include "msg/datatypes.h"
10 #include "simix/smx_process_private.h"
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_msg_process, instr, "MSG process");
16 char *instr_process_id (msg_process_t proc, char *str, int len)
18 return instr_process_id_2 (proc->name, proc->pid, str, len);//MSG_process_get_name(proc), MSG_process_get_PID(proc), str, len);
21 char *instr_process_id_2 (const char *process_name, int process_pid, char *str, int len)
23 snprintf (str, len, "%s-%d", process_name, process_pid);
28 * Instrumentation functions to trace MSG processes (msg_process_t)
30 void TRACE_msg_process_change_host(msg_process_t process, msg_host_t old_host, msg_host_t new_host)
32 if (TRACE_msg_process_is_enabled()){
33 static long long int counter = 0;
35 char key[INSTR_DEFAULT_STR_SIZE];
36 snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", counter++);
38 int len = INSTR_DEFAULT_STR_SIZE;
39 char str[INSTR_DEFAULT_STR_SIZE];
42 container_t msg = PJ_container_get (instr_process_id(process, str, len));
43 type_t type = PJ_type_get ("MSG_PROCESS_LINK", PJ_type_get_root());
44 new_pajeStartLink (MSG_get_clock(), PJ_container_get_root(), type, msg, "M", key);
46 //destroy existing container of this process
47 TRACE_msg_process_destroy (MSG_process_get_name (process), MSG_process_get_PID (process), old_host);
49 //create new container on the new_host location
50 TRACE_msg_process_create (MSG_process_get_name (process), MSG_process_get_PID (process), new_host);
53 msg = PJ_container_get(instr_process_id(process, str, len));
54 type = PJ_type_get ("MSG_PROCESS_LINK", PJ_type_get_root());
55 new_pajeEndLink (MSG_get_clock(), PJ_container_get_root(), type, msg, "M", key);
59 void TRACE_msg_process_create (const char *process_name, int process_pid, msg_host_t host)
61 if (TRACE_msg_process_is_enabled()){
62 int len = INSTR_DEFAULT_STR_SIZE;
63 char str[INSTR_DEFAULT_STR_SIZE];
65 container_t host_container = PJ_container_get (SIMIX_host_get_name(host));
66 PJ_container_new(instr_process_id_2(process_name, process_pid, str, len), INSTR_MSG_PROCESS, host_container);
70 void TRACE_msg_process_destroy (const char *process_name, int process_pid, msg_host_t host)
72 int len = INSTR_DEFAULT_STR_SIZE;
73 char str[INSTR_DEFAULT_STR_SIZE];
75 container_t process = PJ_container_get (instr_process_id_2 (process_name, process_pid, str, len));
76 PJ_container_remove_from_parent (process);
77 PJ_container_free (process);
80 void TRACE_msg_process_kill(msg_process_t process)
82 if (TRACE_msg_process_is_enabled()){
83 //kill means that this process no longer exists, let's destroy it
84 TRACE_msg_process_destroy (MSG_process_get_name (process), MSG_process_get_PID (process), MSG_process_get_host (process));
88 void TRACE_msg_process_suspend(msg_process_t process)
90 if (TRACE_msg_process_is_enabled()){
91 int len = INSTR_DEFAULT_STR_SIZE;
92 char str[INSTR_DEFAULT_STR_SIZE];
94 container_t process_container = PJ_container_get (instr_process_id(process, str, len));
95 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
96 val_t value = PJ_value_get ("suspend", type);
97 new_pajePushState (MSG_get_clock(), process_container, type, value);
101 void TRACE_msg_process_resume(msg_process_t process)
103 if (TRACE_msg_process_is_enabled()){
104 int len = INSTR_DEFAULT_STR_SIZE;
105 char str[INSTR_DEFAULT_STR_SIZE];
107 container_t process_container = PJ_container_get (instr_process_id(process, str, len));
108 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
109 new_pajePopState (MSG_get_clock(), process_container, type);
113 void TRACE_msg_process_sleep_in(msg_process_t process)
115 if (TRACE_msg_process_is_enabled()){
116 int len = INSTR_DEFAULT_STR_SIZE;
117 char str[INSTR_DEFAULT_STR_SIZE];
119 container_t process_container = PJ_container_get (instr_process_id(process, str, len));
120 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
121 val_t value = PJ_value_get ("sleep", type);
122 new_pajePushState (MSG_get_clock(), process_container, type, value);
126 void TRACE_msg_process_sleep_out(msg_process_t process)
128 if (TRACE_msg_process_is_enabled()){
129 int len = INSTR_DEFAULT_STR_SIZE;
130 char str[INSTR_DEFAULT_STR_SIZE];
132 container_t process_container = PJ_container_get (instr_process_id(process, str, len));
133 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
134 new_pajePopState (MSG_get_clock(), process_container, type);
138 void TRACE_msg_process_end(msg_process_t process)
140 if (TRACE_msg_process_is_enabled()) {
141 int len = INSTR_DEFAULT_STR_SIZE;
142 char str[INSTR_DEFAULT_STR_SIZE];
144 //that's the end, let's destroy it
145 container_t container = PJ_container_get (instr_process_id(process, str, len));
146 PJ_container_remove_from_parent (container);
147 PJ_container_free (container);
151 #endif /* HAVE_TRACING */