From e800c9ff33a600be62a9bd4b232e0b4ee1b8a69c Mon Sep 17 00:00:00 2001 From: arlakshm <55814491+arlakshm@users.noreply.github.com> Date: Fri, 22 Jan 2021 09:41:34 -0800 Subject: [PATCH] [logfile]: Add option to specify swss rec file name (#1546) What I did Add new options to specify swss rec and sairedis rec file name. Corresponding change in sairedis Azure/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 --- orchagent/main.cpp | 24 ++++++++++++++++++++---- orchagent/saihelper.cpp | 15 ++++++++++++++- orchagent/saihelper.h | 2 +- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/orchagent/main.cpp b/orchagent/main.cpp index d60112e94e4f..2787cffef353 100644 --- a/orchagent/main.cpp +++ b/orchagent/main.cpp @@ -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; @@ -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) @@ -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) { @@ -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); } @@ -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 attrs; @@ -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()) { diff --git a/orchagent/saihelper.cpp b/orchagent/saihelper.cpp index 15c753b2f030..dbd7683825bb 100644 --- a/orchagent/saihelper.cpp +++ b/orchagent/saihelper.cpp @@ -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 @@ -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(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 */ diff --git a/orchagent/saihelper.h b/orchagent/saihelper.h index 34bef06a6795..450acf8b69fd 100644 --- a/orchagent/saihelper.h +++ b/orchagent/saihelper.h @@ -5,5 +5,5 @@ #include 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);