From 935b4581dbbc70b7c2ad5e1feef9ff688604b5c2 Mon Sep 17 00:00:00 2001 From: "zhe.yang" Date: Thu, 31 Oct 2024 08:57:57 +0800 Subject: [PATCH] add macro to disable query statistics --- tdutils/td/utils/query_stat.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tdutils/td/utils/query_stat.cpp b/tdutils/td/utils/query_stat.cpp index bfd62f3b6..6ec8191b5 100644 --- a/tdutils/td/utils/query_stat.cpp +++ b/tdutils/td/utils/query_stat.cpp @@ -3,9 +3,11 @@ #include #include +// #define ENABLE_STATISTICS QueryStat g_query_stat; size_t QueryStat::append_stat(int64_t counter, const TimeStat&& ts) { +#ifdef ENABLE_STATISTICS std::unique_lock lock(mutex_); auto it = this->stats_.find(counter); @@ -17,9 +19,13 @@ size_t QueryStat::append_stat(int64_t counter, const TimeStat&& ts) { it->second.push_back(ts); return it->second.size() - 1; } +#else + return INVALID_INDEX; +#endif // ENABLE_STATISTICS } void QueryStat::update_stat(const ScheduleContext& sched_ctx) { +#ifdef ENABLE_STATISTICS const auto finish_schedule_at = std::chrono::steady_clock::now(); std::unique_lock lock(mutex_); @@ -35,6 +41,7 @@ void QueryStat::update_stat(const ScheduleContext& sched_ctx) { } it->second[sched_ctx.index()].finish_schedule_at_ = finish_schedule_at; +#endif // ENABLE_STATISTICS } ScheduleContext QueryStat::start_schedule(int64_t counter, const char* tips) { @@ -65,6 +72,7 @@ void QueryStat::execute_cost(int64_t counter, const char* tips, std::chrono::ste } void QueryStat::print(int64_t counter) { +#ifdef ENABLE_STATISTICS if (counter == INVALID_COUNTER) { return; } @@ -103,4 +111,5 @@ void QueryStat::print(int64_t counter) { } LOG(WARNING) << "query stat counter:" << counter << ". " << buf.str(); +#endif // ENABLE_STATISTICS }