@@ -233,9 +233,9 @@ static char* hostif_vlan_tag[] = {
233
233
*/
234
234
PortsOrch::PortsOrch (DBConnector *db, vector<table_name_with_pri_t > &tableNames, DBConnector *chassisAppDb) :
235
235
Orch(db, tableNames),
236
- port_stat_manager(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, PORT_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true ),
237
- port_buffer_drop_stat_manager(PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP, StatsMode::READ, PORT_BUFFER_DROP_STAT_POLLING_INTERVAL_MS, true ),
238
- queue_stat_manager(QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, QUEUE_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true )
236
+ port_stat_manager(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, PORT_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, false ),
237
+ port_buffer_drop_stat_manager(PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP, StatsMode::READ, PORT_BUFFER_DROP_STAT_POLLING_INTERVAL_MS, false ),
238
+ queue_stat_manager(QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, QUEUE_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, false )
239
239
{
240
240
SWSS_LOG_ENTER ();
241
241
@@ -2131,19 +2131,21 @@ bool PortsOrch::initPort(const string &alias, const int index, const set<int> &l
2131
2131
vector<FieldValueTuple> fields;
2132
2132
fields.push_back (tuple);
2133
2133
m_counterTable->set (" " , fields);
2134
+
2134
2135
// Install a flex counter for this port to track stats
2135
- std::unordered_set<std::string> counter_stats;
2136
- for (const auto & it: port_stat_ids)
2136
+ auto flex_counters_orch = gDirectory .get <FlexCounterOrch*>();
2137
+ /* Delay installing the counters if they are yet enabled
2138
+ If they are enabled, install the counters immediately */
2139
+ if (flex_counters_orch->getPortCountersState ())
2137
2140
{
2138
- counter_stats.emplace (sai_serialize_port_stat (it));
2141
+ auto port_counter_stats = generateCounterStats (PORT_STAT_COUNTER_FLEX_COUNTER_GROUP);
2142
+ port_stat_manager.setCounterIdList (p.m_port_id , CounterType::PORT, port_counter_stats);
2139
2143
}
2140
- port_stat_manager.setCounterIdList (p.m_port_id , CounterType::PORT, counter_stats);
2141
- std::unordered_set<std::string> port_buffer_drop_stats;
2142
- for (const auto & it: port_buffer_drop_stat_ids)
2144
+ if (flex_counters_orch->getPortBufferDropCountersState ())
2143
2145
{
2144
- port_buffer_drop_stats.emplace (sai_serialize_port_stat (it));
2146
+ auto port_buffer_drop_stats = generateCounterStats (PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP);
2147
+ port_buffer_drop_stat_manager.setCounterIdList (p.m_port_id , CounterType::PORT, port_buffer_drop_stats);
2145
2148
}
2146
- port_buffer_drop_stat_manager.setCounterIdList (p.m_port_id , CounterType::PORT, port_buffer_drop_stats);
2147
2149
2148
2150
PortUpdate update = { p, true };
2149
2151
notify (SUBJECT_TYPE_PORT_CHANGE, static_cast <void *>(&update));
@@ -2176,8 +2178,11 @@ void PortsOrch::deInitPort(string alias, sai_object_id_t port_id)
2176
2178
p.m_port_id = port_id;
2177
2179
2178
2180
/* remove port from flex_counter_table for updating counters */
2179
- port_stat_manager.clearCounterIdList (p.m_port_id );
2180
-
2181
+ auto flex_counters_orch = gDirectory .get <FlexCounterOrch*>();
2182
+ if ((flex_counters_orch->getPortCountersState ()))
2183
+ {
2184
+ port_stat_manager.clearCounterIdList (p.m_port_id );
2185
+ }
2181
2186
/* remove port name map from counter table */
2182
2187
m_counter_db->hdel (COUNTERS_PORT_NAME_MAP, alias);
2183
2188
@@ -4699,6 +4704,38 @@ void PortsOrch::generatePriorityGroupMapPerPort(const Port& port)
4699
4704
CounterCheckOrch::getInstance ().addPort (port);
4700
4705
}
4701
4706
4707
+ void PortsOrch::generatePortCounterMap ()
4708
+ {
4709
+ if (m_isPortCounterMapGenerated)
4710
+ {
4711
+ return ;
4712
+ }
4713
+
4714
+ auto port_counter_stats = generateCounterStats (PORT_STAT_COUNTER_FLEX_COUNTER_GROUP);
4715
+ for (const auto & it: m_portList)
4716
+ {
4717
+ port_stat_manager.setCounterIdList (it.second .m_port_id , CounterType::PORT, port_counter_stats);
4718
+ }
4719
+
4720
+ m_isPortCounterMapGenerated = true ;
4721
+ }
4722
+
4723
+ void PortsOrch::generatePortBufferDropCounterMap ()
4724
+ {
4725
+ if (m_isPortBufferDropCounterMapGenerated)
4726
+ {
4727
+ return ;
4728
+ }
4729
+
4730
+ auto port_buffer_drop_stats = generateCounterStats (PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP);
4731
+ for (const auto & it: m_portList)
4732
+ {
4733
+ port_buffer_drop_stat_manager.setCounterIdList (it.second .m_port_id , CounterType::PORT, port_buffer_drop_stats);
4734
+ }
4735
+
4736
+ m_isPortBufferDropCounterMapGenerated = true ;
4737
+ }
4738
+
4702
4739
void PortsOrch::doTask (NotificationConsumer &consumer)
4703
4740
{
4704
4741
SWSS_LOG_ENTER ();
@@ -5565,6 +5602,26 @@ bool PortsOrch::setVoqInbandIntf(string &alias, string &type)
5565
5602
return true ;
5566
5603
}
5567
5604
5605
+ std::unordered_set<std::string> PortsOrch::generateCounterStats (const string& type)
5606
+ {
5607
+ std::unordered_set<std::string> counter_stats;
5608
+ if (type == PORT_STAT_COUNTER_FLEX_COUNTER_GROUP)
5609
+ {
5610
+ for (const auto & it: port_stat_ids)
5611
+ {
5612
+ counter_stats.emplace (sai_serialize_port_stat (it));
5613
+ }
5614
+ }
5615
+ else if (type == PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP)
5616
+ {
5617
+ for (const auto & it: port_buffer_drop_stat_ids)
5618
+ {
5619
+ counter_stats.emplace (sai_serialize_port_stat (it));
5620
+ }
5621
+ }
5622
+ return counter_stats;
5623
+ }
5624
+
5568
5625
void PortsOrch::voqSyncAddLag (Port &lag)
5569
5626
{
5570
5627
int32_t switch_id = lag.m_system_lag_info .switch_id ;
0 commit comments