btt: better data file naming
authorAlan D. Brunelle <alan.brunelle@hp.com>
Thu, 8 Oct 2009 12:39:02 +0000 (08:39 -0400)
committerAlan D. Brunelle <alan.brunelle@hp.com>
Thu, 8 Oct 2009 12:39:02 +0000 (08:39 -0400)
More logical naming for .dat files created.

Signed-off-by: Alan D. Brunelle <alan.brunelle@hp.com>
btt/aqd.c
btt/bno_dump.c
btt/devs.c
btt/globals.h
btt/latency.c
btt/misc.c
btt/plat.c
btt/rstats.c
btt/seek.c
btt/unplug_hist.c

index 3a451616952cb43e5e1c28f96f40f3a339d47455..3bb6f8521f0c7935860ff562bf1a0819d6fb6a0a 100644 (file)
--- a/btt/aqd.c
+++ b/btt/aqd.c
@@ -29,7 +29,7 @@ struct aqd_info {
        int na;         /* # active */
 };
 
-void *aqd_alloc(char *str)
+void *aqd_alloc(struct d_info *dip)
 {
        char *oname;
        struct aqd_info *ap;
@@ -39,8 +39,8 @@ void *aqd_alloc(char *str)
        ap = malloc(sizeof(*ap));
        ap->na = 0;
 
-       oname = malloc(strlen(aqd_name) + strlen(str) + 32);
-       sprintf(oname, "%s_%s.dat", aqd_name, str);
+       oname = malloc(strlen(aqd_name) + strlen(dip->dip_name) + 32);
+       sprintf(oname, "%s_%s_aqd.dat", aqd_name, dip->dip_name);
        if ((ap->fp = my_fopen(oname, "w")) == NULL) {
                perror(oname);
                return NULL;
index 7365300de1535fd0cc0db421e22ce5b6da3d7841..02f38111d9b9e70f1bfe09192a826304f2e23e7f 100644 (file)
@@ -24,17 +24,13 @@ struct bno_dump {
        FILE *rfp, *wfp, *cfp;
 };
 
-static FILE *bno_dump_open(__u32 device, char rwc)
+static FILE *bno_dump_open(struct d_info *dip, char rwc)
 {
        FILE *fp;
        char *oname;
-       int mjr, mnr;
 
-       mjr = device >> MINORBITS;
-       mnr = device & ((1 << MINORBITS) - 1);
-
-       oname = malloc(strlen(bno_dump_name) + 32);
-       sprintf(oname, "%s_%03d,%03d_%c.dat", bno_dump_name, mjr, mnr, rwc);
+       oname = malloc(strlen(bno_dump_name) + strlen(dip->dip_name) + 32);
+       sprintf(oname, "%s_%s_%c.dat", bno_dump_name, dip->dip_name, rwc);
        if ((fp = my_fopen(oname, "w")) == NULL)
                perror(oname);
        else
@@ -48,16 +44,16 @@ static inline void bno_dump_write(FILE *fp, struct io *iop)
                (long long)BIT_START(iop), (long long)BIT_END(iop));
 }
 
-void *bno_dump_alloc(__u32 device)
+void *bno_dump_alloc(struct d_info *dip)
 {
        struct bno_dump *bdp;
 
        if (bno_dump_name == NULL) return NULL;
 
        bdp = malloc(sizeof(*bdp));
-       bdp->rfp = bno_dump_open(device, 'r');
-       bdp->wfp = bno_dump_open(device, 'w');
-       bdp->cfp = bno_dump_open(device, 'c');
+       bdp->rfp = bno_dump_open(dip, 'r');
+       bdp->wfp = bno_dump_open(dip, 'w');
+       bdp->cfp = bno_dump_open(dip, 'c');
 
        return bdp;
 }
index 2f1c6c065e840a98a9b39cbebf3d4601b5d96ec6..2e3d3607768da8555d650d71c5149be41dbe78c2 100644 (file)
@@ -104,20 +104,13 @@ void dip_exit(void)
        }
 }
 
-static inline char *mkhandle(char *str, __u32 device, char *post)
+static inline FILE *open_pit(struct d_info *dip)
 {
-       int mjr = device >> MINORBITS;
-       int mnr = device & ((1 << MINORBITS) - 1);
+       FILE *fp;
+       char str[256];
 
-       sprintf(str, "%03d,%03d%s", mjr, mnr, post);
-       return str;
-}
-
-static inline FILE *open_pit(char *str)
-{
-       FILE *fp = my_fopen(str, "w");
-
-       if (fp == NULL)
+       sprintf(str, "%s_pit.dat", dip->dip_name);
+       if ((fp = my_fopen(str, "w")) == NULL)
                perror(str);
 
        return fp;
@@ -128,38 +121,38 @@ struct d_info *dip_alloc(__u32 device, struct io *iop)
        struct d_info *dip = __dip_find(device);
 
        if (dip == NULL) {
-               char str[256];
-
                dip = malloc(sizeof(struct d_info));
                memset(dip, 0, sizeof(*dip));
-               dip->heads = dip_rb_mkhds();
-               region_init(&dip->regions);
                dip->device = device;
-               dip->last_q = (__u64)-1;
                dip->devmap = dev_map_find(device);
-               dip->bno_dump_handle = bno_dump_alloc(device);
-               dip->up_hist_handle = unplug_hist_alloc(device);
-               dip->seek_handle = seeki_alloc(mkhandle(str, device, "_d2d"));
-               dip->q2q_handle = seeki_alloc(mkhandle(str, device, "_q2q"));
-               dip->aqd_handle = aqd_alloc(mkhandle(str, device, "_aqd"));
-               dip->q2d_plat_handle =
-                               plat_alloc(mkhandle(str, device, "_q2d_plat"));
-               dip->q2c_plat_handle =
-                               plat_alloc(mkhandle(str, device, "_q2c_plat"));
-               dip->d2c_plat_handle =
-                               plat_alloc(mkhandle(str, device, "_d2c_plat"));
-               latency_alloc(dip);
-               list_add_tail(&dip->hash_head, &dev_heads[DEV_HASH(device)]);
-               list_add_tail(&dip->all_head, &all_devs);
+               dip->last_q = (__u64)-1;
+               dip->heads = dip_rb_mkhds();
+               region_init(&dip->regions);
                dip->start_time = BIT_TIME(iop->t.time);
                dip->pre_culling = 1;
-               dip->rstat_handle = rstat_alloc(mkhandle(str, device, ""));
+
+               mkhandle(dip, dip->dip_name, 256);
+
+               latency_alloc(dip);
+               dip->aqd_handle = aqd_alloc(dip);
+               dip->bno_dump_handle = bno_dump_alloc(dip);
+               dip->up_hist_handle = unplug_hist_alloc(dip);
+               dip->seek_handle = seeki_alloc(dip, "_d2d");
+               dip->q2q_handle = seeki_alloc(dip, "_q2q");
+               dip->q2d_plat_handle = plat_alloc(dip, "_q2d");
+               dip->q2c_plat_handle = plat_alloc(dip, "_q2c");
+               dip->d2c_plat_handle = plat_alloc(dip, "_d2c");
+               dip->rstat_handle = rstat_alloc(dip);
+
+               if (per_io_trees)
+                       dip->pit_fp = open_pit(dip);
+
                if (output_all_data)
                        dip->q2d_priv = q2d_alloc();
+
+               list_add_tail(&dip->hash_head, &dev_heads[DEV_HASH(device)]);
+               list_add_tail(&dip->all_head, &all_devs);
                n_devs++;
-               if (per_io_trees)
-                       dip->pit_fp = open_pit(mkhandle(per_io_trees,
-                                                         device, "_pit.dat"));
        }
 
        if (dip->pre_culling) {
index 5235ec650b0bc762c1c9b83790ee84bc6267821e..e7d910de5914d47e1208643d4cef69683d69b0fc 100644 (file)
@@ -131,7 +131,7 @@ struct d_info {
        struct list_head all_head, hash_head;
        void *heads;
        struct region_info regions;
-       char *devmap;
+       char *devmap, dip_name[256];
        void *q2q_handle, *seek_handle, *bno_dump_handle, *up_hist_handle;
        void *q2d_priv, *aqd_handle, *rstat_handle;
        void *q2d_plat_handle, *q2c_plat_handle, *d2c_plat_handle;
@@ -192,7 +192,7 @@ void handle_args(int argc, char *argv[]);
 void clean_args();
 
 /* aqd.c */
-void *aqd_alloc(char *str);
+void *aqd_alloc(struct d_info *dip);
 void aqd_free(void *info);
 void aqd_clean(void);
 void aqd_issue(void *info, double ts);
@@ -246,6 +246,7 @@ void latency_q2c(struct d_info *dip, __u64 tstamp, __u64 latency);
 void add_file(FILE *fp, char *oname);
 void add_buf(void *buf);
 char *make_dev_hdr(char *pad, size_t len, struct d_info *dip, int add_parens);
+char *mkhandle(struct d_info *dip, char *str, size_t len);
 FILE *my_fopen(const char *path, const char *mode);
 int my_open(const char *path, int flags);
 void dbg_ping(void);
@@ -269,13 +270,13 @@ void pip_foreach_out(void (*f)(struct p_info *, void *), void *arg);
 void pip_exit(void);
 
 /* bno_dump.c */
-void *bno_dump_alloc(__u32 device);
+void *bno_dump_alloc(struct d_info *dip);
 void bno_dump_free(void *param);
 void bno_dump_add(void *handle, struct io *iop);
 void bno_dump_clean(void);
 
 /* plat.c */
-void *plat_alloc(char *str);
+void *plat_alloc(struct d_info *dip, char *post);
 void plat_free(void *info);
 void plat_clean(void);
 void plat_x2c(void *info, __u64 ts, __u64 latency);
@@ -291,14 +292,14 @@ int q2d_ok(void *priv);
 void q2d_acc(void *a1, void *a2);
 
 /* rstats.c */
-void *rstat_alloc(char *bn);
+void *rstat_alloc(struct d_info *dip);
 void rstat_free(void *ptr);
 void rstat_add(void *ptr, double cur, unsigned long long nblks);
 int rstat_init(void);
 void rstat_exit(void);
 
 /* seek.c */
-void *seeki_alloc(char *str);
+void *seeki_alloc(struct d_info *dip, char *post);
 void seeki_free(void *param);
 void seek_clean(void);
 void seeki_add(void *handle, struct io *iop);
@@ -347,7 +348,7 @@ void trace_remap(struct io *a_iop);
 void trace_requeue(struct io *r_iop);
 
 /* unplug_hist.c */
-void *unplug_hist_alloc(__u32 device);
+void *unplug_hist_alloc(struct d_info *dip);
 void unplug_hist_free(void *arg);
 void unplug_hist_add(struct io *u_iop);
 
index e3ecc268caf8090c149114ac29a0ea510329f0e2..51e6881be1f8d7f7adab43581448e34786659a2d 100644 (file)
@@ -26,18 +26,16 @@ static inline void latency_out(FILE *ofp, __u64 tstamp, __u64 latency)
                fprintf(ofp, "%lf %lf\n", TO_SEC(tstamp), TO_SEC(latency));
 }
 
-FILE *latency_open(__u32 device, char *name, char *post)
+FILE *latency_open(struct d_info *dip, char *name, char *post)
 {
        FILE *fp = NULL;
 
        if (name) {
-               int mjr, mnr;
-               char oname[strlen(name) + 32];
+               size_t tlen = strlen(name) + strlen(dip->dip_name)
+                                          + strlen(post) + 32;
+               char oname[tlen];
 
-               mjr = device >> MINORBITS;
-               mnr = device & ((1 << MINORBITS) - 1);
-
-               sprintf(oname, "%s_%03d,%03d_%s.dat", name, mjr, mnr, post);
+               sprintf(oname, "%s_%s_%s.dat", name, dip->dip_name, post);
                if ((fp = my_fopen(oname, "w")) == NULL)
                        perror(oname);
                else
@@ -49,9 +47,9 @@ FILE *latency_open(__u32 device, char *name, char *post)
 
 void latency_alloc(struct d_info *dip)
 {
-       dip->q2d_ofp = latency_open(dip->device, q2d_name, "q2d");
-       dip->d2c_ofp = latency_open(dip->device, d2c_name, "d2c");
-       dip->q2c_ofp = latency_open(dip->device, q2c_name, "q2c");
+       dip->q2d_ofp = latency_open(dip, q2d_name, "q2d");
+       dip->d2c_ofp = latency_open(dip, d2c_name, "d2c");
+       dip->q2c_ofp = latency_open(dip, q2c_name, "q2c");
 }
 
 void latency_q2d(struct d_info *dip, __u64 tstamp, __u64 latency)
index 022955d1c200d640c14e8066143bae8ed9694969..2e27c81e099dffaa330704d6660bb14ab2126b61 100644 (file)
@@ -146,6 +146,11 @@ char *make_dev_hdr(char *pad, size_t len, struct d_info *dip, int add_parens)
        return pad;
 }
 
+char *mkhandle(struct d_info *dip, char *str, size_t len)
+{
+       return make_dev_hdr(str, len, dip, 0);
+}
+
 FILE *my_fopen(const char *path, const char *mode)
 {
        FILE *fp;
index 7a9bb2a2ea8224b5adb5cfd61eb6fdc6bfd6980d..e7b7dde6d22e49525c5fad2c6bce422dc1646e1e 100644 (file)
@@ -27,7 +27,7 @@ struct plat_info {
        double first_ts, last_ts, tl;
 };
 
-void *plat_alloc(char *str)
+void *plat_alloc(struct d_info *dip, char *post)
 {
        char *oname;
        struct plat_info *pp;
@@ -38,8 +38,8 @@ void *plat_alloc(char *str)
        pp->nl = 0;
        pp->first_ts = pp->last_ts = pp->tl = -1.0;
 
-       oname = malloc(strlen(str) + 32);
-       sprintf(oname, "%s.dat", str);
+       oname = malloc(strlen(dip->dip_name) + strlen(post) + 32);
+       sprintf(oname, "%s%s_plat.dat", dip->dip_name, post);
        if ((pp->fp = my_fopen(oname, "w")) == NULL) {
                perror(oname);
                return NULL;
index c0d2904aa439c6a7e3a527e12a02564b4c3711dc..71f010bfaa27bfbe6d0fbc170f64e85873996c5d 100644 (file)
@@ -51,11 +51,13 @@ static int do_open(struct files *fip, char *bn, char *pn)
        return -1;
 }
 
-static int init_rsip(struct rstat *rsip, char *bn)
+static int init_rsip(struct rstat *rsip, struct d_info *dip)
 {
+       char *nm = dip ? dip->dip_name : "sys";
+
        rsip->ios = rsip->nblks = 0;
-       if (do_open(&rsip->files[0], bn, "iops_fp") ||
-                           do_open(&rsip->files[1], bn, "mbps_fp"))
+       if (do_open(&rsip->files[0], nm, "iops_fp") ||
+                           do_open(&rsip->files[1], nm, "mbps_fp"))
                return -1;
 
        list_add_tail(&rsip->head, &rstats);
@@ -92,11 +94,11 @@ static void __add(struct rstat *rsip, double cur, unsigned long long nblks)
        rsip->nblks += nblks;
 }
 
-void *rstat_alloc(char *bn)
+void *rstat_alloc(struct d_info *dip)
 {
        struct rstat *rsip = malloc(sizeof(*rsip));
 
-       if (!init_rsip(rsip, bn))
+       if (!init_rsip(rsip, dip))
                return rsip;
 
        free(rsip);
@@ -121,7 +123,7 @@ void rstat_add(void *ptr, double cur, unsigned long long nblks)
 
 int rstat_init(void)
 {
-       sys_info = rstat_alloc("sys");
+       sys_info = rstat_alloc(NULL);
        return sys_info != NULL;
 }
 
index 4a03fbea97d6f74fe976b73f5e8922eebea13850..abdb0ee0c0b61324a703fdb5b06dc2b09744d165 100644 (file)
@@ -205,10 +205,12 @@ long long seek_dist(struct seeki *sip, struct io *iop)
        return dist;
 }
 
-void *seeki_alloc(char *str)
+void *seeki_alloc(struct d_info *dip, char *post)
 {
+       char str[256];
        struct seeki *sip = malloc(sizeof(struct seeki));
 
+       sprintf(str, "%s%s", dip->dip_name, post);
        sip->rfp = seek_open(str, 'r');
        sip->wfp = seek_open(str, 'w');
        sip->cfp = seek_open(str, 'c');
@@ -222,8 +224,8 @@ void *seeki_alloc(char *str)
 
                memset(&sip->sps, 0, sizeof(sip->sps));
 
-               oname = malloc(strlen(sps_name) + strlen(str) + 32);
-               sprintf(oname, "%s_%s.dat", sps_name, str);
+               oname = malloc(strlen(sps_name) + strlen(dip->dip_name) + 32);
+               sprintf(oname, "%s_%s.dat", sps_name, dip->dip_name);
                if ((sip->sps_fp = my_fopen(oname, "w")) == NULL)
                        perror(oname);
                else
index 8fd4285f87bb8fe907f502ca8e76004d668184e0..89995ded5297b15c421ca4c6bfec9446d447675b 100644 (file)
 #define NBKTS          (EXCESS_BKT + 1)
 
 struct hist_bkt {
-       __u32 dev;
+       struct d_info *dip;
        int hist[NBKTS * sizeof(int)];
 };
 
-void *unplug_hist_alloc(__u32 device)
+void *unplug_hist_alloc(struct d_info *dip)
 {
        struct hist_bkt *hbp;
 
        if (unplug_hist_name == NULL) return NULL;
 
        hbp = malloc(sizeof(*hbp));
-       hbp->dev = device;
+       hbp->dip = dip;
        memset(hbp->hist, 0, NBKTS * sizeof(int));
 
        return hbp;
@@ -66,11 +66,12 @@ void unplug_hist_free(void *arg)
        if (arg) {
                FILE *fp;
                struct hist_bkt *hbp = arg;
-               int mjr = hbp->dev >> MINORBITS;
-               int mnr = hbp->dev & ((1 << MINORBITS) - 1);
-               char *oname = malloc(strlen(unplug_hist_name) + 32);
+               size_t tlen = strlen(unplug_hist_name)
+                                       + strlen(hbp->dip->dip_name) + 32;
+               char *oname = malloc(tlen);
 
-               sprintf(oname, "%s_%03d,%03d.dat", unplug_hist_name, mjr, mnr);
+               sprintf(oname, "%s_%s.dat", unplug_hist_name,
+                                                       hbp->dip->dip_name);
                if ((fp = my_fopen(oname, "w")) != NULL) {
                        int i;