summaryrefslogtreecommitdiffstats
path: root/extensions
diff options
context:
space:
mode:
authorAatir <aatrapps@gmail.com>2019-12-10 14:40:27 -0600
committerMatt Spinler <spinler@us.ibm.com>2020-01-14 09:43:21 -0600
commit37822f68048c00f49d3b2ac354c2bb80deec1af5 (patch)
tree668e9638768238e56dffeaeb38e6cb1618be719f /extensions
parente340c13f1839cc1051ebe6cef07c3d238e3c5f94 (diff)
downloadphosphor-logging-37822f68048c00f49d3b2ac354c2bb80deec1af5.tar.gz
phosphor-logging-37822f68048c00f49d3b2ac354c2bb80deec1af5.zip
PEL: PEL listing time fix
Previously PELs were being flattened twice before being listed. This commit brings it down to one. Change-Id: I027d1e22e8d6d793c30c6f26a06178a448a6c301 Signed-off-by: Aatir <aatrapps@gmail.com>
Diffstat (limited to 'extensions')
-rw-r--r--extensions/openpower-pels/tools/peltool.cpp292
1 files changed, 196 insertions, 96 deletions
diff --git a/extensions/openpower-pels/tools/peltool.cpp b/extensions/openpower-pels/tools/peltool.cpp
index 959603a..10646de 100644
--- a/extensions/openpower-pels/tools/peltool.cpp
+++ b/extensions/openpower-pels/tools/peltool.cpp
@@ -51,6 +51,112 @@ std::string trim(const std::string& s)
}
/**
+ * @brief helper function to get PEL commit timestamp from file name
+ * @retrun BCDTime - PEL commit timestamp
+ * @param[in] std::string - file name
+ */
+BCDTime fileNameToTimestamp(const std::string& fileName)
+{
+ std::string token = fileName.substr(0, fileName.find("_"));
+ int i = 0;
+ BCDTime tmp;
+ if (token.length() >= 14)
+ {
+ try
+ {
+ tmp.yearMSB = std::stoi(token.substr(i, 2), 0, 16);
+ }
+ catch (std::exception& err)
+ {
+ std::cout << "Conversion failure: " << err.what() << std::endl;
+ }
+ i += 2;
+ try
+ {
+ tmp.yearLSB = std::stoi(token.substr(i, 2), 0, 16);
+ }
+ catch (std::exception& err)
+ {
+ std::cout << "Conversion failure: " << err.what() << std::endl;
+ }
+ i += 2;
+ try
+ {
+ tmp.month = std::stoi(token.substr(i, 2), 0, 16);
+ }
+ catch (std::exception& err)
+ {
+ std::cout << "Conversion failure: " << err.what() << std::endl;
+ }
+ i += 2;
+ try
+ {
+ tmp.day = std::stoi(token.substr(i, 2), 0, 16);
+ }
+ catch (std::exception& err)
+ {
+ std::cout << "Conversion failure: " << err.what() << std::endl;
+ }
+ i += 2;
+ try
+ {
+ tmp.hour = std::stoi(token.substr(i, 2), 0, 16);
+ }
+ catch (std::exception& err)
+ {
+ std::cout << "Conversion failure: " << err.what() << std::endl;
+ }
+ i += 2;
+ try
+ {
+ tmp.minutes = std::stoi(token.substr(i, 2), 0, 16);
+ }
+ catch (std::exception& err)
+ {
+ std::cout << "Conversion failure: " << err.what() << std::endl;
+ }
+ i += 2;
+ try
+ {
+ tmp.seconds = std::stoi(token.substr(i, 2), 0, 16);
+ }
+ catch (std::exception& err)
+ {
+ std::cout << "Conversion failure: " << err.what() << std::endl;
+ }
+ i += 2;
+ try
+ {
+ tmp.hundredths = std::stoi(token.substr(i, 2), 0, 16);
+ }
+ catch (std::exception& err)
+ {
+ std::cout << "Conversion failure: " << err.what() << std::endl;
+ }
+ }
+ return tmp;
+}
+
+/**
+ * @brief helper function to get PEL id from file name
+ * @retrun uint32_t - PEL id
+ * @param[in] std::string - file name
+ */
+uint32_t fileNameToPELId(const std::string& fileName)
+{
+ uint32_t num = 0;
+ try
+ {
+ num = std::stoi(fileName.substr(fileName.find("_") + 1), 0, 16);
+ }
+ catch (std::exception& err)
+ {
+ std::cout << "Conversion failure: " << err.what() << std::endl;
+ }
+ return num;
+}
+
+/**
* @brief helper function to check string suffix
* @retrun bool - true with suffix matches
* @param[in] std::string - string to check for suffix
@@ -69,8 +175,29 @@ bool ends_with(const std::string& str, const std::string& end)
return true;
}
+/**
+ * @brief get data form raw PEL file.
+ * @param[in] std::string Name of file with raw PEL
+ * @return std::vector<uint8_t> char vector read from raw PEL file.
+ */
+std::vector<uint8_t> getFileData(std::string name)
+{
+ std::ifstream file(name, std::ifstream::in);
+ if (file.good())
+ {
+ std::vector<uint8_t> data{std::istreambuf_iterator<char>(file),
+ std::istreambuf_iterator<char>()};
+ return data;
+ }
+ else
+ {
+ printf("Can't open raw PEL file");
+ return {};
+ }
+}
+
template <typename T>
-std::string genPELJSON(T itr)
+std::string genPELJSON(T itr, bool hidden)
{
std::size_t found;
std::string val;
@@ -85,63 +212,73 @@ std::string genPELJSON(T itr)
fileName = EXTENSION_PERSIST_DIR "/pels/logs/" + fileName;
try
{
- std::ifstream stream(fileName, std::ios::in | std::ios::binary);
- std::vector<uint8_t> data((std::istreambuf_iterator<char>(stream)),
- std::istreambuf_iterator<char>());
- stream.close();
- PEL pel{data};
- if (pel.valid())
+ std::vector<uint8_t> data = getFileData(fileName);
+
+ if (!data.empty())
{
- // id
- sprintf(tmpValStr, "0x%X", pel.privateHeader().id());
- val = std::string(tmpValStr);
- listStr += "\t\"" + val + "\": {\n";
- // ASCII
- val = pel.primarySRC() ? pel.primarySRC().value()->asciiString()
- : "No SRC";
- listStr += "\t\t\"SRC\": \"" + trim(val) + "\",\n";
- // platformid
- sprintf(tmpValStr, "0x%X", pel.privateHeader().plid());
- val = std::string(tmpValStr);
- listStr += "\t\t\"PLID\": \"" + val + "\",\n";
- // creatorid
- sprintf(tmpValStr, "%c", pel.privateHeader().creatorID());
- std::string creatorID(tmpValStr);
- val = pv::creatorIDs.count(creatorID) ? pv::creatorIDs.at(creatorID)
- : "Unknown Creator ID";
- listStr += "\t\t\"CreatorID\": \"" + val + "\",\n";
- // subsytem
- std::string subsystem = pv::getValue(pel.userHeader().subsystem(),
- pel_values::subsystemValues);
- listStr += "\t\t\"Subsystem\": \"" + subsystem + "\",\n";
- // commit time
- sprintf(tmpValStr, "%02X/%02X/%02X%02X %02X:%02X:%02X",
- pel.privateHeader().commitTimestamp().month,
- pel.privateHeader().commitTimestamp().day,
- pel.privateHeader().commitTimestamp().yearMSB,
- pel.privateHeader().commitTimestamp().yearLSB,
- pel.privateHeader().commitTimestamp().hour,
- pel.privateHeader().commitTimestamp().minutes,
- pel.privateHeader().commitTimestamp().seconds);
- val = std::string(tmpValStr);
- listStr += "\t\t\"Commit Time\": \"" + val + "\",\n";
- // severity
- std::string severity = pv::getValue(pel.userHeader().severity(),
- pel_values::severityValues);
- listStr += "\t\t\"Sev\": \"" + severity + "\",\n ";
- // compID
- sprintf(tmpValStr, "0x%X",
- pel.privateHeader().header().componentID);
- val = std::string(tmpValStr);
- listStr += "\t\t\"CompID\": \"" + val + "\",\n ";
- found = listStr.rfind(",");
- if (found != std::string::npos)
+ PEL pel{data};
+ std::bitset<16> actionFlags{pel.userHeader().actionFlags()};
+ if (pel.valid() && (hidden || !actionFlags.test(hiddenFlagBit)))
{
- listStr.replace(found, 1, "");
- listStr += "\t}, \n";
+ // id
+ sprintf(tmpValStr, "0x%X", pel.privateHeader().id());
+ val = std::string(tmpValStr);
+ listStr += "\t\"" + val + "\": {\n";
+ // ASCII
+ val = pel.primarySRC() ? pel.primarySRC().value()->asciiString()
+ : "No SRC";
+ listStr += "\t\t\"SRC\": \"" + trim(val) + "\",\n";
+ // platformid
+ sprintf(tmpValStr, "0x%X", pel.privateHeader().plid());
+ val = std::string(tmpValStr);
+ listStr += "\t\t\"PLID\": \"" + val + "\",\n";
+ // creatorid
+ sprintf(tmpValStr, "%c", pel.privateHeader().creatorID());
+ std::string creatorID(tmpValStr);
+ val = pv::creatorIDs.count(creatorID)
+ ? pv::creatorIDs.at(creatorID)
+ : "Unknown Creator ID";
+ listStr += "\t\t\"CreatorID\": \"" + val + "\",\n";
+ // subsytem
+ std::string subsystem = pv::getValue(
+ pel.userHeader().subsystem(), pel_values::subsystemValues);
+ listStr += "\t\t\"Subsystem\": \"" + subsystem + "\",\n";
+ // commit time
+ sprintf(tmpValStr, "%02X/%02X/%02X%02X %02X:%02X:%02X",
+ pel.privateHeader().commitTimestamp().month,
+ pel.privateHeader().commitTimestamp().day,
+ pel.privateHeader().commitTimestamp().yearMSB,
+ pel.privateHeader().commitTimestamp().yearLSB,
+ pel.privateHeader().commitTimestamp().hour,
+ pel.privateHeader().commitTimestamp().minutes,
+ pel.privateHeader().commitTimestamp().seconds);
+ val = std::string(tmpValStr);
+ listStr += "\t\t\"Commit Time\": \"" + val + "\",\n";
+ // severity
+ std::string severity = pv::getValue(pel.userHeader().severity(),
+ pel_values::severityValues);
+ listStr += "\t\t\"Sev\": \"" + severity + "\",\n ";
+ // compID
+ sprintf(tmpValStr, "0x%X",
+ pel.privateHeader().header().componentID);
+ val = std::string(tmpValStr);
+ listStr += "\t\t\"CompID\": \"" + val + "\",\n ";
+
+ found = listStr.rfind(",");
+ if (found != std::string::npos)
+ {
+ listStr.replace(found, 1, "");
+ listStr += "\t}, \n";
+ }
}
}
+ else
+ {
+ log<level::ERR>("Empty PEL file",
+ entry("FILENAME=%s", fileName.c_str()),
+ entry("ERROR=%s", "Empty PEL file"));
+ }
}
catch (std::exception& e)
{
@@ -167,33 +304,16 @@ void printList(bool order, bool hidden)
{
continue;
}
- try
- {
- std::ifstream stream((*it).path(), std::ios::in | std::ios::binary);
- std::vector<uint8_t> data((std::istreambuf_iterator<char>(stream)),
- std::istreambuf_iterator<char>());
- stream.close();
- PEL pel{data};
- if (pel.valid())
- {
-
- std::bitset<16> actionFlags{pel.userHeader().actionFlags()};
- if (hidden || !actionFlags.test(hiddenFlagBit))
- {
- PELs.emplace(pel.id(),
- pel.privateHeader().commitTimestamp());
- }
- }
- }
- catch (std::exception& e)
+ else
{
- log<level::ERR>("Hit exception while reading PEL File",
- entry("FILENAME=%s", (*it).path().c_str()),
- entry("ERROR=%s", e.what()));
+ PELs.emplace(fileNameToPELId((*it).path().filename()),
+ fileNameToTimestamp((*it).path().filename()));
}
}
std::string val;
- auto buildJSON = [&listStr](const auto& i) { listStr += genPELJSON(i); };
+ auto buildJSON = [&listStr, &hidden](const auto& i) {
+ listStr += genPELJSON(i, hidden);
+ };
if (order)
{
std::for_each(PELs.rbegin(), PELs.rend(), buildJSON);
@@ -211,26 +331,6 @@ void printList(bool order, bool hidden)
printf("%s", listStr.c_str());
}
}
-/**
- * @brief get data form raw PEL file.
- * @param[in] std::string Name of file with raw PEL
- * @return std::vector<uint8_t> char vector read from raw PEL file.
- */
-std::vector<uint8_t> getFileData(std::string name)
-{
- std::ifstream file(name, std::ifstream::in);
- if (file.good())
- {
- std::vector<uint8_t> data{std::istreambuf_iterator<char>(file),
- std::istreambuf_iterator<char>()};
- return data;
- }
- else
- {
- printf("Can't open raw PEL file");
- return {};
- }
-}
static void exitWithError(const std::string& help, const char* err)
{
OpenPOWER on IntegriCloud