Skip to content

Commit c58919e

Browse files
authored
[logfile][202012]: Add option to specify swss rec file name (#1946)
**What I did** Backport #1546 to 202012 branch
1 parent ee9c30d commit c58919e

3 files changed

Lines changed: 35 additions & 6 deletions

File tree

orchagent/main.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ string gRecordFile;
6767

6868
void usage()
6969
{
70-
cout << "usage: orchagent [-h] [-r record_type] [-d record_location] [-b batch_size] [-m MAC] [-i INST_ID] [-s] [-z mode] [-k bulk_size]" << endl;
70+
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] [-k bulk_size]" << endl;
7171
cout << " -h: display this message" << endl;
7272
cout << " -r record_type: record orchagent logs with type (default 3)" << endl;
7373
cout << " 0: do not record logs" << endl;
@@ -81,6 +81,8 @@ void usage()
8181
cout << " -s: enable synchronous mode (deprecated, use -z)" << endl;
8282
cout << " -z: redis communication mode (redis_async|redis_sync|zmq_sync), default: redis_async" << endl;
8383
cout << " -k max bulk size in bulk mode (default 1000)";
84+
cout << " -f swss_rec_filename: swss record log filename(default 'swss.rec')" << endl;
85+
cout << " -j sairedis_rec_filename: sairedis record log filename(default sairedis.rec)" << endl;
8486
}
8587

8688
void sighup_handler(int signo)
@@ -164,8 +166,10 @@ int main(int argc, char **argv)
164166
sai_status_t status;
165167

166168
string record_location = ".";
169+
string swss_rec_filename = "swss.rec";
170+
string sairedis_rec_filename = "sairedis.rec";
167171

168-
while ((opt = getopt(argc, argv, "b:m:r:d:i:hsz:k:")) != -1)
172+
while ((opt = getopt(argc, argv, "b:m:r:f:j:d:i:hsz:k:")) != -1)
169173
{
170174
switch (opt)
171175
{
@@ -244,6 +248,18 @@ int main(int argc, char **argv)
244248
}
245249
}
246250
break;
251+
case 'f':
252+
if (optarg)
253+
{
254+
swss_rec_filename = optarg;
255+
}
256+
break;
257+
case 'j':
258+
if (optarg)
259+
{
260+
sairedis_rec_filename = optarg;
261+
}
262+
break;
247263
default: /* '?' */
248264
exit(EXIT_FAILURE);
249265
}
@@ -252,7 +268,7 @@ int main(int argc, char **argv)
252268
SWSS_LOG_NOTICE("--- Starting Orchestration Agent ---");
253269

254270
initSaiApi();
255-
initSaiRedis(record_location);
271+
initSaiRedis(record_location, sairedis_rec_filename);
256272

257273
sai_attribute_t attr;
258274
vector<sai_attribute_t> attrs;
@@ -267,7 +283,7 @@ int main(int argc, char **argv)
267283
/* Disable/enable SwSS recording */
268284
if (gSwssRecord)
269285
{
270-
gRecordFile = record_location + "/" + "swss.rec";
286+
gRecordFile = record_location + "/" + swss_rec_filename;
271287
gRecordOfs.open(gRecordFile, std::ofstream::out | std::ofstream::app);
272288
if (!gRecordOfs.is_open())
273289
{

orchagent/saihelper.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ void initSaiApi()
209209
sai_log_set((sai_api_t)SAI_API_NAT, SAI_LOG_LEVEL_NOTICE);
210210
}
211211

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

240253
/* Disable/enable SAI Redis recording */

orchagent/saihelper.h

Lines changed: 1 addition & 1 deletion
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)