chenBright commented on code in PR #3096:
URL: https://github.com/apache/brpc/pull/3096#discussion_r2428843443


##########
src/bthread/task_group.cpp:
##########
@@ -1088,10 +1098,11 @@ void TaskGroup::yield(TaskGroup** pg) {
     sched(pg);
 }
 
-void print_task(std::ostream& os, bthread_t tid) {
+void print_task(std::ostream& os, bthread_t tid, bool enable_trace,
+    bool ignore_not_matched = false) {

Review Comment:
   ```c++
   void print_task(std::ostream& os, bthread_t tid, bool enable_trace,
                   bool ignore_not_matched = false) {
   ```
   Alignment?



##########
src/bthread/task_control.cpp:
##########
@@ -587,4 +587,21 @@ bvar::LatencyRecorder* 
TaskControl::create_exposed_pending_time() {
     return pt;
 }
 
+std::vector<bthread_t> TaskControl::get_all_bthreads() {
+    std::vector<bthread_t> all_bthread_ids;
+    std::vector<TaskMeta*> all_tasks = butil::list_resources<TaskMeta>();
+    all_bthread_ids.reserve(all_tasks.size());
+    for (TaskMeta* m : all_tasks) {
+        // filter out those bthreads created by bthread_start* functions,
+        // i.e. not those created internally to run main task as they are
+        // opaque to user
+        if (m && !m->main_task) {
+            // the judgement of living bthread is deferred to `print_task`
+            // to avoid extra judgement
+            all_bthread_ids.push_back(m->tid);

Review Comment:
   Support a `ResourcePool::for_each<>(std::function callback)` function to 
iterate over all TaskMeta and filter out the living bthreads. This way the 
vector will not be too large and there will be no need to copy between vectors. 
Isn't this better?



##########
src/bthread/bthread.cpp:
##########
@@ -32,6 +32,8 @@
 #include "bthread/bthread.h"
 
 namespace bthread {
+extern void print_task(std::ostream& os, bthread_t tid, bool enable_trace,
+    bool ignore_not_matched = false);

Review Comment:
   Alignment?



##########
src/bthread/task_control.cpp:
##########
@@ -587,4 +587,21 @@ bvar::LatencyRecorder* 
TaskControl::create_exposed_pending_time() {
     return pt;
 }
 
+std::vector<bthread_t> TaskControl::get_all_bthreads() {
+    std::vector<bthread_t> all_bthread_ids;
+    std::vector<TaskMeta*> all_tasks = butil::list_resources<TaskMeta>();
+    all_bthread_ids.reserve(all_tasks.size());
+    for (TaskMeta* m : all_tasks) {
+        // filter out those bthreads created by bthread_start* functions,
+        // i.e. not those created internally to run main task as they are
+        // opaque to user
+        if (m && !m->main_task) {

Review Comment:
   
https://github.com/apache/brpc/blob/07083331e1496746f4b1cfa54d0b6364f321be34/src/bthread/task_group.cpp#L310
   
https://github.com/apache/brpc/blob/07083331e1496746f4b1cfa54d0b6364f321be34/src/bthread/task_group.cpp#L50-L51
   
   Can we use `m->attr.stack_type == BTHREAD_STACKTYPE_PTHREAD` to judge?
   
   



-- 
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]

Reply via email to