Line data Source code
1 : /*
2 : * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved.
3 : */
4 :
5 : #include <boost/uuid/uuid_io.hpp>
6 : #include <boost/date_time/posix_time/posix_time.hpp>
7 : #include <boost/date_time/posix_time/posix_time_io.hpp>
8 :
9 : #include <vnc_cfg_types.h>
10 : #include <base/util.h>
11 :
12 : #include <oper/agent_profile_types.h>
13 :
14 : #include <cmn/agent_cmn.h>
15 : #include <cfg/cfg_init.h>
16 : #include <oper/operdb_init.h>
17 : #include <oper/agent_profile.h>
18 :
19 : #include <oper/interface_common.h>
20 : #include <oper/vn.h>
21 : #include <oper/vm.h>
22 : #include <oper/vrf.h>
23 : #include <filter/acl.h>
24 : #include "db/db.h"
25 :
26 : using namespace std;
27 :
28 1 : AgentProfile::AgentProfile(Agent *agent, bool enable) :
29 385 : agent_(agent), timer_(NULL), enable_(enable) {
30 :
31 1 : TaskScheduler *task = TaskScheduler::GetInstance();
32 1 : timer_ = TimerManager::CreateTimer
33 1 : (*(agent_->event_manager())->io_service(), "Agent Profile",
34 : task->GetTaskId("Agent::Profile"), 0);
35 1 : time(&start_time_);
36 1 : }
37 :
38 387 : AgentProfile::~AgentProfile() {
39 1 : TimerManager::DeleteTimer(timer_);
40 391 : }
41 :
42 1 : void AgentProfile::Shutdown() {
43 1 : timer_->Cancel();
44 1 : }
45 :
46 1 : void AgentProfile::InitDone() {
47 1 : if (enable_) {
48 1 : timer_->Start(kProfileTimeout, boost::bind(&AgentProfile::TimerRun,
49 : this));
50 : }
51 1 : }
52 :
53 0 : bool AgentProfile::TimerRun() {
54 0 : ProfileData *data = GetLastProfileData();
55 0 : data->Get(agent_);
56 0 : if (pkt_flow_stats_cb_.empty() == false) {
57 0 : pkt_flow_stats_cb_(data);
58 : }
59 0 : if (ksync_stats_cb_.empty() == false) {
60 0 : ksync_stats_cb_(data);
61 : }
62 0 : if (flow_stats_cb_.empty() == false) {
63 0 : flow_stats_cb_(data);
64 : }
65 0 : Log();
66 0 : return true;
67 : }
68 :
69 0 : string GetProfileString(DBTable *table, const char *name) {
70 0 : stringstream str;
71 : str << setw(16) << name
72 0 : << " Size " << setw(6) << table->Size()
73 0 : << " Enqueue " << setw(6) << table->enqueue_count()
74 0 : << " Input " << setw(6) << table->input_count()
75 0 : << " Notify " << setw(6) << table->notify_count();
76 0 : return str.str();
77 0 : }
78 :
79 0 : void AgentProfile::Log() {
80 0 : }
81 :
82 0 : ProfileData *AgentProfile::GetLastProfileData() {
83 0 : uint16_t index = seconds_history_index_ % kSecondsHistoryCount;
84 0 : seconds_history_index_++;
85 0 : return &seconds_history_data_[index];
86 : }
87 :
88 0 : ProfileData *AgentProfile::GetProfileData(uint16_t index) {
89 0 : return &seconds_history_data_[index];
90 : }
91 : //////////////////////////////////////////////////////////////////////////////
92 : // ProfileData collection routines
93 : //////////////////////////////////////////////////////////////////////////////
94 1965 : void ProfileData::DBTableStats::Reset() {
95 1965 : db_entry_count_ = 0;
96 1965 : walker_count_ = 0;
97 1965 : enqueue_count_ = 0;
98 1965 : input_count_ = 0;
99 1965 : notify_count_ = 0;
100 1965 : }
101 :
102 0 : void ProfileData::DBTableStats::Get(const DBTable *table) {
103 0 : db_entry_count_ = table->Size();
104 0 : walker_count_ = table->walker_count();
105 0 : enqueue_count_ = table->enqueue_count();
106 0 : input_count_ = table->input_count();
107 0 : notify_count_ = table->notify_count();
108 0 : }
109 :
110 0 : void ProfileData::DBTableStats::Accumulate(const DBTableBase *table) {
111 0 : db_entry_count_ += table->Size();
112 0 : walker_count_ += table->walker_count();
113 0 : enqueue_count_ += table->enqueue_count();
114 0 : input_count_ += table->input_count();
115 0 : notify_count_ += table->notify_count();
116 0 : }
117 :
118 1965 : void ProfileData::WorkQueueStats::Reset() {
119 1965 : queue_count_ = 0;
120 1965 : enqueue_count_ = 0;
121 1965 : dequeue_count_ = 0;
122 1965 : max_queue_count_ = 0;
123 1965 : start_count_ = 0;
124 1965 : busy_time_ = 0;
125 1965 : }
126 :
127 393 : void ProfileData::FlowTokenStats::Reset() {
128 393 : add_tokens_ = 0;
129 393 : add_failures_ = 0;
130 393 : add_restarts_ = 0;
131 393 : ksync_tokens_ = 0;
132 393 : ksync_failures_ = 0;
133 393 : ksync_restarts_ = 0;
134 393 : update_tokens_ = 0;
135 393 : update_failures_ = 0;
136 393 : update_restarts_ = 0;
137 393 : del_tokens_ = 0;
138 393 : del_failures_ = 0;
139 393 : del_restarts_ = 0;
140 393 : }
141 :
142 393 : void ProfileData::FlowStats::Reset() {
143 393 : flow_count_ = 0;
144 393 : add_count_ = 0;
145 393 : del_count_= 0;
146 393 : audit_count_ = 0;
147 393 : reval_count_ = 0;
148 393 : recompute_count_ = 0;
149 393 : pkt_handler_queue_.Reset();
150 393 : flow_mgmt_queue_.Reset();
151 393 : flow_update_queue_.Reset();
152 393 : for (uint16_t i = 0; i < flow_event_queue_.size(); i++) {
153 0 : flow_event_queue_[i].Reset();
154 : }
155 393 : for (uint16_t i = 0; i < flow_tokenless_queue_.size(); i++) {
156 0 : flow_tokenless_queue_[i].Reset();
157 : }
158 393 : for (uint16_t i = 0; i < flow_delete_queue_.size(); i++) {
159 0 : flow_delete_queue_[i].Reset();
160 : }
161 :
162 393 : for (uint16_t i = 0; i < flow_ksync_queue_.size(); i++) {
163 0 : flow_ksync_queue_[i].Reset();
164 : }
165 :
166 393 : for (uint16_t i = 0; i < flow_stats_queue_.size(); i++) {
167 0 : flow_stats_queue_[i].Reset();
168 : }
169 393 : token_stats_.Reset();
170 393 : }
171 :
172 393 : void ProfileData::PktStats::Reset() {
173 393 : arp_count_ = 0;
174 393 : dhcp_count_ = 0;
175 393 : dns_count_ = 0;
176 393 : icmp_count_ = 0;
177 393 : }
178 786 : void ProfileData::XmppStats::Reset() {
179 786 : inet4_add_count_ = 0;
180 786 : inet4_del_count_ = 0;
181 786 : inet6_add_count_ = 0;
182 786 : inet6_del_count_ = 0;
183 786 : mcast_add_count_ = 0;
184 786 : mcast_del_count_ = 0;
185 786 : bridge_add_count_ = 0;
186 786 : bridge_del_count_ = 0;
187 786 : }
188 :
189 393 : ProfileData::ProfileData():time_() {
190 393 : flow_.Reset();
191 393 : pkt_.Reset();
192 393 : inet4_routes_.Reset();
193 393 : inet6_routes_.Reset();
194 393 : bridge_routes_.Reset();
195 393 : multicast_routes_.Reset();
196 393 : evpn_routes_.Reset();
197 393 : rx_stats_.Reset();
198 393 : tx_stats_.Reset();
199 393 : ksync_tx_queue_count_.Reset();
200 393 : ksync_rx_queue_count_.Reset();
201 393 : }
202 :
203 0 : void ProfileData::Get(Agent *agent) {
204 0 : std::ostringstream str;
205 0 : str << boost::posix_time::second_clock::local_time();
206 0 : time_ = str.str();
207 : DB::TableMap::const_iterator itr =
208 0 : agent->db()->const_begin();
209 : DB::TableMap::const_iterator itrend =
210 0 : agent->db()->const_end();
211 :
212 0 : profile_stats_table_.clear();
213 0 : for ( ;itr != itrend; ++itr) {
214 0 : if(itr->first.rfind(kV4UnicastRouteDbTableSuffix) !=
215 : std::string::npos) {
216 0 : inet4_routes_.Accumulate(itr->second);
217 0 : } else if (itr->first.rfind(kV6UnicastRouteDbTableSuffix) !=
218 : std::string::npos) {
219 0 : inet6_routes_.Accumulate(itr->second);
220 0 : } else if (itr->first.rfind(kL2RouteDbTableSuffix) !=
221 : std::string::npos) {
222 0 : bridge_routes_.Accumulate(itr->second);
223 0 : } else if (itr->first.rfind(kMcastRouteDbTableSuffix) !=
224 : std::string::npos) {
225 0 : multicast_routes_.Accumulate(itr->second);
226 0 : } else if (itr->first.rfind(kEvpnRouteDbTableSuffix) !=
227 : std::string::npos) {
228 0 : evpn_routes_.Accumulate(itr->second);
229 : } else {
230 : ProfileData::DBTableStats stats;
231 0 : stats.Get(dynamic_cast<DBTable*>(itr->second));
232 0 : profile_stats_table_.insert(make_pair(itr->first,stats));
233 : }
234 : }
235 :
236 0 : TaskScheduler *sched = TaskScheduler::GetInstance();
237 0 : task_stats_[2] = *sched->GetTaskGroupStats(2);
238 0 : task_stats_[1] = *sched->GetTaskGroupStats(1);
239 0 : task_stats_[4] = *sched->GetTaskGroupStats(4);
240 0 : task_stats_[6] = *sched->GetTaskGroupStats(6);
241 0 : task_stats_[9] = *sched->GetTaskGroupStats(9);
242 0 : task_stats_[5] = *sched->GetTaskGroupStats(5);
243 0 : task_stats_[11] = *sched->GetTaskGroupStats(11);
244 0 : task_stats_[8] = *sched->GetTaskGroupStats(8);
245 0 : }
246 :
247 : //////////////////////////////////////////////////////////////////////////////
248 : // Sandesh ProfileData routines
249 : //////////////////////////////////////////////////////////////////////////////
250 0 : static void DBStatsToSandesh(SandeshDBTableStats *stats, const string &table,
251 : const ProfileData::DBTableStats &db_stats) {
252 0 : stats->set_table(table);
253 0 : stats->set_db_entry_count(db_stats.db_entry_count_);
254 0 : stats->set_input_count(db_stats.input_count_);
255 0 : stats->set_walker_count(db_stats.walker_count_);
256 0 : stats->set_enqueue_count(db_stats.enqueue_count_);
257 0 : stats->set_notify_count(db_stats.notify_count_);
258 0 : }
259 :
260 0 : static void GetDBTableStats(SandeshDBTableStatsInfo *stats, int index,
261 : ProfileData *data) {
262 0 : stats->set_index(index);
263 0 : stats->set_time_str(data->time_);
264 0 : std::vector<SandeshDBTableStats> db_stats_list;
265 0 : SandeshDBTableStats db_stats;
266 : std::map<std::string, ProfileData::DBTableStats >::iterator itr =
267 0 : data->profile_stats_table_.begin();
268 :
269 0 : DBStatsToSandesh(&db_stats, "Ipv4 Unicast route", data->inet4_routes_);
270 0 : db_stats_list.push_back(db_stats);
271 0 : DBStatsToSandesh(&db_stats, "Ipv6 Unicast route", data->inet6_routes_);
272 0 : db_stats_list.push_back(db_stats);
273 0 : DBStatsToSandesh(&db_stats, "Multicast route", data->multicast_routes_);
274 0 : db_stats_list.push_back(db_stats);
275 0 : DBStatsToSandesh(&db_stats, "Evpn route", data->evpn_routes_);
276 0 : db_stats_list.push_back(db_stats);
277 0 : DBStatsToSandesh(&db_stats, "Bridge", data->bridge_routes_);
278 0 : db_stats_list.push_back(db_stats);
279 0 : while (itr != data->profile_stats_table_.end()) {
280 0 : if(itr->first.find(kInterfaceDbTablePrefix) != std::string::npos) {
281 0 : DBStatsToSandesh(&db_stats, "Interface", itr->second);
282 0 : db_stats_list.push_back(db_stats);
283 0 : } else if (itr->first.find(kMplsDbTablePrefix) != std::string::npos) {
284 0 : DBStatsToSandesh(&db_stats, "Mpls", itr->second);
285 0 : db_stats_list.push_back(db_stats);
286 0 : } else if (itr->first.find(kVnDbTablePrefix) != std::string::npos) {
287 0 : DBStatsToSandesh(&db_stats, "Vn", itr->second);
288 0 : db_stats_list.push_back(db_stats);
289 0 : } else if (itr->first.find(kVmDbTablePrefix) != std::string::npos) {
290 0 : DBStatsToSandesh(&db_stats, "Vm", itr->second);
291 0 : db_stats_list.push_back(db_stats);
292 0 : } else if (itr->first.find(kVrfDbTablePrefix) != std::string::npos) {
293 0 : DBStatsToSandesh(&db_stats, "Vrf", itr->second);
294 0 : db_stats_list.push_back(db_stats);
295 0 : } else if (itr->first.find(kAclDbTablePrefix) != std::string::npos) {
296 0 : DBStatsToSandesh(&db_stats, "Acl", itr->second);
297 0 : db_stats_list.push_back(db_stats);
298 : }
299 0 : ++itr;
300 : }
301 0 : stats->set_stats(db_stats_list);
302 0 : }
303 :
304 0 : void SandeshDBTableStatsRequest::HandleRequest() const {
305 0 : SandeshDBTableStatsList *resp = new SandeshDBTableStatsList();
306 0 : resp->set_context(context());
307 :
308 0 : Agent *agent = Agent::GetInstance();
309 0 : AgentProfile *profile = agent->oper_db()->agent_profile();
310 0 : uint16_t end = profile->seconds_history_index();
311 0 : uint16_t start = 0;
312 0 : if (end > AgentProfile::kSecondsHistoryCount)
313 0 : start = end - AgentProfile::kSecondsHistoryCount;
314 :
315 0 : std::vector<SandeshDBTableStatsInfo> stats_list;
316 0 : for (uint16_t i = start; i < end; i++) {
317 0 : uint16_t index = i % AgentProfile::kSecondsHistoryCount;
318 0 : ProfileData *data = profile->GetProfileData(index);
319 0 : SandeshDBTableStatsInfo stats;
320 0 : GetDBTableStats(&stats, index, data);
321 0 : stats_list.push_back(stats);
322 0 : }
323 0 : resp->set_stats(stats_list);
324 :
325 0 : resp->Response();
326 0 : }
327 :
328 0 : static void GetFlowStats(SandeshFlowStats *stats, int index,
329 : ProfileData *data) {
330 0 : stats->set_index(index);
331 0 : stats->set_time_str(data->time_);
332 0 : stats->set_flow_count(data->flow_.flow_count_);
333 0 : stats->set_add_count(data->flow_.add_count_);
334 0 : stats->set_del_count(data->flow_.del_count_);
335 0 : stats->set_reval_count(data->flow_.reval_count_);
336 0 : stats->set_recompute_count(data->flow_.recompute_count_);
337 0 : stats->set_audit_count(data->flow_.audit_count_);
338 0 : stats->set_vrouter_responses(data->flow_.vrouter_responses_);
339 0 : stats->set_vrouter_error(data->flow_.vrouter_error_);
340 0 : }
341 :
342 0 : void SandeshFlowStatsRequest::HandleRequest() const {
343 0 : SandeshFlowStatsList *resp = new SandeshFlowStatsList();
344 0 : resp->set_context(context());
345 :
346 0 : Agent *agent = Agent::GetInstance();
347 0 : AgentProfile *profile = agent->oper_db()->agent_profile();
348 0 : uint16_t end = profile->seconds_history_index();
349 0 : uint16_t start = 0;
350 0 : if (end > AgentProfile::kSecondsHistoryCount)
351 0 : start = end - AgentProfile::kSecondsHistoryCount;
352 :
353 0 : std::vector<SandeshFlowStats> stats_list;
354 0 : for (uint16_t i = start; i < end; i++) {
355 0 : uint16_t index = i % AgentProfile::kSecondsHistoryCount;
356 0 : ProfileData *data = profile->GetProfileData(index);
357 0 : SandeshFlowStats stats;
358 0 : GetFlowStats(&stats, index, data);
359 0 : stats_list.push_back(stats);
360 0 : }
361 0 : resp->set_stats(stats_list);
362 0 : resp->Response();
363 0 : }
364 :
365 0 : static void GetTaskStats(TaskProfileStats *stats, int index,
366 : ProfileData *data) {
367 0 : stats->set_index(index);
368 :
369 0 : TaskStats *task_stats = NULL;
370 : // Flow Handler
371 0 : task_stats = &data->task_stats_[2];
372 0 : stats->set_flow_wait(task_stats->wait_count_);
373 0 : stats->set_flow_run(task_stats->enqueue_count_);
374 0 : stats->set_flow_defer(task_stats->defer_count_);
375 :
376 : // DB
377 0 : task_stats = &data->task_stats_[1];
378 0 : stats->set_db_wait(task_stats->wait_count_);
379 0 : stats->set_db_run(task_stats->enqueue_count_);
380 0 : stats->set_db_defer(task_stats->defer_count_);
381 :
382 : // Stats Collector
383 0 : task_stats = &data->task_stats_[4];
384 0 : stats->set_stats_wait(task_stats->wait_count_);
385 0 : stats->set_stats_run(task_stats->enqueue_count_);
386 0 : stats->set_stats_defer(task_stats->defer_count_);
387 :
388 : // Io-Reader
389 0 : task_stats = &data->task_stats_[6];
390 0 : stats->set_io_wait(task_stats->wait_count_);
391 0 : stats->set_io_run(task_stats->enqueue_count_);
392 0 : stats->set_io_defer(task_stats->defer_count_);
393 :
394 : // Agent::PktFlowResponder
395 0 : task_stats = &data->task_stats_[9];
396 0 : stats->set_flow_resp_wait(task_stats->wait_count_);
397 0 : stats->set_flow_resp_run(task_stats->enqueue_count_);
398 0 : stats->set_flow_resp_defer(task_stats->defer_count_);
399 : // Sadnesh::RecvQueue
400 0 : task_stats = &data->task_stats_[5];
401 0 : stats->set_sandesh_rcv_wait(task_stats->wait_count_);
402 0 : stats->set_sandesh_rcv_run(task_stats->enqueue_count_);
403 0 : stats->set_sandesh_rcv_defer(task_stats->defer_count_);
404 : // bgp::Config
405 0 : task_stats = &data->task_stats_[11];
406 0 : stats->set_bgp_cfg_wait(task_stats->wait_count_);
407 0 : stats->set_bgp_cfg_run(task_stats->enqueue_count_);
408 0 : stats->set_bgp_cfg_defer(task_stats->defer_count_);
409 : // KSync
410 0 : task_stats = &data->task_stats_[8];
411 0 : stats->set_ksync_wait(task_stats->wait_count_);
412 0 : stats->set_ksync_run(task_stats->enqueue_count_);
413 0 : stats->set_ksync_defer(task_stats->defer_count_);
414 0 : }
415 :
416 0 : void SandeshTaskStatsRequest::HandleRequest() const {
417 0 : SandeshTaskStatsList *resp = new SandeshTaskStatsList();
418 0 : resp->set_context(context());
419 :
420 0 : Agent *agent = Agent::GetInstance();
421 0 : AgentProfile *profile = agent->oper_db()->agent_profile();
422 0 : uint16_t end = profile->seconds_history_index();
423 0 : uint16_t start = 0;
424 0 : if (end > AgentProfile::kSecondsHistoryCount)
425 0 : start = end - AgentProfile::kSecondsHistoryCount;
426 :
427 0 : std::vector<TaskProfileStats> stats_list;
428 0 : for (uint16_t i = start; i < end; i++) {
429 0 : uint16_t index = i % AgentProfile::kSecondsHistoryCount;
430 0 : ProfileData *data = profile->GetProfileData(index);
431 0 : TaskProfileStats stats;
432 0 : GetTaskStats(&stats, index, data);
433 0 : stats_list.push_back(stats);
434 0 : }
435 0 : resp->set_stats(stats_list);
436 0 : resp->Response();
437 0 : }
438 :
439 0 : static void GetOneQueueSummary(SandeshFlowQueueSummaryOneInfo *one,
440 : ProfileData::WorkQueueStats *stats) {
441 0 : one->set_qcount(stats->queue_count_);
442 0 : one->set_enqueues(stats->enqueue_count_);
443 0 : one->set_dequeues(stats->dequeue_count_);
444 0 : one->set_max_qlen(stats->max_queue_count_);
445 0 : one->set_starts(stats->start_count_);
446 0 : one->set_busy_msec(stats->busy_time_);
447 0 : }
448 :
449 0 : static void GetQueueSummaryInfo(SandeshFlowQueueSummaryInfo *info, int index,
450 : ProfileData *data) {
451 0 : ProfileData::FlowStats *flow_stats = &data->flow_;
452 :
453 0 : info->set_index(index);
454 0 : info->set_time_str(data->time_);
455 : // flow_event_queue
456 0 : uint64_t qcount = 0;
457 0 : uint64_t enqueues = 0;
458 0 : uint64_t dequeues = 0;
459 0 : uint64_t max_qlen = 0;
460 0 : uint64_t busy_time = 0;
461 0 : uint64_t starts = 0;
462 : std::vector<ProfileData::WorkQueueStats>::const_iterator it =
463 0 : flow_stats->flow_event_queue_.begin();
464 0 : while (it != flow_stats->flow_event_queue_.end()) {
465 0 : qcount += it->queue_count_;
466 0 : enqueues += it->enqueue_count_;
467 0 : dequeues += it->dequeue_count_;
468 0 : busy_time += it->busy_time_;
469 0 : starts += it->start_count_;
470 0 : if (it->max_queue_count_ > max_qlen) {
471 0 : max_qlen = it->max_queue_count_;
472 : }
473 0 : it++;
474 : }
475 0 : SandeshFlowQueueSummaryOneInfo one;
476 0 : one.set_qcount(qcount);
477 0 : one.set_enqueues(enqueues);
478 0 : one.set_dequeues(dequeues);
479 0 : one.set_max_qlen(max_qlen);
480 0 : one.set_starts(starts);
481 0 : one.set_busy_msec(busy_time);
482 0 : info->set_flow_event_queue(one);
483 :
484 : // flow_tokenless_queue
485 0 : qcount = 0;
486 0 : enqueues = 0;
487 0 : dequeues = 0;
488 0 : max_qlen = 0;
489 0 : busy_time = 0;
490 0 : starts = 0;
491 0 : it = flow_stats->flow_tokenless_queue_.begin();
492 0 : while (it != flow_stats->flow_tokenless_queue_.end()) {
493 0 : qcount += it->queue_count_;
494 0 : enqueues += it->enqueue_count_;
495 0 : dequeues += it->dequeue_count_;
496 0 : busy_time += it->busy_time_;
497 0 : starts += it->start_count_;
498 0 : if (it->max_queue_count_ > max_qlen) {
499 0 : max_qlen = it->max_queue_count_;
500 : }
501 0 : it++;
502 : }
503 0 : one.set_qcount(qcount);
504 0 : one.set_enqueues(enqueues);
505 0 : one.set_dequeues(dequeues);
506 0 : one.set_max_qlen(max_qlen);
507 0 : one.set_starts(starts);
508 0 : one.set_busy_msec(busy_time);
509 0 : info->set_flow_tokenless_queue(one);
510 :
511 : // flow_delete_queue
512 0 : qcount = 0;
513 0 : enqueues = 0;
514 0 : dequeues = 0;
515 0 : max_qlen = 0;
516 0 : busy_time = 0;
517 0 : starts = 0;
518 0 : it = flow_stats->flow_delete_queue_.begin();
519 0 : while (it != flow_stats->flow_delete_queue_.end()) {
520 0 : qcount += it->queue_count_;
521 0 : enqueues += it->enqueue_count_;
522 0 : dequeues += it->dequeue_count_;
523 0 : busy_time += it->busy_time_;
524 0 : starts += it->start_count_;
525 0 : if (it->max_queue_count_ > max_qlen) {
526 0 : max_qlen = it->max_queue_count_;
527 : }
528 0 : it++;
529 : }
530 0 : one.set_qcount(qcount);
531 0 : one.set_enqueues(enqueues);
532 0 : one.set_dequeues(dequeues);
533 0 : one.set_max_qlen(max_qlen);
534 0 : one.set_starts(starts);
535 0 : one.set_busy_msec(busy_time);
536 0 : info->set_flow_delete_queue(one);
537 :
538 : // flow_ksync_queue
539 0 : qcount = 0;
540 0 : enqueues = 0;
541 0 : dequeues = 0;
542 0 : max_qlen = 0;
543 0 : busy_time = 0;
544 0 : starts = 0;
545 0 : it = flow_stats->flow_ksync_queue_.begin();
546 0 : while (it != flow_stats->flow_ksync_queue_.end()) {
547 0 : qcount += it->queue_count_;
548 0 : enqueues += it->enqueue_count_;
549 0 : dequeues += it->dequeue_count_;
550 0 : busy_time += it->busy_time_;
551 0 : starts += it->start_count_;
552 0 : if (it->max_queue_count_ > max_qlen) {
553 0 : max_qlen = it->max_queue_count_;
554 : }
555 0 : it++;
556 : }
557 0 : one.set_qcount(qcount);
558 0 : one.set_enqueues(enqueues);
559 0 : one.set_dequeues(dequeues);
560 0 : one.set_max_qlen(max_qlen);
561 0 : one.set_starts(starts);
562 0 : one.set_busy_msec(busy_time);
563 0 : info->set_flow_ksync_queue(one);
564 :
565 : // flow_mgmt_queue
566 0 : GetOneQueueSummary(&one, &flow_stats->flow_mgmt_queue_);
567 0 : info->set_flow_mgmt_queue(one);
568 :
569 : // flow_update_queue
570 0 : GetOneQueueSummary(&one, &flow_stats->flow_update_queue_);
571 0 : info->set_flow_update_queue(one);
572 :
573 : // flow_stats_queue
574 0 : qcount = 0;
575 0 : enqueues = 0;
576 0 : dequeues = 0;
577 0 : max_qlen = 0;
578 0 : busy_time = 0;
579 0 : starts = 0;
580 0 : it = flow_stats->flow_stats_queue_.begin();
581 0 : while (it != flow_stats->flow_stats_queue_.end()) {
582 0 : qcount += it->queue_count_;
583 0 : enqueues += it->enqueue_count_;
584 0 : dequeues += it->dequeue_count_;
585 0 : busy_time += it->busy_time_;
586 0 : starts += it->start_count_;
587 0 : if (it->max_queue_count_ > max_qlen) {
588 0 : max_qlen = it->max_queue_count_;
589 : }
590 0 : it++;
591 : }
592 0 : one.set_qcount(qcount);
593 0 : one.set_enqueues(enqueues);
594 0 : one.set_dequeues(dequeues);
595 0 : one.set_max_qlen(max_qlen);
596 0 : one.set_starts(starts);
597 0 : one.set_busy_msec(busy_time);
598 0 : info->set_flow_stats_queue(one);
599 :
600 : // pkt_handler queue
601 0 : GetOneQueueSummary(&one, &flow_stats->pkt_handler_queue_);
602 0 : info->set_pkt_handler_queue(one);
603 :
604 : // ksync_tx_queue
605 0 : GetOneQueueSummary(&one, &data->ksync_tx_queue_count_);
606 0 : info->set_ksync_tx_queue(one);
607 :
608 : // ksync_rx_queue
609 0 : GetOneQueueSummary(&one, &data->ksync_rx_queue_count_);
610 0 : info->set_ksync_rx_queue(one);
611 :
612 0 : SandeshFlowTokenInfo token_info;
613 0 : ProfileData::FlowTokenStats *token_stats = &flow_stats->token_stats_;
614 0 : token_info.set_add_tokens(token_stats->add_tokens_);
615 0 : token_info.set_add_token_full(token_stats->add_failures_);
616 0 : token_info.set_add_token_restarts(token_stats->add_restarts_);
617 0 : token_info.set_ksync_tokens(token_stats->ksync_tokens_);
618 0 : token_info.set_ksync_token_full(token_stats->ksync_failures_);
619 0 : token_info.set_ksync_token_restarts(token_stats->ksync_restarts_);
620 0 : token_info.set_update_tokens(token_stats->update_tokens_);
621 0 : token_info.set_update_token_full(token_stats->update_failures_);
622 0 : token_info.set_update_token_restarts(token_stats->update_restarts_);
623 0 : token_info.set_delete_tokens(token_stats->del_tokens_);
624 0 : token_info.set_delete_token_full(token_stats->del_failures_);
625 0 : token_info.set_delete_token_restarts(token_stats->del_restarts_);
626 0 : info->set_token_stats(token_info);
627 0 : }
628 :
629 0 : void SandeshFlowQueueSummaryRequest::HandleRequest() const {
630 0 : SandeshFlowQueueSummaryResp *resp = new SandeshFlowQueueSummaryResp();
631 :
632 0 : Agent *agent = Agent::GetInstance();
633 0 : AgentProfile *profile = agent->oper_db()->agent_profile();
634 0 : uint16_t end = profile->seconds_history_index();
635 0 : uint16_t start = 0;
636 0 : if (end > AgentProfile::kSecondsHistoryCount)
637 0 : start = end - AgentProfile::kSecondsHistoryCount;
638 :
639 0 : std::vector<SandeshFlowQueueSummaryInfo> info_list;
640 0 : for (uint16_t i = start; i < end; i++) {
641 0 : uint16_t index = i % AgentProfile::kSecondsHistoryCount;
642 0 : ProfileData *data = profile->GetProfileData(index);
643 0 : SandeshFlowQueueSummaryInfo info;
644 0 : GetQueueSummaryInfo(&info, index, data);
645 0 : info_list.push_back(info);
646 0 : }
647 :
648 0 : resp->set_summary(info_list);
649 0 : resp->set_context(context());
650 0 : resp->Response();
651 0 : }
652 :
653 0 : void SandeshSetProfileParams::HandleRequest() const {
654 0 : SandeshProfileParams *resp = new SandeshProfileParams();
655 0 : Agent *agent = Agent::GetInstance();
656 0 : TaskScheduler *scheduler = agent->task_scheduler();
657 :
658 0 : scheduler->EnableLatencyThresholds(get_task_exec_threshold() * 1000,
659 0 : get_task_schedule_threshold() * 1000);
660 0 : agent->SetMeasureQueueDelay(get_measure_queue_run_time());
661 :
662 0 : resp->set_task_exec_threshold(scheduler->execute_delay()/1000);
663 0 : resp->set_task_schedule_threshold(scheduler->schedule_delay()/1000);
664 0 : resp->set_measure_queue_run_time(agent->MeasureQueueDelay());
665 0 : resp->set_context(context());
666 0 : resp->Response();
667 0 : }
|