Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[logfile]: Add handling of Sairedis rec filename #747

Merged
merged 4 commits into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 empty
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could make this @default "sairedis.rec"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

address the commit in the latest commit

*/
SAI_REDIS_SWITCH_ATTR_RECORDING_FILENAME,

} sai_redis_switch_attr_t;
52 changes: 52 additions & 0 deletions lib/src/Recorder.cpp
Original file line number Diff line number Diff line change
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 = "sairedis.rec";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this name is also used in constructor, can you make a define on top of file and reuse define here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

address the commit in the latest commit


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