Dump statistics after stacktrace.

This commit is contained in:
levlam 2022-12-29 16:59:38 +03:00
parent e5af2d3133
commit 30da51bc72

View File

@ -86,6 +86,8 @@ void print_log() {
static std::atomic_bool has_failed{false};
static std::atomic_flag need_dump_statistics;
static void dump_stacktrace_signal_handler(int sig) {
if (has_failed) {
return;
@ -96,6 +98,7 @@ static void dump_stacktrace_signal_handler(int sig) {
td::signal_safe_write(td::Slice("\n"), false);
}
td::Stacktrace::print_to_stderr();
need_dump_statistics.clear();
}
static void fail_signal_handler(int sig) {
@ -139,6 +142,7 @@ int main(int argc, char *argv[]) {
need_reopen_log.test_and_set();
need_quit.test_and_set();
need_change_verbosity_level.test_and_set();
need_dump_statistics.test_and_set();
need_dump_log.test_and_set();
td::Stacktrace::init();
@ -548,8 +552,7 @@ int main(int argc, char *argv[]) {
if (!need_dump_log.test_and_set()) {
print_log();
auto guard = sched.get_main_guard();
send_closure(client_manager, &ClientManager::dump_statistics);
need_dump_statistics.clear();
}
double now = td::Time::now();
@ -567,7 +570,7 @@ int main(int argc, char *argv[]) {
next_watchdog_kick_time = now + WATCHDOG_TIMEOUT / 2;
}
if (now > last_dump_time + 300.0) {
if (!need_dump_statistics.test_and_set() || now > last_dump_time + 300.0) {
last_dump_time = now;
auto guard = sched.get_main_guard();
send_closure(client_manager, &ClientManager::dump_statistics);