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

Periodic flush record files instead of flushing them on std::endl. #2782

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion orchagent/orch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ void Orch::recordTuple(ConsumerBase &consumer, const KeyOpFieldsValuesTuple &tup
{
string s = consumer.dumpTuple(tuple);

gRecordOfs << getTimestamp() << "|" << s << endl;
gRecordOfs << getTimestamp() << "|" << s << '\n';

if (gLogRotate)
{
Expand Down
7 changes: 7 additions & 0 deletions orchagent/orchdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ extern sai_switch_api_t* sai_switch_api;
extern sai_object_id_t gSwitchId;
extern bool gSaiRedisLogRotate;

extern ofstream gRecordOfs;
extern ofstream gResponsePublisherRecordOfs;

extern void syncd_apply_view();
/*
* Global orch daemon variables
Expand Down Expand Up @@ -686,6 +689,10 @@ void OrchDaemon::flush()
{
orch->flushResponses();
}

// Flush the record files.
gRecordOfs.flush();
gResponsePublisherRecordOfs.flush();
}

/* Release the file handle so the log can be rotated */
Expand Down
4 changes: 2 additions & 2 deletions orchagent/response_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void RecordDBWrite(const std::string &table, const std::string &key, const std::
}

PerformLogRotate();
gResponsePublisherRecordOfs << swss::getTimestamp() << "|" << s << std::endl;
gResponsePublisherRecordOfs << swss::getTimestamp() << "|" << s << '\n';
}

void RecordResponse(const std::string &response_channel, const std::string &key,
Expand All @@ -85,7 +85,7 @@ void RecordResponse(const std::string &response_channel, const std::string &key,
}

PerformLogRotate();
gResponsePublisherRecordOfs << swss::getTimestamp() << "|" << s << std::endl;
gResponsePublisherRecordOfs << swss::getTimestamp() << "|" << s << '\n';
}

} // namespace
Expand Down
2 changes: 2 additions & 0 deletions tests/mock_tests/mock_orchagent_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ bool gSwssRecord = true;
bool gLogRotate = false;
ofstream gRecordOfs;
string gRecordFile;
std::ofstream gResponsePublisherRecordOfs;
std::string gResponsePublisherRecordFile;
string gMySwitchType = "switch";
int32_t gVoqMySwitchId = 0;
string gMyHostName = "Linecard1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

bool gResponsePublisherRecord{false};
bool gResponsePublisherLogRotate{false};
std::ofstream gResponsePublisherRecordOfs;
std::string gResponsePublisherRecordFile;

using namespace swss;

Expand Down