Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Finish the removal of mc::api by moving the last bits to the side
[simgrid.git] / src / mc / mc_global.cpp
1 /* Copyright (c) 2008-2022. 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 "mc/mc.h"
7 #include "src/kernel/actor/ActorImpl.hpp"
8
9 #if SIMGRID_HAVE_MC
10 #include "src/mc/api/RemoteApp.hpp"
11 #include "src/mc/explo/Exploration.hpp"
12 #include "src/mc/inspect/mc_unw.hpp"
13 #include "src/mc/mc_config.hpp"
14 #include "src/mc/mc_private.hpp"
15 #include "src/mc/mc_safety.hpp"
16 #include "src/mc/remote/AppSide.hpp"
17 #include "src/mc/sosp/Snapshot.hpp"
18
19 #include <array>
20 #include <boost/core/demangle.hpp>
21 #include <cerrno>
22 #include <cstring>
23 #include <libunwind.h>
24 #endif
25
26 #ifndef _WIN32
27 #include <sys/time.h>
28 #include <sys/wait.h>
29 #include <unistd.h>
30 #endif
31
32 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_global, mc, "Logging specific to MC (global)");
33
34 namespace simgrid::mc {
35
36 std::vector<double> processes_time;
37
38 }
39
40 #if SIMGRID_HAVE_MC
41
42 namespace simgrid::mc {
43
44 /*******************************  Core of MC *******************************/
45 /**************************************************************************/
46 void dumpStack(FILE* file, unw_cursor_t* cursor)
47 {
48   int nframe = 0;
49   std::array<char, 100> buffer;
50
51   unw_word_t off;
52   do {
53     const char* name = not unw_get_proc_name(cursor, buffer.data(), buffer.size(), &off) ? buffer.data() : "?";
54     // Unmangle C++ names:
55     std::string realname = boost::core::demangle(name);
56
57 #if defined(__x86_64__)
58     unw_word_t rip = 0;
59     unw_word_t rsp = 0;
60     unw_get_reg(cursor, UNW_X86_64_RIP, &rip);
61     unw_get_reg(cursor, UNW_X86_64_RSP, &rsp);
62     fprintf(file, "  %i: %s (RIP=0x%" PRIx64 " RSP=0x%" PRIx64 ")\n", nframe, realname.c_str(), (std::uint64_t)rip,
63             (std::uint64_t)rsp);
64 #else
65     fprintf(file, "  %i: %s\n", nframe, realname.c_str());
66 #endif
67
68     ++nframe;
69   } while (unw_step(cursor));
70 }
71
72 } // namespace simgrid::mc
73 #endif
74
75 double MC_process_clock_get(const simgrid::kernel::actor::ActorImpl* process)
76 {
77   if (simgrid::mc::processes_time.empty())
78     return 0;
79   if (process == nullptr)
80     return -1;
81   return simgrid::mc::processes_time.at(process->get_pid());
82 }
83
84 void MC_process_clock_add(const simgrid::kernel::actor::ActorImpl* process, double amount)
85 {
86   simgrid::mc::processes_time.at(process->get_pid()) += amount;
87 }