xinyiZzz commented on a change in pull request #8476:
URL: https://github.com/apache/incubator-doris/pull/8476#discussion_r829903761



##########
File path: be/src/runtime/thread_context.h
##########
@@ -50,27 +56,65 @@ class ThreadContext {
     };
 
 public:
-    ThreadContext() : _thread_id(std::this_thread::get_id()), 
_type(TaskType::UNKNOWN) {}
+    ThreadContext() : _thread_id(std::this_thread::get_id()), 
_type(TaskType::UNKNOWN) {
+        _thread_mem_tracker_mgr.reset(new ThreadMemTrackerMgr());
+    }
 
     void attach(const TaskType& type, const std::string& task_id,
-                const TUniqueId& fragment_instance_id) {
+                const TUniqueId& fragment_instance_id,
+                const std::shared_ptr<MemTracker>& mem_tracker) {
         DCHECK(_type == TaskType::UNKNOWN && _task_id == "");
         _type = type;
         _task_id = task_id;
         _fragment_instance_id = fragment_instance_id;
+        _thread_mem_tracker_mgr->attach_task(task_type_string(_type), task_id, 
fragment_instance_id,
+                                             mem_tracker);
     }
 
     void detach() {
         _type = TaskType::UNKNOWN;
         _task_id = "";
         _fragment_instance_id = TUniqueId();
+        _thread_mem_tracker_mgr->detach_task();
     }
 
-    const std::string type() const;
     const std::string& task_id() const { return _task_id; }
     const std::thread::id& thread_id() const { return _thread_id; }
     const TUniqueId& fragment_instance_id() const { return 
_fragment_instance_id; }
 
+    inline static const std::string task_type_string(ThreadContext::TaskType 
type) {
+        switch (type) {
+        case ThreadContext::TaskType::QUERY:
+            return "QUERY";
+        case ThreadContext::TaskType::LOAD:
+            return "LOAD";
+        case ThreadContext::TaskType::COMPACTION:
+            return "COMPACTION";
+        default:
+            return "UNKNOWN";
+        }

Review comment:
       I understand, it seems that compilers does compile switch constructs 
into array of code pointers, as said in the link above.
   
   I changed to array as you said, which seems more concise. thx~ @dataroaring 
   
   Also, I did a simple test in the benchmark and it seems that switch 
constructs are faster, I didn't analyze the assembly code carefully, 
performance is not the bottleneck in this case.
   
   
![image](https://user-images.githubusercontent.com/13197424/158992378-7b821c8f-e528-4cca-b447-7f33a8f425e2.png)
   
![image](https://user-images.githubusercontent.com/13197424/158992899-70740800-6299-471f-a1c3-162fb8ea69ea.png)
   




-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to