Logo AND Algorithmique Numérique Distribuée

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