| 592 | } |
| 593 | |
| 594 | void TaskControl::print_rq_sizes(std::ostream& os) { |
| 595 | size_t ngroup = 0; |
| 596 | std::for_each(_tagged_ngroup.begin(), _tagged_ngroup.end(), [&](butil::atomic<size_t>& index) { |
| 597 | ngroup += index.load(butil::memory_order_relaxed); |
| 598 | }); |
| 599 | DEFINE_SMALL_ARRAY(int, nums, ngroup, 128); |
| 600 | { |
| 601 | BAIDU_SCOPED_LOCK(_modify_group_mutex); |
| 602 | // ngroup > _ngroup: nums[_ngroup ... ngroup-1] = 0 |
| 603 | // ngroup < _ngroup: just ignore _groups[_ngroup ... ngroup-1] |
| 604 | int i = 0; |
| 605 | for_each_task_group([&](TaskGroup* g) { |
| 606 | nums[i] = (g ? g->_rq.volatile_size() : 0); |
| 607 | ++i; |
| 608 | }); |
| 609 | } |
| 610 | for (size_t i = 0; i < ngroup; ++i) { |
| 611 | os << nums[i] << ' '; |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | double TaskControl::get_cumulated_worker_time() { |
| 616 | int64_t cputime_ns = 0; |
| 617 | BAIDU_SCOPED_LOCK(_modify_group_mutex); |
| 618 | for_each_task_group([&](TaskGroup* g) { |
| 619 | cputime_ns += g->cumulated_cputime_ns(); |
| 620 | }); |
| 621 | return cputime_ns / 1000000000.0; |
| 622 | } |
| 623 | |
| 624 | double TaskControl::get_cumulated_worker_time(bthread_tag_t tag) { |
| 625 | int64_t cputime_ns = 0; |
| 626 | BAIDU_SCOPED_LOCK(_modify_group_mutex); |
| 627 | const size_t ngroup = tag_ngroup(tag).load(butil::memory_order_relaxed); |
| 628 | auto& groups = tag_group(tag); |
| 629 | for (size_t i = 0; i < ngroup; ++i) { |
| 630 | cputime_ns += groups[i]->cumulated_cputime_ns(); |
| 631 | } |
| 632 | return cputime_ns / 1000000000.0; |
| 633 | } |
| 634 | |
| 635 | int64_t TaskControl::get_cumulated_switch_count() { |
| 636 | int64_t c = 0; |
| 637 | BAIDU_SCOPED_LOCK(_modify_group_mutex); |
| 638 | for_each_task_group([&](TaskGroup* g) { |
| 639 | if (g) { |
| 640 | c += g->_nswitch; |
| 641 | } |
| 642 | }); |
| 643 | return c; |
| 644 | } |
| 645 | |
| 646 | int64_t TaskControl::get_cumulated_signal_count() { |
| 647 | int64_t c = 0; |
| 648 | BAIDU_SCOPED_LOCK(_modify_group_mutex); |
| 649 | for_each_task_group([&](TaskGroup* g) { |
| 650 | if (g) { |
| 651 | c += g->_nsignaled + g->_remote_nsignaled; |