From 1bbc7fd3559e6d82b7aff8b5c17d498746143f14 Mon Sep 17 00:00:00 2001 From: Arvindsrinivasan Lakshmi Narasimhan Date: Mon, 14 Dec 2020 17:02:31 +0000 Subject: [PATCH 1/3] Add handling of the sairedis log filename Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan --- lib/inc/Recorder.h | 3 ++ lib/inc/sairedis.h | 11 +++++++ lib/src/Recorder.cpp | 50 +++++++++++++++++++++++++++++ lib/src/RedisRemoteSaiInterface.cpp | 9 ++++++ 4 files changed, 73 insertions(+) diff --git a/lib/inc/Recorder.h b/lib/inc/Recorder.h index b747589ce..d11a0e65e 100644 --- a/lib/inc/Recorder.h +++ b/lib/inc/Recorder.h @@ -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 diff --git a/lib/inc/sairedis.h b/lib/inc/sairedis.h index 40f24b504..dc7d43230 100644 --- a/lib/inc/sairedis.h +++ b/lib/inc/sairedis.h @@ -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 + */ + SAI_REDIS_SWITCH_ATTR_RECORDING_FILENAME, + } sai_redis_switch_attr_t; diff --git a/lib/src/Recorder.cpp b/lib/src/Recorder.cpp index 5461cbaf9..82cb0b6d4 100644 --- a/lib/src/Recorder.cpp +++ b/lib/src/Recorder.cpp @@ -97,6 +97,56 @@ 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"; + + SWSS_LOG_NOTICE("setting recording filename to: %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_recordingOutputDirectory = filename; + + /// Start recording with new file + if (m_enabled) + { + startRecording(); + } + return true; +} + void Recorder::enableRecording( _In_ bool enabled) { diff --git a/lib/src/RedisRemoteSaiInterface.cpp b/lib/src/RedisRemoteSaiInterface.cpp index 7f84ef683..574d357fe 100644 --- a/lib/src/RedisRemoteSaiInterface.cpp +++ b/lib/src/RedisRemoteSaiInterface.cpp @@ -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; } From dfbe73beb5a48190b3bff5910baf455e1fd0b33e Mon Sep 17 00:00:00 2001 From: Arvindsrinivasan Lakshmi Narasimhan Date: Tue, 15 Dec 2020 05:21:10 +0000 Subject: [PATCH 2/3] minor fix Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan --- lib/src/Recorder.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/src/Recorder.cpp b/lib/src/Recorder.cpp index 82cb0b6d4..fc2230b32 100644 --- a/lib/src/Recorder.cpp +++ b/lib/src/Recorder.cpp @@ -106,7 +106,7 @@ bool Recorder::setRecordingFilename( { m_recordingFileName = "sairedis.rec"; - SWSS_LOG_NOTICE("setting recording filename to: %s", m_recordingFileName.c_str()); + SWSS_LOG_NOTICE("setting recording filename to default filename: %s", m_recordingFileName.c_str()); requestLogRotate(); @@ -137,7 +137,9 @@ bool Recorder::setRecordingFilename( stopRecording(); } - m_recordingOutputDirectory = filename; + m_recordingFileName = filename; + + SWSS_LOG_NOTICE("setting recording filename : %s", m_recordingFileName.c_str()); /// Start recording with new file if (m_enabled) From de84c1a06e398025bd1bf3aec4caf241c904cbfc Mon Sep 17 00:00:00 2001 From: Arvindsrinivasan Lakshmi Narasimhan Date: Fri, 18 Dec 2020 07:30:31 +0000 Subject: [PATCH 3/3] address review comment Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan --- lib/inc/sairedis.h | 2 +- lib/src/Recorder.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/inc/sairedis.h b/lib/inc/sairedis.h index dc7d43230..fb24e4f14 100644 --- a/lib/inc/sairedis.h +++ b/lib/inc/sairedis.h @@ -201,7 +201,7 @@ typedef enum _sai_redis_switch_attr_t * * @type sai_s8_list_t * @flags CREATE_AND_SET - * @default empty + * @default sairedis.rec */ SAI_REDIS_SWITCH_ATTR_RECORDING_FILENAME, diff --git a/lib/src/Recorder.cpp b/lib/src/Recorder.cpp index fc2230b32..24f7b4ca4 100644 --- a/lib/src/Recorder.cpp +++ b/lib/src/Recorder.cpp @@ -22,12 +22,12 @@ std::vector serialize_counter_id_list( _In_ const sai_stat_id_t *counter_id_list); #define MUTEX() std::lock_guard _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 = "."; @@ -104,7 +104,7 @@ bool Recorder::setRecordingFilename( if (attr.value.s8list.count == 0) { - m_recordingFileName = "sairedis.rec"; + m_recordingFileName = DEFAULT_RECORDING_FILE_NAME; SWSS_LOG_NOTICE("setting recording filename to default filename: %s", m_recordingFileName.c_str());