Skip to content

Commit

Permalink
add macro to disable query statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
fatcat22 committed Oct 31, 2024
1 parent dd96c5c commit 935b458
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tdutils/td/utils/query_stat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
#include <sstream>
#include <mutex>

// #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);
Expand All @@ -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_);

Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -103,4 +111,5 @@ void QueryStat::print(int64_t counter) {
}

LOG(WARNING) << "query stat counter:" << counter << ". " << buf.str();
#endif // ENABLE_STATISTICS
}

0 comments on commit 935b458

Please sign in to comment.