blob: 21808ff30d851f29cf0b940826b26ed31e063ffd [file] [log] [blame] [edit]
#include "include/common_utility.hpp"
#include "include/power_rail/power_rail_utility.hpp"
#include "include/voltage_regulator/voltage_regulator_utility.hpp"
#include <CLI/CLI.hpp>
constexpr std::string_view kPowerRailLogType = "power_rail";
constexpr std::string_view kVoltageRegulatorLogType = "voltage_regulator";
namespace
{
void handlePowerRail(const std::filesystem::path& cfgDirPath,
const std::filesystem::path& logDirPath,
std::string_view specifiedName)
{
fs::path priorityDirPath = cfgDirPath / "priority";
fs::path registerMapDirPath = cfgDirPath / "register_map";
if (!fs::exists(priorityDirPath) || !fs::exists(registerMapDirPath))
{
lg2::error(
"Required directories 'priority' or 'register_map' not found under {PATH}",
"PATH", cfgDirPath);
return;
}
fs::create_directories(logDirPath);
if (!powerfault::logRailState(priorityDirPath, registerMapDirPath,
logDirPath, specifiedName))
{
lg2::error("Logging rail state failed for {PATH}", "PATH", cfgDirPath);
}
}
void handleVoltageRegulator(const std::filesystem::path& cfgDirPath,
const std::filesystem::path& logDirPath,
std::string_view specifiedName)
{
fs::create_directories(logDirPath);
std::vector<fs::path> cfgFiles = util::findFiles(cfgDirPath, ".json");
for (const auto& cfgFile : cfgFiles)
{
if (!vrlog::logSensorState(cfgFile, logDirPath, specifiedName))
{
lg2::error("Logging sensor state failed for {PATH}", "PATH",
cfgFile);
}
}
}
} // namespace
int main(int argc, char* argv[])
{
CLI::App app{"Dump and Parse Logs (power_rail or voltage_regulator)"};
fs::path cfgDirPath;
fs::path logDirPath = "/mnt/luks-mmcblk0_fs/power-fault-logs/";
#ifdef DEFAULT_LOG_DIR_PATH
logDirPath = fs::path(DEFAULT_LOG_DIR_PATH);
#endif
std::string_view specifiedName;
std::string_view logType;
app.add_option("-c,--config", cfgDirPath, "config directory path")
->required()
->check(CLI::ExistingDirectory);
app.add_option("-l,--log", logDirPath, "log directory path");
app.add_option("-n,--name", specifiedName, "specified name");
app.add_option("-t,--type", logType,
"type of log (power_rail or voltage_regulator)")
->required();
try
{
app.parse(argc, argv);
}
catch (const CLI::Error& e)
{
return app.exit(e);
}
if (logType == kPowerRailLogType)
{
handlePowerRail(cfgDirPath, logDirPath, specifiedName);
}
else if (logType == kVoltageRegulatorLogType)
{
handleVoltageRegulator(cfgDirPath, logDirPath, specifiedName);
}
else
{
lg2::error("Type must be either 'power_rail' or 'voltage_regulator'");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}