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