diff --git a/src/bthread/task_control.cpp b/src/bthread/task_control.cpp index 5a6bfe831c..6da8a4ab8d 100644 --- a/src/bthread/task_control.cpp +++ b/src/bthread/task_control.cpp @@ -258,12 +258,20 @@ int TaskControl::init(int concurrency) { for (int i = 0; i < FLAGS_task_group_ntags; ++i) { _tagged_ngroup[i].store(0, std::memory_order_relaxed); auto tag_str = std::to_string(i); - _tagged_nworkers.push_back(new bvar::Adder("bthread_worker_count", tag_str)); - _tagged_cumulated_worker_time.push_back(new bvar::PassiveStatus( - get_cumulated_worker_time_from_this_with_tag, new CumulatedWithTagArgs{this, i})); - _tagged_worker_usage_second.push_back(new bvar::PerSecond>( - "bthread_worker_usage", tag_str, _tagged_cumulated_worker_time[i], 1)); - _tagged_nbthreads.push_back(new bvar::Adder("bthread_count", tag_str)); + _tagged_nworkers.emplace_back( + std::make_unique>("bthread_worker_count", tag_str)); + _tagged_cumulated_worker_time_args.emplace_back( + std::make_unique(this, i)); + _tagged_cumulated_worker_time.emplace_back( + std::make_unique>( + get_cumulated_worker_time_from_this_with_tag, + _tagged_cumulated_worker_time_args.back().get())); + _tagged_worker_usage_second.emplace_back( + std::make_unique>>( + "bthread_worker_usage", tag_str, + _tagged_cumulated_worker_time.back().get(), 1)); + _tagged_nbthreads.emplace_back( + std::make_unique>("bthread_count", tag_str)); } if (init_ed_priority_queues() != 0) { diff --git a/src/bthread/task_control.h b/src/bthread/task_control.h index 8cc8c4ba4e..fed5bcf3b6 100644 --- a/src/bthread/task_control.h +++ b/src/bthread/task_control.h @@ -41,6 +41,7 @@ DECLARE_int32(task_group_ntags); namespace bthread { class TaskGroup; +struct CumulatedWithTagArgs; // Control all task groups class TaskControl { @@ -171,10 +172,14 @@ friend bthread_t init_for_pthread_stack_trace(); bvar::PassiveStatus _status; bvar::Adder _nbthreads; - std::vector*> _tagged_nworkers; - std::vector*> _tagged_cumulated_worker_time; - std::vector>*> _tagged_worker_usage_second; - std::vector*> _tagged_nbthreads; + std::vector>> _tagged_nworkers; + std::vector> + _tagged_cumulated_worker_time_args; + std::vector>> + _tagged_cumulated_worker_time; + std::vector>>> + _tagged_worker_usage_second; + std::vector>> _tagged_nbthreads; bool _enable_priority_queue; int _ed_priority_queue_num_of_each_tag;