[PATCH] blkprase: binary dump capability + notify added
authorAlan D. Brunelle <Alan.Brunelle@hp.com>
Mon, 27 Feb 2006 07:10:32 +0000 (08:10 +0100)
committerJens Axboe <axboe@suse.de>
Mon, 27 Feb 2006 07:10:32 +0000 (08:10 +0100)
Here is a proposed patch which would allow blkparse to dump its output
to a binary file (in addition to the ascii output). It adds a new '-d
<file>' parameter.

The purpose of this would be to allow for the easier handling of the
collected data by analysis tools. [Rather than having to parse the
textual output from blkparse, or duplicate the collation efforts of
blkparse itself.]

README
blkparse.c
doc/blktrace.tex

diff --git a/README b/README
index 14beccc689ef990bdf53bb32064821d0b75f5e1b..4c6d1f7c75bea73e9398a08550419dba5cf6d451 100644 (file)
--- a/README
+++ b/README
@@ -70,6 +70,7 @@ $ blktrace -d <dev> [ -r relay_path ] [ -o output ] [ -k ] [ -w time ]
 
 $ blkparse -i <input> [ -o <output> ] [ -b rb_batch ] [ -s ] [ -t ] [ -q ]
                      [ -w start:stop ] [ -f output format ] [ -F format spec ]
+                     [ -d <binary> ]
 
        -i Input file containing trace data, or '-' for stdin.
        -D Directory to prepend to input file names.
@@ -82,6 +83,7 @@ $ blkparse -i <input> [ -o <output> ] [ -b rb_batch ] [ -s ] [ -t ] [ -q ]
        -q Quiet. Don't display any stats at the end of the trace.
        -w Only parse data between the given time interval in seconds. If
           'start' isn't given, blkparse defaults the start time to 0.
+       -d Dump sorted data in binary format
        -f Output format. Customize the output format. The format field
           identifiers are:
 
index db553c7d45d1149799d70357cf384959f305bfe7..75bc622a1a4539cb0e697455df0039c101d7dcbd 100644 (file)
@@ -103,7 +103,7 @@ static struct per_process_info *ppi_hash_table[PPI_HASH_SIZE];
 static struct per_process_info *ppi_list;
 static int ppi_list_entries;
 
-#define S_OPTS "a:A:i:o:b:stqw:f:F:vVhD:"
+#define S_OPTS "a:A:i:o:b:stqw:f:F:vVhD:d:"
 static struct option l_opts[] = {
        {
                .name = "act-mask",
@@ -195,6 +195,12 @@ static struct option l_opts[] = {
                .flag = NULL,
                .val = 'D'
        },
+       {
+               .name = "dump-binary",
+               .has_arg = required_argument,
+               .flag = NULL,
+               .val = 'd'
+       },
        {
                .name = NULL,
        }
@@ -259,6 +265,9 @@ static unsigned int act_mask = -1U;
 static int stats_printed;
 int data_is_native = -1;
 
+static int dump_fd;
+static char *dump_binary;
+
 static unsigned int t_alloc_cache;
 static unsigned int bit_alloc_cache;
 
@@ -276,6 +285,18 @@ static volatile int done;
 #define CPU_IDX(cpu)   ((cpu) / CPUS_PER_LONG)
 #define CPU_BIT(cpu)   ((cpu) & (CPUS_PER_LONG - 1))
 
+static void output_binary(void *buf, int len)
+{
+       if (dump_binary) {
+               int n = write(dump_fd, buf, len);
+               if (n != len) {
+                       perror(dump_binary);
+                       close(dump_fd);
+                       dump_binary = NULL;
+               }
+       }
+}
+
 static void resize_cpu_info(struct per_dev_info *pdi, int cpu)
 {
        struct per_cpu_info *cpus = pdi->cpus;
@@ -1402,6 +1423,8 @@ static void dump_trace(struct blk_io_trace *t, struct per_cpu_info *pci,
                pdi->first_reported_time = t->time;
 
        pdi->events++;
+
+       output_binary(t, sizeof(*t) + t->pdu_len);
 }
 
 /*
@@ -1942,6 +1965,7 @@ static int read_events(int fd, int always_block, int *fdblock)
                 */
                if (bit->action & BLK_TC_ACT(BLK_TC_NOTIFY)) {
                        add_ppm_hash(bit->pid, (char *) bit + sizeof(*bit));
+                       output_binary(bit, sizeof(*bit) + bit->pdu_len);
                        continue;
                }
 
@@ -2175,6 +2199,7 @@ static char usage_str[] = \
        "\t-i Input file containing trace data, or '-' for stdin\n" \
        "\t-D Directory to prepend to input file names\n" \
        "\t-o Output file. If not given, output is stdout\n" \
+       "\t-d Output file. If specified, binary data is written to file\n" \
        "\t-b stdin read batching\n" \
        "\t-s Show per-program io statistics\n" \
        "\t-h Hash processes by name, not pid\n" \
@@ -2268,6 +2293,9 @@ int main(int argc, char *argv[])
                case 'V':
                        printf("%s version %s\n", argv[0], blkparse_version);
                        return 0;
+               case 'd':
+                       dump_binary = optarg;
+                       break;
                default:
                        usage(argv[0]);
                        return 1;
@@ -2320,6 +2348,15 @@ int main(int argc, char *argv[])
                return 1;
        }
 
+       if (dump_binary) {
+               dump_fd = creat(dump_binary, 0666);
+               if (dump_fd < 0) {
+                       perror(dump_binary);
+                       dump_binary = NULL;
+                       return 1;
+               }
+       }
+
        if (pipeline)
                ret = do_stdin();
        else
index df2051cf8679d088bc41f14628a5a41c143b5d7a..3149335503f5731172933ef24ca0ac6d63fa1e5a 100644 (file)
@@ -1,7 +1,7 @@
 \documentclass{article}
 
 %
-% Copyright (C) 2005 Alan D. Brunelle <Alan.Brunelle@hp.com>
+% Copyright (C) 2005, 2006 Alan D. Brunelle <Alan.Brunelle@hp.com>
 %
 %  This program is free software; you can redistribute it and/or modify
 %  it under the terms of the GNU General Public License as published by
@@ -21,7 +21,7 @@
 \title{blktrace User Guide}
 \author{blktrace: Jens Axboe (axboe@suse.de)\\
         User Guide: Alan D. Brunelle (Alan.Brunelle@hp.com)}
-\date{4 October 2005}
+\date{23 February 2005}
 
 \begin{document}
 \maketitle
@@ -485,6 +485,8 @@ Short              & Long                       & Description \\ \hline\hline
 
 -o \emph{file}     & --output=\emph{file}       & Output file \\ \hline
 
+-d \emph{file}     & --dump-binary=\emph{file}  & Binary output file \\ \hline
+
 -q                 & --quiet                    & Quite mode \\ \hline
 
 -s                 & --per-program-stats        & Displays data sorted by program \\ \hline