@@ -10,6 +10,8 @@ extern "C" {
10
10
#include < thread>
11
11
#include < chrono>
12
12
#include < getopt.h>
13
+ #include < unistd.h>
14
+
13
15
#include < sairedis.h>
14
16
#include " orchdaemon.h"
15
17
#include " logger.h"
@@ -154,13 +156,14 @@ string getTimestamp()
154
156
155
157
void usage ()
156
158
{
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;
158
160
cout << " -h: display this message" << endl;
159
161
cout << " -r record_type: record orchagent logs with type (default 3)" << endl;
160
162
cout << " 0: do not record logs" << endl;
161
163
cout << " 1: record SAI call sequence as sairedis*.rec" << endl;
162
164
cout << " 2: record SwSS task sequence as swss*.rec" << endl;
163
165
cout << " 3: enable both above two records" << endl;
166
+ cout << " -d record_location: set record logs folder location (default .)" << endl;
164
167
cout << " -m MAC: set switch MAC address" << endl;
165
168
}
166
169
@@ -173,7 +176,9 @@ int main(int argc, char **argv)
173
176
int opt;
174
177
sai_status_t status;
175
178
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 )
177
182
{
178
183
switch (opt)
179
184
{
@@ -204,6 +209,14 @@ int main(int argc, char **argv)
204
209
exit (EXIT_FAILURE);
205
210
}
206
211
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 ;
207
220
case ' h' :
208
221
usage ();
209
222
exit (EXIT_SUCCESS);
@@ -224,23 +237,38 @@ int main(int argc, char **argv)
224
237
exit (EXIT_FAILURE);
225
238
}
226
239
227
- /* Enable SAI Redis recording */
228
240
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
+
229
257
attr.id = SAI_REDIS_SWITCH_ATTR_RECORD;
230
258
attr.value .booldata = gSairedisRecord ;
231
259
232
260
status = sai_switch_api->set_switch_attribute (&attr);
233
261
if (status != SAI_STATUS_SUCCESS)
234
262
{
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);
236
264
exit (EXIT_FAILURE);
237
265
}
238
266
239
- /* Enable SwSS recording */
267
+ /* Disable/enable SwSS recording */
240
268
if (gSwssRecord )
241
269
{
242
270
gRecordFile = " swss." + getTimestamp () + " .rec" ;
243
- gRecordOfs .open (gRecordFile );
271
+ gRecordOfs .open (record_location + " / " + gRecordFile );
244
272
if (!gRecordOfs .is_open ())
245
273
{
246
274
SWSS_LOG_ERROR (" Failed to open SwSS recording file %s" , gRecordFile .c_str ());
0 commit comments