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
24 typedef struct avg_info *ai_dip_t;
25 ai_dip_t dip_q2q_avg(struct d_info *dip) { return &dip->avgs.q2q; }
26 ai_dip_t dip_q2c_avg(struct d_info *dip) { return &dip->avgs.q2c; }
27 ai_dip_t dip_q2a_avg(struct d_info *dip) { return &dip->avgs.q2a; }
28 ai_dip_t dip_q2i_avg(struct d_info *dip) { return &dip->avgs.q2i; }
29 ai_dip_t dip_i2d_avg(struct d_info *dip) { return &dip->avgs.i2d; }
30 ai_dip_t dip_d2c_avg(struct d_info *dip) { return &dip->avgs.d2c; }
32 typedef struct avg_info *ai_pip_t;
33 ai_pip_t pip_q2q_avg(struct p_info *pip) { return &pip->avgs.q2q; }
34 ai_pip_t pip_q2c_avg(struct p_info *pip) { return &pip->avgs.q2c; }
35 ai_pip_t pip_q2a_avg(struct p_info *pip) { return &pip->avgs.q2a; }
36 ai_pip_t pip_q2i_avg(struct p_info *pip) { return &pip->avgs.q2i; }
37 ai_pip_t pip_i2d_avg(struct p_info *pip) { return &pip->avgs.i2d; }
38 ai_pip_t pip_d2c_avg(struct p_info *pip) { return &pip->avgs.d2c; }
40 void output_section_hdr(FILE *ofp, char *hdr)
42 fprintf(ofp, "==================== ");
44 fprintf(ofp, " ====================\n\n");
47 void output_hdr(FILE *ofp, char *hdr)
49 fprintf(ofp, "%12s %13s %13s %13s %11s\n",
50 hdr, "MIN", "AVG", "MAX", "N" );
51 fprintf(ofp, "------------ ------------- ------------- ------------- -----------\n");
54 void __output_avg(FILE *ofp, char *hdr, struct avg_info *ap)
57 ap->avg = BIT_TIME(ap->total) / (double)ap->n;
58 fprintf(ofp, "%-12s %13.9f %13.9f %13.9f %11d\n", hdr,
59 BIT_TIME(ap->min), ap->avg, BIT_TIME(ap->max), ap->n);
63 void output_hdr2(FILE *ofp, char*hdr)
65 fprintf(ofp, "%12s %13s %13s %13s %13s %13s %13s\n", hdr, "Q2Q", "Q2A", "Q2I", "I2D", "D2C", "Q2C");
66 fprintf(ofp, "------------ ------------- ------------- ------------- ------------- ------------- -------------\n");
69 static inline char *avg2string(struct avg_info *ap, char *string)
72 sprintf(string, "%13.9f", ap->avg);
78 void __output_avg2(FILE *ofp, char *hdr, struct avgs_info *ap)
80 char c1[16], c2[16], c3[16], c4[16], c5[16], c6[16];
82 if (ap->q2q.n > 0 || ap->q2a.n > 0 || ap->q2i.n > 0 ||
83 ap->i2d.n > 0 || ap->d2c.n > 0 || ap->q2c.n > 0) {
84 fprintf(ofp, "%-12s %13s %13s %13s %13s %13s %13s\n", hdr,
85 avg2string(&ap->q2q,c1), avg2string(&ap->q2a,c2),
86 avg2string(&ap->q2i,c3), avg2string(&ap->i2d,c4),
87 avg2string(&ap->d2c,c5), avg2string(&ap->q2c,c6));
91 void __pip_output_avg2(struct p_info *pip, void *arg)
93 __output_avg2((FILE *)arg, pip->name, &pip->avgs);
96 void __dip_output_avg2(struct d_info *dip, void *arg)
99 __output_avg2((FILE *)arg, make_dev_hdr(dev_info, 12, dip), &dip->avgs);
102 char *make_dev_hdr(char *pad, size_t len, struct d_info *dip)
104 if (dip->map == NULL)
105 snprintf(pad, len, "(%3d,%3d)",
106 MAJOR(dip->device), MINOR(dip->device));
108 snprintf(pad, len, "%s", dip->map->device);
115 ai_dip_t (*func)(struct d_info *);
117 void __output_dip_avg(struct d_info *dip, void *arg)
119 struct __oda *odap = arg;
120 ai_dip_t ap = odap->func(dip);
123 ap->avg = BIT_TIME(ap->total) / (double)ap->n;
124 __output_avg(odap->ofp, make_dev_hdr(dev_info, 12, dip), ap);
128 void output_dip_avg(FILE *ofp, char *hdr, ai_dip_t (*func)(struct d_info *))
130 struct __oda oda = { .ofp = ofp, .func = func};
131 output_hdr(ofp, hdr);
132 dip_foreach_out(__output_dip_avg, &oda);
136 void __output_dip_merge_ratio(struct d_info *dip, void *arg)
140 double ratio, q2c_n = dip->avgs.q2c.n, d2c_n = dip->n_ds;
142 if (q2c_n > 0.0 && d2c_n > 0.0) {
143 ratio = q2c_n / d2c_n;
144 blks_avg = (double)dip->avgs.blks.total / d2c_n;
146 "%10s | %8llu %8llu %7.1lf | %8llu %8llu %8llu %8llu\n",
147 make_dev_hdr(scratch, 12, dip),
148 (unsigned long long)dip->avgs.q2c.n,
149 (unsigned long long)dip->n_ds,
151 (unsigned long long)dip->avgs.blks.min,
152 (unsigned long long)blks_avg,
153 (unsigned long long)dip->avgs.blks.max,
154 (unsigned long long)dip->avgs.blks.total);
159 void output_dip_merge_ratio(FILE *ofp)
161 fprintf(ofp, "%10s | %8s %8s %7s | %8s %8s %8s %8s\n", "DEV", "#Q", "#D", "Ratio", "BLKmin", "BLKavg", "BLKmax", "Total");
162 fprintf(ofp, "---------- | -------- -------- ------- | -------- -------- -------- --------\n");
163 dip_foreach_out(__output_dip_merge_ratio, ofp);
167 #define AVG(a,b) (100.0 * ((double)(a) / (double)(b)))
168 #define CALC_AVG(ap) (ap)->avg = ((ap)->n == 0 ? 0.0 : \
169 (BIT_TIME((ap)->total) / \
171 char *q2i_v_q2C(struct d_info *dip, char *s)
175 if (dip->avgs.q2i.n == 0) return " ";
177 q2c = dip->avgs.q2i.avg + dip->avgs.i2d.avg + dip->avgs.d2c.avg;
178 sprintf(s, "%5.1lf%%", AVG(dip->avgs.q2i.avg, q2c));
183 char *i2d_v_q2C(struct d_info *dip, char *s)
187 if (dip->avgs.d2c.n == 0) return " ";
189 q2c = dip->avgs.q2i.avg + dip->avgs.i2d.avg + dip->avgs.d2c.avg;
190 sprintf(s, "%5.1lf%%", AVG(dip->avgs.i2d.avg, q2c));
195 char *d2c_v_q2C(struct d_info *dip, char *s)
199 if (dip->avgs.d2c.n == 0) return " ";
201 q2c = dip->avgs.q2i.avg + dip->avgs.i2d.avg + dip->avgs.d2c.avg;
202 sprintf(s, "%5.1lf%%", AVG(dip->avgs.d2c.avg, q2c));
207 void __output_dip_prep_ohead(struct d_info *dip, void *arg)
210 char s1[16], s2[16], s3[16];
212 if ((dip->avgs.q2i.n > 0 && dip->avgs.i2d.n > 0 &&
213 dip->avgs.d2c.n > 0)) {
214 CALC_AVG(&dip->avgs.q2i);
215 CALC_AVG(&dip->avgs.i2d);
216 CALC_AVG(&dip->avgs.d2c);
218 fprintf((FILE *)arg, "%10s | %6s %6s %6s\n",
219 make_dev_hdr(dev_info, 12, dip),
220 q2i_v_q2C(dip, s1), i2d_v_q2C(dip, s2),
225 void output_dip_prep_ohead(FILE *ofp)
227 fprintf(ofp, "%10s | %6s %6s %6s\n", "DEV", "Q2I", "I2D", "D2C");
228 fprintf(ofp, "---------- | ------ ------ ------\n");
229 dip_foreach_out(__output_dip_prep_ohead, ofp);
233 void __output_dip_seek_info(struct d_info *dip, void *arg)
243 nseeks = seeki_nseeks(dip->seek_handle);
245 mean = seeki_mean(dip->seek_handle);
246 median = seeki_median(dip->seek_handle);
247 nmodes = seeki_mode(dip->seek_handle, &m);
249 fprintf(ofp, "%10s | %15lld %15.1lf %15lld | %lld(%d)",
250 make_dev_hdr(dev_info, 12, dip), nseeks, mean, median,
251 nmodes > 0 ? m.modes[0] : 0, m.most_seeks);
252 for (i = 1; i < nmodes; i++)
253 fprintf(ofp, " %lld", m.modes[i]);
258 void output_dip_seek_info(FILE *ofp)
260 fprintf(ofp, "%10s | %15s %15s %15s | %-15s\n", "DEV", "NSEEKS",
261 "MEAN", "MEDIAN", "MODE");
262 fprintf(ofp, "---------- "
263 "| --------------- --------------- --------------- "
264 "| ---------------\n");
265 dip_foreach_out(__output_dip_seek_info, ofp);
271 ai_pip_t (*func)(struct p_info *);
274 void __output_pip_avg(struct p_info *pip, void *arg)
276 struct __opa *opap = arg;
277 ai_pip_t ap = opap->func(pip);
281 snprintf(proc_name, 12, pip->name);
283 ap->avg = BIT_TIME(ap->total) / (double)ap->n;
284 __output_avg(opap->ofp, proc_name, ap);
288 void output_pip_avg(FILE *ofp, char *hdr, ai_pip_t (*func)(struct p_info *))
290 struct __opa opa = { .ofp = ofp, .func = func };
292 output_hdr(ofp, hdr);
293 pip_foreach_out(__output_pip_avg, &opa);
297 void output_dip_avgs(FILE *ofp)
299 output_hdr2(ofp,"Dev");
300 dip_foreach_out(__dip_output_avg2, ofp);
304 void output_pip_avgs(FILE *ofp)
306 output_hdr2(ofp,"Exe");
307 pip_foreach_out(__pip_output_avg2, ofp);
311 int output_avgs(FILE *ofp)
313 if (exes == NULL || *exes != '\0') {
314 output_section_hdr(ofp, "Per Process");
315 output_pip_avg(ofp, "Q2Q", pip_q2q_avg);
316 output_pip_avg(ofp, "Q2A", pip_q2a_avg);
317 output_pip_avg(ofp, "Q2I", pip_q2i_avg);
318 output_pip_avg(ofp, "I2D", pip_i2d_avg);
319 output_pip_avg(ofp, "D2C", pip_d2c_avg);
320 output_pip_avg(ofp, "Q2C", pip_q2c_avg);
323 output_section_hdr(ofp, "Per Device");
324 output_dip_avg(ofp, "Q2Q", dip_q2q_avg);
325 output_dip_avg(ofp, "Q2A", dip_q2a_avg);
326 output_dip_avg(ofp, "Q2I", dip_q2i_avg);
327 output_dip_avg(ofp, "I2D", dip_i2d_avg);
328 output_dip_avg(ofp, "D2C", dip_d2c_avg);
329 output_dip_avg(ofp, "Q2C", dip_q2c_avg);
331 output_section_hdr(ofp, "All Devices");
332 output_hdr(ofp, "ALL");
333 __output_avg(ofp, "Q2Q", &all_avgs.q2q);
334 __output_avg(ofp, "Q2A", &all_avgs.q2a);
335 __output_avg(ofp, "Q2I", &all_avgs.q2i);
336 __output_avg(ofp, "I2D", &all_avgs.i2d);
337 __output_avg(ofp, "D2C", &all_avgs.d2c);
338 __output_avg(ofp, "Q2C", &all_avgs.q2c);
340 if (exes == NULL || *exes != '\0') {
341 output_section_hdr(ofp, "Per Process (avgs)");
342 output_pip_avgs(ofp);
345 output_section_hdr(ofp, "Per Device (avgs)");
346 output_dip_avgs(ofp);
348 output_section_hdr(ofp, "Device Merge Information");
349 output_dip_merge_ratio(ofp);
351 output_section_hdr(ofp, "Device Overhead");
352 output_dip_prep_ohead(ofp);
355 output_section_hdr(ofp, "Device Seek Information");
356 output_dip_seek_info(ofp);
362 void __output_ranges(FILE *ofp, struct list_head *head_p, float base)
364 struct range_info *rip;
366 float limit = base + 0.4;
368 __list_for_each(p, head_p) {
369 rip = list_entry(p, struct range_info, head);
370 fprintf(ofp, "%13.9lf %5.1f\n", BIT_TIME(rip->start), base);
371 fprintf(ofp, "%13.9lf %5.1f\n", BIT_TIME(rip->start), limit);
372 fprintf(ofp, "%13.9lf %5.1f\n", BIT_TIME(rip->end), limit);
373 fprintf(ofp, "%13.9lf %5.1f\n", BIT_TIME(rip->end), base);
377 int output_regions(FILE *ofp, char *header, struct region_info *reg,
380 if (reg->qr_cur != NULL)
381 list_add_tail(®->qr_cur->head, ®->qranges);
382 if (reg->cr_cur != NULL)
383 list_add_tail(®->cr_cur->head, ®->cranges);
385 if (list_len(®->qranges) == 0 && list_len(®->cranges) == 0)
388 fprintf(ofp, "# %16s : q activity\n", header);
389 __output_ranges(ofp, ®->qranges, base);
392 fprintf(ofp, "# %16s : c activity\n", header);
393 __output_ranges(ofp, ®->cranges, base + 0.5);
403 void __output_dev(struct d_info *dip, void *arg)
406 struct __od *odp = arg;
408 sprintf(header, "%d,%d", MAJOR(dip->device), MINOR(dip->device));
409 if (output_regions(odp->ofp, header, &dip->regions, odp->base))
413 float output_devs(FILE *ofp, float base)
415 struct __od od = { .ofp = ofp, .base = base };
417 fprintf(ofp, "# Per device\n" );
418 dip_foreach_out(__output_dev, &od);
422 static inline int exe_match(char *exe, char *name)
424 return (exe == NULL) || (strstr(name, exe) != NULL);
431 void __output_procs(struct p_info *pip, void *arg)
433 struct __op *opp = arg;
434 output_regions(opp->ofp, pip->name, &pip->regions, opp->base);
438 float output_procs(FILE *ofp, float base)
440 struct __op op = { .ofp = ofp, .base = base };
442 fprintf(ofp, "# Per process\n" );
443 pip_foreach_out(__output_procs, &op);
447 int output_ranges(FILE *ofp)
451 fprintf(ofp, "# %s\n", "Total System");
452 if (output_regions(ofp, "Total System", &all_regions, base))
456 base = output_devs(ofp, base);
458 base = output_procs(ofp, base);