Skip to content

Commit

Permalink
Fix errors in test
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Sun <[email protected]>
  • Loading branch information
stephenxs committed Dec 31, 2024
1 parent 17497f4 commit a985e51
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions syncd/FlexCounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,24 +569,35 @@ class CounterContext : public BaseCounterContext
}
}

void parseCounterPrefixConfigString(
bool parseCounterPrefixConfigString(
_In_ const std::string& prefixConfigString)
{
SWSS_LOG_ENTER();

m_counterChunkSizeMapFromPrefix.clear();

if (!prefixConfigString.empty())
if (!prefixConfigString.empty() && prefixConfigString != "NULL")
{
auto tokens = swss::tokenize(prefixConfigString, ';');
try
{
auto tokens = swss::tokenize(prefixConfigString, ';');

for (auto &token: tokens)
for (auto &token: tokens)
{
auto counter_name_bulk_size = swss::tokenize(token, ':');
SWSS_LOG_INFO("New partition %s bulk chunk size %s", counter_name_bulk_size[0].c_str(), counter_name_bulk_size[1].c_str());
m_counterChunkSizeMapFromPrefix[counter_name_bulk_size[0]] = stoi(counter_name_bulk_size[1]);
}
}
catch (...)
{
auto counter_name_bulk_size = swss::tokenize(token, ':');
SWSS_LOG_INFO("New partition %s bulk chunk size %s", counter_name_bulk_size[0].c_str(), counter_name_bulk_size[1].c_str());
m_counterChunkSizeMapFromPrefix[counter_name_bulk_size[0]] = stoi(counter_name_bulk_size[1]);
SWSS_LOG_ERROR("Invalid bulk chunk size per counter ID field %s", prefixConfigString.c_str());
m_counterChunkSizeMapFromPrefix.clear();
return false;
}
}

return true;
}

void mapCountersByPrefix(
Expand Down Expand Up @@ -632,7 +643,7 @@ class CounterContext : public BaseCounterContext
{
SWSS_LOG_ENTER();
default_bulk_chunk_size = bulkChunkSize;
SWSS_LOG_INFO("Bulk chunk size updatd to %u", bulkChunkSize);
SWSS_LOG_INFO("Bulk chunk size updated to %u", bulkChunkSize);

for (auto &bulkStatsContext : m_bulkContexts)
{

Check warning

Code scanning / CodeQL

Poorly documented large function Warning

Poorly documented function: fewer than 2% comments for a function of 132 lines.
Expand All @@ -653,8 +664,7 @@ class CounterContext : public BaseCounterContext

m_bulkChunkSizePerPrefix = bulkChunkSizePerPrefix;

parseCounterPrefixConfigString(bulkChunkSizePerPrefix);
if (m_bulkContexts.empty())
if (!parseCounterPrefixConfigString(bulkChunkSizePerPrefix) || m_bulkContexts.empty())
{
return;
}
Expand Down Expand Up @@ -1832,20 +1842,30 @@ void FlexCounter::addCounterPlugin(
}
else if (field == BULK_CHUNK_SIZE_FIELD)
{
bulkChunkSize = stoi(value);
if (value != "NULL")
{
try
{
bulkChunkSize = stoi(value);
}
catch (...)
{
SWSS_LOG_ERROR("Invalid bulk chunk size %s", value.c_str());
}
}
for (auto &context : m_counterContext)
{
context.second->setBulkChunkSize(bulkChunkSize);
SWSS_LOG_NOTICE("Set counter context %s %s bulk size %u", m_instanceId.c_str(), COUNTER_TYPE_PORT.c_str(), bulkChunkSize);
context.second->setBulkChunkSize(bulkChunkSize);
}
}
else if (field == BULK_CHUNK_SIZE_PER_PREFIX_FIELD)
{
bulkChunkSizePerPrefix = value;
for (auto &context : m_counterContext)
{
context.second->setBulkChunkSizePerPrefix(bulkChunkSizePerPrefix);
SWSS_LOG_NOTICE("Set counter context %s %s bulk chunk prefix map %s", m_instanceId.c_str(), COUNTER_TYPE_PORT.c_str(), bulkChunkSizePerPrefix.c_str());
context.second->setBulkChunkSizePerPrefix(bulkChunkSizePerPrefix);
}
}
else if (field == FLEX_COUNTER_STATUS_FIELD)
Expand Down

0 comments on commit a985e51

Please sign in to comment.