blob: c362ee642d56d822abb3ebe860c1624d589989d3 [file] [log] [blame]
Dhruvaraj Subhashchandran93f06412024-06-02 05:16:51 -05001#include "config.h"
2
Jayanth Othayothd31be2c2020-02-04 02:56:45 -06003#include "dump_utils.hpp"
4
Dhruvaraj Subhashchandran36047102023-06-29 03:46:25 -05005#include "dump_types.hpp"
6
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -05007#include <phosphor-logging/lg2.hpp>
Jayanth Othayothd31be2c2020-02-04 02:56:45 -06008
Dhruvaraj Subhashchandran93f06412024-06-02 05:16:51 -05009#include <ctime>
10#include <filesystem>
11#include <optional>
12#include <regex>
13#include <tuple>
14
Jayanth Othayothd31be2c2020-02-04 02:56:45 -060015namespace phosphor
16{
17namespace dump
18{
19
Patrick Williams9b18bf22022-07-22 19:26:55 -050020std::string getService(sdbusplus::bus_t& bus, const std::string& path,
Jayanth Othayothd31be2c2020-02-04 02:56:45 -060021 const std::string& interface)
22{
23 constexpr auto objectMapperName = "xyz.openbmc_project.ObjectMapper";
24 constexpr auto objectMapperPath = "/xyz/openbmc_project/object_mapper";
Jayanth Othayothd31be2c2020-02-04 02:56:45 -060025
26 auto method = bus.new_method_call(objectMapperName, objectMapperPath,
27 objectMapperName, "GetObject");
28
29 method.append(path);
30 method.append(std::vector<std::string>({interface}));
31
32 std::vector<std::pair<std::string, std::vector<std::string>>> response;
33
34 try
35 {
36 auto reply = bus.call(method);
37 reply.read(response);
38 if (response.empty())
39 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050040 lg2::error(
41 "Error in mapper response for getting service name, PATH: "
42 "{PATH}, INTERFACE: {INTERFACE}",
43 "PATH", path, "INTERFACE", interface);
Jayanth Othayothd31be2c2020-02-04 02:56:45 -060044 return std::string{};
45 }
46 }
Patrick Williams9b18bf22022-07-22 19:26:55 -050047 catch (const sdbusplus::exception_t& e)
Jayanth Othayothd31be2c2020-02-04 02:56:45 -060048 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050049 lg2::error("Error in mapper method call, errormsg: {ERROR}, "
50 "PATH: {PATH}, INTERFACE: {INTERFACE}",
51 "ERROR", e, "PATH", path, "INTERFACE", interface);
Dhruvaraj Subhashchandran3a25e5b2022-03-22 08:06:20 -050052 throw;
Jayanth Othayothd31be2c2020-02-04 02:56:45 -060053 }
54 return response[0].first;
55}
56
Dhruvaraj Subhashchandran93f06412024-06-02 05:16:51 -050057std::optional<std::tuple<uint32_t, uint64_t, uint64_t>>
58 extractDumpDetails(const std::filesystem::path& file)
59{
60 static constexpr auto ID_POS = 1;
61 static constexpr auto EPOCHTIME_POS = 2;
62 std::regex file_regex("obmcdump_([0-9]+)_([0-9]+).([a-zA-Z0-9]+)");
63
64 std::smatch match;
65 std::string name = file.filename().string();
66
67 if (!((std::regex_search(name, match, file_regex)) && (match.size() > 0)))
68 {
69 lg2::error("Invalid Dump file name, FILENAME: {FILENAME}", "FILENAME",
70 file);
71 return std::nullopt;
72 }
73
74 auto idString = match[ID_POS];
75 uint64_t timestamp = stoull(match[EPOCHTIME_POS]) * 1000 * 1000;
76
77 return std::make_tuple(stoul(idString), timestamp,
78 std::filesystem::file_size(file));
79}
80
Jayanth Othayothd31be2c2020-02-04 02:56:45 -060081} // namespace dump
82} // namespace phosphor