Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'actor-yield' of github.com:Takishipp/simgrid into actor-yield
[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_pid(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     counter++;
25
26     //start link
27     container_t msg                = simgrid::instr::Container::byName(instr_pid(process));
28     simgrid::instr::LinkType* link = simgrid::instr::Container::getRoot()->getLink("MSG_PROCESS_LINK");
29     link->startEvent(msg, "M", 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_pid(process));
39     link->endEvent(msg, "M", key);
40   }
41 }
42
43 void TRACE_msg_process_create(std::string process_name, int process_pid, msg_host_t host)
44 {
45   if (TRACE_msg_process_is_enabled()){
46     container_t host_container = simgrid::instr::Container::byName(host->getName());
47     new simgrid::instr::Container(process_name + "-" + std::to_string(process_pid), "MSG_PROCESS", host_container);
48   }
49 }
50
51 void TRACE_msg_process_destroy(std::string process_name, int process_pid)
52 {
53   if (TRACE_msg_process_is_enabled()) {
54     container_t process = simgrid::instr::Container::byNameOrNull(process_name + "-" + std::to_string(process_pid));
55     if (process) {
56       process->removeFromParent();
57       delete process;
58     }
59   }
60 }
61
62 void TRACE_msg_process_kill(smx_process_exit_status_t status, msg_process_t process)
63 {
64   if (TRACE_msg_process_is_enabled() && status == SMX_EXIT_FAILURE) {
65     //kill means that this process no longer exists, let's destroy it
66     TRACE_msg_process_destroy(process->getCname(), process->getPid());
67   }
68 }
69
70 void TRACE_msg_process_suspend(msg_process_t process)
71 {
72   if (TRACE_msg_process_is_enabled())
73     simgrid::instr::Container::byName(instr_pid(process))->getState("MSG_PROCESS_STATE")->pushEvent("suspend");
74 }
75
76 void TRACE_msg_process_resume(msg_process_t process)
77 {
78   if (TRACE_msg_process_is_enabled())
79     simgrid::instr::Container::byName(instr_pid(process))->getState("MSG_PROCESS_STATE")->popEvent();
80 }
81
82 void TRACE_msg_process_sleep_in(msg_process_t process)
83 {
84   if (TRACE_msg_process_is_enabled())
85     simgrid::instr::Container::byName(instr_pid(process))->getState("MSG_PROCESS_STATE")->pushEvent("sleep");
86 }
87
88 void TRACE_msg_process_sleep_out(msg_process_t process)
89 {
90   if (TRACE_msg_process_is_enabled())
91     simgrid::instr::Container::byName(instr_pid(process))->getState("MSG_PROCESS_STATE")->popEvent();
92 }