Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
5e621ae13a9e76f2095e2d543c62b7b69aba7a89
[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 std::string instr_process_id(msg_process_t proc)
14 {
15   return std::string(proc->getCname()) + "-" + std::to_string(proc->getPid());
16 }
17
18 void TRACE_msg_process_change_host(msg_process_t process, msg_host_t new_host)
19 {
20   if (TRACE_msg_process_is_enabled()){
21     static long long int counter = 0;
22
23     std::string key = std::to_string(counter++);
24
25     //start link
26     container_t msg            = simgrid::instr::Container::byName(instr_process_id(process));
27     simgrid::instr::Type* type = simgrid::instr::Type::getRootType()->byName("MSG_PROCESS_LINK");
28     new simgrid::instr::StartLinkEvent(MSG_get_clock(), simgrid::instr::Container::getRootContainer(), type, msg, "M",
29                                        key);
30
31     //destroy existing container of this process
32     TRACE_msg_process_destroy (MSG_process_get_name (process), MSG_process_get_PID (process));
33
34     //create new container on the new_host location
35     TRACE_msg_process_create (MSG_process_get_name (process), MSG_process_get_PID (process), new_host);
36
37     //end link
38     msg  = simgrid::instr::Container::byName(instr_process_id(process));
39     type = simgrid::instr::Type::getRootType()->byName("MSG_PROCESS_LINK");
40     new simgrid::instr::EndLinkEvent(MSG_get_clock(), simgrid::instr::Container::getRootContainer(), type, msg, "M",
41                                      key);
42   }
43 }
44
45 void TRACE_msg_process_create (const char *process_name, int process_pid, msg_host_t host)
46 {
47   if (TRACE_msg_process_is_enabled()){
48     container_t host_container = simgrid::instr::Container::byName(host->getName());
49     new simgrid::instr::Container(std::string(process_name) + "-" + std::to_string(process_pid), "MSG_PROCESS",
50                                   host_container);
51   }
52 }
53
54 void TRACE_msg_process_destroy (const char *process_name, int process_pid)
55 {
56   if (TRACE_msg_process_is_enabled()) {
57     container_t process =
58         simgrid::instr::Container::byNameOrNull(std::string(process_name) + "-" + std::to_string(process_pid));
59     if (process) {
60       process->removeFromParent();
61       delete process;
62     }
63   }
64 }
65
66 void TRACE_msg_process_kill(smx_process_exit_status_t status, msg_process_t process)
67 {
68   if (TRACE_msg_process_is_enabled() && status == SMX_EXIT_FAILURE) {
69     //kill means that this process no longer exists, let's destroy it
70     TRACE_msg_process_destroy(process->getCname(), process->getPid());
71   }
72 }
73
74 void TRACE_msg_process_suspend(msg_process_t process)
75 {
76   if (TRACE_msg_process_is_enabled()){
77     container_t process_container = simgrid::instr::Container::byName(instr_process_id(process));
78     simgrid::instr::StateType* state =
79         static_cast<simgrid::instr::StateType*>(process_container->type_->byName("MSG_PROCESS_STATE"));
80     simgrid::instr::EntityValue* val = state->getEntityValue("suspend");
81     new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, state, val);
82   }
83 }
84
85 void TRACE_msg_process_resume(msg_process_t process)
86 {
87   if (TRACE_msg_process_is_enabled()){
88     container_t process_container = simgrid::instr::Container::byName(instr_process_id(process));
89     simgrid::instr::Type* type    = process_container->type_->byName("MSG_PROCESS_STATE");
90     new simgrid::instr::PopStateEvent(MSG_get_clock(), process_container, type);
91   }
92 }
93
94 void TRACE_msg_process_sleep_in(msg_process_t process)
95 {
96   if (TRACE_msg_process_is_enabled()){
97     container_t process_container = simgrid::instr::Container::byName(instr_process_id(process));
98     simgrid::instr::StateType* state =
99         static_cast<simgrid::instr::StateType*>(process_container->type_->byName("MSG_PROCESS_STATE"));
100     simgrid::instr::EntityValue* val = state->getEntityValue("sleep");
101     new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, state, val);
102   }
103 }
104
105 void TRACE_msg_process_sleep_out(msg_process_t process)
106 {
107   if (TRACE_msg_process_is_enabled()){
108     container_t process_container = simgrid::instr::Container::byName(instr_process_id(process));
109     simgrid::instr::Type* type    = process_container->type_->byName("MSG_PROCESS_STATE");
110     new simgrid::instr::PopStateEvent(MSG_get_clock(), process_container, type);
111   }
112 }