wwbmmm commented on code in PR #3009:
URL: https://github.com/apache/brpc/pull/3009#discussion_r2204483399
##########
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:
This name is confusing. Maybe change to 'last_run_ns_and_state', and offer
reader and writer function like
```cpp
last_run_ns()
is_main_task()
set_last_run_ns(last_run_ns, is_main_task)
```
##########
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:
Maybe wrap these code in a data structure like 'AtomicInteger128' for better
maintainability
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]