From 572d406c89c80da2bb7ec4ccb42d2de3236000e1 Mon Sep 17 00:00:00 2001 From: Matthew Barth Date: Tue, 8 May 2018 14:16:04 -0500 Subject: Enhance precondition function and tracing Replace count_if with all_of in the property states match precondition to stop iterating over the group members once a property state does not match. Include additional debug tracing when the precondition passes and fails to help in determining where the precondition causes fans to be at full speed. Tested: Verify debug traces align with precondition state Change-Id: I1c3d8f096a645ac3bfcdfb7b9197682cf7ca52a0 Signed-off-by: Matthew Barth --- control/preconditions.hpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/control/preconditions.hpp b/control/preconditions.hpp index f989f0d..1423ac0 100644 --- a/control/preconditions.hpp +++ b/control/preconditions.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include namespace phosphor { @@ -11,6 +12,8 @@ namespace control namespace precondition { +using namespace phosphor::logging; + /** * @brief A precondition to compare a group of property values and * subscribe/unsubscribe a set speed event group @@ -34,7 +37,7 @@ auto property_states_match(std::vector&& pg, sse = std::move(sse)](auto& zone, auto& group) { // Compare given precondition entries - size_t precondState = std::count_if( + auto precondState = std::all_of( pg.begin(), pg.end(), [&zone](auto const& entry) @@ -54,8 +57,11 @@ auto property_states_match(std::vector&& pg, } }); - if (precondState == pg.size()) + if (precondState) { + log( + "Preconditions passed, init the associated events", + entry("EVENT_COUNT=%u", sse.size())); // Init the events when all the precondition(s) are true std::for_each( sse.begin(), @@ -67,6 +73,9 @@ auto property_states_match(std::vector&& pg, } else { + log( + "Preconditions not met for events, events removed if present", + entry("EVENT_COUNT=%u", sse.size())); // Unsubscribe the events' signals when any precondition is false std::for_each( sse.begin(), @@ -78,7 +87,7 @@ auto property_states_match(std::vector&& pg, zone.setFullSpeed(); } // Update group's fan control active allowed - zone.setActiveAllow(&group, (precondState == pg.size())); + zone.setActiveAllow(&group, precondState); }; } -- cgit v1.2.1