Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fbffce2e036430a517455ad32bd79e56e557bd87
[simgrid.git] / src / msg / instr_msg_process.cpp
1 /* Copyright (c) 2010, 2012-2017. The SimGrid Team. All rights reserved.    */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "simgrid/s4u/Host.hpp"
7 #include "src/instr/instr_private.hpp"
8 #include "src/msg/msg_private.hpp"
9 #include "src/simix/ActorImpl.hpp"
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_msg_process, instr, "MSG process");
12
13 char *instr_process_id (msg_process_t proc, char *str, int len)
14 {
15   return instr_process_id_2(proc->getCname(), proc->getPid(), 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 (msg_process_t)
26  */
27 void TRACE_msg_process_change_host(msg_process_t process, msg_host_t new_host)
28 {
29   if (TRACE_msg_process_is_enabled()){
30     static long long int counter = 0;
31
32     char key[INSTR_DEFAULT_STR_SIZE];
33     snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", counter++);
34
35     int len = INSTR_DEFAULT_STR_SIZE;
36     char str[INSTR_DEFAULT_STR_SIZE];
37
38     //start link
39     container_t msg            = simgrid::instr::Container::byName(instr_process_id(process, str, len));
40     simgrid::instr::Type* type = simgrid::instr::Type::getRootType()->byName("MSG_PROCESS_LINK");
41     new simgrid::instr::StartLinkEvent(MSG_get_clock(), PJ_container_get_root(), type, msg, "M", key);
42
43     //destroy existing container of this process
44     TRACE_msg_process_destroy (MSG_process_get_name (process), MSG_process_get_PID (process));
45
46     //create new container on the new_host location
47     TRACE_msg_process_create (MSG_process_get_name (process), MSG_process_get_PID (process), new_host);
48
49     //end link
50     msg  = simgrid::instr::Container::byName(instr_process_id(process, str, len));
51     type = simgrid::instr::Type::getRootType()->byName("MSG_PROCESS_LINK");
52     new simgrid::instr::EndLinkEvent(MSG_get_clock(), PJ_container_get_root(), type, msg, "M", key);
53   }
54 }
55
56 void TRACE_msg_process_create (const char *process_name, int process_pid, msg_host_t host)
57 {
58   if (TRACE_msg_process_is_enabled()){
59     int len = INSTR_DEFAULT_STR_SIZE;
60     char str[INSTR_DEFAULT_STR_SIZE];
61
62     container_t host_container = simgrid::instr::Container::byName(host->getName());
63     new simgrid::instr::Container(instr_process_id_2(process_name, process_pid, str, len),
64                                   simgrid::instr::INSTR_MSG_PROCESS, host_container);
65   }
66 }
67
68 void TRACE_msg_process_destroy (const char *process_name, int process_pid)
69 {
70   if (TRACE_msg_process_is_enabled()) {
71     int len = INSTR_DEFAULT_STR_SIZE;
72     char str[INSTR_DEFAULT_STR_SIZE];
73
74     container_t process =
75         simgrid::instr::Container::byNameOrNull(instr_process_id_2(process_name, process_pid, str, len));
76     if (process) {
77       process->removeFromParent();
78       delete process;
79     }
80   }
81 }
82
83 void TRACE_msg_process_kill(smx_process_exit_status_t status, msg_process_t process)
84 {
85   if (TRACE_msg_process_is_enabled() && status==SMX_EXIT_FAILURE){
86     //kill means that this process no longer exists, let's destroy it
87     TRACE_msg_process_destroy(process->getCname(), process->getPid());
88   }
89 }
90
91 void TRACE_msg_process_suspend(msg_process_t process)
92 {
93   if (TRACE_msg_process_is_enabled()){
94     int len = INSTR_DEFAULT_STR_SIZE;
95     char str[INSTR_DEFAULT_STR_SIZE];
96
97     container_t process_container = simgrid::instr::Container::byName(instr_process_id(process, str, len));
98     simgrid::instr::Type* state   = process_container->type_->byName("MSG_PROCESS_STATE");
99     simgrid::instr::Value* val    = state->getEntityValue("suspend");
100     new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, state, val);
101   }
102 }
103
104 void TRACE_msg_process_resume(msg_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 = simgrid::instr::Container::byName(instr_process_id(process, str, len));
111     simgrid::instr::Type* type    = process_container->type_->byName("MSG_PROCESS_STATE");
112     new simgrid::instr::PopStateEvent(MSG_get_clock(), process_container, type);
113   }
114 }
115
116 void TRACE_msg_process_sleep_in(msg_process_t process)
117 {
118   if (TRACE_msg_process_is_enabled()){
119     int len = INSTR_DEFAULT_STR_SIZE;
120     char str[INSTR_DEFAULT_STR_SIZE];
121
122     container_t process_container = simgrid::instr::Container::byName(instr_process_id(process, str, len));
123     simgrid::instr::Type* state   = process_container->type_->byName("MSG_PROCESS_STATE");
124     simgrid::instr::Value* val    = state->getEntityValue("sleep");
125     new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, state, val);
126   }
127 }
128
129 void TRACE_msg_process_sleep_out(msg_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     container_t process_container = simgrid::instr::Container::byName(instr_process_id(process, str, len));
136     simgrid::instr::Type* type    = process_container->type_->byName("MSG_PROCESS_STATE");
137     new simgrid::instr::PopStateEvent(MSG_get_clock(), process_container, type);
138   }
139 }