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