Dhruvaraj Subhashchandran | 93f0641 | 2024-06-02 05:16:51 -0500 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
Jayanth Othayoth | d31be2c | 2020-02-04 02:56:45 -0600 | [diff] [blame] | 3 | #include "dump_utils.hpp" |
| 4 | |
Dhruvaraj Subhashchandran | 3604710 | 2023-06-29 03:46:25 -0500 | [diff] [blame] | 5 | #include "dump_types.hpp" |
| 6 | |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 7 | #include <phosphor-logging/lg2.hpp> |
Jayanth Othayoth | d31be2c | 2020-02-04 02:56:45 -0600 | [diff] [blame] | 8 | |
Dhruvaraj Subhashchandran | 93f0641 | 2024-06-02 05:16:51 -0500 | [diff] [blame] | 9 | #include <ctime> |
| 10 | #include <filesystem> |
| 11 | #include <optional> |
| 12 | #include <regex> |
| 13 | #include <tuple> |
| 14 | |
Jayanth Othayoth | d31be2c | 2020-02-04 02:56:45 -0600 | [diff] [blame] | 15 | namespace phosphor |
| 16 | { |
| 17 | namespace dump |
| 18 | { |
| 19 | |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 20 | std::string getService(sdbusplus::bus_t& bus, const std::string& path, |
Jayanth Othayoth | d31be2c | 2020-02-04 02:56:45 -0600 | [diff] [blame] | 21 | const std::string& interface) |
| 22 | { |
| 23 | constexpr auto objectMapperName = "xyz.openbmc_project.ObjectMapper"; |
| 24 | constexpr auto objectMapperPath = "/xyz/openbmc_project/object_mapper"; |
Jayanth Othayoth | d31be2c | 2020-02-04 02:56:45 -0600 | [diff] [blame] | 25 | |
| 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 Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 40 | lg2::error( |
| 41 | "Error in mapper response for getting service name, PATH: " |
| 42 | "{PATH}, INTERFACE: {INTERFACE}", |
| 43 | "PATH", path, "INTERFACE", interface); |
Jayanth Othayoth | d31be2c | 2020-02-04 02:56:45 -0600 | [diff] [blame] | 44 | return std::string{}; |
| 45 | } |
| 46 | } |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 47 | catch (const sdbusplus::exception_t& e) |
Jayanth Othayoth | d31be2c | 2020-02-04 02:56:45 -0600 | [diff] [blame] | 48 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 49 | lg2::error("Error in mapper method call, errormsg: {ERROR}, " |
| 50 | "PATH: {PATH}, INTERFACE: {INTERFACE}", |
| 51 | "ERROR", e, "PATH", path, "INTERFACE", interface); |
Dhruvaraj Subhashchandran | 3a25e5b | 2022-03-22 08:06:20 -0500 | [diff] [blame] | 52 | throw; |
Jayanth Othayoth | d31be2c | 2020-02-04 02:56:45 -0600 | [diff] [blame] | 53 | } |
| 54 | return response[0].first; |
| 55 | } |
| 56 | |
Dhruvaraj Subhashchandran | 93f0641 | 2024-06-02 05:16:51 -0500 | [diff] [blame] | 57 | std::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 Othayoth | d31be2c | 2020-02-04 02:56:45 -0600 | [diff] [blame] | 81 | } // namespace dump |
| 82 | } // namespace phosphor |