Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Improve FUSE trace facility



details:   https://anonhg.NetBSD.org/src/rev/bc4583c401f6
branches:  trunk
changeset: 773159:bc4583c401f6
user:      manu <manu%NetBSD.org@localhost>
date:      Sun Jan 29 06:22:01 2012 +0000

description:
Improve FUSE trace facility

diffstat:

 lib/libperfuse/debug.c        |  70 +++++++++++++++++++++++++++++++++++++++---
 lib/libperfuse/ops.c          |  64 +++++++++-----------------------------
 lib/libperfuse/perfuse_priv.h |   5 ++-
 lib/libperfuse/subr.c         |   5 ++-
 usr.sbin/perfused/perfused.8  |   8 +++-
 usr.sbin/perfused/perfused.c  |  36 ++++++++++++++++-----
 usr.sbin/perfused/perfused.h  |   4 +-
 7 files changed, 123 insertions(+), 69 deletions(-)

diffs (truncated from 381 to 300 lines):

diff -r 1af31fde5627 -r bc4583c401f6 lib/libperfuse/debug.c
--- a/lib/libperfuse/debug.c    Sun Jan 29 00:58:13 2012 +0000
+++ b/lib/libperfuse/debug.c    Sun Jan 29 06:22:01 2012 +0000
@@ -1,4 +1,4 @@
-/*  $NetBSD: debug.c,v 1.8 2011/12/29 04:25:49 riz Exp $ */
+/*  $NetBSD: debug.c,v 1.9 2012/01/29 06:22:01 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -27,6 +27,9 @@
 
 #include <puffs.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <err.h>
+#include <errno.h>
 #include <sys/types.h>
 
 #include "perfuse_if.h"
@@ -127,6 +130,64 @@
        return buf;
 }
 
+struct perfuse_trace *
+perfuse_trace_begin(ps, opc, pm)
+       struct perfuse_state *ps;
+       puffs_cookie_t opc;
+       perfuse_msg_t *pm;
+{
+       struct perfuse_trace *pt;
+
+       if ((pt = malloc(sizeof(*pt))) == NULL)
+               DERR(EX_OSERR, "malloc failed");
+
+       pt->pt_opcode = ps->ps_get_inhdr(pm)->opcode;
+       pt->pt_status = inxchg;
+
+       if (clock_gettime(CLOCK_REALTIME, &pt->pt_start) != 0)
+               DERR(EX_OSERR, "clock_gettime failed");
+
+       if (opc == 0)
+               (void)strcpy(pt->pt_path, "");
+       else
+               (void)strlcpy(pt->pt_path, 
+                             perfuse_node_path(opc),
+                             sizeof(pt->pt_path));
+
+       (void)strlcpy(pt->pt_extra,
+                     perfuse_opdump_in(ps, pm),
+                     sizeof(pt->pt_extra));
+
+       TAILQ_INSERT_TAIL(&ps->ps_trace, pt, pt_list);
+       ps->ps_tracecount++;
+
+       return pt;
+}
+
+void
+perfuse_trace_end(ps, pt, error)
+       struct perfuse_state *ps;
+       struct perfuse_trace *pt;
+       int error;
+{
+       if (clock_gettime(CLOCK_REALTIME, &pt->pt_end) != 0)
+               DERR(EX_OSERR, "clock_gettime failed");
+
+       pt->pt_status = done;
+       pt->pt_error = error;
+
+       while (ps->ps_tracecount > PERFUSE_TRACECOUNT_MAX) {
+               struct perfuse_trace *fpt = TAILQ_FIRST(&ps->ps_trace);
+
+               if (fpt == NULL || fpt->pt_status != done)
+                       break;
+
+               TAILQ_REMOVE(&ps->ps_trace, fpt, pt_list);
+               free(fpt);
+               ps->ps_tracecount--;
+       }
+}
+
 void
 perfuse_trace_dump(pu, fp)
        struct puffs_usermount *pu;
@@ -159,7 +220,7 @@
        TAILQ_FOREACH(pt, &ps->ps_trace, pt_list) {
                const char *quote = pt->pt_path[0] != '\0' ? "\"" : "";
 
-               fprintf(fp, "%" PRIu64 ".%09ld %s %s%s%s %s ",  
+               fprintf(fp, "%ld.%09ld %s %s%s%s %s ",  
                        pt->pt_start.tv_sec, pt->pt_start.tv_nsec,
                        perfuse_opname(pt->pt_opcode),
                        quote, pt->pt_path, quote,
@@ -172,7 +233,7 @@
                        ts.tv_nsec = 0; /* delint */
                        timespecsub(&pt->pt_end, &pt->pt_start, &ts);
 
-                       fprintf(fp, "error = %d elapsed = %" PRIu64 ".%09lu ",
+                       fprintf(fp, "error = %d elapsed = %ld.%09lu ",
                                pt->pt_error, ts.tv_sec, ts.tv_nsec);
 
                        count[pt->pt_opcode]++;
@@ -206,8 +267,7 @@
                        min = 0;
                }
                        
-               fprintf(fp, "%s\t%d\t%" PRId64 ".%09ld\t%" PRId64 
-                   ".%09ld\t%" PRId64 ".%09ld\t\n",
+               fprintf(fp, "%s\t%d\t%ld.%09ld\t%ld.%09ld\t%ld.%09ld\t\n",
                        perfuse_opname(i), count[i],
                        min, ts_min[i].tv_nsec,
                        (time_t)(avg / 1000000000L), (long)(avg % 1000000000L),
diff -r 1af31fde5627 -r bc4583c401f6 lib/libperfuse/ops.c
--- a/lib/libperfuse/ops.c      Sun Jan 29 00:58:13 2012 +0000
+++ b/lib/libperfuse/ops.c      Sun Jan 29 06:22:01 2012 +0000
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.49 2011/12/28 17:33:53 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.50 2012/01/29 06:22:02 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -207,7 +207,6 @@
        struct perfuse_state *ps;
        struct perfuse_node_data *pnd;
        struct perfuse_trace *pt = NULL;
-       int opcode;
        int error;
 
        ps = puffs_getspecific(pu);
@@ -228,31 +227,8 @@
        /*
         * Record FUSE call start if requested
         */
-       opcode = ps->ps_get_inhdr(pm)->opcode;
-       if (perfuse_diagflags & PDF_TRACE) {
-               if ((pt = malloc(sizeof(*pt))) == NULL)
-                       DERR(EX_OSERR, "malloc failed");
-
-               pt->pt_opcode = opcode;
-               pt->pt_status = inxchg;
-
-               if (opc == 0)
-                       (void)strcpy(pt->pt_path, "");
-               else
-                       (void)strlcpy(pt->pt_path, 
-                                     perfuse_node_path(opc),
-                                     sizeof(pt->pt_path));
-
-               (void)strlcpy(pt->pt_extra,
-                             perfuse_opdump_in(ps, pm),
-                             sizeof(pt->pt_extra));
-
-               if (clock_gettime(CLOCK_REALTIME, &pt->pt_start) != 0)
-                       DERR(EX_OSERR, "clock_gettime failed");
-
-               TAILQ_INSERT_TAIL(&ps->ps_trace, pt, pt_list);
-               ps->ps_tracecount++;
-       }
+       if (perfuse_diagflags & PDF_TRACE)
+               pt = perfuse_trace_begin(ps, opc, pm);
 
        /*
         * Do actual FUSE exchange
@@ -263,23 +239,8 @@
        /*
         * Record FUSE call end if requested
         */
-       if (perfuse_diagflags & PDF_TRACE) {
-               if (clock_gettime(CLOCK_REALTIME, &pt->pt_end) != 0)
-                       DERR(EX_OSERR, "clock_gettime failed");
-
-               pt->pt_status = done;
-               pt->pt_error = error;
-               while (ps->ps_tracecount > PERFUSE_TRACECOUNT_MAX) {
-                       struct perfuse_trace *fpt = TAILQ_FIRST(&ps->ps_trace);
-
-                       if (fpt->pt_status != done)
-                               break;
-
-                       TAILQ_REMOVE(&ps->ps_trace, fpt, pt_list);
-                       ps->ps_tracecount--;
-                       free(fpt);
-               }
-       }
+       if (pt != NULL)
+               perfuse_trace_end(ps, pt, error);
 
        if (pnd) {
                pnd->pnd_flags &= ~PND_INXCHG;
@@ -434,23 +395,30 @@
 attr_expired(opc)
        puffs_cookie_t opc;
 {
-       struct perfuse_node_data *pnd = PERFUSE_NODE_DATA(opc);
+       struct perfuse_node_data *pnd;
+       struct timespec expire;
        struct timespec now;
 
+       pnd = PERFUSE_NODE_DATA(opc);
+       expire = pnd->pnd_attr_expire;
+
        if (clock_gettime(CLOCK_REALTIME, &now) != 0)
                DERR(EX_OSERR, "clock_gettime failed");
 
-       return timespeccmp(&pnd->pnd_attr_expire, &now, <);
+       return timespeccmp(&expire, &now, <);
 }
 
 static int
 entry_expired(opc)
        puffs_cookie_t opc;
 {
-       struct perfuse_node_data *pnd = PERFUSE_NODE_DATA(opc);
-       struct timespec expire = pnd->pnd_entry_expire;
+       struct perfuse_node_data *pnd;
+       struct timespec expire;
        struct timespec now;
 
+       pnd = PERFUSE_NODE_DATA(opc);
+       expire = pnd->pnd_entry_expire;
+
        if (clock_gettime(CLOCK_REALTIME, &now) != 0)
                DERR(EX_OSERR, "clock_gettime failed");
 
diff -r 1af31fde5627 -r bc4583c401f6 lib/libperfuse/perfuse_priv.h
--- a/lib/libperfuse/perfuse_priv.h     Sun Jan 29 00:58:13 2012 +0000
+++ b/lib/libperfuse/perfuse_priv.h     Sun Jan 29 06:22:01 2012 +0000
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse_priv.h,v 1.24 2011/12/28 17:33:53 manu Exp $ */
+/*  $NetBSD: perfuse_priv.h,v 1.25 2012/01/29 06:22:02 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -252,6 +252,9 @@
 int perfuse_node_deleteextattr(struct puffs_usermount *, puffs_cookie_t,
     int, const char *, const struct puffs_cred *);
 
+struct perfuse_trace *perfuse_trace_begin(struct perfuse_state *, 
+    puffs_cookie_t, perfuse_msg_t *);
+void perfuse_trace_end(struct perfuse_state *, struct perfuse_trace *, int);
 char *perfuse_opdump_in(struct perfuse_state *, perfuse_msg_t *);
 
 __END_DECLS
diff -r 1af31fde5627 -r bc4583c401f6 lib/libperfuse/subr.c
--- a/lib/libperfuse/subr.c     Sun Jan 29 00:58:13 2012 +0000
+++ b/lib/libperfuse/subr.c     Sun Jan 29 06:22:01 2012 +0000
@@ -1,4 +1,4 @@
-/*  $NetBSD: subr.c,v 1.14 2011/10/30 05:11:37 manu Exp $ */
+/*  $NetBSD: subr.c,v 1.15 2012/01/29 06:22:02 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -116,6 +116,9 @@
 
                if (!TAILQ_EMPTY(&pnd->pnd_pcq))
                        DERRX(EX_SOFTWARE, "%s: non empty pnd_pcq", __func__);
+
+               if (pnd == NULL)
+                       DERRX(EX_SOFTWARE, "%s: pnd == NULL ???", __func__);
 #endif /* PERFUSE_DEBUG */
 
                free(pnd);
diff -r 1af31fde5627 -r bc4583c401f6 usr.sbin/perfused/perfused.8
--- a/usr.sbin/perfused/perfused.8      Sun Jan 29 00:58:13 2012 +0000
+++ b/usr.sbin/perfused/perfused.8      Sun Jan 29 06:22:01 2012 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: perfused.8,v 1.9 2011/12/28 18:56:38 wiz Exp $
+.\" $NetBSD: perfused.8,v 1.10 2012/01/29 06:22:02 manu Exp $
 .\"
 .\" Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
 .\"
@@ -126,8 +126,10 @@
 flag was used, toggle debug output.
 Do nothing otherwise.
 .It Dv SIGUSR1
-Dump FUSE operation trace to
-.Pa /var/run/perfuse.trace .
+Toggle FUSE operation dump on and off. When toggling off, the trace
+is is stored in 
+.Pa /var/run/perfuse-xxx.trace
+(xxx is the filesystem mount point).
 .El
 .Sh ERRORS
 The program logs to the syslog daemon as facility
diff -r 1af31fde5627 -r bc4583c401f6 usr.sbin/perfused/perfused.c
--- a/usr.sbin/perfused/perfused.c      Sun Jan 29 00:58:13 2012 +0000
+++ b/usr.sbin/perfused/perfused.c      Sun Jan 29 06:22:01 2012 +0000
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfused.c,v 1.18 2012/01/17 17:58:36 joerg Exp $ */
+/*  $NetBSD: perfused.c,v 1.19 2012/01/29 06:22:02 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -55,8 +55,8 @@
  * we ever mount multiple filesystems in a single perfused, 
  * but it is not sure we will ever want to do that.
  */
-static struct puffs_usermount *my_perfuse_mount = NULL;
-static FILE *perfuse_trace = NULL;
+struct puffs_usermount *perfuse_mount = NULL;



Home | Main Index | Thread Index | Old Index