From 85f8f11158b52c693a83a988b7a8bb8efdd60986 Mon Sep 17 00:00:00 2001 From: Teemu Toivola Date: Sat, 11 May 2019 01:43:15 +0300 Subject: [PATCH] show warning in log if writing cached data to database takes longer than 3 seconds, it should take less than a second normally --- CHANGES | 1 + src/common.h | 1 + src/daemon.c | 9 +++++++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 4e4d544..9f02ed7 100644 --- a/CHANGES +++ b/CHANGES @@ -11,6 +11,7 @@ Write-Ahead Logging mode which may provide some disk i/o benefits, see https://www.sqlite.org/wal.html for more details and note that SQLite 3.22.0 or later is required to support read-only operations + - Show warning in log if writing cached data to database is slow 2.2 / 28-Apr-2018 diff --git a/src/common.h b/src/common.h index 827d5ff..2ce581f 100644 --- a/src/common.h +++ b/src/common.h @@ -233,6 +233,7 @@ and most can be changed later from the config file. #define IS64BIT -2 #define WALDB 0 #define WALDBCHECKPOINTINTERVALMINS 240 +#define SLOWDBFLUSHWARNLIMIT 3.0 /* no transparency by default */ #define TRANSBG 0 diff --git a/src/daemon.c b/src/daemon.c index 57b4ea5..3f6830a 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -582,12 +582,13 @@ int processifinfo(DSTATE *s, datacache **dc) void flushcachetodisk(DSTATE *s) { int ret; + double used_secs = 0.0; uint32_t logcount = 0; datacache *iterator = s->dcache; xferlog *logiterator; interfaceinfo info; - timeused_debug(__func__, 1); + timeused(__func__, 1); if (!db_begintransaction()) { handledatabaseerror(s); @@ -678,7 +679,11 @@ void flushcachetodisk(DSTATE *s) } else { db_rollbacktransaction(); } - timeused_debug(__func__, 0); + used_secs = timeused(__func__, 0); + if (used_secs > SLOWDBFLUSHWARNLIMIT) { + snprintf(errorstring, 1024, "Writing cached data to database took %.2f seconds.", used_secs); + printe(PT_Warning); + } } void handledatabaseerror(DSTATE *s) -- 2.40.0