Skip to content

Commit

Permalink
[syncd] Respect each api log level after sai discovery (#1303)
Browse files Browse the repository at this point in the history
Previously log after sai discovery log level was set to NOTICE not
respecting actual API log level or what user set via swsslog
  • Loading branch information
kcudnik authored Oct 10, 2023
1 parent 7c07d81 commit d520642
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 1 deletion.
10 changes: 10 additions & 0 deletions meta/SaiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,13 @@ sai_status_t SaiInterface::switchMdioCl22Write(

return SAI_STATUS_FAILURE;
}

sai_log_level_t SaiInterface::logGet(
_In_ sai_api_t api)
{
SWSS_LOG_ENTER();

// default for all apis

return SAI_LOG_LEVEL_NOTICE;
}
5 changes: 5 additions & 0 deletions meta/SaiInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,5 +316,10 @@ namespace sairedis
virtual sai_status_t logSet(
_In_ sai_api_t api,
_In_ sai_log_level_t log_level) = 0;

public: // non SAI API

virtual sai_log_level_t logGet(
_In_ sai_api_t api);
};
}
48 changes: 47 additions & 1 deletion syncd/SaiDiscovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,13 @@ std::set<sai_object_id_t> SaiDiscovery::discover(
{
SWSS_LOG_TIMER("discover");

auto levels = getApiLogLevel();

setApiLogLevel(SAI_LOG_LEVEL_CRITICAL);

discover(startRid, discovered_rids);

setApiLogLevel(SAI_LOG_LEVEL_NOTICE);
setApiLogLevel(levels);
}

SWSS_LOG_NOTICE("discovered objects count: %zu", discovered_rids.size());
Expand Down Expand Up @@ -323,3 +325,47 @@ void SaiDiscovery::setApiLogLevel(
}
}
}

void SaiDiscovery::setApiLogLevel(
_In_ const std::map<sai_api_t, sai_log_level_t>& levels)
{
SWSS_LOG_ENTER();

// We start from 1 since 0 is SAI_API_UNSPECIFIED.

for (uint32_t api = 1; api < sai_metadata_enum_sai_api_t.valuescount; ++api)
{
auto it = levels.find((sai_api_t)api);

sai_log_level_t logLevel = (it == levels.end()) ? SAI_LOG_LEVEL_NOTICE : it->second;

sai_status_t status = m_sai->logSet((sai_api_t)api, logLevel);

if (status == SAI_STATUS_SUCCESS)
{
SWSS_LOG_INFO("setting SAI loglevel %s on %s",
sai_serialize_log_level(logLevel).c_str(),
sai_serialize_api((sai_api_t)api).c_str());
}
else
{
SWSS_LOG_INFO("set loglevel failed: %s", sai_serialize_status(status).c_str());
}
}
}

std::map<sai_api_t, sai_log_level_t> SaiDiscovery::getApiLogLevel()
{
SWSS_LOG_ENTER();

std::map<sai_api_t, sai_log_level_t> levels;

// We start from 1 since 0 is SAI_API_UNSPECIFIED.

for (uint32_t api = 1; api < sai_metadata_enum_sai_api_t.valuescount; ++api)
{
levels[(sai_api_t)api] = m_sai->logGet((sai_api_t)api);
}

return levels;
}
6 changes: 6 additions & 0 deletions syncd/SaiDiscovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <memory>
#include <set>
#include <map>
#include <unordered_map>

namespace syncd
Expand Down Expand Up @@ -50,6 +51,11 @@ namespace syncd
void setApiLogLevel(
_In_ sai_log_level_t logLevel);

void setApiLogLevel(
_In_ const std::map<sai_api_t, sai_log_level_t>& levels);

std::map<sai_api_t, sai_log_level_t> getApiLogLevel();

private:

std::shared_ptr<sairedis::SaiInterface> m_sai;
Expand Down
19 changes: 19 additions & 0 deletions syncd/VendorSai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1681,5 +1681,24 @@ sai_status_t VendorSai::logSet(
{
SWSS_LOG_ENTER();

m_logLevelMap[api] = log_level;

return m_globalApis.log_set(api, log_level);
}

sai_log_level_t VendorSai::logGet(
_In_ sai_api_t api)
{
SWSS_LOG_ENTER();

auto it = m_logLevelMap.find(api);

if (it != m_logLevelMap.end())
{
return it->second;
}

// no level defined yet, just return default

return SAI_LOG_LEVEL_NOTICE;
}
8 changes: 8 additions & 0 deletions syncd/VendorSai.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ extern "C" {
#include <vector>
#include <memory>
#include <mutex>
#include <map>

namespace syncd
{
Expand Down Expand Up @@ -201,6 +202,11 @@ namespace syncd
_In_ sai_api_t api,
_In_ sai_log_level_t log_level) override;

public: // extra API

virtual sai_log_level_t logGet(
_In_ sai_api_t api) override;

private:

bool m_apiInitialized;
Expand All @@ -212,5 +218,7 @@ namespace syncd
sai_apis_t m_apis;

sai_global_apis_t m_globalApis;

std::map<sai_api_t, sai_log_level_t> m_logLevelMap;
};
}

0 comments on commit d520642

Please sign in to comment.