WingsGo commented on a change in pull request #4110: URL: https://github.com/apache/incubator-doris/pull/4110#discussion_r457221304
########## File path: be/src/util/thread.cpp ########## @@ -169,6 +174,81 @@ void ThreadMgr::remove_thread(const pthread_t& pthread_id, const std::string& ca ANNOTATE_IGNORE_READS_AND_WRITES_END(); } +void ThreadMgr::start_instrumentation(const WebPageHandler::ArgumentMap& args, EasyJson* ej) const { + const auto* category_name = FindOrNull(args, "group"); + if (category_name) { + bool requested_all = (*category_name == "all"); + ej->Set("requested_thread_group", EasyJson::kObject); + (*ej)["group_name"] = escape_for_html_to_string(*category_name); + (*ej)["requested_all"] = requested_all; + + // The critical section is as short as possible so as to minimize the delay + // imposed on new threads that acquire the lock in write mode. + vector<ThreadDescriptor> descriptors_to_print; + if (!requested_all) { + MutexLock l(&_lock); + const auto* category = FindOrNull(_thread_categories, *category_name); + if (category) { + for (const auto& elem : *category) { + descriptors_to_print.emplace_back(elem.second); + } + } + } else { + MutexLock l(&_lock); + for (const auto& category : _thread_categories) { + for (const auto& elem : category.second) { + descriptors_to_print.emplace_back(elem.second); + } + } + } + + EasyJson found = (*ej).Set("found", EasyJson::kObject); + EasyJson threads = found.Set("threads", EasyJson::kArray); + for (const auto& desc : descriptors_to_print) { + summarize_thread_descriptor(desc, &threads); + } + } else { + // List all thread groups and the number of threads running in each. + vector<pair<string, uint64_t>> thread_categories_info; + uint64_t running; + { + MutexLock l(&_lock); + running = _threads_running_metric; + thread_categories_info.reserve(_thread_categories.size()); + for (const auto& category : _thread_categories) { + thread_categories_info.emplace_back(category.first, category.second.size()); + } + + (*ej)["total_threads_running"] = running; + EasyJson groups = ej->Set("groups", EasyJson::kArray); + for (const auto& elem : thread_categories_info) { + string category_arg; + url_encode(elem.first, &category_arg); + LOG(INFO) << "encode url path: " << category_arg; Review comment: ok, I removed it. ---------------------------------------------------------------- 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. 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