]> granicus.if.org Git - vnstat/commitdiff
show warning in log if writing cached data to database takes longer than 3 seconds...
authorTeemu Toivola <git@humdi.net>
Fri, 10 May 2019 22:43:15 +0000 (01:43 +0300)
committerTeemu Toivola <git@humdi.net>
Fri, 10 May 2019 22:43:15 +0000 (01:43 +0300)
CHANGES
src/common.h
src/daemon.c

diff --git a/CHANGES b/CHANGES
index 4e4d54475243405c2915f1c46680608cdc82d00d..9f02ed75e1045fbf1f5fe2d2aa4f9a306b6eb38b 100644 (file)
--- 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
index 827d5ff7105b3ef78f7eca031640616cf4a55017..2ce581f9e9dcfff46f0f714400da5fc8e9ce2f16 100644 (file)
@@ -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
index 57b4ea549b1fa87916bc6f6582d88d5551495ef5..3f6830aa7f21d41038c6e916508b70d699530c6c 100644 (file)
@@ -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)