@@ -13,6 +13,8 @@ extern "C" {
13
13
#include < getopt.h>
14
14
#include < unistd.h>
15
15
#include < inttypes.h>
16
+ #include < sstream>
17
+ #include < stdexcept>
16
18
#include < stdlib.h>
17
19
#include < string.h>
18
20
@@ -54,8 +56,10 @@ int gBatchSize = DEFAULT_BATCH_SIZE;
54
56
55
57
bool gSairedisRecord = true ;
56
58
bool gSwssRecord = true ;
59
+ bool gResponsePublisherRecord = false ;
57
60
bool gLogRotate = false ;
58
61
bool gSaiRedisLogRotate = false ;
62
+ bool gResponsePublisherLogRotate = false ;
59
63
bool gSyncMode = false ;
60
64
sai_redis_communication_mode_t gRedisCommunicationMode = SAI_REDIS_COMMUNICATION_MODE_REDIS_ASYNC;
61
65
string gAsicInstance ;
@@ -64,6 +68,12 @@ extern bool gIsNatSupported;
64
68
65
69
ofstream gRecordOfs ;
66
70
string gRecordFile ;
71
+ ofstream gResponsePublisherRecordOfs ;
72
+ string gResponsePublisherRecordFile ;
73
+
74
+ #define SAIREDIS_RECORD_ENABLE 0x1
75
+ #define SWSS_RECORD_ENABLE (0x1 << 1 )
76
+ #define RESPONSE_PUBLISHER_RECORD_ENABLE (0x1 << 2 )
67
77
68
78
string gMySwitchType = " " ;
69
79
int32_t gVoqMySwitchId = -1 ;
@@ -77,10 +87,12 @@ void usage()
77
87
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;
78
88
cout << " -h: display this message" << endl;
79
89
cout << " -r record_type: record orchagent logs with type (default 3)" << endl;
90
+ cout << " Bit 0: sairedis.rec, Bit 1: swss.rec, Bit 2: responsepublisher.rec. For example:" << endl;
80
91
cout << " 0: do not record logs" << endl;
81
92
cout << " 1: record SAI call sequence as sairedis.rec" << endl;
82
93
cout << " 2: record SwSS task sequence as swss.rec" << endl;
83
94
cout << " 3: enable both above two records" << endl;
95
+ cout << " 7: enable sairedis.rec, swss.rec and responsepublisher.rec" << endl;
84
96
cout << " -d record_location: set record logs folder location (default .)" << endl;
85
97
cout << " -b batch_size: set consumer table pop operation batch size (default 128)" << endl;
86
98
cout << " -m MAC: set switch MAC address" << endl;
@@ -99,6 +111,7 @@ void sighup_handler(int signo)
99
111
*/
100
112
gLogRotate = true ;
101
113
gSaiRedisLogRotate = true ;
114
+ gResponsePublisherLogRotate = true ;
102
115
}
103
116
104
117
void syncd_apply_view ()
@@ -115,7 +128,7 @@ void syncd_apply_view()
115
128
{
116
129
SWSS_LOG_ERROR (" Failed to notify syncd APPLY_VIEW %d" , status);
117
130
exit (EXIT_FAILURE);
118
- }
131
+ }
119
132
}
120
133
121
134
/*
@@ -321,6 +334,8 @@ int main(int argc, char **argv)
321
334
string record_location = " ." ;
322
335
string swss_rec_filename = " swss.rec" ;
323
336
string sairedis_rec_filename = " sairedis.rec" ;
337
+ string responsepublisher_rec_filename = " responsepublisher.rec" ;
338
+ int record_type = 3 ; // Only swss and sairedis recordings enabled by default.
324
339
325
340
while ((opt = getopt (argc, argv, " b:m:r:f:j:d:i:hsz:k:" )) != -1 )
326
341
{
@@ -346,24 +361,10 @@ int main(int argc, char **argv)
346
361
gMacAddress = MacAddress (optarg );
347
362
break ;
348
363
case ' r' :
349
- if (!strcmp (optarg , " 0" ))
350
- {
351
- gSairedisRecord = false ;
352
- gSwssRecord = false ;
353
- }
354
- else if (!strcmp (optarg , " 1" ))
355
- {
356
- gSwssRecord = false ;
357
- }
358
- else if (!strcmp (optarg , " 2" ))
359
- {
360
- gSairedisRecord = false ;
361
- }
362
- else if (!strcmp (optarg , " 3" ))
363
- {
364
- continue ; /* default behavior */
365
- }
366
- else
364
+ // Disable all recordings if atoi() fails i.e. returns 0 due to
365
+ // invalid command line argument.
366
+ record_type = atoi (optarg );
367
+ if (record_type < 0 || record_type > 7 )
367
368
{
368
369
usage ();
369
370
exit (EXIT_FAILURE);
@@ -434,6 +435,14 @@ int main(int argc, char **argv)
434
435
attr.value .ptr = (void *)on_fdb_event;
435
436
attrs.push_back (attr);
436
437
438
+ // Initialize recording parameters.
439
+ gSairedisRecord =
440
+ (record_type & SAIREDIS_RECORD_ENABLE) == SAIREDIS_RECORD_ENABLE;
441
+ gSwssRecord = (record_type & SWSS_RECORD_ENABLE) == SWSS_RECORD_ENABLE;
442
+ gResponsePublisherRecord =
443
+ (record_type & RESPONSE_PUBLISHER_RECORD_ENABLE) ==
444
+ RESPONSE_PUBLISHER_RECORD_ENABLE;
445
+
437
446
/* Disable/enable SwSS recording */
438
447
if (gSwssRecord )
439
448
{
@@ -447,6 +456,24 @@ int main(int argc, char **argv)
447
456
gRecordOfs << getTimestamp () << " |recording started" << endl;
448
457
}
449
458
459
+ // Disable/Enable response publisher recording.
460
+ if (gResponsePublisherRecord )
461
+ {
462
+ gResponsePublisherRecordFile = record_location + " /" + responsepublisher_rec_filename;
463
+ gResponsePublisherRecordOfs .open (gResponsePublisherRecordFile , std::ofstream::out | std::ofstream::app);
464
+ if (!gResponsePublisherRecordOfs .is_open ())
465
+ {
466
+ SWSS_LOG_ERROR (" Failed to open Response Publisher recording file %s" ,
467
+ gResponsePublisherRecordFile .c_str ());
468
+ gResponsePublisherRecord = false ;
469
+ }
470
+ else
471
+ {
472
+ gResponsePublisherRecordOfs << getTimestamp () << " |recording started"
473
+ << endl;
474
+ }
475
+ }
476
+
450
477
attr.id = SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY;
451
478
attr.value .ptr = (void *)on_port_state_change;
452
479
attrs.push_back (attr);
@@ -644,7 +671,7 @@ int main(int argc, char **argv)
644
671
}
645
672
else
646
673
{
647
- orchDaemon = make_shared<FabricOrchDaemon>(&appl_db, &config_db, &state_db, chassis_app_db.get ());
674
+ orchDaemon = make_shared<FabricOrchDaemon>(&appl_db, &config_db, &state_db, chassis_app_db.get ());
648
675
}
649
676
650
677
if (!orchDaemon->init ())
0 commit comments