Dhruvaraj Subhashchandran | 858d1aa | 2021-10-27 03:26:06 -0500 | [diff] [blame] | 1 | #include "sbe_consts.hpp" |
| 2 | #include "sbe_dump_collector.hpp" |
| 3 | |
Dhruvaraj Subhashchandran | 62881c5 | 2021-09-20 20:25:51 -0500 | [diff] [blame] | 4 | #include <libphal.H> |
| 5 | |
Dhruvaraj Subhashchandran | 858d1aa | 2021-10-27 03:26:06 -0500 | [diff] [blame] | 6 | #include <CLI/App.hpp> |
| 7 | #include <CLI/Config.hpp> |
| 8 | #include <CLI/Formatter.hpp> |
| 9 | |
| 10 | #include <filesystem> |
| 11 | #include <iostream> |
| 12 | |
| 13 | int main(int argc, char** argv) |
| 14 | { |
| 15 | using namespace openpower::dump::sbe_chipop; |
| 16 | using std::filesystem::path; |
| 17 | using namespace openpower::dump::SBE; |
Dhruvaraj Subhashchandran | 62881c5 | 2021-09-20 20:25:51 -0500 | [diff] [blame] | 18 | using namespace openpower::phal::dump; |
Dhruvaraj Subhashchandran | 858d1aa | 2021-10-27 03:26:06 -0500 | [diff] [blame] | 19 | |
| 20 | CLI::App app{"Dump Collector Application", "dump-collect"}; |
| 21 | app.description( |
| 22 | "Collects dumps from the Self Boot Engine (SBE) based on " |
| 23 | "provided parameters.\nSupports different types of dumps and requires " |
| 24 | "specific options based on the dump type."); |
| 25 | |
| 26 | int type = 0; |
| 27 | uint32_t id; |
| 28 | std::string pathStr; |
| 29 | std::optional<uint64_t> failingUnit; |
| 30 | |
| 31 | app.add_option("--type, -t", type, "Type of the dump") |
| 32 | ->required() |
Patrick Williams | 540521e | 2024-08-16 15:20:03 -0400 | [diff] [blame^] | 33 | ->check(CLI::IsMember( |
| 34 | {SBE_DUMP_TYPE_HARDWARE, SBE_DUMP_TYPE_HOSTBOOT, SBE_DUMP_TYPE_SBE, |
| 35 | SBE_DUMP_TYPE_PERFORMANCE, SBE_DUMP_TYPE_MSBE})); |
Dhruvaraj Subhashchandran | 858d1aa | 2021-10-27 03:26:06 -0500 | [diff] [blame] | 36 | |
| 37 | app.add_option("--id, -i", id, "ID of the dump")->required(); |
| 38 | |
| 39 | app.add_option("--path, -p", pathStr, |
| 40 | "Path to store the collected dump files") |
| 41 | ->required(); |
| 42 | |
| 43 | app.add_option("--failingunit, -f", failingUnit, "ID of the failing unit"); |
| 44 | |
| 45 | try |
| 46 | { |
| 47 | CLI11_PARSE(app, argc, argv); |
| 48 | } |
| 49 | catch (const CLI::ParseError& e) |
| 50 | { |
| 51 | return app.exit(e); |
| 52 | } |
| 53 | |
Dhruvaraj Subhashchandran | 6f1be97 | 2024-04-01 00:42:38 -0500 | [diff] [blame] | 54 | if (((type == SBE_DUMP_TYPE_HARDWARE) || (type == SBE_DUMP_TYPE_SBE) || |
| 55 | (type == SBE_DUMP_TYPE_MSBE)) && |
Dhruvaraj Subhashchandran | 62881c5 | 2021-09-20 20:25:51 -0500 | [diff] [blame] | 56 | !failingUnit.has_value()) |
Dhruvaraj Subhashchandran | 858d1aa | 2021-10-27 03:26:06 -0500 | [diff] [blame] | 57 | { |
Dhruvaraj Subhashchandran | 62881c5 | 2021-09-20 20:25:51 -0500 | [diff] [blame] | 58 | std::cerr |
| 59 | << "Failing unit ID is required for Hardware and SBE type dumps\n"; |
Dhruvaraj Subhashchandran | 858d1aa | 2021-10-27 03:26:06 -0500 | [diff] [blame] | 60 | return EXIT_FAILURE; |
| 61 | } |
| 62 | |
| 63 | // Directory creation should happen here, after successful parsing |
| 64 | std::filesystem::path dirPath{pathStr}; |
| 65 | if (!std::filesystem::exists(dirPath)) |
| 66 | { |
| 67 | std::filesystem::create_directories(dirPath); |
| 68 | } |
| 69 | |
| 70 | SbeDumpCollector dumpCollector; |
| 71 | |
| 72 | auto failingUnitId = 0xFFFFFF; // Default or unspecified value |
| 73 | if (failingUnit.has_value()) |
| 74 | { |
| 75 | failingUnitId = failingUnit.value(); |
| 76 | } |
| 77 | |
| 78 | try |
| 79 | { |
Dhruvaraj Subhashchandran | 6f1be97 | 2024-04-01 00:42:38 -0500 | [diff] [blame] | 80 | if ((type == SBE_DUMP_TYPE_SBE) || (type == SBE_DUMP_TYPE_MSBE)) |
Dhruvaraj Subhashchandran | 62881c5 | 2021-09-20 20:25:51 -0500 | [diff] [blame] | 81 | { |
| 82 | collectSBEDump(id, failingUnitId, pathStr, type); |
| 83 | } |
| 84 | else |
| 85 | { |
| 86 | dumpCollector.collectDump(type, id, failingUnitId, pathStr); |
| 87 | } |
Dhruvaraj Subhashchandran | 858d1aa | 2021-10-27 03:26:06 -0500 | [diff] [blame] | 88 | } |
| 89 | catch (const std::exception& e) |
| 90 | { |
| 91 | std::cerr << "Failed to collect dump: " << e.what() << std::endl; |
| 92 | std::exit(EXIT_FAILURE); |
| 93 | } |
| 94 | |
| 95 | return 0; |
| 96 | } |