diff --git a/syncd/syncd.cpp b/syncd/syncd.cpp index 8b29f9bec..5d4d535ac 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 bdca49710..fee495eb1 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 @@ -586,8 +608,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 1771feb2a..f411ffca9 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, @@ -119,6 +123,7 @@ class FlexCounter uint32_t m_pollInterval = 0; std::string m_instanceId; + bool m_enable = false; }; #endif