Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fc96c0cd8674ec599c1c25e38a174ee34737fdf2
[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
9 #ifdef HAVE_TRACING
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_msg_process, instr, "MSG process");
12
13 char *instr_process_id (m_process_t proc, char *str, int len)
14 {
15   return instr_process_id_2 (proc->name, proc->pid, str, len);//MSG_process_get_name(proc), MSG_process_get_PID(proc), str, len);
16 }
17
18 char *instr_process_id_2 (const char *process_name, int process_pid, char *str, int len)
19 {
20   snprintf (str, len, "%s-%d", process_name, process_pid);
21   return str;
22 }
23
24 /*
25  * Instrumentation functions to trace MSG processes (m_process_t)
26  */
27 void TRACE_msg_process_change_host(m_process_t process, m_host_t old_host, m_host_t new_host)
28 {
29   if (TRACE_msg_process_is_enabled()){
30     static long long int counter = 0;
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     container_t existing_container = PJ_container_get(instr_process_id(process, str, len));
44     PJ_container_remove_from_parent (existing_container);
45     PJ_container_free(existing_container);
46
47     //create new container on the new_host location
48     msg = PJ_container_new(instr_process_id(process, str, len), INSTR_MSG_PROCESS, PJ_container_get(new_host->name));
49
50     //end link
51     msg = PJ_container_get(instr_process_id(process, str, len));
52     type = PJ_type_get ("MSG_PROCESS_LINK", PJ_type_get_root());
53     new_pajeEndLink (MSG_get_clock(), PJ_container_get_root(), type, msg, "M", key);
54   }
55 }
56
57 void TRACE_msg_process_create (const char *process_name, int process_pid, m_host_t host)
58 {
59   if (TRACE_msg_process_is_enabled()){
60     int len = INSTR_DEFAULT_STR_SIZE;
61     char str[INSTR_DEFAULT_STR_SIZE];
62
63     container_t host_container = PJ_container_get (host->name);
64     PJ_container_new(instr_process_id_2(process_name, process_pid, str, len), INSTR_MSG_PROCESS, host_container);
65   }
66 }
67
68 void TRACE_msg_process_kill(m_process_t process)
69 {
70   if (TRACE_msg_process_is_enabled()){
71     int len = INSTR_DEFAULT_STR_SIZE;
72     char str[INSTR_DEFAULT_STR_SIZE];
73
74     //kill means that this process no longer exists, let's destroy it
75     PJ_container_free (PJ_container_get (instr_process_id(process, str, len)));
76   }
77 }
78
79 void TRACE_msg_process_suspend(m_process_t process)
80 {
81   if (TRACE_msg_process_is_enabled()){
82     int len = INSTR_DEFAULT_STR_SIZE;
83     char str[INSTR_DEFAULT_STR_SIZE];
84
85     container_t process_container = PJ_container_get (instr_process_id(process, str, len));
86     type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
87     val_t value = PJ_value_get ("suspend", type);
88     new_pajePushState (MSG_get_clock(), process_container, type, value);
89   }
90 }
91
92 void TRACE_msg_process_resume(m_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     new_pajePopState (MSG_get_clock(), process_container, type);
101   }
102 }
103
104 void TRACE_msg_process_sleep_in(m_process_t process)
105 {
106   if (TRACE_msg_process_is_enabled()){
107     int len = INSTR_DEFAULT_STR_SIZE;
108     char str[INSTR_DEFAULT_STR_SIZE];
109
110     container_t process_container = PJ_container_get (instr_process_id(process, str, len));
111     type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
112     val_t value = PJ_value_get ("sleep", type);
113     new_pajePushState (MSG_get_clock(), process_container, type, value);
114   }
115 }
116
117 void TRACE_msg_process_sleep_out(m_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     new_pajePopState (MSG_get_clock(), process_container, type);
126   }
127 }
128
129 void TRACE_msg_process_end(m_process_t process)
130 {
131   if (TRACE_msg_process_is_enabled()) {
132     int len = INSTR_DEFAULT_STR_SIZE;
133     char str[INSTR_DEFAULT_STR_SIZE];
134
135     //that's the end, let's destroy it
136     container_t container = PJ_container_get (instr_process_id(process, str, len));
137     PJ_container_remove_from_parent (container);
138     PJ_container_free (container);
139   }
140 }
141
142 #endif /* HAVE_TRACING */