Skip to content

Commit

Permalink
Periodic flush record files instead of flushing them on std::endl
Browse files Browse the repository at this point in the history
  • Loading branch information
tejatam authored and mint570 committed May 17, 2023
1 parent 654f0f3 commit 9b161f9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/Recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void Recorder::recordLine(

if (m_ofstream.is_open())
{
m_ofstream << getTimestamp() << "|" << line << std::endl;
m_ofstream << getTimestamp() << "|" << line << '\n';
}
}

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions lib/Recorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,8 @@ namespace sairedis
void recordStats(
_In_ bool enable);

void flush();

private: // recording helpers

void recordCreate(
Expand Down
2 changes: 2 additions & 0 deletions lib/RedisRemoteSaiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions lib/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,7 @@ static void test_recorder_enum_value_capability_query_request(
attr_id,
&enum_values_capability
);
recorder.flush();

auto tokens = parseFirstRecordedAPI();

Expand Down Expand Up @@ -827,6 +828,7 @@ static void test_recorder_enum_value_capability_query_response(
attr_id,
&enum_values_capability
);
recorder.flush();

auto tokens = parseFirstRecordedAPI();

Expand Down

0 comments on commit 9b161f9

Please sign in to comment.