Add Serialization Support for Dump Entry Attributes
Implemented serialization of dump entry attributes using the
nlohmann::json library. Added serialization support in the Dump Entry
class, serializing attributes including originatorId, originatorType,
and startTime. These attributes are not part of the dump filename and
thus require serialization to ensure their state is preserved.
Deserialization will occur only if the serialization version matches
and the dump ID in the dump object matches the ID in the
serialized file.
Tests:
- Created BMC dumps and restarted service
- Created BMC dumps and restarted BMC
- Created 200 BMC dumps and restarted service and BMC multiple times
File:
```
{"dumpId":2,"originatorId":"","originatorType":1,"startTime":1718199238942411,"version":1}
```
Change-Id: I16ecb058bddd464c8771bd8d08a50ea1877747ed
Signed-off-by: Dhruvaraj Subhashchandran <dhruvaraj@in.ibm.com>
diff --git a/dump_utils.cpp b/dump_utils.cpp
index da703ec..c362ee6 100644
--- a/dump_utils.cpp
+++ b/dump_utils.cpp
@@ -1,9 +1,17 @@
+#include "config.h"
+
#include "dump_utils.hpp"
#include "dump_types.hpp"
#include <phosphor-logging/lg2.hpp>
+#include <ctime>
+#include <filesystem>
+#include <optional>
+#include <regex>
+#include <tuple>
+
namespace phosphor
{
namespace dump
@@ -46,5 +54,29 @@
return response[0].first;
}
+std::optional<std::tuple<uint32_t, uint64_t, uint64_t>>
+ extractDumpDetails(const std::filesystem::path& file)
+{
+ 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().string();
+
+ if (!((std::regex_search(name, match, file_regex)) && (match.size() > 0)))
+ {
+ lg2::error("Invalid Dump file name, FILENAME: {FILENAME}", "FILENAME",
+ file);
+ return std::nullopt;
+ }
+
+ auto idString = match[ID_POS];
+ uint64_t timestamp = stoull(match[EPOCHTIME_POS]) * 1000 * 1000;
+
+ return std::make_tuple(stoul(idString), timestamp,
+ std::filesystem::file_size(file));
+}
+
} // namespace dump
} // namespace phosphor