42 class EMANE::QueueMetricManager::Implementation
54 std::uint32_t u32MaxQueueSize,
55 std::uint32_t u32CurrentQueueDepth,
56 std::uint32_t u32NumDiscards,
59 std::lock_guard<std::mutex> m(mutex_);
61 QueueData & rData = getQueueData_i(u16QueueId);
64 rData.u32NumSamples_ += 1;
67 rData.sumDelayMicroseconds_ += delayMicroseconds;
70 if(rData.u32MaxQueueSize_ != u32MaxQueueSize)
73 rData.u32MaxQueueSize_ = u32MaxQueueSize;
76 rData.u32QueueHighWaterMark_ = 0;
80 if(rData.u32QueueHighWaterMark_ < u32CurrentQueueDepth)
82 rData.u32QueueHighWaterMark_ = u32CurrentQueueDepth;
86 if(rData.u32NumDiscardsHighWaterMark_ < u32NumDiscards)
88 rData.u32NumDiscardsHighWaterMark_ = u32NumDiscards;
95 std::lock_guard<std::mutex> m(mutex_);
99 for(
auto & iter : queueDataMap_)
103 iter.second.u32NumSamples_)};
106 iter.second.u32MaxQueueSize_,
107 iter.second.u32QueueHighWaterMark_,
108 iter.second.u32NumDiscardsHighWaterMark_,
109 avgDelayMicroseconds};
111 metrics.push_back(metric);
121 bool addQueueMetric(std::uint16_t queueId, std::uint32_t u32MaxQueueSize)
123 std::lock_guard<std::mutex> m(mutex_);
125 return queueDataMap_.insert(std::make_pair(queueId, QueueData(u32MaxQueueSize))).second;
131 std::lock_guard<std::mutex> m(mutex_);
133 auto iter = queueDataMap_.find(queueId);
135 if(iter != queueDataMap_.end())
138 queueDataMap_.erase(iter);
151 std::uint32_t u32MaxQueueSize_;
152 std::uint32_t u32QueueHighWaterMark_;
153 std::uint32_t u32NumSamples_;
154 std::uint32_t u32NumDiscardsHighWaterMark_;
159 u32QueueHighWaterMark_{},
161 u32NumDiscardsHighWaterMark_{},
162 sumDelayMicroseconds_{}
165 QueueData(std::uint32_t u32MaxSize) :
166 u32MaxQueueSize_(u32MaxSize),
167 u32QueueHighWaterMark_{},
169 u32NumDiscardsHighWaterMark_{},
170 sumDelayMicroseconds_{}
175 u32NumDiscardsHighWaterMark_ = 0;
177 sumDelayMicroseconds_ = EMANE::Microseconds::zero();
181 u32QueueHighWaterMark_ = 0;
185 using QueueDataMap = std::map<std::uint16_t, QueueData>;
189 QueueDataMap queueDataMap_;
194 QueueData & getQueueData_i(std::uint16_t queueId)
196 auto iter = queueDataMap_.find(queueId);
198 if(iter == queueDataMap_.end())
201 iter = queueDataMap_.insert(std::make_pair(queueId, QueueData())).first;
216 else if(samples == 1)
218 return delayMicroseconds;
222 return EMANE::Microseconds::zero();
229 pImpl_{
new Implementation{
id}}
240 return pImpl_->getQueueMetrics();
246 std::uint32_t u32MaxQueueSize,
247 std::uint32_t u32CurrentQueueDepth,
248 std::uint32_t u32NumDiscards,
251 pImpl_->updateQueueMetric(u16QueueId,
253 u32CurrentQueueDepth,
262 return pImpl_->addQueueMetric(u16QueueId, u32MaxQueueSize);
269 return pImpl_->removeQueueMetric(u16QueueId);
bool removeQueueMetric(std::uint16_t u16QueueId)
Controls::R2RIQueueMetrics getQueueMetrics()
std::chrono::microseconds Microseconds
std::chrono::duration< double > DoubleSeconds
void updateQueueMetric(std::uint16_t u16QueueId, std::uint32_t u32QueueSize, std::uint32_t u32QueueDepth, std::uint32_t u32NumDiscards, const Microseconds &queueDelay)
const float USEC_PER_SEC_F
QueueMetricManager(NEMId id)
std::list< R2RIQueueMetric > R2RIQueueMetrics
R2RI queue metrics are used in conjunction with the R2RIQueueMetricControlMessage to inform an NEM's ...
bool addQueueMetric(std::uint16_t u16QueueId, std::uint32_t u32QueueSize)