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 option to specify swss rec file name #1546

Merged
merged 6 commits into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
27 changes: 22 additions & 5 deletions orchagent/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ string gRecordFile;

void usage()
{
cout << "usage: orchagent [-h] [-r record_type] [-d record_location] [-b batch_size] [-m MAC] [-i INST_ID] [-s] [-z mode]" << endl;
cout << "usage: orchagent [-h] [-r record_type] [-d record_location] [-f swss_rec_filename] [-j sairedis_rec_filename] [-b batch_size] [-m MAC] [-i INST_ID] [-s] [-z mode]" << endl;
cout << " -h: display this message" << endl;
cout << " -r record_type: record orchagent logs with type (default 3)" << endl;
cout << " 0: do not record logs" << endl;
Expand All @@ -78,6 +78,8 @@ void usage()
cout << " -i INST_ID: set the ASIC instance_id in multi-asic platform" << endl;
cout << " -s: enable synchronous mode (depreacated, use -z)" << endl;
cout << " -z: redis communication mode (redis_async|redis_sync|zmq_sync), default: redis_async" << endl;
cout << " -f swss_rec_filename: swss record log filename(default 'swss.rec')" << endl;
cout << " -j sairedis_rec_filename: sairedis record log filename(default sairedis.rec)" << endl;
shi-su marked this conversation as resolved.
Show resolved Hide resolved
}

void sighup_handler(int signo)
Expand Down Expand Up @@ -161,8 +163,10 @@ int main(int argc, char **argv)
sai_status_t status;

string record_location = ".";
string swss_rec_filename = "swss.rec";
string sairedis_rec_filename = "sairedis.rec";

while ((opt = getopt(argc, argv, "b:m:r:d:i:hsz:")) != -1)
while ((opt = getopt(argc, argv, "b:m:r:f:j:d:i:hsz:")) != -1)
{
switch (opt)
{
Expand Down Expand Up @@ -227,7 +231,20 @@ int main(int argc, char **argv)
case 'z':
sai_deserialize_redis_communication_mode(optarg, gRedisCommunicationMode);
break;

case 'f':
swss_rec_filename = optarg;
if (swss_rec_filename.empty())
{
swss_rec_filename= "swss.rec";
shi-su marked this conversation as resolved.
Show resolved Hide resolved
}
break;
shi-su marked this conversation as resolved.
Show resolved Hide resolved
case 'j':
sairedis_rec_filename = optarg;
if (sairedis_rec_filename.empty())
{
sairedis_rec_filename= "sairedis.rec";
shi-su marked this conversation as resolved.
Show resolved Hide resolved
}
break;
shi-su marked this conversation as resolved.
Show resolved Hide resolved
default: /* '?' */
exit(EXIT_FAILURE);
}
Expand All @@ -236,7 +253,7 @@ int main(int argc, char **argv)
SWSS_LOG_NOTICE("--- Starting Orchestration Agent ---");

initSaiApi();
initSaiRedis(record_location);
initSaiRedis(record_location, sairedis_rec_filename);

sai_attribute_t attr;
vector<sai_attribute_t> attrs;
Expand All @@ -251,7 +268,7 @@ int main(int argc, char **argv)
/* Disable/enable SwSS recording */
if (gSwssRecord)
{
gRecordFile = record_location + "/" + "swss.rec";
gRecordFile = record_location + "/" + swss_rec_filename;
gRecordOfs.open(gRecordFile, std::ofstream::out | std::ofstream::app);
if (!gRecordOfs.is_open())
{
Expand Down
15 changes: 14 additions & 1 deletion orchagent/saihelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ void initSaiApi()
sai_log_set((sai_api_t)SAI_API_NAT, SAI_LOG_LEVEL_NOTICE);
}

void initSaiRedis(const string &record_location)
void initSaiRedis(const string &record_location, const std::string &record_filename)
{
/**
* NOTE: Notice that all Redis attributes here are using SAI_NULL_OBJECT_ID
Expand All @@ -226,6 +226,19 @@ void initSaiRedis(const string &record_location)
record_location.c_str(), status);
exit(EXIT_FAILURE);
}

attr.id = SAI_REDIS_SWITCH_ATTR_RECORDING_FILENAME;
attr.value.s8list.count = (uint32_t)record_filename.size();
attr.value.s8list.list = (int8_t*)const_cast<char *>(record_filename.c_str());

status = sai_switch_api->set_switch_attribute(gSwitchId, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to set SAI Redis recording logfile to %s, rv:%d",
record_filename.c_str(), status);
exit(EXIT_FAILURE);
}

}

/* Disable/enable SAI Redis recording */
Expand Down
2 changes: 1 addition & 1 deletion orchagent/saihelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
#include <string>

void initSaiApi();
void initSaiRedis(const std::string &record_location);
void initSaiRedis(const std::string &record_location, const std::string &record_filename);
sai_status_t initSaiPhyApi(swss::gearbox_phy_t *phy);