Cleanups: Fixed IOPs in btt left over at end of run
[blktrace.git] / btt / output.c
CommitLineData
63eba147
JA
1/*
2 * blktrace output analysis: generate a timeline & gather statistics
3 *
4 * Copyright (C) 2006 Alan D. Brunelle <Alan.Brunelle@hp.com>
5 *
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.
10 *
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.
15 *
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
19 *
20 */
21#include <stdio.h>
22#include "globals.h"
23
24typedef struct avg_info *ai_dip_t;
ae6d30f4
AB
25ai_dip_t dip_q2q_dm_avg(struct d_info *dip) { return &dip->avgs.q2q_dm; }
26ai_dip_t dip_q2a_dm_avg(struct d_info *dip) { return &dip->avgs.q2a_dm; }
27ai_dip_t dip_q2c_dm_avg(struct d_info *dip) { return &dip->avgs.q2c_dm; }
28
63eba147
JA
29ai_dip_t dip_q2q_avg(struct d_info *dip) { return &dip->avgs.q2q; }
30ai_dip_t dip_q2c_avg(struct d_info *dip) { return &dip->avgs.q2c; }
31ai_dip_t dip_q2a_avg(struct d_info *dip) { return &dip->avgs.q2a; }
ae6d30f4
AB
32ai_dip_t dip_q2g_avg(struct d_info *dip) { return &dip->avgs.q2g; }
33ai_dip_t dip_g2i_avg(struct d_info *dip) { return &dip->avgs.g2i; }
34ai_dip_t dip_q2m_avg(struct d_info *dip) { return &dip->avgs.q2m; }
63eba147
JA
35ai_dip_t dip_i2d_avg(struct d_info *dip) { return &dip->avgs.i2d; }
36ai_dip_t dip_d2c_avg(struct d_info *dip) { return &dip->avgs.d2c; }
37
38typedef struct avg_info *ai_pip_t;
ae6d30f4
AB
39ai_pip_t pip_q2q_dm_avg(struct p_info *pip) { return &pip->avgs.q2q_dm; }
40ai_pip_t pip_q2a_dm_avg(struct p_info *pip) { return &pip->avgs.q2a_dm; }
41ai_pip_t pip_q2c_dm_avg(struct p_info *pip) { return &pip->avgs.q2c_dm; }
42
63eba147
JA
43ai_pip_t pip_q2q_avg(struct p_info *pip) { return &pip->avgs.q2q; }
44ai_pip_t pip_q2c_avg(struct p_info *pip) { return &pip->avgs.q2c; }
45ai_pip_t pip_q2a_avg(struct p_info *pip) { return &pip->avgs.q2a; }
ae6d30f4
AB
46ai_pip_t pip_q2g_avg(struct p_info *pip) { return &pip->avgs.q2g; }
47ai_pip_t pip_g2i_avg(struct p_info *pip) { return &pip->avgs.g2i; }
48ai_pip_t pip_q2m_avg(struct p_info *pip) { return &pip->avgs.q2m; }
63eba147
JA
49ai_pip_t pip_i2d_avg(struct p_info *pip) { return &pip->avgs.i2d; }
50ai_pip_t pip_d2c_avg(struct p_info *pip) { return &pip->avgs.d2c; }
51
52void output_section_hdr(FILE *ofp, char *hdr)
53{
54 fprintf(ofp, "==================== ");
55 fprintf(ofp, hdr);
56 fprintf(ofp, " ====================\n\n");
57}
58
59void output_hdr(FILE *ofp, char *hdr)
60{
095181f2 61 fprintf(ofp, "%15s %13s %13s %13s %11s\n",
63eba147 62 hdr, "MIN", "AVG", "MAX", "N" );
095181f2 63 fprintf(ofp, "--------------- ------------- ------------- ------------- -----------\n");
63eba147
JA
64}
65
66void __output_avg(FILE *ofp, char *hdr, struct avg_info *ap)
67{
68 if (ap->n > 0) {
69 ap->avg = BIT_TIME(ap->total) / (double)ap->n;
095181f2 70 fprintf(ofp, "%-15s %13.9f %13.9f %13.9f %11d\n", hdr,
63eba147
JA
71 BIT_TIME(ap->min), ap->avg, BIT_TIME(ap->max), ap->n);
72 }
73}
74
63eba147
JA
75static inline char *avg2string(struct avg_info *ap, char *string)
76{
77 if (ap->n > 0)
78 sprintf(string, "%13.9f", ap->avg);
79 else
80 sprintf(string, " ");
81 return string;
82}
83
63eba147
JA
84char *make_dev_hdr(char *pad, size_t len, struct d_info *dip)
85{
6119854c 86 if (dip->map == NULL)
b70a6642 87 snprintf(pad, len, "(%3d,%3d)",
63eba147 88 MAJOR(dip->device), MINOR(dip->device));
6119854c
ADB
89 else
90 snprintf(pad, len, "%s", dip->map->device);
63eba147
JA
91
92 return pad;
93}
94
6eb42155
ADB
95struct __oda {
96 FILE *ofp;
97 ai_dip_t (*func)(struct d_info *);
98};
99void __output_dip_avg(struct d_info *dip, void *arg)
63eba147 100{
6eb42155
ADB
101 struct __oda *odap = arg;
102 ai_dip_t ap = odap->func(dip);
63eba147 103 if (ap->n > 0) {
095181f2 104 char dev_info[15];
63eba147 105 ap->avg = BIT_TIME(ap->total) / (double)ap->n;
095181f2 106 __output_avg(odap->ofp, make_dev_hdr(dev_info, 15, dip), ap);
63eba147
JA
107 }
108}
109
110void output_dip_avg(FILE *ofp, char *hdr, ai_dip_t (*func)(struct d_info *))
111{
6eb42155 112 struct __oda oda = { .ofp = ofp, .func = func};
63eba147 113 output_hdr(ofp, hdr);
6eb42155 114 dip_foreach_out(__output_dip_avg, &oda);
63eba147
JA
115 fprintf(ofp, "\n");
116}
117
951ea56c
AB
118struct __q2d {
119 FILE *ofp;
120 void *q2d_all;
121 int n;
122};
123void __output_q2d_histo(struct d_info *dip, void *arg)
124{
125 struct __q2d *q2dp = arg;
126
127 if (q2d_ok(dip->q2d_priv)) {
128 char scratch[15];
129 FILE *ofp = q2dp->ofp;
130
131 fprintf(q2dp->ofp, "%10s | ", make_dev_hdr(scratch, 15, dip));
132 q2d_display(ofp, dip->q2d_priv);
133 q2d_acc(q2dp->q2d_all, dip->q2d_priv);
134 q2dp->n++;
135 }
136}
137
138void output_q2d_histo(FILE *ofp)
139{
140 struct __q2d __q2d = {
141 .ofp = ofp,
142 .q2d_all = q2d_init(),
143 .n = 0
144 };
145
146 fprintf(ofp, "%10s | ", "DEV");
147 q2d_display_header(ofp);
148 fprintf(ofp, "--------- | ");
149 q2d_display_dashes(ofp);
150 dip_foreach_out(__output_q2d_histo, &__q2d);
151
152 if (__q2d.n) {
153 fprintf(ofp, "========== | ");
154 q2d_display_dashes(ofp);
155 fprintf(ofp, "%10s | ", "AVG");
156 q2d_display(ofp, __q2d.q2d_all);
157 fprintf(ofp, "\n");
158 }
159}
160
773c17a0
AB
161int n_merges = 0;
162struct {
163 unsigned long long nq, nd, blkmin, blkmax, total;
164} merge_data;
6eb42155 165void __output_dip_merge_ratio(struct d_info *dip, void *arg)
63eba147
JA
166{
167 double blks_avg;
095181f2 168 char scratch[15];
77f256cd 169 double ratio, q2c_n, d2c_n;
63eba147 170
77f256cd
AB
171 if (dip->n_qs == 0 || dip->n_ds == 0)
172 return;
173 else if (dip->n_qs < dip->n_ds)
174 dip->n_qs = dip->n_ds;
175
176 q2c_n = dip->n_qs;
177 d2c_n = dip->n_ds;
63eba147 178 if (q2c_n > 0.0 && d2c_n > 0.0) {
77f256cd
AB
179 if (q2c_n < d2c_n)
180 ratio = 1.0;
181 else
182 ratio = q2c_n / d2c_n;
9f11c1a7 183 blks_avg = (double)dip->avgs.blks.total / d2c_n;
b70a6642 184 fprintf((FILE *)arg,
6eb42155 185 "%10s | %8llu %8llu %7.1lf | %8llu %8llu %8llu %8llu\n",
095181f2 186 make_dev_hdr(scratch, 15, dip),
77f256cd 187 (unsigned long long)dip->n_qs,
63eba147
JA
188 (unsigned long long)dip->n_ds,
189 ratio,
190 (unsigned long long)dip->avgs.blks.min,
191 (unsigned long long)blks_avg,
192 (unsigned long long)dip->avgs.blks.max,
193 (unsigned long long)dip->avgs.blks.total);
194
773c17a0
AB
195 if (n_merges++ == 0) {
196 merge_data.blkmin = dip->avgs.blks.min;
197 merge_data.blkmax = dip->avgs.blks.max;
198 }
199
77f256cd 200 merge_data.nq += dip->n_qs;
773c17a0
AB
201 merge_data.nd += dip->n_ds;
202 merge_data.total += dip->avgs.blks.total;
203 if (dip->avgs.blks.min < merge_data.blkmin)
204 merge_data.blkmin = dip->avgs.blks.min;
205 if (dip->avgs.blks.max > merge_data.blkmax)
206 merge_data.blkmax = dip->avgs.blks.max;
63eba147
JA
207 }
208}
209
210void output_dip_merge_ratio(FILE *ofp)
211{
63eba147
JA
212 fprintf(ofp, "%10s | %8s %8s %7s | %8s %8s %8s %8s\n", "DEV", "#Q", "#D", "Ratio", "BLKmin", "BLKavg", "BLKmax", "Total");
213 fprintf(ofp, "---------- | -------- -------- ------- | -------- -------- -------- --------\n");
6eb42155 214 dip_foreach_out(__output_dip_merge_ratio, ofp);
773c17a0
AB
215 if (n_merges > 1) {
216 fprintf(ofp, "---------- | -------- -------- ------- | -------- -------- -------- --------\n");
217 fprintf(ofp, "%10s | %8s %8s %7s | %8s %8s %8s %8s\n", "DEV", "#Q", "#D", "Ratio", "BLKmin", "BLKavg", "BLKmax", "Total");
b70a6642 218 fprintf((FILE *)ofp,
773c17a0 219 "%10s | %8llu %8llu %7.1lf | %8llu %8llu %8llu %8llu\n",
b70a6642 220 "TOTAL", merge_data.nq, merge_data.nd,
773c17a0 221 (float)merge_data.nq / (float)merge_data.nd,
b70a6642 222 merge_data.blkmin,
773c17a0
AB
223 merge_data.total / merge_data.nd,
224 merge_data.blkmax, merge_data.total);
225 }
63eba147
JA
226 fprintf(ofp, "\n");
227}
228
ae6d30f4
AB
229struct __ohead_data {
230 __u64 total;
231 int n;
232};
233
234struct ohead_data {
235 FILE *ofp;
236 struct __ohead_data q2g, g2i, q2m, i2d, d2c;
237};
238
63eba147
JA
239#define AVG(a,b) (100.0 * ((double)(a) / (double)(b)))
240#define CALC_AVG(ap) (ap)->avg = ((ap)->n == 0 ? 0.0 : \
241 (BIT_TIME((ap)->total) / \
242 (double)(ap)->n))
63eba147 243
ae6d30f4
AB
244#define x_v_q2C(fld, dip, s, odp) \
245 double q2c; \
246 if (dip->avgs. fld .n == 0) return " "; \
247 q2c = dip->avgs.g2i.avg + dip->avgs.g2i.avg + \
248 dip->avgs.i2d.avg + dip->avgs.d2c.avg; \
249 sprintf(s, "%8.4lf%%", AVG(dip->avgs. fld .avg, q2c)); \
250 odp-> fld .n += dip->avgs. fld .n; \
251 odp-> fld .total += dip->avgs. fld .total; \
63eba147 252 return s;
63eba147 253
ae6d30f4 254char *q2g_v_q2C(struct d_info *dip, char *s, struct ohead_data *odp)
63eba147 255{
ae6d30f4 256 x_v_q2C(q2g, dip, s, odp);
63eba147
JA
257}
258
ae6d30f4 259char *g2i_v_q2C(struct d_info *dip, char *s, struct ohead_data *odp)
63eba147 260{
ae6d30f4
AB
261 x_v_q2C(g2i, dip, s, odp);
262}
63eba147 263
ae6d30f4
AB
264char *q2m_v_q2C(struct d_info *dip, char *s, struct ohead_data *odp)
265{
266 x_v_q2C(q2m, dip, s, odp);
267}
63eba147 268
ae6d30f4
AB
269char *i2d_v_q2C(struct d_info *dip, char *s, struct ohead_data *odp)
270{
271 x_v_q2C(i2d, dip, s, odp);
272}
63eba147 273
ae6d30f4
AB
274char *d2c_v_q2C(struct d_info *dip, char *s, struct ohead_data *odp)
275{
276 x_v_q2C(d2c, dip, s, odp);
63eba147
JA
277}
278
6eb42155 279void __output_dip_prep_ohead(struct d_info *dip, void *arg)
63eba147 280{
095181f2 281 char dev_info[15];
ae6d30f4
AB
282 char s1[16], s2[16], s3[16], s4[16], s5[16];
283 struct ohead_data *odp = arg;
284
b70a6642 285 if (dip->avgs.q2g.n > 0 && dip->avgs.g2i.n > 0 &&
ae6d30f4
AB
286 dip->avgs.i2d.n > 0 && dip->avgs.d2c.n > 0) {
287 CALC_AVG(&dip->avgs.q2g);
288 CALC_AVG(&dip->avgs.g2i);
289 CALC_AVG(&dip->avgs.q2m);
63eba147
JA
290 CALC_AVG(&dip->avgs.i2d);
291 CALC_AVG(&dip->avgs.d2c);
292
ae6d30f4 293 fprintf(odp->ofp, "%10s | %9s %9s %9s %9s %9s\n",
095181f2 294 make_dev_hdr(dev_info, 15, dip),
b70a6642
AB
295 q2g_v_q2C(dip, s1, odp),
296 g2i_v_q2C(dip, s2, odp),
ae6d30f4
AB
297 q2m_v_q2C(dip, s3, odp),
298 i2d_v_q2C(dip, s4, odp),
299 d2c_v_q2C(dip, s5, odp));
63eba147
JA
300 }
301}
302
ae6d30f4
AB
303#define OD_AVG(od, fld, q2c) \
304 (od. fld .n == 0) ? (double)0.0 : \
305 (100.0 * ((double)((od). fld . total) / q2c))
306
63eba147
JA
307void output_dip_prep_ohead(FILE *ofp)
308{
ae6d30f4
AB
309 double q2c;
310 struct ohead_data od;
311
312 memset(&od, 0, sizeof(od));
313 od.ofp = ofp;
314
b70a6642 315 fprintf(ofp, "%10s | %9s %9s %9s %9s %9s\n",
ae6d30f4
AB
316 "DEV", "Q2G", "G2I", "Q2M", "I2D", "D2C");
317 fprintf(ofp, "---------- | --------- --------- --------- --------- ---------\n");
318 dip_foreach_out(__output_dip_prep_ohead, &od);
319
b70a6642 320 if (od.q2g.n == 0 && od.g2i.n == 0 && od.q2m.n == 0 &&
ae6d30f4
AB
321 od.i2d.n == 0 && od.d2c.n == 0)
322 goto out;
323
b70a6642 324 q2c = od.q2g.total + od.g2i.total + od.q2m.total +
ae6d30f4
AB
325 od.i2d.total + od.d2c.total;
326 fprintf(ofp, "---------- | --------- --------- --------- --------- ---------\n");
b70a6642
AB
327 fprintf(ofp, "%10s | %8.4lf%% %8.4lf%% %8.4lf%% %8.4lf%% %8.4lf%%\n", "Overall",
328 OD_AVG(od, q2g, q2c), OD_AVG(od, g2i, q2c),
329 OD_AVG(od, q2m, q2c), OD_AVG(od, i2d, q2c),
ae6d30f4
AB
330 OD_AVG(od, d2c, q2c));
331
332out:
63eba147
JA
333 fprintf(ofp, "\n");
334}
335
756d1f46
AB
336struct seek_mode_info {
337 struct seek_mode_info *next;
338 long long mode;
339 int nseeks;
340};
341struct o_seek_info {
342 long long nseeks, median;
343 double mean;
344 struct seek_mode_info *head;
4c48f14e
AB
345} seek_info;
346int n_seeks;
347
756d1f46
AB
348void output_seek_mode_info(FILE *ofp, struct o_seek_info *sip)
349{
350 struct seek_mode_info *p, *this, *new_list = NULL;
351
756d1f46
AB
352 while ((this = sip->head) != NULL) {
353 sip->head = this->next;
4c48f14e
AB
354 this->next = NULL;
355
356 if (new_list == NULL || this->nseeks > new_list->nseeks)
756d1f46 357 new_list = this;
4c48f14e 358 else if (this->nseeks == new_list->nseeks) {
4c48f14e
AB
359 for (p = new_list; p != NULL; p = p->next)
360 if (p->mode == this->mode)
361 break;
362
363 if (p)
364 this->nseeks += p->nseeks;
365 else
366 this->next = new_list;
756d1f46 367 new_list = this;
756d1f46 368 }
756d1f46
AB
369 }
370
371 fprintf(ofp, "%10s | %15lld %15.1lf %15lld | %lld(%d)",
b70a6642 372 "Average", sip->nseeks, sip->mean / sip->nseeks,
756d1f46
AB
373 sip->median / sip->nseeks, new_list->mode, new_list->nseeks);
374
4c48f14e
AB
375 for (p = new_list->next; p != NULL; p = p->next)
376 fprintf(ofp, " %lld(%d)", p->mode, p->nseeks);
756d1f46 377}
69040794 378
756d1f46
AB
379void add_seek_mode_info(struct o_seek_info *sip, struct mode *mp)
380{
381 int i;
382 long long *lp = mp->modes;
383 struct seek_mode_info *smip;
384
385 n_seeks++;
4c48f14e 386 for (i = 0; i < mp->nmds; i++, lp++) {
756d1f46 387 for (smip = sip->head; smip; smip = smip->next) {
4c48f14e 388 if (smip->mode == *lp) {
756d1f46
AB
389 smip->nseeks += mp->most_seeks;
390 break;
391 }
392 }
393 if (!smip) {
394 struct seek_mode_info *new = malloc(sizeof(*new));
395
b70a6642 396 new->next = sip->head;
756d1f46 397 sip->head = new;
4c48f14e 398 new->mode = *lp;
756d1f46 399 new->nseeks = mp->most_seeks;
69040794
AB
400
401 add_buf(new);
756d1f46
AB
402 }
403 }
404}
405
4c48f14e 406static void do_output_dip_seek_info(struct d_info *dip, FILE *ofp, int is_q2q)
5225e788
AB
407{
408 double mean;
6eb42155 409 int i, nmodes;
5225e788 410 long long nseeks;
095181f2 411 char dev_info[15];
6eb42155
ADB
412 long long median;
413 struct mode m;
4c48f14e 414 void *handle = is_q2q ? dip->q2q_handle : dip->seek_handle;
5225e788 415
4c48f14e 416 nseeks = seeki_nseeks(handle);
165e0a18 417 if (nseeks > 0) {
4c48f14e
AB
418 mean = seeki_mean(handle);
419 median = seeki_median(handle);
420 nmodes = seeki_mode(handle, &m);
165e0a18
AB
421
422 fprintf(ofp, "%10s | %15lld %15.1lf %15lld | %lld(%d)",
b70a6642 423 make_dev_hdr(dev_info, 15, dip), nseeks, mean, median,
6eb42155 424 nmodes > 0 ? m.modes[0] : 0, m.most_seeks);
165e0a18 425 for (i = 1; i < nmodes; i++)
6eb42155 426 fprintf(ofp, " %lld", m.modes[i]);
165e0a18 427 fprintf(ofp, "\n");
756d1f46
AB
428
429 seek_info.nseeks += nseeks;
430 seek_info.mean += (nseeks * mean);
431 seek_info.median += (nseeks * median);
432 add_seek_mode_info(&seek_info, &m);
69040794 433 free(m.modes);
165e0a18 434 }
5225e788
AB
435}
436
4c48f14e
AB
437void __output_dip_seek_info(struct d_info *dip, void *arg)
438{
439 do_output_dip_seek_info(dip, (FILE *)arg, 0);
440}
441
442void __output_dip_q2q_seek_info(struct d_info *dip, void *arg)
443{
444 do_output_dip_seek_info(dip, (FILE *)arg, 1);
445}
446
5225e788
AB
447void output_dip_seek_info(FILE *ofp)
448{
4c48f14e
AB
449 n_seeks = 1;
450 memset(&seek_info, 0, sizeof(seek_info));
451
b70a6642 452 fprintf(ofp, "%10s | %15s %15s %15s | %-15s\n", "DEV", "NSEEKS",
5225e788 453 "MEAN", "MEDIAN", "MODE");
756d1f46 454 fprintf(ofp, "---------- | --------------- --------------- --------------- | ---------------\n");
6eb42155 455 dip_foreach_out(__output_dip_seek_info, ofp);
756d1f46
AB
456 if (n_seeks > 1) {
457 fprintf(ofp, "---------- | --------------- --------------- --------------- | ---------------\n");
b70a6642 458 fprintf(ofp, "%10s | %15s %15s %15s | %-15s\n",
756d1f46
AB
459 "Overall", "NSEEKS", "MEAN", "MEDIAN", "MODE");
460 output_seek_mode_info(ofp, &seek_info);
db8570e9 461 fprintf(ofp, "\n");
756d1f46 462 }
5225e788
AB
463 fprintf(ofp, "\n");
464}
465
4c48f14e
AB
466void output_dip_q2q_seek_info(FILE *ofp)
467{
468 n_seeks = 1;
469 memset(&seek_info, 0, sizeof(seek_info));
470
b70a6642 471 fprintf(ofp, "%10s | %15s %15s %15s | %-15s\n", "DEV", "NSEEKS",
4c48f14e
AB
472 "MEAN", "MEDIAN", "MODE");
473 fprintf(ofp, "---------- | --------------- --------------- --------------- | ---------------\n");
474 dip_foreach_out(__output_dip_q2q_seek_info, ofp);
475 if (n_seeks > 1) {
476 fprintf(ofp, "---------- | --------------- --------------- --------------- | ---------------\n");
b70a6642 477 fprintf(ofp, "%10s | %15s %15s %15s | %-15s\n",
4c48f14e
AB
478 "Overall", "NSEEKS", "MEAN", "MEDIAN", "MODE");
479 output_seek_mode_info(ofp, &seek_info);
480 fprintf(ofp, "\n");
481 }
482 fprintf(ofp, "\n");
483}
484
6eb42155
ADB
485struct __opa {
486 FILE *ofp;
487 ai_pip_t (*func)(struct p_info *);
488};
489
490void __output_pip_avg(struct p_info *pip, void *arg)
63eba147 491{
6eb42155
ADB
492 struct __opa *opap = arg;
493 ai_pip_t ap = opap->func(pip);
494
63eba147 495 if (ap->n > 0) {
095181f2
JA
496 char proc_name[15];
497 snprintf(proc_name, 15, pip->name);
63eba147
JA
498
499 ap->avg = BIT_TIME(ap->total) / (double)ap->n;
6eb42155 500 __output_avg(opap->ofp, proc_name, ap);
63eba147
JA
501 }
502}
503
504void output_pip_avg(FILE *ofp, char *hdr, ai_pip_t (*func)(struct p_info *))
505{
6eb42155 506 struct __opa opa = { .ofp = ofp, .func = func };
63eba147
JA
507
508 output_hdr(ofp, hdr);
6eb42155 509 pip_foreach_out(__output_pip_avg, &opa);
63eba147
JA
510 fprintf(ofp, "\n");
511}
512
33f35150
AB
513int n_plugs;
514struct plug_info {
515 long n_plugs, n_timer_unplugs;
516 double t_percent;
517} plug_info;
518
b2822cea
AB
519void __dip_output_plug(struct d_info *dip, void *arg)
520{
521 char dev_info[15];
522 FILE *ofp = arg;
33f35150 523 double delta, pct;
b2822cea 524
db8570e9 525 if (dip->nplugs > 0) {
b70a6642 526 if (dip->is_plugged) dip_unplug(dip->device, dip->end_time, 0);
db8570e9
AB
527 delta = dip->end_time - dip->start_time;
528 pct = 100.0 * ((dip->plugged_time / delta) / delta);
33f35150 529
b70a6642
AB
530 fprintf(ofp, "%10s | %10d(%10d) | %13.9lf%%\n",
531 make_dev_hdr(dev_info, 15, dip),
db8570e9 532 dip->nplugs, dip->n_timer_unplugs, pct);
33f35150 533
db8570e9
AB
534 n_plugs++;
535 plug_info.n_plugs += dip->nplugs;
536 plug_info.n_timer_unplugs += dip->n_timer_unplugs;
537 plug_info.t_percent += pct;
538 }
33f35150
AB
539}
540
541void __dip_output_plug_all(FILE *ofp, struct plug_info *p)
542{
543 fprintf(ofp, "---------- | ---------- ---------- | ----------------\n");
b70a6642 544 fprintf(ofp, "%10s | %10s %10s | %s\n",
69040794
AB
545 "Overall", "# Plugs", "# Timer Us", "% Time Q Plugged");
546 fprintf(ofp, "%10s | %10ld(%10ld) | %13.9lf%%\n", "Average",
b70a6642 547 p->n_plugs / n_plugs, p->n_timer_unplugs / n_plugs,
33f35150
AB
548 p->t_percent / n_plugs);
549
b2822cea
AB
550}
551
b70a6642
AB
552__u64 n_nios_uplugs, n_nios_uplugs_t;
553struct nios_plug_info {
554 __u64 tot_nios_up, tot_nios_up_t;
555} nios_plug_info;
556
557void __dip_output_plug_nios(struct d_info *dip, void *arg)
558{
559 char dev_info[15];
560 FILE *ofp = arg;
561 double a_nios_uplug = 0.0, a_nios_uplug_t = 0.0;
562
563 if (dip->nios_up && dip->nplugs) {
564 a_nios_uplug = (double)dip->nios_up / (double)dip->nplugs;
565 n_nios_uplugs += dip->nplugs;
566 nios_plug_info.tot_nios_up += dip->nios_up;
567 }
568 if (dip->nios_upt && dip->nplugs_t) {
569 a_nios_uplug_t = (double)dip->nios_upt / (double)dip->nplugs_t;
570 n_nios_uplugs_t += dip->nplugs_t;
571 nios_plug_info.tot_nios_up_t += dip->nios_upt;
572 }
573
574 fprintf(ofp, "%10s | %10.1lf %10.1lf\n",
575 make_dev_hdr(dev_info, 15, dip),
576 a_nios_uplug, a_nios_uplug_t);
577}
578
579void __dip_output_uplug_all(FILE *ofp, struct nios_plug_info *p)
580{
581 double ios_unp = 0.0, ios_unp_to = 0.0;
582
583 if (n_nios_uplugs)
584 ios_unp = (double)p->tot_nios_up / (double)n_nios_uplugs;
585 if (n_nios_uplugs_t)
586 ios_unp_to = (double)p->tot_nios_up_t / (double)n_nios_uplugs_t;
587
588 fprintf(ofp, "---------- | ---------- ----------\n");
589 fprintf(ofp, "%10s | %10s %10s\n",
590 "Overall", "IOs/Unp", "IOs/Unp(to)");
591 fprintf(ofp, "%10s | %10.1lf %10.1lf\n",
592 "Average", ios_unp, ios_unp_to);
593}
594
b2822cea
AB
595void output_plug_info(FILE *ofp)
596{
b70a6642 597 fprintf(ofp, "%10s | %10s %10s | %s\n",
33f35150
AB
598 "DEV", "# Plugs", "# Timer Us", "% Time Q Plugged");
599 fprintf(ofp, "---------- | ---------- ---------- | ----------------\n");
b2822cea 600 dip_foreach_out(__dip_output_plug, ofp);
33f35150
AB
601 if (n_plugs > 1)
602 __dip_output_plug_all(ofp, &plug_info);
b2822cea 603 fprintf(ofp, "\n");
b70a6642
AB
604
605 fprintf(ofp, "%10s | %10s %10s\n",
606 "DEV", "IOs/Unp", "IOs/Unp(to)");
607 fprintf(ofp, "---------- | ---------- ----------\n");
608 dip_foreach_out(__dip_output_plug_nios, ofp);
609 if (n_nios_uplugs || n_nios_uplugs_t)
610 __dip_output_uplug_all(ofp, &nios_plug_info);
611 fprintf(ofp, "\n");
b2822cea
AB
612}
613
50f73899
AB
614int n_actQs;
615struct actQ_info {
616 __u64 t_qs;
617 __u64 t_act_qs;
618} actQ_info;
619
620void __dip_output_actQ(struct d_info *dip, void *arg)
621{
622 if (dip->n_qs > 0 && !remapper_dev(dip->device)) {
623 char dev_info[15];
624 double a_actQs = (double)dip->t_act_q / (double)dip->n_qs;
625
b70a6642 626 fprintf((FILE *)arg, "%10s | %13.1lf\n",
50f73899 627 make_dev_hdr(dev_info, 15, dip), a_actQs);
b70a6642 628
50f73899
AB
629 n_actQs++;
630 actQ_info.t_qs += dip->n_qs;
631 actQ_info.t_act_qs += dip->t_act_q;
632 }
633}
634
635void __dip_output_actQ_all(FILE *ofp, struct actQ_info *p)
636{
637 fprintf(ofp, "---------- | -------------\n");
638 fprintf(ofp, "%10s | %13s\n", "Overall", "Avgs Reqs @ Q");
b70a6642 639 fprintf(ofp, "%10s | %13.1lf\n", "Average",
50f73899
AB
640 (double)p->t_act_qs / (double)p->t_qs);
641}
642
643void output_actQ_info(FILE *ofp)
644{
645 fprintf(ofp, "%10s | %13s\n", "DEV", "Avg Reqs @ Q");
646 fprintf(ofp, "---------- | -------------\n");
647 dip_foreach_out(__dip_output_actQ, ofp);
648 if (n_actQs > 1)
649 __dip_output_actQ_all(ofp, &actQ_info);
650 fprintf(ofp, "\n");
651}
652
fa0ab85d
AB
653void output_histos(void)
654{
655 int i;
656 FILE *ofp;
657 char fname[256];
658
659 if (output_name == NULL) return;
660
661 sprintf(fname, "%s_qhist.dat", output_name);
662 ofp = fopen(fname, "w");
663 if (!ofp) {
664 perror(fname);
665 return;
666 }
667
668 fprintf(ofp, "# BTT histogram data\n");
669 fprintf(ofp, "# Q buckets\n");
b70a6642 670 for (i = 0; i < (N_HIST_BKTS-1); i++)
fa0ab85d
AB
671 fprintf(ofp, "%4d %lld\n", (i+1), (long long)q_histo[i]);
672 fprintf(ofp, "\n# Q bucket for > %d\n%4d %lld\n", (int)N_HIST_BKTS-1,
37d40cb2 673 N_HIST_BKTS-1, (long long)q_histo[N_HIST_BKTS-1]);
fa0ab85d
AB
674 fclose(ofp);
675
676 sprintf(fname, "%s_dhist.dat", output_name);
677 ofp = fopen(fname, "w");
678 if (!ofp) {
679 perror(fname);
680 return;
681 }
682 fprintf(ofp, "# D buckets\n");
683 for (i = 0; i < (N_HIST_BKTS-1); i++)
684 fprintf(ofp, "%4d %lld\n", (i+1), (long long)d_histo[i]);
685 fprintf(ofp, "\n# D bucket for > %d\n%4d %lld\n", (int)N_HIST_BKTS-1,
37d40cb2 686 N_HIST_BKTS-1, (long long)d_histo[N_HIST_BKTS-1]);
fa0ab85d
AB
687 fclose(ofp);
688}
689
63eba147
JA
690int output_avgs(FILE *ofp)
691{
74dc9101
AB
692 if (output_all_data) {
693 if (exes == NULL || *exes != '\0') {
694 output_section_hdr(ofp, "Per Process");
ae6d30f4
AB
695 output_pip_avg(ofp, "Q2Qdm", pip_q2q_dm_avg);
696 output_pip_avg(ofp, "Q2Adm", pip_q2a_dm_avg);
697 output_pip_avg(ofp, "Q2Cdm", pip_q2c_dm_avg);
698 fprintf(ofp, "\n");
699
74dc9101
AB
700 output_pip_avg(ofp, "Q2Q", pip_q2q_avg);
701 output_pip_avg(ofp, "Q2A", pip_q2a_avg);
ae6d30f4
AB
702 output_pip_avg(ofp, "Q2G", pip_q2g_avg);
703 output_pip_avg(ofp, "G2I", pip_g2i_avg);
704 output_pip_avg(ofp, "Q2M", pip_q2m_avg);
74dc9101
AB
705 output_pip_avg(ofp, "I2D", pip_i2d_avg);
706 output_pip_avg(ofp, "D2C", pip_d2c_avg);
707 output_pip_avg(ofp, "Q2C", pip_q2c_avg);
708 }
63eba147 709
74dc9101 710 output_section_hdr(ofp, "Per Device");
ae6d30f4
AB
711 output_dip_avg(ofp, "Q2Qdm", dip_q2q_dm_avg);
712 output_dip_avg(ofp, "Q2Adm", dip_q2a_dm_avg);
713 output_dip_avg(ofp, "Q2Cdm", dip_q2c_dm_avg);
714 fprintf(ofp, "\n");
715
74dc9101
AB
716 output_dip_avg(ofp, "Q2Q", dip_q2q_avg);
717 output_dip_avg(ofp, "Q2A", dip_q2a_avg);
ae6d30f4
AB
718 output_dip_avg(ofp, "Q2G", dip_q2g_avg);
719 output_dip_avg(ofp, "G2I", dip_g2i_avg);
720 output_dip_avg(ofp, "Q2M", dip_q2m_avg);
74dc9101
AB
721 output_dip_avg(ofp, "I2D", dip_i2d_avg);
722 output_dip_avg(ofp, "D2C", dip_d2c_avg);
723 output_dip_avg(ofp, "Q2C", dip_q2c_avg);
724 }
63eba147
JA
725
726 output_section_hdr(ofp, "All Devices");
727 output_hdr(ofp, "ALL");
ae6d30f4
AB
728 __output_avg(ofp, "Q2Qdm", &all_avgs.q2q_dm);
729 __output_avg(ofp, "Q2Adm", &all_avgs.q2a_dm);
730 __output_avg(ofp, "Q2Cdm", &all_avgs.q2c_dm);
731 fprintf(ofp, "\n");
732
63eba147
JA
733 __output_avg(ofp, "Q2Q", &all_avgs.q2q);
734 __output_avg(ofp, "Q2A", &all_avgs.q2a);
ae6d30f4
AB
735 __output_avg(ofp, "Q2G", &all_avgs.q2g);
736 __output_avg(ofp, "G2I", &all_avgs.g2i);
737 __output_avg(ofp, "Q2M", &all_avgs.q2m);
63eba147 738 __output_avg(ofp, "I2D", &all_avgs.i2d);
ae6d30f4 739 __output_avg(ofp, "M2D", &all_avgs.m2d);
63eba147
JA
740 __output_avg(ofp, "D2C", &all_avgs.d2c);
741 __output_avg(ofp, "Q2C", &all_avgs.q2c);
b2822cea
AB
742 fprintf(ofp, "\n");
743
744 output_section_hdr(ofp, "Device Overhead");
745 output_dip_prep_ohead(ofp);
63eba147 746
63eba147
JA
747 output_section_hdr(ofp, "Device Merge Information");
748 output_dip_merge_ratio(ofp);
749
4c48f14e
AB
750 output_section_hdr(ofp, "Device Q2Q Seek Information");
751 output_dip_q2q_seek_info(ofp);
752
753 output_section_hdr(ofp, "Device D2D Seek Information");
5cd3c859 754 output_dip_seek_info(ofp);
5225e788 755
b2822cea
AB
756 output_section_hdr(ofp, "Plug Information");
757 output_plug_info(ofp);
758
50f73899
AB
759 output_section_hdr(ofp, "Active Requests At Q Information");
760 output_actQ_info(ofp);
761
fa0ab85d
AB
762 output_histos();
763
951ea56c
AB
764 if (output_all_data) {
765 output_section_hdr(ofp, "Q2D Histogram");
766 output_q2d_histo(ofp);
767 }
768
63eba147
JA
769 return 0;
770}
771
772void __output_ranges(FILE *ofp, struct list_head *head_p, float base)
773{
774 struct range_info *rip;
775 struct list_head *p;
776 float limit = base + 0.4;
777
778 __list_for_each(p, head_p) {
779 rip = list_entry(p, struct range_info, head);
780 fprintf(ofp, "%13.9lf %5.1f\n", BIT_TIME(rip->start), base);
781 fprintf(ofp, "%13.9lf %5.1f\n", BIT_TIME(rip->start), limit);
782 fprintf(ofp, "%13.9lf %5.1f\n", BIT_TIME(rip->end), limit);
783 fprintf(ofp, "%13.9lf %5.1f\n", BIT_TIME(rip->end), base);
784 }
785}
786
b70a6642 787int output_regions(FILE *ofp, char *header, struct region_info *reg,
63eba147
JA
788 float base)
789{
63eba147
JA
790 if (list_len(&reg->qranges) == 0 && list_len(&reg->cranges) == 0)
791 return 0;
792
793 fprintf(ofp, "# %16s : q activity\n", header);
794 __output_ranges(ofp, &reg->qranges, base);
795 fprintf(ofp, "\n");
796
797 fprintf(ofp, "# %16s : c activity\n", header);
798 __output_ranges(ofp, &reg->cranges, base + 0.5);
799 fprintf(ofp, "\n");
800
801 return 1;
802}
803
6eb42155
ADB
804struct __od {
805 FILE *ofp;
806 float base;
807};
808void __output_dev(struct d_info *dip, void *arg)
63eba147
JA
809{
810 char header[128];
6eb42155 811 struct __od *odp = arg;
63eba147 812
6eb42155
ADB
813 sprintf(header, "%d,%d", MAJOR(dip->device), MINOR(dip->device));
814 if (output_regions(odp->ofp, header, &dip->regions, odp->base))
815 odp->base += 1.0;
63eba147
JA
816}
817
818float output_devs(FILE *ofp, float base)
819{
6eb42155 820 struct __od od = { .ofp = ofp, .base = base };
63eba147
JA
821
822 fprintf(ofp, "# Per device\n" );
6eb42155
ADB
823 dip_foreach_out(__output_dev, &od);
824 return od.base;
63eba147
JA
825}
826
827static inline int exe_match(char *exe, char *name)
828{
829 return (exe == NULL) || (strstr(name, exe) != NULL);
830}
831
6eb42155
ADB
832struct __op {
833 FILE *ofp;
834 float base;
835};
836void __output_procs(struct p_info *pip, void *arg)
63eba147 837{
6eb42155
ADB
838 struct __op *opp = arg;
839 output_regions(opp->ofp, pip->name, &pip->regions, opp->base);
840 opp->base += 1.0;
63eba147
JA
841}
842
843float output_procs(FILE *ofp, float base)
844{
6eb42155 845 struct __op op = { .ofp = ofp, .base = base };
63eba147 846
6eb42155
ADB
847 fprintf(ofp, "# Per process\n" );
848 pip_foreach_out(__output_procs, &op);
849 return op.base;
63eba147
JA
850}
851
852int output_ranges(FILE *ofp)
853{
854 float base = 0.0;
855
856 fprintf(ofp, "# %s\n", "Total System");
857 if (output_regions(ofp, "Total System", &all_regions, base))
858 base += 1.0;
859
860 if (n_devs > 1)
861 base = output_devs(ofp, base);
862
863 base = output_procs(ofp, base);
864
865 return 0;
866}