Code

plugin.c: add timer on plugins read functions
authorMarc Fournier <marc.fournier@camptocamp.com>
Tue, 15 Sep 2015 16:16:07 +0000 (18:16 +0200)
committerMarc Fournier <marc.fournier@camptocamp.com>
Tue, 13 Oct 2015 07:35:51 +0000 (09:35 +0200)
Print out the value in a debug message. Also emit a warning when it
exceeds the configured Interval.

src/daemon/plugin.c

index b57dd4a21281a486b3356fe863aeec3fbebc305a..36c1b60ddd9651cc5308d9e285564f7db253c865 100644 (file)
@@ -483,7 +483,9 @@ static void *plugin_read_thread (void __attribute__((unused)) *args)
        {
                read_func_t *rf;
                plugin_ctx_t old_ctx;
+               cdtime_t start;
                cdtime_t now;
+               cdtime_t elapsed;
                int status;
                int rf_type;
                int rc;
@@ -562,6 +564,8 @@ static void *plugin_read_thread (void __attribute__((unused)) *args)
 
                DEBUG ("plugin_read_thread: Handling `%s'.", rf->rf_name);
 
+               start = cdtime ();
+
                old_ctx = plugin_set_ctx (rf->rf_ctx);
 
                if (rf_type == RF_SIMPLE)
@@ -605,6 +609,20 @@ static void *plugin_read_thread (void __attribute__((unused)) *args)
                /* update the ``next read due'' field */
                now = cdtime ();
 
+               /* calculate the time spent in the read function */
+               elapsed = (now - start);
+
+               if (elapsed > rf->rf_effective_interval)
+                       WARNING ("plugin_read_thread: read-function of the `%s' plugin took %.3f "
+                               "seconds, which is above its read interval (%.3f seconds). You might "
+                               "want to adjust the `Interval' or `ReadThreads' settings.",
+                               rf->rf_name, CDTIME_T_TO_DOUBLE(elapsed),
+                               CDTIME_T_TO_DOUBLE(rf->rf_effective_interval));
+
+               DEBUG ("plugin_read_thread: read-function of the `%s' plugin took "
+                               "%.6f seconds.",
+                               rf->rf_name, CDTIME_T_TO_DOUBLE(elapsed));
+
                DEBUG ("plugin_read_thread: Effective interval of the "
                                "%s plugin is %.3f seconds.",
                                rf->rf_name,