diff --git a/syncd/syncd.cpp b/syncd/syncd.cpp index e3d704ba8..c018455f8 100644 --- a/syncd/syncd.cpp +++ b/syncd/syncd.cpp @@ -2580,6 +2580,10 @@ void processFlexCounterGroupEvent( FlexCounter::addPortCounterPlugin(sha, groupName); } } + else if (field == FLEX_COUNTER_STATUS_FIELD) + { + FlexCounter::updateFlexCounterStatus(value, groupName); + } else { SWSS_LOG_ERROR("Field is not supported %s", field.c_str()); diff --git a/syncd/syncd_flex_counter.cpp b/syncd/syncd_flex_counter.cpp index c2f39e8bc..f3a4537dc 100644 --- a/syncd/syncd_flex_counter.cpp +++ b/syncd/syncd_flex_counter.cpp @@ -42,6 +42,28 @@ void FlexCounter::setPollInterval( fc.m_pollInterval = pollInterval; } +void FlexCounter::updateFlexCounterStatus( + _In_ std::string status, + _In_ std::string instanceId) +{ + SWSS_LOG_ENTER(); + + FlexCounter &fc = getInstance(instanceId); + if (status == "enable") + { + fc.m_enable = true; + } + else if (status == "disable") + { + fc.m_enable = false; + } + else + { + SWSS_LOG_NOTICE("Input value %s is not supported for Flex counter status, enter enable or disable", status.c_str()); + } + +} + /* The current implementation of 'setPortCounterList' and 'setQueueCounterList' are * not the same. Need to refactor these two functions to have the similar logic. * Either the full SAI attributes are queried once, or each of the needed counters @@ -593,8 +615,11 @@ void FlexCounter::flexCounterThread(void) { auto start = std::chrono::steady_clock::now(); - collectCounters(countersTable); - runPlugins(db); + if (m_enable) + { + collectCounters(countersTable); + runPlugins(db); + } auto finish = std::chrono::steady_clock::now(); uint32_t delay = static_cast( diff --git a/syncd/syncd_flex_counter.h b/syncd/syncd_flex_counter.h index 111fc8260..51499be86 100644 --- a/syncd/syncd_flex_counter.h +++ b/syncd/syncd_flex_counter.h @@ -32,6 +32,10 @@ class FlexCounter _In_ sai_object_id_t queueId, _In_ std::string instanceId, _In_ const std::vector &attrIds); + static void updateFlexCounterStatus( + _In_ std::string status, + _In_ std::string instanceId); + static void removePort( _In_ sai_object_id_t portVid, @@ -120,6 +124,7 @@ class FlexCounter uint32_t m_pollInterval = 0; std::string m_instanceId; + bool m_enable = false; }; #endif