Commit | Line | Data |
---|---|---|
951ea56c AB |
1 | /* |
2 | * blktrace output analysis: generate a timeline & gather statistics | |
3 | * | |
4 | * (C) Copyright 2007 Hewlett-Packard Development Company, L.P. | |
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 <stdlib.h> | |
23 | #include <string.h> | |
24 | ||
25 | #include "globals.h" | |
26 | ||
27 | #define Q2D_MAX_HISTO 9 | |
28 | struct q2d_info { | |
29 | unsigned long nhistos; | |
30 | unsigned long histos[Q2D_MAX_HISTO + 1]; | |
31 | }; | |
32 | ||
33 | void q2d_histo_add(void *priv, __u64 q2d_in) | |
34 | { | |
35 | int index; | |
36 | struct q2d_info *q2dp = priv; | |
37 | double q2d = BIT_TIME(q2d_in); | |
38 | long msec = (long)(q2d / 0.001); | |
39 | ||
40 | switch (msec) { | |
41 | default: index = 9; break; | |
42 | case 500 ... 999: index = 8; break; | |
43 | case 250 ... 499: index = 7; break; | |
44 | case 100 ... 249: index = 6; break; | |
45 | case 75 ... 99: index = 5; break; | |
46 | case 50 ... 74: index = 4; break; | |
47 | case 25 ... 49: index = 3; break; | |
48 | case 10 ... 24: index = 2; break; | |
49 | case 5 ... 9: index = 1; break; | |
50 | case 0 ... 4: index = 0; break; | |
51 | } | |
52 | ||
53 | q2dp->histos[index]++; | |
54 | q2dp->nhistos++; | |
55 | } | |
56 | ||
c053af42 | 57 | void *q2d_alloc(void) |
951ea56c AB |
58 | { |
59 | struct q2d_info *q2dp = malloc(sizeof(*q2dp)); | |
60 | ||
61 | return memset(q2dp, 0, sizeof(*q2dp)); | |
62 | } | |
63 | ||
c053af42 | 64 | void q2d_free(void *priv) |
951ea56c AB |
65 | { |
66 | free(priv); | |
67 | } | |
68 | ||
69 | void q2d_display_header(FILE *fp) | |
70 | { | |
71 | fprintf(fp, "%5s ", "<.005"); | |
72 | fprintf(fp, "%5s ", "<.010"); | |
73 | fprintf(fp, "%5s ", "<.025"); | |
74 | fprintf(fp, "%5s ", "<.050"); | |
75 | fprintf(fp, "%5s ", "<.075"); | |
76 | fprintf(fp, "%5s ", "<.100"); | |
77 | fprintf(fp, "%5s ", "<.250"); | |
78 | fprintf(fp, "%5s ", "<.500"); | |
79 | fprintf(fp, "%5s ", "< 1.0"); | |
80 | fprintf(fp, "%5s ", ">=1.0\n"); | |
81 | } | |
82 | ||
83 | void q2d_display_dashes(FILE *fp) | |
84 | { | |
85 | int i; | |
86 | ||
87 | for (i = 0; i <= Q2D_MAX_HISTO; i++) | |
88 | fprintf(fp, "===== "); | |
89 | fprintf(fp, "\n"); | |
90 | } | |
91 | ||
92 | void q2d_display(FILE *fp, void *priv) | |
93 | { | |
94 | int i; | |
95 | struct q2d_info *q2dp = priv; | |
96 | double nh = (double)q2dp->nhistos; | |
97 | ||
98 | for (i = 0; i <= Q2D_MAX_HISTO; i++) { | |
99 | double p = 100.0 * (double)q2dp->histos[i] / nh; | |
100 | fprintf(fp, "%5.1lf ", p); | |
101 | } | |
102 | fprintf(fp, "\n"); | |
103 | } | |
104 | ||
105 | int q2d_ok(void *priv) | |
106 | { | |
107 | struct q2d_info *q2dp = priv; | |
108 | ||
109 | return q2dp && q2dp->nhistos > 0; | |
110 | } | |
111 | ||
112 | void q2d_acc(void *a1, void *a2) | |
113 | { | |
114 | int i; | |
115 | struct q2d_info *ap = a1; | |
116 | struct q2d_info *tp = a2; | |
117 | ||
118 | for (i = 0; i <= Q2D_MAX_HISTO; i++) | |
119 | ap->histos[i] += tp->histos[i]; | |
120 | ap->nhistos += tp->nhistos; | |
121 | } |