BTT: Clean up output in preparation for first major documentation effort.
[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
773c17a0
AB
136int n_merges = 0;
137struct {
138 unsigned long long nq, nd, blkmin, blkmax, total;
139} merge_data;
6eb42155 140void __output_dip_merge_ratio(struct d_info *dip, void *arg)
63eba147
JA
141{
142 double blks_avg;
095181f2 143 char scratch[15];
63eba147
JA
144 double ratio, q2c_n = dip->avgs.q2c.n, d2c_n = dip->n_ds;
145
146 if (q2c_n > 0.0 && d2c_n > 0.0) {
147 ratio = q2c_n / d2c_n;
9f11c1a7 148 blks_avg = (double)dip->avgs.blks.total / d2c_n;
6eb42155
ADB
149 fprintf((FILE *)arg,
150 "%10s | %8llu %8llu %7.1lf | %8llu %8llu %8llu %8llu\n",
095181f2 151 make_dev_hdr(scratch, 15, dip),
63eba147
JA
152 (unsigned long long)dip->avgs.q2c.n,
153 (unsigned long long)dip->n_ds,
154 ratio,
155 (unsigned long long)dip->avgs.blks.min,
156 (unsigned long long)blks_avg,
157 (unsigned long long)dip->avgs.blks.max,
158 (unsigned long long)dip->avgs.blks.total);
159
773c17a0
AB
160 if (n_merges++ == 0) {
161 merge_data.blkmin = dip->avgs.blks.min;
162 merge_data.blkmax = dip->avgs.blks.max;
163 }
164
165 merge_data.nq += dip->avgs.q2c.n;
166 merge_data.nd += dip->n_ds;
167 merge_data.total += dip->avgs.blks.total;
168 if (dip->avgs.blks.min < merge_data.blkmin)
169 merge_data.blkmin = dip->avgs.blks.min;
170 if (dip->avgs.blks.max > merge_data.blkmax)
171 merge_data.blkmax = dip->avgs.blks.max;
63eba147
JA
172 }
173}
174
175void output_dip_merge_ratio(FILE *ofp)
176{
63eba147
JA
177 fprintf(ofp, "%10s | %8s %8s %7s | %8s %8s %8s %8s\n", "DEV", "#Q", "#D", "Ratio", "BLKmin", "BLKavg", "BLKmax", "Total");
178 fprintf(ofp, "---------- | -------- -------- ------- | -------- -------- -------- --------\n");
6eb42155 179 dip_foreach_out(__output_dip_merge_ratio, ofp);
773c17a0
AB
180 if (n_merges > 1) {
181 fprintf(ofp, "---------- | -------- -------- ------- | -------- -------- -------- --------\n");
182 fprintf(ofp, "%10s | %8s %8s %7s | %8s %8s %8s %8s\n", "DEV", "#Q", "#D", "Ratio", "BLKmin", "BLKavg", "BLKmax", "Total");
183 fprintf((FILE *)ofp,
184 "%10s | %8llu %8llu %7.1lf | %8llu %8llu %8llu %8llu\n",
185 "TOTAL", merge_data.nq, merge_data.nd,
186 (float)merge_data.nq / (float)merge_data.nd,
187 merge_data.blkmin,
188 merge_data.total / merge_data.nd,
189 merge_data.blkmax, merge_data.total);
190 }
63eba147
JA
191 fprintf(ofp, "\n");
192}
193
194#define AVG(a,b) (100.0 * ((double)(a) / (double)(b)))
195#define CALC_AVG(ap) (ap)->avg = ((ap)->n == 0 ? 0.0 : \
196 (BIT_TIME((ap)->total) / \
197 (double)(ap)->n))
198char *q2i_v_q2C(struct d_info *dip, char *s)
199{
200 double q2c;
201
202 if (dip->avgs.q2i.n == 0) return " ";
203
204 q2c = dip->avgs.q2i.avg + dip->avgs.i2d.avg + dip->avgs.d2c.avg;
205 sprintf(s, "%5.1lf%%", AVG(dip->avgs.q2i.avg, q2c));
206
207 return s;
208}
209
210char *i2d_v_q2C(struct d_info *dip, char *s)
211{
212 double q2c;
213
5225e788 214 if (dip->avgs.d2c.n == 0) return " ";
63eba147
JA
215
216 q2c = dip->avgs.q2i.avg + dip->avgs.i2d.avg + dip->avgs.d2c.avg;
217 sprintf(s, "%5.1lf%%", AVG(dip->avgs.i2d.avg, q2c));
218
219 return s;
220}
221
222char *d2c_v_q2C(struct d_info *dip, char *s)
223{
224 double q2c;
225
aa994ec5 226 if (dip->avgs.d2c.n == 0) return " ";
63eba147
JA
227
228 q2c = dip->avgs.q2i.avg + dip->avgs.i2d.avg + dip->avgs.d2c.avg;
229 sprintf(s, "%5.1lf%%", AVG(dip->avgs.d2c.avg, q2c));
230
231 return s;
232}
233
6eb42155 234void __output_dip_prep_ohead(struct d_info *dip, void *arg)
63eba147 235{
095181f2 236 char dev_info[15];
63eba147
JA
237 char s1[16], s2[16], s3[16];
238
239 if ((dip->avgs.q2i.n > 0 && dip->avgs.i2d.n > 0 &&
240 dip->avgs.d2c.n > 0)) {
241 CALC_AVG(&dip->avgs.q2i);
242 CALC_AVG(&dip->avgs.i2d);
243 CALC_AVG(&dip->avgs.d2c);
244
6eb42155 245 fprintf((FILE *)arg, "%10s | %6s %6s %6s\n",
095181f2 246 make_dev_hdr(dev_info, 15, dip),
63eba147
JA
247 q2i_v_q2C(dip, s1), i2d_v_q2C(dip, s2),
248 d2c_v_q2C(dip, s3));
249 }
250}
251
252void output_dip_prep_ohead(FILE *ofp)
253{
63eba147
JA
254 fprintf(ofp, "%10s | %6s %6s %6s\n", "DEV", "Q2I", "I2D", "D2C");
255 fprintf(ofp, "---------- | ------ ------ ------\n");
6eb42155 256 dip_foreach_out(__output_dip_prep_ohead, ofp);
63eba147
JA
257 fprintf(ofp, "\n");
258}
259
756d1f46
AB
260int n_seeks;
261struct seek_mode_info {
262 struct seek_mode_info *next;
263 long long mode;
264 int nseeks;
265};
266struct o_seek_info {
267 long long nseeks, median;
268 double mean;
269 struct seek_mode_info *head;
270} seek_info = {
271 .nseeks = 0L,
272 .median = 0L,
273 .mean = 0.0,
274 .head = NULL
275};
276void output_seek_mode_info(FILE *ofp, struct o_seek_info *sip)
277{
278 struct seek_mode_info *p, *this, *new_list = NULL;
279
280 ASSERT(sip->head != NULL);
281 while ((this = sip->head) != NULL) {
282 sip->head = this->next;
283 if (new_list == NULL) {
284 this->next = NULL;
285 new_list = this;
286 continue;
287 }
288 if (this->nseeks < new_list->nseeks) {
289 free(this);
290 continue;
291 }
292 if (this->nseeks > new_list->nseeks) {
293 while ((p = new_list) != NULL) {
294 new_list = p->next;
295 free(p);
296 }
297 this->next = NULL;
298 new_list = this;
299 continue;
300 }
301 for (p = new_list; p; p++)
302 if (p->mode == this->mode) {
303 this->nseeks += p->nseeks;
304 free(p);
305 break;
306 }
307 if (p)
308 p->next = new_list;
309 }
310
311 fprintf(ofp, "%10s | %15lld %15.1lf %15lld | %lld(%d)",
312 "Average", sip->nseeks, sip->mean / sip->nseeks,
313 sip->median / sip->nseeks, new_list->mode, new_list->nseeks);
314
315 p = new_list;
316 new_list = p->next;
317 free(p);
318 while((p = new_list) != NULL) {
319 fprintf(ofp, " %lld", p->mode);
320 new_list = p->next;
321 free(p);
322 }
323}
324void add_seek_mode_info(struct o_seek_info *sip, struct mode *mp)
325{
326 int i;
327 long long *lp = mp->modes;
328 struct seek_mode_info *smip;
329
330 n_seeks++;
331 for (i = 0; i < mp->nmds; i++) {
332 for (smip = sip->head; smip; smip = smip->next) {
333 if (smip->mode == lp[i]) {
334 smip->nseeks += mp->most_seeks;
335 break;
336 }
337 }
338 if (!smip) {
339 struct seek_mode_info *new = malloc(sizeof(*new));
340
341 new->next = sip->head;
342 sip->head = new;
343 new->mode = lp[i];
344 new->nseeks = mp->most_seeks;
345 }
346 }
347}
348
6eb42155 349void __output_dip_seek_info(struct d_info *dip, void *arg)
5225e788
AB
350{
351 double mean;
6eb42155 352 int i, nmodes;
5225e788 353 long long nseeks;
095181f2 354 char dev_info[15];
6eb42155
ADB
355 long long median;
356 struct mode m;
357 FILE *ofp = arg;
5225e788
AB
358
359 nseeks = seeki_nseeks(dip->seek_handle);
165e0a18
AB
360 if (nseeks > 0) {
361 mean = seeki_mean(dip->seek_handle);
362 median = seeki_median(dip->seek_handle);
6eb42155 363 nmodes = seeki_mode(dip->seek_handle, &m);
165e0a18
AB
364
365 fprintf(ofp, "%10s | %15lld %15.1lf %15lld | %lld(%d)",
095181f2 366 make_dev_hdr(dev_info, 15, dip), nseeks, mean, median,
6eb42155 367 nmodes > 0 ? m.modes[0] : 0, m.most_seeks);
165e0a18 368 for (i = 1; i < nmodes; i++)
6eb42155 369 fprintf(ofp, " %lld", m.modes[i]);
165e0a18 370 fprintf(ofp, "\n");
756d1f46
AB
371
372 seek_info.nseeks += nseeks;
373 seek_info.mean += (nseeks * mean);
374 seek_info.median += (nseeks * median);
375 add_seek_mode_info(&seek_info, &m);
165e0a18 376 }
5225e788
AB
377}
378
379void output_dip_seek_info(FILE *ofp)
380{
5225e788
AB
381 fprintf(ofp, "%10s | %15s %15s %15s | %-15s\n", "DEV", "NSEEKS",
382 "MEAN", "MEDIAN", "MODE");
756d1f46 383 fprintf(ofp, "---------- | --------------- --------------- --------------- | ---------------\n");
6eb42155 384 dip_foreach_out(__output_dip_seek_info, ofp);
756d1f46
AB
385 if (n_seeks > 1) {
386 fprintf(ofp, "---------- | --------------- --------------- --------------- | ---------------\n");
387 fprintf(ofp, "%10s | %15s %15s %15s | %-15s\n",
388 "Overall", "NSEEKS", "MEAN", "MEDIAN", "MODE");
389 output_seek_mode_info(ofp, &seek_info);
db8570e9 390 fprintf(ofp, "\n");
756d1f46 391 }
5225e788
AB
392 fprintf(ofp, "\n");
393}
394
6eb42155
ADB
395struct __opa {
396 FILE *ofp;
397 ai_pip_t (*func)(struct p_info *);
398};
399
400void __output_pip_avg(struct p_info *pip, void *arg)
63eba147 401{
6eb42155
ADB
402 struct __opa *opap = arg;
403 ai_pip_t ap = opap->func(pip);
404
63eba147 405 if (ap->n > 0) {
095181f2
JA
406 char proc_name[15];
407 snprintf(proc_name, 15, pip->name);
63eba147
JA
408
409 ap->avg = BIT_TIME(ap->total) / (double)ap->n;
6eb42155 410 __output_avg(opap->ofp, proc_name, ap);
63eba147
JA
411 }
412}
413
414void output_pip_avg(FILE *ofp, char *hdr, ai_pip_t (*func)(struct p_info *))
415{
6eb42155 416 struct __opa opa = { .ofp = ofp, .func = func };
63eba147
JA
417
418 output_hdr(ofp, hdr);
6eb42155 419 pip_foreach_out(__output_pip_avg, &opa);
63eba147
JA
420 fprintf(ofp, "\n");
421}
422
423void output_dip_avgs(FILE *ofp)
424{
63eba147 425 output_hdr2(ofp,"Dev");
6eb42155 426 dip_foreach_out(__dip_output_avg2, ofp);
63eba147
JA
427 fprintf(ofp, "\n");
428}
429
430void output_pip_avgs(FILE *ofp)
431{
63eba147 432 output_hdr2(ofp,"Exe");
6eb42155 433 pip_foreach_out(__pip_output_avg2, ofp);
63eba147
JA
434 fprintf(ofp, "\n");
435}
436
33f35150
AB
437int n_plugs;
438struct plug_info {
439 long n_plugs, n_timer_unplugs;
440 double t_percent;
441} plug_info;
442
b2822cea
AB
443void __dip_output_plug(struct d_info *dip, void *arg)
444{
445 char dev_info[15];
446 FILE *ofp = arg;
33f35150 447 double delta, pct;
b2822cea 448
db8570e9
AB
449 if (dip->nplugs > 0) {
450 if (dip->is_plugged) dip_unplug(dip->device, dip->end_time, 0);
451 delta = dip->end_time - dip->start_time;
452 pct = 100.0 * ((dip->plugged_time / delta) / delta);
33f35150 453
db8570e9
AB
454 fprintf(ofp, "%10s | %10d(%10d) | %13.9lf%%\n",
455 make_dev_hdr(dev_info, 15, dip),
456 dip->nplugs, dip->n_timer_unplugs, pct);
33f35150 457
db8570e9
AB
458 n_plugs++;
459 plug_info.n_plugs += dip->nplugs;
460 plug_info.n_timer_unplugs += dip->n_timer_unplugs;
461 plug_info.t_percent += pct;
462 }
33f35150
AB
463}
464
465void __dip_output_plug_all(FILE *ofp, struct plug_info *p)
466{
467 fprintf(ofp, "---------- | ---------- ---------- | ----------------\n");
468 fprintf(ofp, "%10s | %10s %10s | %s\n",
469 "DEV", "# Plugs", "# Timer Us", "% Time Q Plugged");
470 fprintf(ofp, "%10s | %10ld(%10ld) | %13.9lf%%\n", "OVERALL",
471 p->n_plugs / n_plugs, p->n_timer_unplugs / n_plugs,
472 p->t_percent / n_plugs);
473
b2822cea
AB
474}
475
476void output_plug_info(FILE *ofp)
477{
33f35150
AB
478 fprintf(ofp, "%10s | %10s %10s | %s\n",
479 "DEV", "# Plugs", "# Timer Us", "% Time Q Plugged");
480 fprintf(ofp, "---------- | ---------- ---------- | ----------------\n");
b2822cea 481 dip_foreach_out(__dip_output_plug, ofp);
33f35150
AB
482 if (n_plugs > 1)
483 __dip_output_plug_all(ofp, &plug_info);
b2822cea
AB
484 fprintf(ofp, "\n");
485}
486
fa0ab85d
AB
487void output_histos(void)
488{
489 int i;
490 FILE *ofp;
491 char fname[256];
492
493 if (output_name == NULL) return;
494
495 sprintf(fname, "%s_qhist.dat", output_name);
496 ofp = fopen(fname, "w");
497 if (!ofp) {
498 perror(fname);
499 return;
500 }
501
502 fprintf(ofp, "# BTT histogram data\n");
503 fprintf(ofp, "# Q buckets\n");
504 for (i = 0; i < (N_HIST_BKTS-1); i++)
505 fprintf(ofp, "%4d %lld\n", (i+1), (long long)q_histo[i]);
506 fprintf(ofp, "\n# Q bucket for > %d\n%4d %lld\n", (int)N_HIST_BKTS-1,
507 N_HIST_BKTS-1, q_histo[N_HIST_BKTS-1]);
508 fclose(ofp);
509
510 sprintf(fname, "%s_dhist.dat", output_name);
511 ofp = fopen(fname, "w");
512 if (!ofp) {
513 perror(fname);
514 return;
515 }
516 fprintf(ofp, "# D buckets\n");
517 for (i = 0; i < (N_HIST_BKTS-1); i++)
518 fprintf(ofp, "%4d %lld\n", (i+1), (long long)d_histo[i]);
519 fprintf(ofp, "\n# D bucket for > %d\n%4d %lld\n", (int)N_HIST_BKTS-1,
520 N_HIST_BKTS-1, d_histo[N_HIST_BKTS-1]);
521 fclose(ofp);
522}
523
63eba147
JA
524int output_avgs(FILE *ofp)
525{
74dc9101
AB
526 if (output_all_data) {
527 if (exes == NULL || *exes != '\0') {
528 output_section_hdr(ofp, "Per Process");
529 output_pip_avg(ofp, "Q2Q", pip_q2q_avg);
530 output_pip_avg(ofp, "Q2A", pip_q2a_avg);
531 output_pip_avg(ofp, "Q2I", pip_q2i_avg);
532 output_pip_avg(ofp, "I2D", pip_i2d_avg);
533 output_pip_avg(ofp, "D2C", pip_d2c_avg);
534 output_pip_avg(ofp, "Q2C", pip_q2c_avg);
535 }
63eba147 536
74dc9101
AB
537 output_section_hdr(ofp, "Per Device");
538 output_dip_avg(ofp, "Q2Q", dip_q2q_avg);
539 output_dip_avg(ofp, "Q2A", dip_q2a_avg);
540 output_dip_avg(ofp, "Q2I", dip_q2i_avg);
541 output_dip_avg(ofp, "I2D", dip_i2d_avg);
542 output_dip_avg(ofp, "D2C", dip_d2c_avg);
543 output_dip_avg(ofp, "Q2C", dip_q2c_avg);
544 }
63eba147
JA
545
546 output_section_hdr(ofp, "All Devices");
547 output_hdr(ofp, "ALL");
548 __output_avg(ofp, "Q2Q", &all_avgs.q2q);
549 __output_avg(ofp, "Q2A", &all_avgs.q2a);
550 __output_avg(ofp, "Q2I", &all_avgs.q2i);
551 __output_avg(ofp, "I2D", &all_avgs.i2d);
552 __output_avg(ofp, "D2C", &all_avgs.d2c);
553 __output_avg(ofp, "Q2C", &all_avgs.q2c);
b2822cea
AB
554 fprintf(ofp, "\n");
555
556 output_section_hdr(ofp, "Device Overhead");
557 output_dip_prep_ohead(ofp);
63eba147 558
74dc9101
AB
559 if (output_all_data) {
560 if (exes == NULL || *exes != '\0') {
561 output_section_hdr(ofp, "Per Process (avgs)");
562 output_pip_avgs(ofp);
563 }
63eba147 564
74dc9101
AB
565 output_section_hdr(ofp, "Per Device (avgs)");
566 output_dip_avgs(ofp);
567 }
63eba147
JA
568
569 output_section_hdr(ofp, "Device Merge Information");
570 output_dip_merge_ratio(ofp);
571
5cd3c859
AB
572 output_section_hdr(ofp, "Device Seek Information");
573 output_dip_seek_info(ofp);
5225e788 574
b2822cea
AB
575 output_section_hdr(ofp, "Plug Information");
576 output_plug_info(ofp);
577
fa0ab85d
AB
578 output_histos();
579
63eba147
JA
580 return 0;
581}
582
583void __output_ranges(FILE *ofp, struct list_head *head_p, float base)
584{
585 struct range_info *rip;
586 struct list_head *p;
587 float limit = base + 0.4;
588
589 __list_for_each(p, head_p) {
590 rip = list_entry(p, struct range_info, head);
591 fprintf(ofp, "%13.9lf %5.1f\n", BIT_TIME(rip->start), base);
592 fprintf(ofp, "%13.9lf %5.1f\n", BIT_TIME(rip->start), limit);
593 fprintf(ofp, "%13.9lf %5.1f\n", BIT_TIME(rip->end), limit);
594 fprintf(ofp, "%13.9lf %5.1f\n", BIT_TIME(rip->end), base);
595 }
596}
597
598int output_regions(FILE *ofp, char *header, struct region_info *reg,
599 float base)
600{
601 if (reg->qr_cur != NULL)
602 list_add_tail(&reg->qr_cur->head, &reg->qranges);
603 if (reg->cr_cur != NULL)
604 list_add_tail(&reg->cr_cur->head, &reg->cranges);
605
606 if (list_len(&reg->qranges) == 0 && list_len(&reg->cranges) == 0)
607 return 0;
608
609 fprintf(ofp, "# %16s : q activity\n", header);
610 __output_ranges(ofp, &reg->qranges, base);
611 fprintf(ofp, "\n");
612
613 fprintf(ofp, "# %16s : c activity\n", header);
614 __output_ranges(ofp, &reg->cranges, base + 0.5);
615 fprintf(ofp, "\n");
616
617 return 1;
618}
619
6eb42155
ADB
620struct __od {
621 FILE *ofp;
622 float base;
623};
624void __output_dev(struct d_info *dip, void *arg)
63eba147
JA
625{
626 char header[128];
6eb42155 627 struct __od *odp = arg;
63eba147 628
6eb42155
ADB
629 sprintf(header, "%d,%d", MAJOR(dip->device), MINOR(dip->device));
630 if (output_regions(odp->ofp, header, &dip->regions, odp->base))
631 odp->base += 1.0;
63eba147
JA
632}
633
634float output_devs(FILE *ofp, float base)
635{
6eb42155 636 struct __od od = { .ofp = ofp, .base = base };
63eba147
JA
637
638 fprintf(ofp, "# Per device\n" );
6eb42155
ADB
639 dip_foreach_out(__output_dev, &od);
640 return od.base;
63eba147
JA
641}
642
643static inline int exe_match(char *exe, char *name)
644{
645 return (exe == NULL) || (strstr(name, exe) != NULL);
646}
647
6eb42155
ADB
648struct __op {
649 FILE *ofp;
650 float base;
651};
652void __output_procs(struct p_info *pip, void *arg)
63eba147 653{
6eb42155
ADB
654 struct __op *opp = arg;
655 output_regions(opp->ofp, pip->name, &pip->regions, opp->base);
656 opp->base += 1.0;
63eba147
JA
657}
658
659float output_procs(FILE *ofp, float base)
660{
6eb42155 661 struct __op op = { .ofp = ofp, .base = base };
63eba147 662
6eb42155
ADB
663 fprintf(ofp, "# Per process\n" );
664 pip_foreach_out(__output_procs, &op);
665 return op.base;
63eba147
JA
666}
667
668int output_ranges(FILE *ofp)
669{
670 float base = 0.0;
671
672 fprintf(ofp, "# %s\n", "Total System");
673 if (output_regions(ofp, "Total System", &all_regions, base))
674 base += 1.0;
675
676 if (n_devs > 1)
677 base = output_devs(ofp, base);
678
679 base = output_procs(ofp, base);
680
681 return 0;
682}