From 9b161f9300f894137a3d26603a0352530267c673 Mon Sep 17 00:00:00 2001 From: Teja Tamboli Date: Thu, 20 Apr 2023 20:39:08 +0000 Subject: [PATCH] Periodic flush record files instead of flushing them on std::endl --- lib/Recorder.cpp | 7 ++++++- lib/Recorder.h | 2 ++ lib/RedisRemoteSaiInterface.cpp | 2 ++ lib/tests.cpp | 2 ++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/Recorder.cpp b/lib/Recorder.cpp index 32bc2d0d8..63a2fcf3e 100644 --- a/lib/Recorder.cpp +++ b/lib/Recorder.cpp @@ -177,7 +177,7 @@ void Recorder::recordLine( if (m_ofstream.is_open()) { - m_ofstream << getTimestamp() << "|" << line << std::endl; + m_ofstream << getTimestamp() << "|" << line << '\n'; } } @@ -1110,6 +1110,11 @@ void Recorder::recordStats( m_recordStats = enable; } +void Recorder::flush() +{ + MUTEX(); + m_ofstream.flush(); +} void Recorder::recordGenericResponse( _In_ sai_status_t status) diff --git a/lib/Recorder.h b/lib/Recorder.h index ccda2bacb..9e82ece46 100644 --- a/lib/Recorder.h +++ b/lib/Recorder.h @@ -420,6 +420,8 @@ namespace sairedis void recordStats( _In_ bool enable); + void flush(); + private: // recording helpers void recordCreate( diff --git a/lib/RedisRemoteSaiInterface.cpp b/lib/RedisRemoteSaiInterface.cpp index 4e0e284b9..ccd5d104e 100644 --- a/lib/RedisRemoteSaiInterface.cpp +++ b/lib/RedisRemoteSaiInterface.cpp @@ -452,6 +452,8 @@ sai_status_t RedisRemoteSaiInterface::setRedisExtensionAttribute( m_communicationChannel->flush(); + m_recorder->flush(); + return SAI_STATUS_SUCCESS; case SAI_REDIS_SWITCH_ATTR_RECORDING_OUTPUT_DIR: diff --git a/lib/tests.cpp b/lib/tests.cpp index 355f3e1de..36c8e3266 100644 --- a/lib/tests.cpp +++ b/lib/tests.cpp @@ -795,6 +795,7 @@ static void test_recorder_enum_value_capability_query_request( attr_id, &enum_values_capability ); + recorder.flush(); auto tokens = parseFirstRecordedAPI(); @@ -827,6 +828,7 @@ static void test_recorder_enum_value_capability_query_response( attr_id, &enum_values_capability ); + recorder.flush(); auto tokens = parseFirstRecordedAPI();