Skip to content

Commit e800c9f

Browse files
authored
[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 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
1 parent 1acf60e commit e800c9f

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

orchagent/main.cpp

+20-4
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ uint32_t gCfgSystemPorts = 0;
7070

7171
void usage()
7272
{
73-
cout << "usage: orchagent [-h] [-r record_type] [-d record_location] [-b batch_size] [-m MAC] [-i INST_ID] [-s] [-z mode]" << endl;
73+
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;
7474
cout << " -h: display this message" << endl;
7575
cout << " -r record_type: record orchagent logs with type (default 3)" << endl;
7676
cout << " 0: do not record logs" << endl;
@@ -83,6 +83,8 @@ void usage()
8383
cout << " -i INST_ID: set the ASIC instance_id in multi-asic platform" << endl;
8484
cout << " -s: enable synchronous mode (depreacated, use -z)" << endl;
8585
cout << " -z: redis communication mode (redis_async|redis_sync|zmq_sync), default: redis_async" << endl;
86+
cout << " -f swss_rec_filename: swss record log filename(default 'swss.rec')" << endl;
87+
cout << " -j sairedis_rec_filename: sairedis record log filename(default sairedis.rec)" << endl;
8688
}
8789

8890
void sighup_handler(int signo)
@@ -284,8 +286,10 @@ int main(int argc, char **argv)
284286
sai_status_t status;
285287

286288
string record_location = ".";
289+
string swss_rec_filename = "swss.rec";
290+
string sairedis_rec_filename = "sairedis.rec";
287291

288-
while ((opt = getopt(argc, argv, "b:m:r:d:i:hsz:")) != -1)
292+
while ((opt = getopt(argc, argv, "b:m:r:f:j:d:i:hsz:")) != -1)
289293
{
290294
switch (opt)
291295
{
@@ -350,7 +354,19 @@ int main(int argc, char **argv)
350354
case 'z':
351355
sai_deserialize_redis_communication_mode(optarg, gRedisCommunicationMode);
352356
break;
357+
case 'f':
353358

359+
if (optarg)
360+
{
361+
swss_rec_filename = optarg;
362+
}
363+
break;
364+
case 'j':
365+
if (optarg)
366+
{
367+
sairedis_rec_filename = optarg;
368+
}
369+
break;
354370
default: /* '?' */
355371
exit(EXIT_FAILURE);
356372
}
@@ -359,7 +375,7 @@ int main(int argc, char **argv)
359375
SWSS_LOG_NOTICE("--- Starting Orchestration Agent ---");
360376

361377
initSaiApi();
362-
initSaiRedis(record_location);
378+
initSaiRedis(record_location, sairedis_rec_filename);
363379

364380
sai_attribute_t attr;
365381
vector<sai_attribute_t> attrs;
@@ -374,7 +390,7 @@ int main(int argc, char **argv)
374390
/* Disable/enable SwSS recording */
375391
if (gSwssRecord)
376392
{
377-
gRecordFile = record_location + "/" + "swss.rec";
393+
gRecordFile = record_location + "/" + swss_rec_filename;
378394
gRecordOfs.open(gRecordFile, std::ofstream::out | std::ofstream::app);
379395
if (!gRecordOfs.is_open())
380396
{

orchagent/saihelper.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ void initSaiApi()
210210
sai_log_set(SAI_API_SYSTEM_PORT, SAI_LOG_LEVEL_NOTICE);
211211
}
212212

213-
void initSaiRedis(const string &record_location)
213+
void initSaiRedis(const string &record_location, const std::string &record_filename)
214214
{
215215
/**
216216
* NOTE: Notice that all Redis attributes here are using SAI_NULL_OBJECT_ID
@@ -236,6 +236,19 @@ void initSaiRedis(const string &record_location)
236236
record_location.c_str(), status);
237237
exit(EXIT_FAILURE);
238238
}
239+
240+
attr.id = SAI_REDIS_SWITCH_ATTR_RECORDING_FILENAME;
241+
attr.value.s8list.count = (uint32_t)record_filename.size();
242+
attr.value.s8list.list = (int8_t*)const_cast<char *>(record_filename.c_str());
243+
244+
status = sai_switch_api->set_switch_attribute(gSwitchId, &attr);
245+
if (status != SAI_STATUS_SUCCESS)
246+
{
247+
SWSS_LOG_ERROR("Failed to set SAI Redis recording logfile to %s, rv:%d",
248+
record_filename.c_str(), status);
249+
exit(EXIT_FAILURE);
250+
}
251+
239252
}
240253

241254
/* Disable/enable SAI Redis recording */

orchagent/saihelper.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
#include <string>
66

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

0 commit comments

Comments
 (0)