Adding useful error messages when sensors ignored
Useful output for every case in which a configured sensor is skipped over
Adding DEBUG global boolean constant, similar to other dbus-sensors usage
Also useful output along success path when DEBUG true
Reformatted some long std::cerr statements to pass clang-format
Tested: With corresponding patches elsewhere,
all ISL68137 devices on my system were instantiated,
and periodically read from, by PSUSensor,
and showed up in the output of busctl.
Change-Id: I95f56216a9c5d7719503c82c0e4eb8815cdb2c08
Signed-off-by: Josh Lehan <krellan@google.com>
diff --git a/src/PSUSensor.cpp b/src/PSUSensor.cpp
index 7c9e109..e18f739 100644
--- a/src/PSUSensor.cpp
+++ b/src/PSUSensor.cpp
@@ -28,6 +28,8 @@
static constexpr const char* sensorPathPrefix = "/xyz/openbmc_project/sensors/";
+static constexpr bool DEBUG = false;
+
PSUSensor::PSUSensor(const std::string& path, const std::string& objectType,
sdbusplus::asio::object_server& objectServer,
std::shared_ptr<sdbusplus::asio::connection>& conn,
@@ -42,6 +44,15 @@
inputDev(io, open(path.c_str(), O_RDONLY)), waitTimer(io), errCount(0),
sensorFactor(factor)
{
+ if constexpr (DEBUG)
+ {
+ std::cerr << "Constructed sensor: path " << path << " type "
+ << objectType << " config " << sensorConfiguration
+ << " typename " << sensorTypeName << " factor " << factor
+ << " min " << min << " max " << max << " name \""
+ << sensorName << "\"\n";
+ }
+
std::string dbusPath = sensorPathPrefix + sensorTypeName + name;
sensorInterface = objectServer.add_interface(
@@ -86,6 +97,7 @@
{
if (err == boost::system::errc::bad_file_descriptor)
{
+ std::cerr << "Bad file descriptor from " << path << "\n";
return;
}
std::istream responseStream(&readBuf);
@@ -98,6 +110,12 @@
float nvalue = std::stof(response);
responseStream.clear();
nvalue /= sensorFactor;
+
+ if constexpr (DEBUG)
+ {
+ std::cerr << "Read " << path << " scale " << sensorFactor
+ << " value " << nvalue << "\n";
+ }
if (static_cast<double>(nvalue) != value)
{
updateValue(nvalue);
@@ -106,11 +124,14 @@
}
catch (const std::invalid_argument&)
{
+ std::cerr << "Could not parse " << response << " from path " << path
+ << "\n";
errCount++;
}
}
else
{
+ std::cerr << "System error " << err << " from path " << path << "\n";
errCount++;
}
@@ -130,6 +151,7 @@
int fd = open(path.c_str(), O_RDONLY);
if (fd < 0)
{
+ std::cerr << "Failed to open path " << path << "\n";
return;
}
inputDev.assign(fd);
@@ -137,6 +159,7 @@
waitTimer.async_wait([&](const boost::system::error_code& ec) {
if (ec == boost::asio::error::operation_aborted)
{
+ std::cerr << "Failed to reschedule wait for " << path << "\n";
return;
}
setupRead();