s3:lib/asys: measure async request syscall duration
authorRalph Boehme <slow@samba.org>
Thu, 25 Feb 2016 07:06:00 +0000 (08:06 +0100)
committerJeremy Allison <jra@samba.org>
Wed, 2 Mar 2016 00:22:14 +0000 (01:22 +0100)
This uses time functions from lib/util/ which requires pulling in
samba-util. This sucks, but there's just no way of rewrapping a minimal
time utility library without modifying the public samba-util.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/lib/asys/asys.c
source3/lib/asys/asys.h
source3/lib/asys/wscript_build

index 906d8cf1c1e148eeb4ab19ea0ec814e9713014a9..068b4600e2573eb4deee0cdc7598abf1d759377b 100644 (file)
@@ -20,6 +20,7 @@
 #include <stdlib.h>
 #include <errno.h>
 #include "../pthreadpool/pthreadpool.h"
+#include "lib/util/time.h"
 
 struct asys_pwrite_args {
        int fildes;
@@ -52,6 +53,8 @@ struct asys_job {
        int err;
        char busy;
        char canceled;
+       struct timespec start_time;
+       struct timespec end_time;
 };
 
 struct asys_context {
@@ -189,7 +192,10 @@ static void asys_pwrite_do(void *private_data)
        struct asys_job *job = (struct asys_job *)private_data;
        struct asys_pwrite_args *args = &job->args.pwrite_args;
 
+       clock_gettime_mono(&job->start_time);
        job->ret = pwrite(args->fildes, args->buf, args->nbyte, args->offset);
+       clock_gettime_mono(&job->end_time);
+
        if (job->ret == -1) {
                job->err = errno;
        }
@@ -231,7 +237,10 @@ static void asys_pread_do(void *private_data)
        struct asys_job *job = (struct asys_job *)private_data;
        struct asys_pread_args *args = &job->args.pread_args;
 
+       clock_gettime_mono(&job->start_time);
        job->ret = pread(args->fildes, args->buf, args->nbyte, args->offset);
+       clock_gettime_mono(&job->end_time);
+
        if (job->ret == -1) {
                job->err = errno;
        }
@@ -269,7 +278,10 @@ static void asys_fsync_do(void *private_data)
        struct asys_job *job = (struct asys_job *)private_data;
        struct asys_fsync_args *args = &job->args.fsync_args;
 
+       clock_gettime_mono(&job->start_time);
        job->ret = fsync(args->fildes);
+       clock_gettime_mono(&job->end_time);
+
        if (job->ret == -1) {
                job->err = errno;
        }
@@ -320,6 +332,7 @@ int asys_results(struct asys_context *ctx, struct asys_result *results,
                        result->err = job->err;
                }
                result->private_data = job->private_data;
+               result->duration = nsec_time_diff(&job->end_time, &job->start_time);
 
                job->busy = 0;
        }
index 7c3dfdfbaf5d090e4e5d61b323f0b47d5bdbacf8..f576bd327815d4ca9ac8710a3b3409973ebafb0d 100644 (file)
@@ -108,6 +108,7 @@ struct asys_result {
        ssize_t ret;
        int err;
        void *private_data;
+       uint64_t duration;      /* nanoseconds */
 };
 
 /**
index 15de9770b80bd00bd7fe9cffcac050d7c322faac..520994ff2bb3e7d25290c95e2df5755cf83d93a4 100644 (file)
@@ -2,7 +2,7 @@
 
 bld.SAMBA3_SUBSYSTEM('LIBASYS',
                     source='asys.c',
-                    deps='PTHREADPOOL')
+                    deps='PTHREADPOOL samba-util')
 
 bld.SAMBA3_BINARY('asystest',
                  source='tests.c',