@@ -2243,10 +2243,10 @@ sai_status_t processBulkEvent(
2243
2243
sai_status_t processEvent (
2244
2244
_In_ swss::ConsumerTable &consumer)
2245
2245
{
2246
- std::lock_guard<std::mutex> lock (g_mutex);
2247
-
2248
2246
SWSS_LOG_ENTER ();
2249
2247
2248
+ std::lock_guard<std::mutex> lock (g_mutex);
2249
+
2250
2250
swss::KeyOpFieldsValuesTuple kco;
2251
2251
2252
2252
if (isInitViewMode ())
@@ -2472,18 +2472,40 @@ sai_status_t processEvent(
2472
2472
void processFlexCounterEvent (
2473
2473
_In_ swss::ConsumerStateTable &consumer)
2474
2474
{
2475
- std::lock_guard<std::mutex> lock (g_mutex);
2476
-
2477
2475
SWSS_LOG_ENTER ();
2478
2476
2477
+ std::lock_guard<std::mutex> lock (g_mutex);
2478
+
2479
2479
swss::KeyOpFieldsValuesTuple kco;
2480
2480
consumer.pop (kco);
2481
2481
2482
2482
const auto &key = kfvKey (kco);
2483
2483
const auto &op = kfvOp (kco);
2484
2484
2485
+ std::size_t delimiter = key.find_last_of (" :" );
2486
+
2487
+ if (delimiter == std::string::npos)
2488
+ {
2489
+ SWSS_LOG_ERROR (" Failed to parse the key %s" , key.c_str ());
2490
+ return ;
2491
+ }
2492
+
2493
+ const auto intervalStr = key.substr (delimiter + 1 );
2494
+ const auto vidStr = key.substr (0 , delimiter);
2495
+ int pollInterval;
2496
+
2497
+ try
2498
+ {
2499
+ pollInterval = std::stoi (intervalStr);
2500
+ }
2501
+ catch (const std::invalid_argument)
2502
+ {
2503
+ SWSS_LOG_ERROR (" Failed to convert the poll intervall, key = %s" , key.c_str ());
2504
+ return ;
2505
+ }
2506
+
2485
2507
sai_object_id_t vid = SAI_NULL_OBJECT_ID;
2486
- sai_deserialize_object_id (key , vid);
2508
+ sai_deserialize_object_id (vidStr , vid);
2487
2509
sai_object_id_t rid = translate_vid_to_rid (vid);
2488
2510
sai_object_type_t objectType = sai_object_type_query (rid);
2489
2511
@@ -2497,11 +2519,11 @@ void processFlexCounterEvent(
2497
2519
{
2498
2520
if (objectType == SAI_OBJECT_TYPE_PORT)
2499
2521
{
2500
- FlexCounter::removePort (vid);
2522
+ FlexCounter::removePort (vid, pollInterval );
2501
2523
}
2502
2524
else if (objectType == SAI_OBJECT_TYPE_QUEUE)
2503
2525
{
2504
- FlexCounter::removeQueue (vid);
2526
+ FlexCounter::removeQueue (vid, pollInterval );
2505
2527
}
2506
2528
else
2507
2529
{
@@ -2521,7 +2543,7 @@ void processFlexCounterEvent(
2521
2543
sai_deserialize_port_stat (str, stat);
2522
2544
portCounterIds.push_back (stat);
2523
2545
}
2524
- FlexCounter::setPortCounterList (vid, rid, portCounterIds);
2546
+ FlexCounter::setPortCounterList (vid, rid, pollInterval, portCounterIds);
2525
2547
}
2526
2548
else if (objectType == SAI_OBJECT_TYPE_QUEUE && field == PFC_WD_QUEUE_COUNTER_ID_LIST)
2527
2549
{
@@ -2532,7 +2554,7 @@ void processFlexCounterEvent(
2532
2554
sai_deserialize_queue_stat (str, stat);
2533
2555
queueCounterIds.push_back (stat);
2534
2556
}
2535
- FlexCounter::setQueueCounterList (vid, rid, queueCounterIds);
2557
+ FlexCounter::setQueueCounterList (vid, rid, pollInterval, queueCounterIds);
2536
2558
}
2537
2559
else if (objectType == SAI_OBJECT_TYPE_QUEUE && field == PFC_WD_QUEUE_ATTR_ID_LIST)
2538
2560
{
@@ -2544,7 +2566,7 @@ void processFlexCounterEvent(
2544
2566
queueAttrIds.push_back (attr);
2545
2567
}
2546
2568
2547
- FlexCounter::setQueueAttrList (vid, rid, queueAttrIds);
2569
+ FlexCounter::setQueueAttrList (vid, rid, pollInterval, queueAttrIds);
2548
2570
}
2549
2571
else
2550
2572
{
@@ -2557,19 +2579,41 @@ void processFlexCounterEvent(
2557
2579
void processFlexCounterPluginEvent (
2558
2580
_In_ swss::ConsumerStateTable &consumer)
2559
2581
{
2560
- std::lock_guard<std::mutex> lock (g_mutex);
2561
-
2562
2582
SWSS_LOG_ENTER ();
2563
2583
2584
+ std::lock_guard<std::mutex> lock (g_mutex);
2585
+
2564
2586
swss::KeyOpFieldsValuesTuple kco;
2565
2587
consumer.pop (kco);
2566
2588
2567
2589
const auto &key = kfvKey (kco);
2568
2590
const auto &op = kfvOp (kco);
2569
2591
2592
+ std::size_t delimiter = key.find_last_of (" :" );
2593
+
2594
+ if (delimiter == std::string::npos)
2595
+ {
2596
+ SWSS_LOG_ERROR (" Failed to parse the key %s" , key.c_str ());
2597
+ return ;
2598
+ }
2599
+
2600
+ const auto intervalStr = key.substr (delimiter + 1 );
2601
+ const auto sha = key.substr (0 , delimiter);
2602
+ int pollInterval;
2603
+
2604
+ try
2605
+ {
2606
+ pollInterval = std::stoi (intervalStr);
2607
+ }
2608
+ catch (const std::invalid_argument)
2609
+ {
2610
+ SWSS_LOG_ERROR (" Failed to convert the poll intervall, key = %s" , key.c_str ());
2611
+ return ;
2612
+ }
2613
+
2570
2614
if (op == DEL_COMMAND)
2571
2615
{
2572
- FlexCounter::removeCounterPlugin (key );
2616
+ FlexCounter::removeCounterPlugin (sha, pollInterval );
2573
2617
return ;
2574
2618
}
2575
2619
@@ -2586,11 +2630,11 @@ void processFlexCounterPluginEvent(
2586
2630
2587
2631
if (value == sai_serialize_object_type (SAI_OBJECT_TYPE_PORT))
2588
2632
{
2589
- FlexCounter::addPortCounterPlugin (key );
2633
+ FlexCounter::addPortCounterPlugin (sha, pollInterval );
2590
2634
}
2591
2635
else if (value == sai_serialize_object_type (SAI_OBJECT_TYPE_QUEUE))
2592
2636
{
2593
- FlexCounter::addQueueCounterPlugin (key );
2637
+ FlexCounter::addQueueCounterPlugin (sha, pollInterval );
2594
2638
}
2595
2639
else
2596
2640
{
@@ -3036,6 +3080,7 @@ void performWarmRestart()
3036
3080
3037
3081
void onSyncdStart (bool warmStart)
3038
3082
{
3083
+ SWSS_LOG_ENTER ();
3039
3084
std::lock_guard<std::mutex> lock (g_mutex);
3040
3085
3041
3086
/*
@@ -3046,7 +3091,7 @@ void onSyncdStart(bool warmStart)
3046
3091
* need to use a lock here to prevent that.
3047
3092
*/
3048
3093
3049
- SWSS_LOG_ENTER ();
3094
+
3050
3095
3051
3096
SWSS_LOG_TIMER (" on syncd start" );
3052
3097
@@ -3260,13 +3305,6 @@ int syncd_main(int argc, char **argv)
3260
3305
onSyncdStart (options.startType == SAI_WARM_BOOT);
3261
3306
SWSS_LOG_NOTICE (" after onSyncdStart" );
3262
3307
3263
- if (options.disableCountersThread == false )
3264
- {
3265
- SWSS_LOG_NOTICE (" starting counters thread" );
3266
-
3267
- startCountersThread (options.countersThreadIntervalInSeconds );
3268
- }
3269
-
3270
3308
startNotificationsProcessingThread ();
3271
3309
3272
3310
SWSS_LOG_NOTICE (" syncd listening for events" );
@@ -3322,8 +3360,6 @@ int syncd_main(int argc, char **argv)
3322
3360
exit_and_notify (EXIT_FAILURE);
3323
3361
}
3324
3362
3325
- endCountersThread ();
3326
-
3327
3363
if (warmRestartHint)
3328
3364
{
3329
3365
const char *warmBootWriteFile = profile_get_value (0 , SAI_KEY_WARM_BOOT_WRITE_FILE);
0 commit comments