[PATCH] blkparse: Add -a/-A options to blkparse as well
authorAlan D. Brunelle <Alan.Brunelle@hp.com>
Wed, 5 Oct 2005 07:12:17 +0000 (09:12 +0200)
committerJens Axboe <axboe@suse.de>
Wed, 5 Oct 2005 07:12:17 +0000 (09:12 +0200)
This moves the mask stuff into a seperate file, act_mask.c

Makefile
act_mask.c [new file with mode: 0644]
blkparse.c
blktrace.c
blktrace.h

index 96edc555d5057ee9a594394f828cc11561e5b78f..16baa9ee4fafec092b10a1298c8299dc4833c80d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -6,10 +6,10 @@ SCRIPTS       = btrace
 
 all: $(PROGS) $(SCRIPTS)
 
-blkparse: blkparse.o blkparse_fmt.o rbtree.o
+blkparse: blkparse.o blkparse_fmt.o rbtree.o act_mask.o
        $(CC) $(CFLAGS) -o $@ $(filter %.o,$^)
 
-blktrace: blktrace.o $(LIBS)
+blktrace: blktrace.o act_mask.o $(LIBS)
        $(CC) $(CFLAGS) -o $@ $(filter %.o,$^) $(LIBS)
 
 verify_blkparse: verify_blkparse.o
diff --git a/act_mask.c b/act_mask.c
new file mode 100644 (file)
index 0000000..f2767bd
--- /dev/null
@@ -0,0 +1,42 @@
+#include <strings.h>
+#include "blktrace.h"
+
+#define DECLARE_MASK_MAP(mask)          { BLK_TC_##mask, #mask, "BLK_TC_"#mask }
+#define COMPARE_MASK_MAP(mmp, str)                                      \
+        (!strcasecmp((mmp)->short_form, (str)) ||                      \
+         !strcasecmp((mmp)->long_form, (str)))
+
+struct mask_map {
+       int mask;
+       char *short_form;
+       char *long_form;
+};
+
+static struct mask_map mask_maps[] = {
+       DECLARE_MASK_MAP(READ),
+       DECLARE_MASK_MAP(WRITE),
+       DECLARE_MASK_MAP(BARRIER),
+       DECLARE_MASK_MAP(SYNC),
+       DECLARE_MASK_MAP(QUEUE),
+       DECLARE_MASK_MAP(REQUEUE),
+       DECLARE_MASK_MAP(ISSUE),
+       DECLARE_MASK_MAP(COMPLETE),
+       DECLARE_MASK_MAP(FS),
+       DECLARE_MASK_MAP(PC),
+};
+
+int find_mask_map(char *string)
+{
+       unsigned int i;
+
+       for (i = 0; i < sizeof(mask_maps)/sizeof(mask_maps[0]); i++)
+               if (COMPARE_MASK_MAP(&mask_maps[i], string))
+                       return mask_maps[i].mask;
+
+       return -1;
+}
+
+int valid_act_opt(int x)
+{
+       return (1 <= x) && (x < (1 << BLK_TC_SHIFT));
+}
index 11354a75db4a0b1ba279b6f3a6c9a3d3dae3594f..9d67dab45a998e3a2ff1d59a544a14cf70072e3a 100644 (file)
@@ -81,8 +81,20 @@ 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 "i:o:b:stqw:f:F:vnmD:"
+#define S_OPTS "a:A:i:o:b:stqw:f:F:vnmD:"
 static struct option l_opts[] = {
+       {
+               .name = "act-mask",
+               .has_arg = required_argument,
+               .flag = NULL,
+               .val = 'a'
+       },
+       {
+               .name = "set-mask",
+               .has_arg = required_argument,
+               .flag = NULL,
+               .val = 'A'
+       },
        {
                .name = "input",
                .has_arg = required_argument,
@@ -216,6 +228,7 @@ static int per_process_stats;
 static int track_ios;
 static int ppi_hash_by_pid = 1;
 static int print_missing;
+static unsigned int act_mask = -1U;
 
 static unsigned int t_alloc_cache;
 static unsigned int bit_alloc_cache;
@@ -1397,7 +1410,8 @@ static void show_entries_rb(int force)
                if (!pci || pci->cpu != bit->cpu)
                        pci = get_cpu_info(pdi, bit->cpu);
 
-               dump_trace(bit, pci, pdi);
+               if (bit->action & (act_mask << BLK_TC_SHIFT)) 
+                       dump_trace(bit, pci, pdi);
 
                put_trace(pdi, t);
        }
@@ -1696,11 +1710,32 @@ static void usage(char *prog)
 int main(int argc, char *argv[])
 {
        char *ofp_buffer;
-       int c, ret, mode;
+       int i, c, ret, mode;
        int per_device_and_cpu_stats = 1;
+       int act_mask_tmp = 0;
 
        while ((c = getopt_long(argc, argv, S_OPTS, l_opts, NULL)) != -1) {
                switch (c) {
+               case 'a':
+                       i = find_mask_map(optarg);
+                       if (i < 0) {
+                               fprintf(stderr,"Invalid action mask %s\n",
+                                       optarg);
+                               return 1;
+                       }
+                       act_mask_tmp |= i;
+                       break;
+
+               case 'A':
+                       if ((sscanf(optarg, "%x", &i) != 1) || 
+                                                       !valid_act_opt(i)) {
+                               fprintf(stderr,
+                                       "Invalid set action mask %s/0x%x\n",
+                                       optarg, i);
+                               return 1;
+                       }
+                       act_mask_tmp = i;
+                       break;
                case 'i':
                        if (!strcmp(optarg, "-") && !pipeline)
                                pipeline = 1;
@@ -1766,6 +1801,9 @@ int main(int argc, char *argv[])
                return 1;
        }
 
+       if (act_mask_tmp != 0)
+               act_mask = act_mask_tmp;
+
        memset(&rb_sort_root, 0, sizeof(rb_sort_root));
 
        signal(SIGINT, handle_sigint);
index 7394a92c1d77349a05c522339e44be85090be335..b945e0e2839586d0963fbb807a6d869c44ead0c9 100644 (file)
@@ -44,32 +44,6 @@ static char blktrace_version[] = "0.90";
 
 #define RELAYFS_TYPE   0xF0B4A981
 
-#define DECLARE_MASK_MAP(mask)          { BLK_TC_##mask, #mask, "BLK_TC_"#mask }
-#define COMPARE_MASK_MAP(mmp, str)                                      \
-        (!strcasecmp((mmp)->short_form, (str)) ||                      \
-         !strcasecmp((mmp)->long_form, (str)))
-
-#define VALID_SET(x)   ((1 <= (x)) && ((x) < (1 << BLK_TC_SHIFT)))
-
-struct mask_map {
-       int mask;
-       char *short_form;
-       char *long_form;
-};
-
-static struct mask_map mask_maps[] = {
-       DECLARE_MASK_MAP(READ),
-       DECLARE_MASK_MAP(WRITE),
-       DECLARE_MASK_MAP(BARRIER),
-       DECLARE_MASK_MAP(SYNC),
-       DECLARE_MASK_MAP(QUEUE),
-       DECLARE_MASK_MAP(REQUEUE),
-       DECLARE_MASK_MAP(ISSUE),
-       DECLARE_MASK_MAP(COMPLETE),
-       DECLARE_MASK_MAP(FS),
-       DECLARE_MASK_MAP(PC),
-};
-
 #define S_OPTS "d:a:A:r:o:kw:vb:n:D:"
 static struct option l_opts[] = {
        {
@@ -187,17 +161,6 @@ static pthread_mutex_t stdout_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 static void exit_trace(int status);
 
-static int find_mask_map(char *string)
-{
-       unsigned int i;
-
-       for (i = 0; i < sizeof(mask_maps)/sizeof(mask_maps[0]); i++)
-               if (COMPARE_MASK_MAP(&mask_maps[i], string))
-                       return mask_maps[i].mask;
-
-       return -1;
-}
-
 static int start_trace(struct device_information *dip)
 {
        struct blk_user_trace_setup buts;
@@ -705,7 +668,8 @@ int main(int argc, char *argv[])
                        break;
 
                case 'A':
-                       if ((sscanf(optarg, "%x", &i) != 1) || !VALID_SET(i)) {
+                       if ((sscanf(optarg, "%x", &i) != 1) || 
+                                                       !valid_act_opt(i)) {
                                fprintf(stderr,
                                        "Invalid set action mask %s/0x%x\n",
                                        optarg, i);
index 799acf869613a1562eb3d75b8a31b0d91627dc82..c1e5df13cd9f0d75d1497cf6fd687b0fc698b15d 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef BLKTRACE_H
 #define BLKTRACE_H
 
+#include <stdio.h>
 #include <byteswap.h>
 #include <asm/types.h>
 #include <asm/byteorder.h>
@@ -112,5 +113,7 @@ extern void set_all_format_specs(char *);
 extern int add_format_spec(char *);
 extern void process_fmt(char *, struct per_cpu_info *, struct blk_io_trace *,
                        unsigned long long, int, unsigned char *);
+extern int valid_act_opt(int);
+extern int find_mask_map(char *);
 
 #endif