PEL: Capture the journal in UserData sections
If a PEL message registry entry has a 'JournalCapture' section, capture
the listed portions of the journal in UserData sections for that error.
If the JSON looks like:
"JournalCapture": {
"NumLines": 30
}
Then the code will capture the previous 30 lines from the journal into a
single UserData section.
If the JSON looks like:
"JournalCapture":
{
"Sections": [
{
"SyslogID": "phosphor-bmc-state-manager",
"NumLines": 20
},
{
"SyslogID": "phosphor-log-manager",
"NumLines": 15
}
]
}
Then the code will create two UserData sections, the first with the most
recent 20 lines from phosphor-bmc-state-manager, and the second with 15
lines from phosphor-log-manager.
If a section would cause the PEL to exceed its maximum size of 16KB, it
will be dropped. While the UserData class does have a shrink() method,
it prunes data from the end, which would cause the most recent journal
entries to be removed, which could be misleading.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I2ecbd8002b0e7087eb166a1219c6ab9da14a122a
diff --git a/extensions/openpower-pels/journal.cpp b/extensions/openpower-pels/journal.cpp
index 0a728f0..18359fd 100644
--- a/extensions/openpower-pels/journal.cpp
+++ b/extensions/openpower-pels/journal.cpp
@@ -15,10 +15,11 @@
*/
#include "journal.hpp"
-#include <phosphor-logging/log.hpp>
+#include "util.hpp"
-#include <stdexcept>
-#include <thread>
+#include <fmt/format.h>
+
+#include <phosphor-logging/log.hpp>
namespace openpower::pels
{
@@ -50,6 +51,23 @@
sd_journal* journal{nullptr};
};
+void Journal::sync() const
+{
+ auto start = std::chrono::steady_clock::now();
+
+ util::journalSync();
+
+ auto end = std::chrono::steady_clock::now();
+ auto duration =
+ std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
+
+ if (duration.count() > 100)
+ {
+ log<level::INFO>(
+ fmt::format("Journal sync took {}ms", duration.count()).c_str());
+ }
+}
+
std::vector<std::string> Journal::getMessages(const std::string& syslogID,
size_t maxMessages) const
{