Logo AND Algorithmique Numérique Distribuée

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