diff options
author | Jayanth Othayoth <ojayanth@in.ibm.com> | 2017-07-13 03:33:34 -0500 |
---|---|---|
committer | Jayanth Othayoth <ojayanth@in.ibm.com> | 2017-07-27 21:08:25 -0500 |
commit | 481bb3d424d17dd6416041c47afd0bc804f9daf4 (patch) | |
tree | a8d41d5951ce8b64a067e0f74430cc286ccfb65d /dump_manager.cpp | |
parent | d3273ead359a036c2d86a06fe7e3a72dc978d46d (diff) | |
download | phosphor-debug-collector-481bb3d424d17dd6416041c47afd0bc804f9daf4.tar.gz phosphor-debug-collector-481bb3d424d17dd6416041c47afd0bc804f9daf4.zip |
Dump entries properties update based on Dump file name
Added support to get id and epochtime from filename.
Change-Id: I57064fc69c8fe67380d76bb4bdd71d3a1316179c
Signed-off-by: Jayanth Othayoth <ojayanth@in.ibm.com>
Diffstat (limited to 'dump_manager.cpp')
-rw-r--r-- | dump_manager.cpp | 65 |
1 files changed, 42 insertions, 23 deletions
diff --git a/dump_manager.cpp b/dump_manager.cpp index 571ced5..7e753c0 100644 --- a/dump_manager.cpp +++ b/dump_manager.cpp @@ -1,5 +1,6 @@ #include <unistd.h> #include <sys/inotify.h> +#include <regex> #include <phosphor-logging/elog-errors.hpp> @@ -15,6 +16,7 @@ namespace dump using namespace sdbusplus::xyz::openbmc_project::Common::Error; using namespace phosphor::logging; +using namespace std; namespace internal { @@ -83,29 +85,46 @@ uint32_t Manager::captureDump( void Manager::createEntry(const fs::path& file) { - // TODO openbmc/openbmc#1795 - // Get Dump ID and Epoch time from Dump file name. - // Validate the Dump file name. - auto id = lastEntryId; - - //Get Epoch time. - auto ms = std::chrono::duration_cast<std::chrono::milliseconds>( - std::chrono::system_clock::now().time_since_epoch()).count(); - - // Entry Object path. - auto objPath = fs::path(OBJ_ENTRY) / std::to_string(id); - - auto size = fs::file_size(file); - - entries.insert(std::make_pair(id, - std::make_unique<Entry>( - bus, - objPath.c_str(), - id, - ms, - size, - file, - *this))); + //Dump File Name format obmcdump_ID_EPOCHTIME.EXT + static constexpr auto ID_POS = 1; + static constexpr auto EPOCHTIME_POS = 2; + std::regex file_regex("obmcdump_([0-9]+)_([0-9]+).([a-zA-Z0-9]+)"); + + std::smatch match; + std::string name = file.filename(); + + if (!((std::regex_search(name, match, file_regex)) && + (match.size() > 0))) + { + log<level::ERR>("Invalid Dump file name", + entry("Filename=%s", file.filename())); + return; + } + + auto idString = match[ID_POS]; + auto msString = match[EPOCHTIME_POS]; + + try + { + auto id = stoul(idString); + // Entry Object path. + auto objPath = fs::path(OBJ_ENTRY) / std::to_string(id); + + entries.insert(std::make_pair(id, + std::make_unique<Entry>( + bus, + objPath.c_str(), + id, + stoull(msString), + fs::file_size(file), + file, + *this))); + } + catch (const std::invalid_argument& e) + { + log<level::ERR>(e.what()); + return; + } } void Manager::erase(uint32_t entryId) |