Capture time stamp for FRU collection
The commit adds code to capture start and end time with respect to VPD
collection of respective FRU.
This information will help in troubleshooting efficiency issue as well
as improving performance in case required.
Change-Id: I91977b981dd6fbed7db565721457f0bb5dc704dd
Signed-off-by: Sunny Srivastava <sunnsr25@in.ibm.com>
diff --git a/vpd-manager/include/utility/common_utility.hpp b/vpd-manager/include/utility/common_utility.hpp
index b5ff13c..b4d164f 100644
--- a/vpd-manager/include/utility/common_utility.hpp
+++ b/vpd-manager/include/utility/common_utility.hpp
@@ -4,6 +4,7 @@
#include "logger.hpp"
#include <algorithm>
+#include <chrono>
#include <cstdio>
#include <cstdlib>
#include <vector>
@@ -235,5 +236,22 @@
return l_binaryValue;
}
+/**
+ * @brief API to get current time stamp since Epoch.
+ *
+ * @return time stamp in seconds.
+ */
+inline size_t getCurrentTimeSinceEpoch() noexcept
+{
+ // Use high_resolution_clock for better precision
+ const auto l_now = std::chrono::high_resolution_clock::now();
+ auto l_durationSinceEpoch = l_now.time_since_epoch();
+
+ auto l_timeStampSeconds =
+ std::chrono::duration_cast<std::chrono::seconds>(l_durationSinceEpoch)
+ .count();
+ return static_cast<size_t>(l_timeStampSeconds);
+}
+
} // namespace commonUtility
} // namespace vpd
diff --git a/vpd-manager/include/utility/vpd_specific_utility.hpp b/vpd-manager/include/utility/vpd_specific_utility.hpp
index 4dbe488..93fce3f 100644
--- a/vpd-manager/include/utility/vpd_specific_utility.hpp
+++ b/vpd-manager/include/utility/vpd_specific_utility.hpp
@@ -1067,5 +1067,48 @@
i_fruPath + "]. Error: " + std::string(l_ex.what()));
}
}
+
+/**
+ * @brief API to save current time stamp in PIM.
+ *
+ * This API will capture current time stamp and save it in progress interface
+ * for the given inventory path.
+ *
+ * @param[in] i_inventoryPath - Inventory path of FRU.
+ * @param[in] i_property - Property to save the time.
+ */
+inline void saveTimeStampInPim(const std::string& i_inventoryPath,
+ const std::string& i_property) noexcept
+{
+ if (i_inventoryPath.empty() || i_property.empty())
+ {
+ logging::logMessage("Invalid input parameter. Can't save time in PIM.");
+ return;
+ }
+
+ try
+ {
+ types::ObjectMap l_ObjMap = {std::make_pair(
+ i_inventoryPath,
+ types::InterfaceMap{std::make_pair(
+ constants::vpdCollectionInterface,
+ types::PropertyMap{std::make_pair(
+ i_property,
+ types::DbusVariantType{
+ commonUtility::getCurrentTimeSinceEpoch()})})})};
+
+ if (!dbusUtility::callPIM(move(l_ObjMap)))
+ {
+ logging::logMessage(
+ "Call to PIM failed while saving time for path " +
+ i_inventoryPath);
+ }
+ }
+ catch (const std::exception& l_ex)
+ {
+ logging::logMessage("Failed to save time stamp under PIM for reason: " +
+ std::string(l_ex.what()));
+ }
+}
} // namespace vpdSpecificUtility
} // namespace vpd
diff --git a/vpd-manager/src/worker.cpp b/vpd-manager/src/worker.cpp
index f2731e0..179e7ec 100644
--- a/vpd-manager/src/worker.cpp
+++ b/vpd-manager/src/worker.cpp
@@ -1376,6 +1376,10 @@
if (!l_inventoryPath.empty())
{
+ // save time stamp under PIM.
+ vpdSpecificUtility::saveTimeStampInPim(l_inventoryPath,
+ "StartTime");
+
if (!dbusUtility::writeDbusProperty(
jsonUtility::getServiceName(m_parsedJson, l_inventoryPath),
l_inventoryPath, constants::vpdCollectionInterface,
@@ -1394,6 +1398,10 @@
types::ObjectMap objectInterfaceMap;
populateDbus(parsedVpdMap, objectInterfaceMap, i_vpdFilePath);
+ // save end time stamp under PIM.
+ vpdSpecificUtility::saveTimeStampInPim(l_inventoryPath,
+ "CompletedTime");
+
// Notify PIM
if (!dbusUtility::callPIM(move(objectInterfaceMap)))
{
@@ -1413,6 +1421,10 @@
setCollectionStatusProperty(i_vpdFilePath,
constants::vpdCollectionFailed);
+ // save end time stamp under PIM.
+ vpdSpecificUtility::saveTimeStampInPim(l_inventoryPath,
+ "CompletedTime");
+
// handle all the exceptions internally. Return only true/false
// based on status of execution.
if (typeid(ex) == std::type_index(typeid(DataException)))