Skip to content

Commit 0342846

Browse files
Shuotian Chengkcudnik
Shuotian Cheng
authored andcommitted
[orchagent]: Add option to set record log folder (sonic-net#225)
- Add -d record_location option to indicate the folder for putting SAI Redis recording file and SwSS recording file. - The size of this folder should be monitored and limited to prevent disk space full issue.
1 parent cc48b0b commit 0342846

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

orchagent/main.cpp

+34-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ extern "C" {
1010
#include <thread>
1111
#include <chrono>
1212
#include <getopt.h>
13+
#include <unistd.h>
14+
1315
#include <sairedis.h>
1416
#include "orchdaemon.h"
1517
#include "logger.h"
@@ -154,13 +156,14 @@ string getTimestamp()
154156

155157
void usage()
156158
{
157-
cout << "usage: orchagent [-h] [-r record_type] [-m MAC]" << endl;
159+
cout << "usage: orchagent [-h] [-r record_type] [-d record_location] [-m MAC]" << endl;
158160
cout << " -h: display this message" << endl;
159161
cout << " -r record_type: record orchagent logs with type (default 3)" << endl;
160162
cout << " 0: do not record logs" << endl;
161163
cout << " 1: record SAI call sequence as sairedis*.rec" << endl;
162164
cout << " 2: record SwSS task sequence as swss*.rec" << endl;
163165
cout << " 3: enable both above two records" << endl;
166+
cout << " -d record_location: set record logs folder location (default .)" << endl;
164167
cout << " -m MAC: set switch MAC address" << endl;
165168
}
166169

@@ -173,7 +176,9 @@ int main(int argc, char **argv)
173176
int opt;
174177
sai_status_t status;
175178

176-
while ((opt = getopt(argc, argv, "m:r:h")) != -1)
179+
string record_location = ".";
180+
181+
while ((opt = getopt(argc, argv, "m:r:d:h")) != -1)
177182
{
178183
switch (opt)
179184
{
@@ -204,6 +209,14 @@ int main(int argc, char **argv)
204209
exit(EXIT_FAILURE);
205210
}
206211
break;
212+
case 'd':
213+
record_location = optarg;
214+
if (access(record_location.c_str(), W_OK))
215+
{
216+
SWSS_LOG_ERROR("Failed to access writable directory %s", record_location.c_str());
217+
exit(EXIT_FAILURE);
218+
}
219+
break;
207220
case 'h':
208221
usage();
209222
exit(EXIT_SUCCESS);
@@ -224,23 +237,38 @@ int main(int argc, char **argv)
224237
exit(EXIT_FAILURE);
225238
}
226239

227-
/* Enable SAI Redis recording */
228240
sai_attribute_t attr;
241+
242+
/* Disable/enable SAI Redis recording */
243+
if (gSairedisRecord)
244+
{
245+
attr.id = SAI_REDIS_SWITCH_ATTR_RECORDING_OUTPUT_DIR;
246+
attr.value.s8list.count = record_location.size();
247+
attr.value.s8list.list = (signed char *) record_location.c_str();
248+
249+
status = sai_switch_api->set_switch_attribute(&attr);
250+
if (status != SAI_STATUS_SUCCESS)
251+
{
252+
SWSS_LOG_ERROR("Failed to set SAI Redis recording output folder to %s, rv:%d", record_location.c_str(), status);
253+
exit(EXIT_FAILURE);
254+
}
255+
}
256+
229257
attr.id = SAI_REDIS_SWITCH_ATTR_RECORD;
230258
attr.value.booldata = gSairedisRecord;
231259

232260
status = sai_switch_api->set_switch_attribute(&attr);
233261
if (status != SAI_STATUS_SUCCESS)
234262
{
235-
SWSS_LOG_ERROR("Failed to enable SAI Redis recording %d", status);
263+
SWSS_LOG_ERROR("Failed to set SAI Redis recording to %s, rv:%d", gSairedisRecord ? "true" : "false", status);
236264
exit(EXIT_FAILURE);
237265
}
238266

239-
/* Enable SwSS recording */
267+
/* Disable/enable SwSS recording */
240268
if (gSwssRecord)
241269
{
242270
gRecordFile = "swss." + getTimestamp() + ".rec";
243-
gRecordOfs.open(gRecordFile);
271+
gRecordOfs.open(record_location + "/" + gRecordFile);
244272
if (!gRecordOfs.is_open())
245273
{
246274
SWSS_LOG_ERROR("Failed to open SwSS recording file %s", gRecordFile.c_str());

0 commit comments

Comments
 (0)