Skip to content

Commit

Permalink
[logfile]: Add option to specify swss rec file name (#1546)
Browse files Browse the repository at this point in the history
What I did
Add new options to specify swss rec and sairedis rec file name.
Corresponding change in sairedis sonic-net/sonic-sairedis#747

Why I did it
This option will be used in the multi asic system. The swss and sairedis record filename will be different for each asic and will be passed from the orchagent.sh
  • Loading branch information
arlakshm authored Jan 22, 2021
1 parent 1acf60e commit e800c9f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
24 changes: 20 additions & 4 deletions orchagent/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ uint32_t gCfgSystemPorts = 0;

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 @@ -83,6 +83,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;
}

void sighup_handler(int signo)
Expand Down Expand Up @@ -284,8 +286,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 @@ -350,7 +354,19 @@ int main(int argc, char **argv)
case 'z':
sai_deserialize_redis_communication_mode(optarg, gRedisCommunicationMode);
break;
case 'f':

if (optarg)
{
swss_rec_filename = optarg;
}
break;
case 'j':
if (optarg)
{
sairedis_rec_filename = optarg;
}
break;
default: /* '?' */
exit(EXIT_FAILURE);
}
Expand All @@ -359,7 +375,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 @@ -374,7 +390,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 @@ -210,7 +210,7 @@ void initSaiApi()
sai_log_set(SAI_API_SYSTEM_PORT, 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 @@ -236,6 +236,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);

0 comments on commit e800c9f

Please sign in to comment.