summaryrefslogtreecommitdiff
path: root/redfish-core/lib/sensors.hpp
diff options
context:
space:
mode:
authorEd Tanous <ed@tanous.net>2020-09-30 02:16:58 +0300
committerEd Tanous <ed@tanous.net>2020-10-15 18:52:46 +0300
commitb5a76932eab7d40487ffb305cd745ec155813c4e (patch)
tree193d0ba4e679be07880d661130930cd4adcb38b9 /redfish-core/lib/sensors.hpp
parentc370fad0ae67480fac19a2fe6a08be3401f48ae7 (diff)
downloadbmcweb-b5a76932eab7d40487ffb305cd745ec155813c4e.tar.xz
Lots of performance improvements
(In the voice of the kid from sixth sense) I see string copies... Apparently there are a lot of places we make unnecessary copies. This fixes all of them. Not sure how to split this up into smaller patches, or if it even needs split up. It seems pretty easy to review to me, because basically every diff is identical. Change-Id: I22b4ae4f96f7e4082d2bc701098a04f7bed95369 Signed-off-by: Ed Tanous <ed@tanous.net> Signed-off-by: Wludzik, Jozef <jozef.wludzik@intel.com>
Diffstat (limited to 'redfish-core/lib/sensors.hpp')
-rw-r--r--redfish-core/lib/sensors.hpp99
1 files changed, 51 insertions, 48 deletions
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index 91e54bbb9f..6480861ab7 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -25,6 +25,7 @@
#include <utils/json_utils.hpp>
#include <cmath>
+#include <utility>
#include <variant>
namespace redfish
@@ -89,7 +90,7 @@ class SensorsAsyncResp
};
SensorsAsyncResp(crow::Response& response, const std::string& chassisIdIn,
- const std::vector<const char*> typesIn,
+ const std::vector<const char*>& typesIn,
const std::string_view& subNode) :
res(response),
chassisId(chassisIdIn), types(typesIn), chassisSubNode(subNode)
@@ -97,7 +98,7 @@ class SensorsAsyncResp
// Store extra data about sensor mapping and return it in callback
SensorsAsyncResp(crow::Response& response, const std::string& chassisIdIn,
- const std::vector<const char*> typesIn,
+ const std::vector<const char*>& typesIn,
const std::string_view& subNode,
DataCompleteCb&& creationComplete) :
res(response),
@@ -222,8 +223,8 @@ class InventoryItem
*/
template <typename Callback>
void getObjectsWithConnection(
- std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp,
- const std::shared_ptr<boost::container::flat_set<std::string>> sensorNames,
+ const std::shared_ptr<SensorsAsyncResp>& SensorsAsyncResp,
+ const std::shared_ptr<boost::container::flat_set<std::string>>& sensorNames,
Callback&& callback)
{
BMCWEB_LOG_DEBUG << "getObjectsWithConnection enter";
@@ -319,9 +320,10 @@ void getConnections(
* made, and eliminate Power sensors when a Thermal request is made.
*/
inline void reduceSensorList(
- std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp,
+ const std::shared_ptr<SensorsAsyncResp>& SensorsAsyncResp,
const std::vector<std::string>* allSensors,
- std::shared_ptr<boost::container::flat_set<std::string>> activeSensors)
+ const std::shared_ptr<boost::container::flat_set<std::string>>&
+ activeSensors)
{
if (SensorsAsyncResp == nullptr)
{
@@ -361,7 +363,7 @@ inline void reduceSensorList(
* @param callback Callback for next step to get valid chassis path
*/
template <typename Callback>
-void getValidChassisPath(std::shared_ptr<SensorsAsyncResp> asyncResp,
+void getValidChassisPath(const std::shared_ptr<SensorsAsyncResp>& asyncResp,
Callback&& callback)
{
BMCWEB_LOG_DEBUG << "checkChassisId enter";
@@ -417,7 +419,7 @@ void getValidChassisPath(std::shared_ptr<SensorsAsyncResp> asyncResp,
* @param callback Callback for next step in gathered sensor processing
*/
template <typename Callback>
-void getChassis(std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
+void getChassis(const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp,
Callback&& callback)
{
BMCWEB_LOG_DEBUG << "getChassis enter";
@@ -563,8 +565,9 @@ void getChassis(std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
* @param callback Callback to invoke when object paths obtained.
*/
template <typename Callback>
-void getObjectManagerPaths(std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp,
- Callback&& callback)
+void getObjectManagerPaths(
+ const std::shared_ptr<SensorsAsyncResp>& SensorsAsyncResp,
+ Callback&& callback)
{
BMCWEB_LOG_DEBUG << "getObjectManagerPaths enter";
const std::array<std::string, 1> interfaces = {
@@ -793,7 +796,7 @@ inline void setLedState(nlohmann::json& sensorJson,
*/
inline void objectInterfacesToJson(
const std::string& sensorName, const std::string& sensorType,
- std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
+ const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp,
const boost::container::flat_map<
std::string, boost::container::flat_map<std::string, SensorVariant>>&
interfacesDict,
@@ -1041,8 +1044,8 @@ inline void objectInterfacesToJson(
BMCWEB_LOG_DEBUG << "Added sensor " << sensorName;
}
-inline void
- populateFanRedundancy(std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp)
+inline void populateFanRedundancy(
+ const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp)
{
crow::connections::systemBus->async_method_call(
[sensorsAsyncResp](const boost::system::error_code ec,
@@ -1248,7 +1251,8 @@ inline void
"xyz.openbmc_project.Control.FanRedundancy"});
}
-inline void sortJSONResponse(std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp)
+inline void
+ sortJSONResponse(const std::shared_ptr<SensorsAsyncResp>& SensorsAsyncResp)
{
nlohmann::json& response = SensorsAsyncResp->res.jsonValue;
std::array<std::string, 2> sensorHeaders{"Temperatures", "Fans"};
@@ -1294,7 +1298,7 @@ inline void sortJSONResponse(std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp)
* @return Inventory item within vector, or nullptr if no match found.
*/
inline InventoryItem* findInventoryItem(
- std::shared_ptr<std::vector<InventoryItem>> inventoryItems,
+ const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems,
const std::string& invItemObjPath)
{
for (InventoryItem& inventoryItem : *inventoryItems)
@@ -1314,7 +1318,7 @@ inline InventoryItem* findInventoryItem(
* @return Inventory item within vector, or nullptr if no match found.
*/
inline InventoryItem* findInventoryItemForSensor(
- std::shared_ptr<std::vector<InventoryItem>> inventoryItems,
+ const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems,
const std::string& sensorObjPath)
{
for (InventoryItem& inventoryItem : *inventoryItems)
@@ -1361,10 +1365,9 @@ inline InventoryItem*
* @param invItemObjPath D-Bus object path of inventory item.
* @param sensorObjPath D-Bus object path of sensor
*/
-inline void
- addInventoryItem(std::shared_ptr<std::vector<InventoryItem>> inventoryItems,
- const std::string& invItemObjPath,
- const std::string& sensorObjPath)
+inline void addInventoryItem(
+ const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems,
+ const std::string& invItemObjPath, const std::string& sensorObjPath)
{
// Look for inventory item in vector
InventoryItem* inventoryItem =
@@ -1624,8 +1627,8 @@ static void getInventoryItemsData(
*/
template <typename Callback>
static void getInventoryItemsConnections(
- std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
- std::shared_ptr<std::vector<InventoryItem>> inventoryItems,
+ const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp,
+ const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems,
Callback&& callback)
{
BMCWEB_LOG_DEBUG << "getInventoryItemsConnections enter";
@@ -1711,9 +1714,9 @@ static void getInventoryItemsConnections(
*/
template <typename Callback>
static void getInventoryItemAssociations(
- std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
- const std::shared_ptr<boost::container::flat_set<std::string>> sensorNames,
- std::shared_ptr<boost::container::flat_map<std::string, std::string>>
+ const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp,
+ const std::shared_ptr<boost::container::flat_set<std::string>>& sensorNames,
+ const std::shared_ptr<boost::container::flat_map<std::string, std::string>>&
objectMgrPaths,
Callback&& callback)
{
@@ -2074,7 +2077,7 @@ void getInventoryLeds(
*/
template <typename Callback>
void getPowerSupplyAttributesData(
- std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
+ const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp,
std::shared_ptr<std::vector<InventoryItem>> inventoryItems,
const boost::container::flat_map<std::string, std::string>&
psAttributesConnections,
@@ -2415,12 +2418,12 @@ inline nlohmann::json& getPowerSupply(nlohmann::json& powerSupplyArray,
* @param inventoryItems Inventory items associated with the sensors.
*/
inline void getSensorData(
- std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp,
- const std::shared_ptr<boost::container::flat_set<std::string>> sensorNames,
+ const std::shared_ptr<SensorsAsyncResp>& SensorsAsyncResp,
+ const std::shared_ptr<boost::container::flat_set<std::string>>& sensorNames,
const boost::container::flat_set<std::string>& connections,
- std::shared_ptr<boost::container::flat_map<std::string, std::string>>
+ const std::shared_ptr<boost::container::flat_map<std::string, std::string>>&
objectMgrPaths,
- std::shared_ptr<std::vector<InventoryItem>> inventoryItems)
+ const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems)
{
BMCWEB_LOG_DEBUG << "getSensorData enter";
// Get managed objects from all services exposing sensors
@@ -2599,18 +2602,17 @@ inline void getSensorData(
}
inline void processSensorList(
- std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp,
- std::shared_ptr<boost::container::flat_set<std::string>> sensorNames)
+ const std::shared_ptr<SensorsAsyncResp>& SensorsAsyncResp,
+ const std::shared_ptr<boost::container::flat_set<std::string>>& sensorNames)
{
auto getConnectionCb =
[SensorsAsyncResp, sensorNames](
const boost::container::flat_set<std::string>& connections) {
BMCWEB_LOG_DEBUG << "getConnectionCb enter";
auto getObjectManagerPathsCb =
- [SensorsAsyncResp, sensorNames, connections](
- std::shared_ptr<
- boost::container::flat_map<std::string, std::string>>
- objectMgrPaths) {
+ [SensorsAsyncResp, sensorNames,
+ connections](const std::shared_ptr<boost::container::flat_map<
+ std::string, std::string>>& objectMgrPaths) {
BMCWEB_LOG_DEBUG << "getObjectManagerPathsCb enter";
auto getInventoryItemsCb =
[SensorsAsyncResp, sensorNames, connections,
@@ -2621,7 +2623,7 @@ inline void processSensorList(
// Get sensor data and store results in JSON
getSensorData(SensorsAsyncResp, sensorNames,
connections, objectMgrPaths,
- inventoryItems);
+ std::move(inventoryItems));
BMCWEB_LOG_DEBUG << "getInventoryItemsCb exit";
};
@@ -2649,7 +2651,8 @@ inline void processSensorList(
* chassis.
* @param SensorsAsyncResp Pointer to object holding response data
*/
-inline void getChassisData(std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp)
+inline void
+ getChassisData(const std::shared_ptr<SensorsAsyncResp>& SensorsAsyncResp)
{
BMCWEB_LOG_DEBUG << "getChassisData enter";
auto getChassisCb =
@@ -2657,7 +2660,7 @@ inline void getChassisData(std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp)
std::shared_ptr<boost::container::flat_set<std::string>>
sensorNames) {
BMCWEB_LOG_DEBUG << "getChassisCb enter";
- processSensorList(SensorsAsyncResp, sensorNames);
+ processSensorList(SensorsAsyncResp, std::move(sensorNames));
BMCWEB_LOG_DEBUG << "getChassisCb exit";
};
SensorsAsyncResp->res.jsonValue["Redundancy"] = nlohmann::json::array();
@@ -2706,7 +2709,7 @@ inline bool findSensorNameUsingSensorPath(
* @param chassisSubNode Chassis Node for which the query has to happen
*/
inline void setSensorsOverride(
- std::shared_ptr<SensorsAsyncResp> sensorAsyncResp,
+ const std::shared_ptr<SensorsAsyncResp>& sensorAsyncResp,
std::unordered_map<std::string, std::vector<nlohmann::json>>&
allCollections)
{
@@ -2743,11 +2746,10 @@ inline void setSensorsOverride(
}
}
- auto getChassisSensorListCb = [sensorAsyncResp,
- overrideMap](const std::shared_ptr<
- boost::container::flat_set<
- std::string>>
- sensorsList) {
+ auto getChassisSensorListCb = [sensorAsyncResp, overrideMap](
+ const std::shared_ptr<
+ boost::container::flat_set<
+ std::string>>& sensorsList) {
// Match sensor names in the PATCH request to those managed by the
// chassis node
const std::shared_ptr<boost::container::flat_set<std::string>>
@@ -2859,7 +2861,7 @@ inline bool isOverridingAllowed(const std::string& manufacturingModeStatus)
* @param chassisSubNode Chassis Node for which the query has to happen
*/
inline void checkAndDoSensorsOverride(
- std::shared_ptr<SensorsAsyncResp> sensorAsyncResp,
+ const std::shared_ptr<SensorsAsyncResp>& sensorAsyncResp,
std::unordered_map<std::string, std::vector<nlohmann::json>>&
allCollections)
{
@@ -3029,8 +3031,9 @@ class SensorCollection : public Node
sensors::node::sensors);
auto getChassisCb =
- [asyncResp](std::shared_ptr<boost::container::flat_set<std::string>>
- sensorNames) {
+ [asyncResp](
+ const std::shared_ptr<boost::container::flat_set<std::string>>&
+ sensorNames) {
BMCWEB_LOG_DEBUG << "getChassisCb enter";
nlohmann::json& entriesArray =