From bea05f43965a69c90db43713ca6adfa23f3f7e3d Mon Sep 17 00:00:00 2001 From: Sihui Han Date: Thu, 24 May 2018 18:31:32 +0000 Subject: [PATCH 1/2] [counter]: support enable/disable counter query Signed-off-by: Sihui Han --- syncd/syncd.cpp | 4 ++++ syncd/syncd_flex_counter.cpp | 29 +++++++++++++++++++++++++++-- syncd/syncd_flex_counter.h | 5 +++++ 3 files changed, 36 insertions(+), 2 deletions(-) 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..00cb29a1f 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 = true; }; #endif From 30c13a7ca2af399a12e36f041da47d1b1dc3dc96 Mon Sep 17 00:00:00 2001 From: Sihui Han Date: Fri, 8 Jun 2018 19:32:42 +0000 Subject: [PATCH 2/2] Set counter polling by default disabled Signed-off-by: Sihui Han --- syncd/syncd_flex_counter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syncd/syncd_flex_counter.h b/syncd/syncd_flex_counter.h index 00cb29a1f..f411ffca9 100644 --- a/syncd/syncd_flex_counter.h +++ b/syncd/syncd_flex_counter.h @@ -123,7 +123,7 @@ class FlexCounter uint32_t m_pollInterval = 0; std::string m_instanceId; - bool m_enable = true; + bool m_enable = false; }; #endif