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