Merge branch 'master' of ssh://axboe@router.home.kernel.dk/data/git/blktrace
[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 {
516 long n_plugs, n_timer_unplugs;
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
db8570e9 526 if (dip->nplugs > 0) {
b70a6642 527 if (dip->is_plugged) dip_unplug(dip->device, dip->end_time, 0);
db8570e9
AB
528 delta = dip->end_time - dip->start_time;
529 pct = 100.0 * ((dip->plugged_time / delta) / delta);
33f35150 530
b70a6642 531 fprintf(ofp, "%10s | %10d(%10d) | %13.9lf%%\n",
84a26fcd 532 make_dev_hdr(dev_info, 15, dip, 1),
db8570e9 533 dip->nplugs, dip->n_timer_unplugs, pct);
33f35150 534
f028c958
AB
535 if (easy_parse_avgs) {
536 fprintf(xavgs_ofp,
537 "PLG %s %d %d %.9lf\n",
84a26fcd 538 make_dev_hdr(dev_info, 15, dip, 0),
f028c958
AB
539 dip->nplugs, dip->n_timer_unplugs, pct);
540 }
541
db8570e9
AB
542 n_plugs++;
543 plug_info.n_plugs += dip->nplugs;
544 plug_info.n_timer_unplugs += dip->n_timer_unplugs;
545 plug_info.t_percent += pct;
546 }
33f35150
AB
547}
548
549void __dip_output_plug_all(FILE *ofp, struct plug_info *p)
550{
551 fprintf(ofp, "---------- | ---------- ---------- | ----------------\n");
b70a6642 552 fprintf(ofp, "%10s | %10s %10s | %s\n",
69040794
AB
553 "Overall", "# Plugs", "# Timer Us", "% Time Q Plugged");
554 fprintf(ofp, "%10s | %10ld(%10ld) | %13.9lf%%\n", "Average",
b70a6642 555 p->n_plugs / n_plugs, p->n_timer_unplugs / n_plugs,
33f35150
AB
556 p->t_percent / n_plugs);
557
b2822cea
AB
558}
559
b70a6642
AB
560__u64 n_nios_uplugs, n_nios_uplugs_t;
561struct nios_plug_info {
562 __u64 tot_nios_up, tot_nios_up_t;
563} nios_plug_info;
564
565void __dip_output_plug_nios(struct d_info *dip, void *arg)
566{
567 char dev_info[15];
568 FILE *ofp = arg;
569 double a_nios_uplug = 0.0, a_nios_uplug_t = 0.0;
570
571 if (dip->nios_up && dip->nplugs) {
572 a_nios_uplug = (double)dip->nios_up / (double)dip->nplugs;
573 n_nios_uplugs += dip->nplugs;
574 nios_plug_info.tot_nios_up += dip->nios_up;
575 }
576 if (dip->nios_upt && dip->nplugs_t) {
577 a_nios_uplug_t = (double)dip->nios_upt / (double)dip->nplugs_t;
578 n_nios_uplugs_t += dip->nplugs_t;
579 nios_plug_info.tot_nios_up_t += dip->nios_upt;
580 }
581
582 fprintf(ofp, "%10s | %10.1lf %10.1lf\n",
84a26fcd 583 make_dev_hdr(dev_info, 15, dip, 1),
b70a6642 584 a_nios_uplug, a_nios_uplug_t);
f028c958
AB
585
586 if (easy_parse_avgs) {
587 fprintf(xavgs_ofp,
588 "UPG %s %.9lf %.9lf\n",
84a26fcd 589 make_dev_hdr(dev_info, 15, dip, 0),
f028c958
AB
590 a_nios_uplug, a_nios_uplug_t);
591 }
b70a6642
AB
592}
593
594void __dip_output_uplug_all(FILE *ofp, struct nios_plug_info *p)
595{
596 double ios_unp = 0.0, ios_unp_to = 0.0;
597
598 if (n_nios_uplugs)
599 ios_unp = (double)p->tot_nios_up / (double)n_nios_uplugs;
600 if (n_nios_uplugs_t)
601 ios_unp_to = (double)p->tot_nios_up_t / (double)n_nios_uplugs_t;
602
603 fprintf(ofp, "---------- | ---------- ----------\n");
604 fprintf(ofp, "%10s | %10s %10s\n",
605 "Overall", "IOs/Unp", "IOs/Unp(to)");
606 fprintf(ofp, "%10s | %10.1lf %10.1lf\n",
607 "Average", ios_unp, ios_unp_to);
608}
609
b2822cea
AB
610void output_plug_info(FILE *ofp)
611{
b70a6642 612 fprintf(ofp, "%10s | %10s %10s | %s\n",
33f35150
AB
613 "DEV", "# Plugs", "# Timer Us", "% Time Q Plugged");
614 fprintf(ofp, "---------- | ---------- ---------- | ----------------\n");
b2822cea 615 dip_foreach_out(__dip_output_plug, ofp);
33f35150
AB
616 if (n_plugs > 1)
617 __dip_output_plug_all(ofp, &plug_info);
b2822cea 618 fprintf(ofp, "\n");
b70a6642
AB
619
620 fprintf(ofp, "%10s | %10s %10s\n",
621 "DEV", "IOs/Unp", "IOs/Unp(to)");
622 fprintf(ofp, "---------- | ---------- ----------\n");
623 dip_foreach_out(__dip_output_plug_nios, ofp);
624 if (n_nios_uplugs || n_nios_uplugs_t)
625 __dip_output_uplug_all(ofp, &nios_plug_info);
626 fprintf(ofp, "\n");
b2822cea
AB
627}
628
50f73899
AB
629int n_actQs;
630struct actQ_info {
631 __u64 t_qs;
632 __u64 t_act_qs;
633} actQ_info;
634
635void __dip_output_actQ(struct d_info *dip, void *arg)
636{
637 if (dip->n_qs > 0 && !remapper_dev(dip->device)) {
638 char dev_info[15];
639 double a_actQs = (double)dip->t_act_q / (double)dip->n_qs;
640
b70a6642 641 fprintf((FILE *)arg, "%10s | %13.1lf\n",
84a26fcd 642 make_dev_hdr(dev_info, 15, dip, 1), a_actQs);
b70a6642 643
f028c958
AB
644 if (easy_parse_avgs) {
645 fprintf(xavgs_ofp,
646 "ARQ %s %.9lf\n",
84a26fcd 647 make_dev_hdr(dev_info, 15, dip, 0), a_actQs);
f028c958
AB
648 }
649
50f73899
AB
650 n_actQs++;
651 actQ_info.t_qs += dip->n_qs;
652 actQ_info.t_act_qs += dip->t_act_q;
653 }
654}
655
656void __dip_output_actQ_all(FILE *ofp, struct actQ_info *p)
657{
658 fprintf(ofp, "---------- | -------------\n");
659 fprintf(ofp, "%10s | %13s\n", "Overall", "Avgs Reqs @ Q");
b70a6642 660 fprintf(ofp, "%10s | %13.1lf\n", "Average",
50f73899
AB
661 (double)p->t_act_qs / (double)p->t_qs);
662}
663
664void output_actQ_info(FILE *ofp)
665{
666 fprintf(ofp, "%10s | %13s\n", "DEV", "Avg Reqs @ Q");
667 fprintf(ofp, "---------- | -------------\n");
668 dip_foreach_out(__dip_output_actQ, ofp);
669 if (n_actQs > 1)
670 __dip_output_actQ_all(ofp, &actQ_info);
671 fprintf(ofp, "\n");
672}
673
fa0ab85d
AB
674void output_histos(void)
675{
676 int i;
677 FILE *ofp;
678 char fname[256];
679
680 if (output_name == NULL) return;
681
682 sprintf(fname, "%s_qhist.dat", output_name);
99bb5ebc 683 ofp = my_fopen(fname, "w");
fa0ab85d
AB
684 if (!ofp) {
685 perror(fname);
686 return;
687 }
688
689 fprintf(ofp, "# BTT histogram data\n");
690 fprintf(ofp, "# Q buckets\n");
b70a6642 691 for (i = 0; i < (N_HIST_BKTS-1); i++)
fa0ab85d
AB
692 fprintf(ofp, "%4d %lld\n", (i+1), (long long)q_histo[i]);
693 fprintf(ofp, "\n# Q bucket for > %d\n%4d %lld\n", (int)N_HIST_BKTS-1,
37d40cb2 694 N_HIST_BKTS-1, (long long)q_histo[N_HIST_BKTS-1]);
fa0ab85d
AB
695 fclose(ofp);
696
697 sprintf(fname, "%s_dhist.dat", output_name);
99bb5ebc 698 ofp = my_fopen(fname, "w");
fa0ab85d
AB
699 if (!ofp) {
700 perror(fname);
701 return;
702 }
703 fprintf(ofp, "# D buckets\n");
704 for (i = 0; i < (N_HIST_BKTS-1); i++)
705 fprintf(ofp, "%4d %lld\n", (i+1), (long long)d_histo[i]);
706 fprintf(ofp, "\n# D bucket for > %d\n%4d %lld\n", (int)N_HIST_BKTS-1,
37d40cb2 707 N_HIST_BKTS-1, (long long)d_histo[N_HIST_BKTS-1]);
fa0ab85d
AB
708 fclose(ofp);
709}
710
63eba147
JA
711int output_avgs(FILE *ofp)
712{
74dc9101
AB
713 if (output_all_data) {
714 if (exes == NULL || *exes != '\0') {
715 output_section_hdr(ofp, "Per Process");
ae6d30f4
AB
716 output_pip_avg(ofp, "Q2Qdm", pip_q2q_dm_avg);
717 output_pip_avg(ofp, "Q2Adm", pip_q2a_dm_avg);
718 output_pip_avg(ofp, "Q2Cdm", pip_q2c_dm_avg);
719 fprintf(ofp, "\n");
720
74dc9101
AB
721 output_pip_avg(ofp, "Q2Q", pip_q2q_avg);
722 output_pip_avg(ofp, "Q2A", pip_q2a_avg);
ae6d30f4 723 output_pip_avg(ofp, "Q2G", pip_q2g_avg);
354db430 724 output_pip_avg(ofp, "S2G", pip_s2g_avg);
ae6d30f4
AB
725 output_pip_avg(ofp, "G2I", pip_g2i_avg);
726 output_pip_avg(ofp, "Q2M", pip_q2m_avg);
74dc9101
AB
727 output_pip_avg(ofp, "I2D", pip_i2d_avg);
728 output_pip_avg(ofp, "D2C", pip_d2c_avg);
729 output_pip_avg(ofp, "Q2C", pip_q2c_avg);
730 }
63eba147 731
74dc9101 732 output_section_hdr(ofp, "Per Device");
ae6d30f4
AB
733 output_dip_avg(ofp, "Q2Qdm", dip_q2q_dm_avg);
734 output_dip_avg(ofp, "Q2Adm", dip_q2a_dm_avg);
735 output_dip_avg(ofp, "Q2Cdm", dip_q2c_dm_avg);
736 fprintf(ofp, "\n");
737
74dc9101
AB
738 output_dip_avg(ofp, "Q2Q", dip_q2q_avg);
739 output_dip_avg(ofp, "Q2A", dip_q2a_avg);
ae6d30f4 740 output_dip_avg(ofp, "Q2G", dip_q2g_avg);
354db430 741 output_dip_avg(ofp, "S2G", dip_s2g_avg);
ae6d30f4
AB
742 output_dip_avg(ofp, "G2I", dip_g2i_avg);
743 output_dip_avg(ofp, "Q2M", dip_q2m_avg);
74dc9101
AB
744 output_dip_avg(ofp, "I2D", dip_i2d_avg);
745 output_dip_avg(ofp, "D2C", dip_d2c_avg);
746 output_dip_avg(ofp, "Q2C", dip_q2c_avg);
747 }
63eba147
JA
748
749 output_section_hdr(ofp, "All Devices");
750 output_hdr(ofp, "ALL");
354db430
AB
751 __output_avg(ofp, "Q2Qdm", &all_avgs.q2q_dm, 0);
752 __output_avg(ofp, "Q2Adm", &all_avgs.q2a_dm, 0);
753 __output_avg(ofp, "Q2Cdm", &all_avgs.q2c_dm, 0);
ae6d30f4
AB
754 fprintf(ofp, "\n");
755
354db430
AB
756 __output_avg(ofp, "Q2Q", &all_avgs.q2q, 1);
757 __output_avg(ofp, "Q2A", &all_avgs.q2a, 1);
758 __output_avg(ofp, "Q2G", &all_avgs.q2g, 1);
759 __output_avg(ofp, "S2G", &all_avgs.s2g, 1);
760 __output_avg(ofp, "G2I", &all_avgs.g2i, 1);
761 __output_avg(ofp, "Q2M", &all_avgs.q2m, 1);
762 __output_avg(ofp, "I2D", &all_avgs.i2d, 1);
763 __output_avg(ofp, "M2D", &all_avgs.m2d, 1);
764 __output_avg(ofp, "D2C", &all_avgs.d2c, 1);
765 __output_avg(ofp, "Q2C", &all_avgs.q2c, 1);
b2822cea
AB
766 fprintf(ofp, "\n");
767
768 output_section_hdr(ofp, "Device Overhead");
769 output_dip_prep_ohead(ofp);
63eba147 770
63eba147
JA
771 output_section_hdr(ofp, "Device Merge Information");
772 output_dip_merge_ratio(ofp);
773
4c48f14e
AB
774 output_section_hdr(ofp, "Device Q2Q Seek Information");
775 output_dip_q2q_seek_info(ofp);
776
777 output_section_hdr(ofp, "Device D2D Seek Information");
5cd3c859 778 output_dip_seek_info(ofp);
5225e788 779
b2822cea
AB
780 output_section_hdr(ofp, "Plug Information");
781 output_plug_info(ofp);
782
50f73899
AB
783 output_section_hdr(ofp, "Active Requests At Q Information");
784 output_actQ_info(ofp);
785
fa0ab85d
AB
786 output_histos();
787
951ea56c
AB
788 if (output_all_data) {
789 output_section_hdr(ofp, "Q2D Histogram");
790 output_q2d_histo(ofp);
791 }
792
63eba147
JA
793 return 0;
794}
795
796void __output_ranges(FILE *ofp, struct list_head *head_p, float base)
797{
798 struct range_info *rip;
799 struct list_head *p;
800 float limit = base + 0.4;
801
802 __list_for_each(p, head_p) {
803 rip = list_entry(p, struct range_info, head);
804 fprintf(ofp, "%13.9lf %5.1f\n", BIT_TIME(rip->start), base);
805 fprintf(ofp, "%13.9lf %5.1f\n", BIT_TIME(rip->start), limit);
806 fprintf(ofp, "%13.9lf %5.1f\n", BIT_TIME(rip->end), limit);
807 fprintf(ofp, "%13.9lf %5.1f\n", BIT_TIME(rip->end), base);
808 }
809}
810
b70a6642 811int output_regions(FILE *ofp, char *header, struct region_info *reg,
63eba147
JA
812 float base)
813{
63eba147
JA
814 if (list_len(&reg->qranges) == 0 && list_len(&reg->cranges) == 0)
815 return 0;
816
817 fprintf(ofp, "# %16s : q activity\n", header);
818 __output_ranges(ofp, &reg->qranges, base);
819 fprintf(ofp, "\n");
820
821 fprintf(ofp, "# %16s : c activity\n", header);
822 __output_ranges(ofp, &reg->cranges, base + 0.5);
823 fprintf(ofp, "\n");
824
825 return 1;
826}
827
6eb42155
ADB
828struct __od {
829 FILE *ofp;
830 float base;
831};
832void __output_dev(struct d_info *dip, void *arg)
63eba147
JA
833{
834 char header[128];
6eb42155 835 struct __od *odp = arg;
63eba147 836
6eb42155
ADB
837 sprintf(header, "%d,%d", MAJOR(dip->device), MINOR(dip->device));
838 if (output_regions(odp->ofp, header, &dip->regions, odp->base))
839 odp->base += 1.0;
63eba147
JA
840}
841
842float output_devs(FILE *ofp, float base)
843{
6eb42155 844 struct __od od = { .ofp = ofp, .base = base };
63eba147
JA
845
846 fprintf(ofp, "# Per device\n" );
6eb42155
ADB
847 dip_foreach_out(__output_dev, &od);
848 return od.base;
63eba147
JA
849}
850
851static inline int exe_match(char *exe, char *name)
852{
853 return (exe == NULL) || (strstr(name, exe) != NULL);
854}
855
6eb42155
ADB
856struct __op {
857 FILE *ofp;
858 float base;
859};
860void __output_procs(struct p_info *pip, void *arg)
63eba147 861{
6eb42155
ADB
862 struct __op *opp = arg;
863 output_regions(opp->ofp, pip->name, &pip->regions, opp->base);
864 opp->base += 1.0;
63eba147
JA
865}
866
867float output_procs(FILE *ofp, float base)
868{
6eb42155 869 struct __op op = { .ofp = ofp, .base = base };
63eba147 870
6eb42155
ADB
871 fprintf(ofp, "# Per process\n" );
872 pip_foreach_out(__output_procs, &op);
873 return op.base;
63eba147
JA
874}
875
876int output_ranges(FILE *ofp)
877{
878 float base = 0.0;
879
880 fprintf(ofp, "# %s\n", "Total System");
881 if (output_regions(ofp, "Total System", &all_regions, base))
882 base += 1.0;
883
884 if (n_devs > 1)
885 base = output_devs(ofp, base);
886
887 base = output_procs(ofp, base);
888
889 return 0;
890}