ctdb-daemon: Log a message when fork() takes long time
authorAmitay Isaacs <amitay@gmail.com>
Thu, 15 Sep 2016 06:10:49 +0000 (16:10 +1000)
committerMartin Schwenke <martins@samba.org>
Mon, 19 Sep 2016 06:23:22 +0000 (08:23 +0200)
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/server/ctdb_fork.c

index 4edbe88e15434eaae4109bbcffdbdf0444ebf1ce..54ffd02ae0c4994ed2cd6fd20873cc69da4c3dd5 100644 (file)
@@ -25,6 +25,7 @@
 #include <tevent.h>
 
 #include "lib/util/debug.h"
+#include "lib/util/time.h"
 
 #include "ctdb_private.h"
 #include "ctdb_client.h"
@@ -68,6 +69,10 @@ void ctdb_track_child(struct ctdb_context *ctdb, pid_t pid)
 pid_t ctdb_fork(struct ctdb_context *ctdb)
 {
        pid_t pid;
+       struct timeval before;
+       double delta_t;
+
+       before = timeval_current();
 
        pid = fork();
        if (pid == -1) {
@@ -104,6 +109,11 @@ pid_t ctdb_fork(struct ctdb_context *ctdb)
                return 0;
        }
 
+       delta_t = timeval_elapsed(&before);
+       if (delta_t > 3.0) {
+               DEBUG(DEBUG_WARNING, ("fork() took %lf seconds\n", delta_t));
+       }
+
        ctdb_track_child(ctdb, pid);
        return pid;
 }