2 * blktrace output analysis: generate a timeline & gather statistics
4 * Copyright (C) 2006 Alan D. Brunelle <Alan.Brunelle@hp.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #define NBKTS (EXCESS_BKT + 1)
30 int hist[NBKTS * sizeof(int)];
33 void *unplug_hist_alloc(struct d_info *dip)
37 if (unplug_hist_name == NULL)
40 hbp = calloc(1, sizeof(*hbp));
46 void unplug_hist_add(struct io *u_iop)
50 dip = __dip_find(u_iop->t.device);
51 if (dip && dip->up_hist_handle) {
52 __u64 *val = u_iop->pdu;
53 int idx, n_unplugs = be64_to_cpu(*val);
54 struct hist_bkt *hbp = dip->up_hist_handle;
56 idx = (n_unplugs / BKT_WIDTH);
64 void unplug_hist_free(void *arg)
68 struct hist_bkt *hbp = arg;
69 size_t tlen = strlen(unplug_hist_name)
70 + strlen(hbp->dip->dip_name) + 32;
71 char *oname = malloc(tlen);
73 sprintf(oname, "%s_%s.dat", unplug_hist_name,
75 if ((fp = my_fopen(oname, "w")) != NULL) {
78 for (i = 0; i < NBKTS; i++)
79 fprintf(fp, "%d %d\n", i, hbp->hist[i]);