From 75caf1b0e79c492f4e18f14b4c96625edaa27134 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 6 Jan 2023 16:29:09 +0300 Subject: [PATCH] Log top bots in dump_statistics. --- td | 2 +- telegram-bot-api/ClientManager.cpp | 31 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/td b/td index 5ee9c73..ac0de06 160000 --- a/td +++ b/td @@ -1 +1 @@ -Subproject commit 5ee9c7365b9533d207887e32a9d71645e5d30fd8 +Subproject commit ac0de06b5f55e7bb5c2904ed6ef3aeb8c2df8c85 diff --git a/telegram-bot-api/ClientManager.cpp b/telegram-bot-api/ClientManager.cpp index e07e86f..dea4536 100644 --- a/telegram-bot-api/ClientManager.cpp +++ b/telegram-bot-api/ClientManager.cpp @@ -488,6 +488,37 @@ void ClientManager::dump_statistics() { } td::dump_pending_network_queries(*parameters_->net_query_stats_); + + auto now = td::Time::now(); + auto top_clients = get_top_clients(10, {}); + for (auto top_client_id : top_clients.top_client_ids) { + auto *client_info = clients_.get(top_client_id); + CHECK(client_info); + + auto bot_info = client_info->client_.get_actor_unsafe()->get_bot_info(); + td::string update_count; + td::string request_count; + auto replace_tabs = [](td::string &str) { + for (auto &c : str) { + if (c == '\t') { + c = ' '; + } + } + }; + auto stats = client_info->stat_.as_vector(now); + for (auto &stat : stats) { + if (stat.key_ == "update_count") { + replace_tabs(stat.value_); + update_count = std::move(stat.value_); + } + if (stat.key_ == "request_count") { + replace_tabs(stat.value_); + request_count = std::move(stat.value_); + } + } + LOG(WARNING) << td::tag("id", bot_info.id_) << td::tag("update_count", update_count) + << td::tag("request_count", request_count); + } } void ClientManager::raw_event(const td::Event::Raw &event) {