Skip to content

Commit

Permalink
[logfile]: Add handling of Sairedis rec filename (sonic-net#747)
Browse files Browse the repository at this point in the history
The PR implements the handling of the sairedis rec filename passed to the orchagent.
Corresponding swss pr : sonic-net/sonic-swss#1546
This change is mainly to be used for multi asic devices where each asic.

Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan <arlakshm@microsoft.com>
  • Loading branch information
arlakshm committed Dec 18, 2020
1 parent ab5a348 commit aa4958c
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/inc/Recorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ namespace sairedis
bool setRecordingOutputDirectory(
_In_ const sai_attribute_t &attr);

bool setRecordingFilename(
_In_ const sai_attribute_t &attr);

void requestLogRotate();

public: // static helper functions
Expand Down
11 changes: 11 additions & 0 deletions lib/inc/sairedis.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,15 @@ typedef enum _sai_redis_switch_attr_t
*/
SAI_REDIS_SWITCH_ATTR_CONTEXT,

/**
* @brief Recording log filename.
*
* Default valus is sairedis.rec
*
* @type sai_s8_list_t
* @flags CREATE_AND_SET
* @default sairedis.rec
*/
SAI_REDIS_SWITCH_ATTR_RECORDING_FILENAME,

} sai_redis_switch_attr_t;
56 changes: 54 additions & 2 deletions lib/src/Recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ std::vector<swss::FieldValueTuple> serialize_counter_id_list(
_In_ const sai_stat_id_t *counter_id_list);

#define MUTEX() std::lock_guard<std::mutex> _lock(m_mutex)

#define DEFAULT_RECORDING_FILE_NAME "sairedis.rec"
Recorder::Recorder()
{
SWSS_LOG_ENTER();

m_recordingFileName = "sairedis.rec";
m_recordingFileName = DEFAULT_RECORDING_FILE_NAME;

m_recordingOutputDirectory = ".";

Expand Down Expand Up @@ -97,6 +97,58 @@ bool Recorder::setRecordingOutputDirectory(
return true;
}

bool Recorder::setRecordingFilename(
_In_ const sai_attribute_t &attr)
{
SWSS_LOG_ENTER();

if (attr.value.s8list.count == 0)
{
m_recordingFileName = DEFAULT_RECORDING_FILE_NAME;

SWSS_LOG_NOTICE("setting recording filename to default filename: %s", m_recordingFileName.c_str());

requestLogRotate();

return true;
}

if (attr.value.s8list.list == NULL)
{
SWSS_LOG_ERROR("list pointer is NULL");

return false;
}

size_t len = strnlen((const char *)attr.value.s8list.list, attr.value.s8list.count);

if (len != (size_t)attr.value.s8list.count)
{
SWSS_LOG_ERROR("count (%u) is different than strnlen (%zu)", attr.value.s8list.count, len);

return false;
}

std::string filename((const char*)attr.value.s8list.list, len);

/// Stop the recording with old file before updating the filename
if (m_enabled)
{
stopRecording();
}

m_recordingFileName = filename;

SWSS_LOG_NOTICE("setting recording filename : %s", m_recordingFileName.c_str());

/// Start recording with new file
if (m_enabled)
{
startRecording();
}
return true;
}

void Recorder::enableRecording(
_In_ bool enabled)
{
Expand Down
9 changes: 9 additions & 0 deletions lib/src/RedisRemoteSaiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,15 @@ sai_status_t RedisRemoteSaiInterface::setRedisExtensionAttribute(

return SAI_STATUS_SUCCESS;

case SAI_REDIS_SWITCH_ATTR_RECORDING_FILENAME:

if (m_recorder)
{
m_recorder->setRecordingFilename(*attr);
}

return SAI_STATUS_SUCCESS;

default:
break;
}
Expand Down

0 comments on commit aa4958c

Please sign in to comment.