Skip to content

Commit

Permalink
[counter]: support enable/disable counter query (sonic-net#322)
Browse files Browse the repository at this point in the history
* [counter]: support enable/disable counter query

Signed-off-by: Sihui Han <sihan@microsoft.com>

* Set counter polling by default disabled

Signed-off-by: Sihui Han <sihan@microsoft.com>
  • Loading branch information
sihuihan88 authored and Volodymyr Samotiy committed Jul 30, 2019
1 parent ffb2f43 commit b2dfe06
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
4 changes: 4 additions & 0 deletions syncd/syncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
29 changes: 27 additions & 2 deletions syncd/syncd_flex_counter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<uint32_t>(
Expand Down
5 changes: 5 additions & 0 deletions syncd/syncd_flex_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class FlexCounter
_In_ sai_object_id_t queueId,
_In_ std::string instanceId,
_In_ const std::vector<sai_queue_attr_t> &attrIds);
static void updateFlexCounterStatus(
_In_ std::string status,
_In_ std::string instanceId);


static void removePort(
_In_ sai_object_id_t portVid,
Expand Down Expand Up @@ -120,6 +124,7 @@ class FlexCounter

uint32_t m_pollInterval = 0;
std::string m_instanceId;
bool m_enable = false;
};

#endif

0 comments on commit b2dfe06

Please sign in to comment.