xref: /openbmc/phosphor-debug-collector/dump-extensions/openpower-dumps/dump_manager_system.cpp (revision 8b9b4690a4460ada5bf60a285ff6065eda6d5d4a)
1 #include "config.h"
2 
3 #include "dump_manager_system.hpp"
4 
5 #include "system_dump_entry.hpp"
6 
7 #include <phosphor-logging/elog.hpp>
8 
9 namespace phosphor
10 {
11 namespace dump
12 {
13 namespace system
14 {
15 
16 using namespace phosphor::logging;
17 
18 void Manager::notify(NewDump::DumpType dumpType, uint32_t dumpId, uint64_t size)
19 {
20 
21     if (dumpType != NewDump::DumpType::System)
22     {
23         log<level::ERR>("Only system dump is supported",
24                         entry("DUMPTYPE=%d", dumpType));
25         return;
26     }
27     // Get the timestamp
28     auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(
29                   std::chrono::system_clock::now().time_since_epoch())
30                   .count();
31     // Get the id
32     auto id = lastEntryId + 1;
33     auto idString = std::to_string(id);
34     auto objPath = fs::path(baseEntryPath) / idString;
35     entries.insert(std::make_pair(
36         id, std::make_unique<system::Entry>(bus, objPath.c_str(), id, ms, size,
37                                             dumpId, *this)));
38     lastEntryId++;
39 }
40 
41 uint32_t Manager::createDump()
42 {
43     constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1";
44     constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1";
45     constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager";
46     constexpr auto DIAG_MOD_TARGET = "obmc-host-diagnostic-mode@0.target";
47     auto b = sdbusplus::bus::new_default();
48     auto method = bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH,
49                                       SYSTEMD_INTERFACE, "StartUnit");
50     method.append(DIAG_MOD_TARGET); // unit to activate
51     method.append("replace");
52     bus.call_noreply(method);
53     return ++lastEntryId;
54 }
55 
56 } // namespace system
57 } // namespace dump
58 } // namespace phosphor
59