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