Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c2307ca7c75b7251a7b90809156758773418088d
[simgrid.git] / src / msg / instr_msg_process.c
1 /* Copyright (c) 2010, 2012-2014. 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 "msg_private.h"
8 #include "simix/smx_process_private.h"
9
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_msg_process, instr, "MSG process");
11
12 char *instr_process_id (msg_process_t proc, char *str, int len)
13 {
14   return instr_process_id_2 (proc->name, proc->pid, str, len);//MSG_process_get_name(proc), MSG_process_get_PID(proc), str, len);
15 }
16
17 char *instr_process_id_2 (const char *process_name, int process_pid, char *str, int len)
18 {
19   snprintf (str, len, "%s-%d", process_name, process_pid);
20   return str;
21 }
22
23 /*
24  * Instrumentation functions to trace MSG processes (msg_process_t)
25  */
26 void TRACE_msg_process_change_host(msg_process_t process, msg_host_t old_host, msg_host_t new_host)
27 {
28   if (TRACE_msg_process_is_enabled()){
29     static long long int counter = 0;
30
31     char key[INSTR_DEFAULT_STR_SIZE];
32     snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", counter++);
33
34     int len = INSTR_DEFAULT_STR_SIZE;
35     char str[INSTR_DEFAULT_STR_SIZE];
36
37     //start link
38     container_t msg = PJ_container_get (instr_process_id(process, str, len));
39     type_t type = PJ_type_get ("MSG_PROCESS_LINK", PJ_type_get_root());
40     new_pajeStartLink (MSG_get_clock(), PJ_container_get_root(), type, msg, "M", key);
41
42     //destroy existing container of this process
43     TRACE_msg_process_destroy (MSG_process_get_name (process), MSG_process_get_PID (process), old_host);
44
45     //create new container on the new_host location
46     TRACE_msg_process_create (MSG_process_get_name (process), MSG_process_get_PID (process), new_host);
47
48     //end link
49     msg = PJ_container_get(instr_process_id(process, str, len));
50     type = PJ_type_get ("MSG_PROCESS_LINK", PJ_type_get_root());
51     new_pajeEndLink (MSG_get_clock(), PJ_container_get_root(), type, msg, "M", key);
52   }
53 }
54
55 void TRACE_msg_process_create (const char *process_name, int process_pid, msg_host_t host)
56 {
57   if (TRACE_msg_process_is_enabled()){
58     int len = INSTR_DEFAULT_STR_SIZE;
59     char str[INSTR_DEFAULT_STR_SIZE];
60
61     container_t host_container = PJ_container_get (SIMIX_host_get_name(host));
62     PJ_container_new(instr_process_id_2(process_name, process_pid, str, len), INSTR_MSG_PROCESS, host_container);
63   }
64 }
65
66 void TRACE_msg_process_destroy (const char *process_name, int process_pid, msg_host_t host)
67 {
68   int len = INSTR_DEFAULT_STR_SIZE;
69   char str[INSTR_DEFAULT_STR_SIZE];
70
71   container_t process = PJ_container_get (instr_process_id_2 (process_name, process_pid, str, len));
72   PJ_container_remove_from_parent (process);
73   PJ_container_free (process);
74 }
75
76 void TRACE_msg_process_kill(smx_process_exit_status_t status, msg_process_t process)
77 {
78   if (TRACE_msg_process_is_enabled() && status==SMX_EXIT_FAILURE){
79     //kill means that this process no longer exists, let's destroy it
80     TRACE_msg_process_destroy(MSG_process_get_name (process), MSG_process_get_PID (process), MSG_process_get_host (process));
81   }
82 }
83
84 void TRACE_msg_process_suspend(msg_process_t process)
85 {
86   if (TRACE_msg_process_is_enabled()){
87     int len = INSTR_DEFAULT_STR_SIZE;
88     char str[INSTR_DEFAULT_STR_SIZE];
89
90     container_t process_container = PJ_container_get (instr_process_id(process, str, len));
91     type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
92     val_t value = PJ_value_get ("suspend", type);
93     new_pajePushState (MSG_get_clock(), process_container, type, value);
94   }
95 }
96
97 void TRACE_msg_process_resume(msg_process_t process)
98 {
99   if (TRACE_msg_process_is_enabled()){
100     int len = INSTR_DEFAULT_STR_SIZE;
101     char str[INSTR_DEFAULT_STR_SIZE];
102
103     container_t process_container = PJ_container_get (instr_process_id(process, str, len));
104     type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
105     new_pajePopState (MSG_get_clock(), process_container, type);
106   }
107 }
108
109 void TRACE_msg_process_sleep_in(msg_process_t process)
110 {
111   if (TRACE_msg_process_is_enabled()){
112     int len = INSTR_DEFAULT_STR_SIZE;
113     char str[INSTR_DEFAULT_STR_SIZE];
114
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     val_t value = PJ_value_get ("sleep", type);
118     new_pajePushState (MSG_get_clock(), process_container, type, value);
119   }
120 }
121
122 void TRACE_msg_process_sleep_out(msg_process_t process)
123 {
124   if (TRACE_msg_process_is_enabled()){
125     int len = INSTR_DEFAULT_STR_SIZE;
126     char str[INSTR_DEFAULT_STR_SIZE];
127
128     container_t process_container = PJ_container_get (instr_process_id(process, str, len));
129     type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
130     new_pajePopState (MSG_get_clock(), process_container, type);
131   }
132 }
133
134 void TRACE_msg_process_end(msg_process_t process)
135 {
136   if (TRACE_msg_process_is_enabled()) {
137     int len = INSTR_DEFAULT_STR_SIZE;
138     char str[INSTR_DEFAULT_STR_SIZE];
139
140     //that's the end, let's destroy it
141     container_t container = PJ_container_get (instr_process_id(process, str, len));
142     PJ_container_remove_from_parent (container);
143     PJ_container_free (container);
144   }
145 }