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