chenBright commented on code in PR #3009: URL: https://github.com/apache/brpc/pull/3009#discussion_r2215084966
########## src/bthread/task_control.cpp: ########## @@ -526,26 +533,51 @@ double TaskControl::get_cumulated_worker_time() { int64_t cputime_ns = 0; BAIDU_SCOPED_LOCK(_modify_group_mutex); for_each_task_group([&](TaskGroup* g) { - if (g) { - cputime_ns += g->_cumulated_cputime_ns; - } + cputime_ns += get_cumulated_worker_time(g); }); return cputime_ns / 1000000000.0; } -double TaskControl::get_cumulated_worker_time_with_tag(bthread_tag_t tag) { +double TaskControl::get_cumulated_worker_time(bthread_tag_t tag) { int64_t cputime_ns = 0; BAIDU_SCOPED_LOCK(_modify_group_mutex); const size_t ngroup = tag_ngroup(tag).load(butil::memory_order_relaxed); auto& groups = tag_group(tag); for (size_t i = 0; i < ngroup; ++i) { - if (groups[i]) { - cputime_ns += groups[i]->_cumulated_cputime_ns; - } + cputime_ns += get_cumulated_worker_time(groups[i]); } return cputime_ns / 1000000000.0; } +double TaskControl::get_cumulated_worker_time(TaskGroup* g) { + if (NULL == g) { + return 0.0; + } + +#if __x86_64__ || __ARM_NEON Review Comment: done ########## src/bthread/task_group.h: ########## @@ -203,6 +206,14 @@ class TaskGroup { private: friend class TaskControl; + struct CPUTimeStat { + // Last scheduling time. + // If this value is negative, + // it means that it is the main task. + int64_t last_run_ns; Review Comment: done ########## src/bthread/task_group.cpp: ########## @@ -292,7 +282,7 @@ int TaskGroup::init(size_t runqueue_capacity) { _cur_meta = m; _main_tid = m->tid; _main_stack = stk; - _last_run_ns = butil::cpuwide_time_ns(); + _cpu_time_stat.last_run_ns = -m->cpuwide_start_ns; Review Comment: The higher bit for task type, main task is 1, otherwise 0. Worker usage does not calculate CPU time of the main task. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org For additional commands, e-mail: dev-h...@brpc.apache.org