blob: ec87debaf61580cbff89c7049d53e1009a085c2d [file] [log] [blame]
Jens Axboe3c39a372006-06-06 20:56:12 +02001#include <stdio.h>
2#include <string.h>
3#include <sys/time.h>
4#include <sys/types.h>
Jens Axboe5c4e1db2006-06-07 14:17:08 +02005#include <sys/stat.h>
Jens Axboe3c39a372006-06-06 20:56:12 +02006#include <dirent.h>
7#include <libgen.h>
8#include <math.h>
9
10#include "fio.h"
Jens Axboe7c9b1bc2009-06-03 09:25:57 +020011#include "diskutil.h"
Jens Axboe3c39a372006-06-06 20:56:12 +020012
Jens Axboe3c39a372006-06-06 20:56:12 +020013void update_rusage_stat(struct thread_data *td)
14{
Jens Axboe756867b2007-03-06 15:19:24 +010015 struct thread_stat *ts = &td->ts;
Jens Axboe3c39a372006-06-06 20:56:12 +020016
Jens Axboe079ad092007-02-20 13:58:20 +010017 getrusage(RUSAGE_SELF, &ts->ru_end);
18
Jens Axboe5ec10ea2008-03-06 15:42:00 +010019 ts->usr_time += mtime_since(&ts->ru_start.ru_utime,
20 &ts->ru_end.ru_utime);
21 ts->sys_time += mtime_since(&ts->ru_start.ru_stime,
22 &ts->ru_end.ru_stime);
23 ts->ctx += ts->ru_end.ru_nvcsw + ts->ru_end.ru_nivcsw
24 - (ts->ru_start.ru_nvcsw + ts->ru_start.ru_nivcsw);
Jens Axboee7823a92007-09-07 20:33:33 +020025 ts->minf += ts->ru_end.ru_minflt - ts->ru_start.ru_minflt;
26 ts->majf += ts->ru_end.ru_majflt - ts->ru_start.ru_majflt;
Jens Axboe5ec10ea2008-03-06 15:42:00 +010027
Jens Axboe079ad092007-02-20 13:58:20 +010028 memcpy(&ts->ru_start, &ts->ru_end, sizeof(ts->ru_end));
Jens Axboe3c39a372006-06-06 20:56:12 +020029}
30
31static int calc_lat(struct io_stat *is, unsigned long *min, unsigned long *max,
32 double *mean, double *dev)
33{
Jens Axboe68704082007-01-10 19:56:37 +010034 double n = is->samples;
Jens Axboe3c39a372006-06-06 20:56:12 +020035
36 if (is->samples == 0)
37 return 0;
38
39 *min = is->min_val;
40 *max = is->max_val;
41
42 n = (double) is->samples;
Jens Axboe68704082007-01-10 19:56:37 +010043 *mean = is->mean;
Jens Axboe3c39a372006-06-06 20:56:12 +020044
Jens Axboe68704082007-01-10 19:56:37 +010045 if (n > 1.0)
46 *dev = sqrt(is->S / (n - 1.0));
Jens Axboeef9c5c42007-01-03 14:21:13 +010047 else
Jens Axboe4b43f542007-07-19 21:38:35 +020048 *dev = 0;
Jens Axboeef9c5c42007-01-03 14:21:13 +010049
Jens Axboe3c39a372006-06-06 20:56:12 +020050 return 1;
51}
52
53static void show_group_stats(struct group_run_stats *rs, int id)
54{
Jens Axboedbe11252007-02-11 00:19:51 +010055 char *p1, *p2, *p3, *p4;
56 const char *ddir_str[] = { " READ", " WRITE" };
57 int i;
58
Jens Axboe6d861442007-03-15 09:22:23 +010059 log_info("\nRun status group %d (all jobs):\n", id);
Jens Axboe3c39a372006-06-06 20:56:12 +020060
Jens Axboedbe11252007-02-11 00:19:51 +010061 for (i = 0; i <= DDIR_WRITE; i++) {
62 if (!rs->max_run[i])
63 continue;
64
Jens Axboe8879fd12009-04-20 10:06:02 +020065 p1 = num2str(rs->io_kb[i], 6, 1024, 1);
66 p2 = num2str(rs->agg[i], 6, 1024, 1);
67 p3 = num2str(rs->min_bw[i], 6, 1024, 1);
68 p4 = num2str(rs->max_bw[i], 6, 1024, 1);
Jens Axboedbe11252007-02-11 00:19:51 +010069
Jens Axboe5ec10ea2008-03-06 15:42:00 +010070 log_info("%s: io=%siB, aggrb=%siB/s, minb=%siB/s, maxb=%siB/s,"
71 " mint=%llumsec, maxt=%llumsec\n", ddir_str[i], p1, p2,
72 p3, p4, rs->min_run[i],
73 rs->max_run[i]);
Jens Axboedbe11252007-02-11 00:19:51 +010074
75 free(p1);
76 free(p2);
77 free(p3);
78 free(p4);
79 }
Jens Axboe3c39a372006-06-06 20:56:12 +020080}
81
Jens Axboeb3605062007-03-12 14:19:47 +010082#define ts_total_io_u(ts) \
83 ((ts)->total_io_u[0] + (ts)->total_io_u[1])
84
Jens Axboe838bc702008-05-22 13:08:23 +020085static void stat_calc_dist(unsigned int *map, unsigned long total,
86 double *io_u_dist)
Jens Axboe22708902007-03-06 17:05:32 +010087{
88 int i;
89
90 /*
91 * Do depth distribution calculations
92 */
93 for (i = 0; i < FIO_IO_U_MAP_NR; i++) {
Jens Axboe838bc702008-05-22 13:08:23 +020094 if (total) {
95 io_u_dist[i] = (double) map[i] / (double) total;
96 io_u_dist[i] *= 100.0;
97 if (io_u_dist[i] < 0.1 && map[i])
98 io_u_dist[i] = 0.1;
99 } else
100 io_u_dist[i] = 0.0;
Jens Axboe22708902007-03-06 17:05:32 +0100101 }
102}
103
Jens Axboe04a0fea2007-06-19 12:48:41 +0200104static void stat_calc_lat(struct thread_stat *ts, double *dst,
105 unsigned int *src, int nr)
Jens Axboe22708902007-03-06 17:05:32 +0100106{
Jens Axboe838bc702008-05-22 13:08:23 +0200107 unsigned long total = ts_total_io_u(ts);
Jens Axboe22708902007-03-06 17:05:32 +0100108 int i;
109
110 /*
111 * Do latency distribution calculations
112 */
Jens Axboe04a0fea2007-06-19 12:48:41 +0200113 for (i = 0; i < nr; i++) {
Jens Axboe838bc702008-05-22 13:08:23 +0200114 if (total) {
115 dst[i] = (double) src[i] / (double) total;
116 dst[i] *= 100.0;
117 if (dst[i] < 0.01 && src[i])
118 dst[i] = 0.01;
119 } else
120 dst[i] = 0.0;
Jens Axboe22708902007-03-06 17:05:32 +0100121 }
122}
123
Jens Axboe04a0fea2007-06-19 12:48:41 +0200124static void stat_calc_lat_u(struct thread_stat *ts, double *io_u_lat)
125{
126 stat_calc_lat(ts, io_u_lat, ts->io_u_lat_u, FIO_IO_U_LAT_U_NR);
127}
128
129static void stat_calc_lat_m(struct thread_stat *ts, double *io_u_lat)
130{
131 stat_calc_lat(ts, io_u_lat, ts->io_u_lat_m, FIO_IO_U_LAT_M_NR);
132}
133
Jens Axboeea2accc2007-06-19 09:48:44 +0200134static int usec_to_msec(unsigned long *min, unsigned long *max, double *mean,
135 double *dev)
136{
137 if (*min > 1000 && *max > 1000 && *mean > 1000.0 && *dev > 1000.0) {
138 *min /= 1000;
139 *max /= 1000;
140 *mean /= 1000.0;
141 *dev /= 1000.0;
142 return 0;
143 }
144
145 return 1;
146}
147
Jens Axboe756867b2007-03-06 15:19:24 +0100148static void show_ddir_status(struct group_run_stats *rs, struct thread_stat *ts,
Jens Axboe3c39a372006-06-06 20:56:12 +0200149 int ddir)
150{
Jens Axboe3c9b60c2006-11-07 08:36:14 +0100151 const char *ddir_str[] = { "read ", "write" };
Jens Axboe8879fd12009-04-20 10:06:02 +0200152 unsigned long min, max, runt;
Jens Axboeb3605062007-03-12 14:19:47 +0100153 unsigned long long bw, iops;
Jens Axboe3c39a372006-06-06 20:56:12 +0200154 double mean, dev;
Jens Axboeb3605062007-03-12 14:19:47 +0100155 char *io_p, *bw_p, *iops_p;
Jens Axboe3c39a372006-06-06 20:56:12 +0200156
Jens Axboe756867b2007-03-06 15:19:24 +0100157 if (!ts->runtime[ddir])
Jens Axboe3c39a372006-06-06 20:56:12 +0200158 return;
159
Jens Axboe8879fd12009-04-20 10:06:02 +0200160 runt = ts->runtime[ddir];
161
162 bw = (1000 * ts->io_bytes[ddir]) / runt;
163 io_p = num2str(ts->io_bytes[ddir] >> 10, 6, 1024, 1);
164 bw_p = num2str(bw >> 10, 6, 1024, 1);
165
166 iops = (1000 * ts->total_io_u[ddir]) / runt;
Jens Axboeb3605062007-03-12 14:19:47 +0100167 iops_p = num2str(iops, 6, 1, 0);
Jens Axboedbe11252007-02-11 00:19:51 +0100168
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100169 log_info(" %s: io=%siB, bw=%siB/s, iops=%s, runt=%6lumsec\n",
170 ddir_str[ddir], io_p, bw_p, iops_p,
171 ts->runtime[ddir]);
Jens Axboedbe11252007-02-11 00:19:51 +0100172
173 free(io_p);
174 free(bw_p);
Jens Axboeb3605062007-03-12 14:19:47 +0100175 free(iops_p);
Jens Axboe3c39a372006-06-06 20:56:12 +0200176
Jens Axboed85f5112007-06-18 09:41:23 +0200177 if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) {
178 const char *base = "(usec)";
Jens Axboed9309cb2007-08-16 13:07:46 +0200179 char *minp, *maxp;
Jens Axboe3c39a372006-06-06 20:56:12 +0200180
Jens Axboeea2accc2007-06-19 09:48:44 +0200181 if (!usec_to_msec(&min, &max, &mean, &dev))
Jens Axboed85f5112007-06-18 09:41:23 +0200182 base = "(msec)";
Jens Axboeea2accc2007-06-19 09:48:44 +0200183
Jens Axboed9309cb2007-08-16 13:07:46 +0200184 minp = num2str(min, 6, 1, 0);
185 maxp = num2str(max, 6, 1, 0);
186
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100187 log_info(" slat %s: min=%s, max=%s, avg=%5.02f,"
188 " stdev=%5.02f\n", base, minp, maxp, mean, dev);
Jens Axboed9309cb2007-08-16 13:07:46 +0200189
190 free(minp);
191 free(maxp);
Jens Axboed85f5112007-06-18 09:41:23 +0200192 }
193 if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) {
194 const char *base = "(usec)";
Jens Axboed9309cb2007-08-16 13:07:46 +0200195 char *minp, *maxp;
Jens Axboe3c39a372006-06-06 20:56:12 +0200196
Jens Axboeea2accc2007-06-19 09:48:44 +0200197 if (!usec_to_msec(&min, &max, &mean, &dev))
198 base = "(msec)";
199
Jens Axboed9309cb2007-08-16 13:07:46 +0200200 minp = num2str(min, 6, 1, 0);
201 maxp = num2str(max, 6, 1, 0);
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100202
203 log_info(" clat %s: min=%s, max=%s, avg=%5.02f,"
204 " stdev=%5.02f\n", base, minp, maxp, mean, dev);
Jens Axboed9309cb2007-08-16 13:07:46 +0200205
206 free(minp);
207 free(maxp);
Jens Axboed85f5112007-06-18 09:41:23 +0200208 }
Jens Axboe079ad092007-02-20 13:58:20 +0100209 if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
Jens Axboe3c39a372006-06-06 20:56:12 +0200210 double p_of_agg;
211
212 p_of_agg = mean * 100 / (double) rs->agg[ddir];
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100213 log_info(" bw (KiB/s) : min=%5lu, max=%5lu, per=%3.2f%%,"
214 " avg=%5.02f, stdev=%5.02f\n", min, max, p_of_agg,
215 mean, dev);
Jens Axboe3c39a372006-06-06 20:56:12 +0200216 }
217}
218
Jens Axboe04a0fea2007-06-19 12:48:41 +0200219static void show_lat(double *io_u_lat, int nr, const char **ranges,
220 const char *msg)
221{
222 int new_line = 1, i, line = 0;
223
224 for (i = 0; i < nr; i++) {
225 if (io_u_lat[i] <= 0.0)
226 continue;
227 if (new_line) {
Jens Axboe4539ed72007-07-23 14:21:17 +0200228 if (line)
229 log_info("\n");
Jens Axboe04a0fea2007-06-19 12:48:41 +0200230 log_info(" lat (%s): ", msg);
231 new_line = 0;
232 line = 0;
233 }
234 if (line)
235 log_info(", ");
236 log_info("%s%3.2f%%", ranges[i], io_u_lat[i]);
237 line++;
238 if (line == 5)
239 new_line = 1;
240 }
Jens Axboe04a0fea2007-06-19 12:48:41 +0200241}
242
243static void show_lat_u(double *io_u_lat_u)
244{
245 const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=",
246 "250=", "500=", "750=", "1000=", };
247
248 show_lat(io_u_lat_u, FIO_IO_U_LAT_U_NR, ranges, "usec");
249}
250
251static void show_lat_m(double *io_u_lat_m)
252{
253 const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=",
254 "250=", "500=", "750=", "1000=", "2000=",
255 ">=2000=", };
256
257 show_lat(io_u_lat_m, FIO_IO_U_LAT_M_NR, ranges, "msec");
258}
259
260static void show_latencies(double *io_u_lat_u, double *io_u_lat_m)
261{
262 show_lat_u(io_u_lat_u);
Jens Axboe4539ed72007-07-23 14:21:17 +0200263 log_info("\n");
Jens Axboe04a0fea2007-06-19 12:48:41 +0200264 show_lat_m(io_u_lat_m);
265 log_info("\n");
266}
267
Jens Axboe756867b2007-03-06 15:19:24 +0100268static void show_thread_status(struct thread_stat *ts,
Jens Axboe3c39a372006-06-06 20:56:12 +0200269 struct group_run_stats *rs)
270{
271 double usr_cpu, sys_cpu;
Jens Axboe69008992006-11-24 13:12:56 +0100272 unsigned long runtime;
Jens Axboe71619dc2007-01-13 23:56:33 +0100273 double io_u_dist[FIO_IO_U_MAP_NR];
Jens Axboe04a0fea2007-06-19 12:48:41 +0200274 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
275 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
Jens Axboe3c39a372006-06-06 20:56:12 +0200276
Jens Axboeb4c5e1a2007-10-25 18:44:45 +0200277 if (!(ts->io_bytes[0] + ts->io_bytes[1]) &&
278 !(ts->total_io_u[0] + ts->total_io_u[1]))
Jens Axboe3c39a372006-06-06 20:56:12 +0200279 return;
280
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100281 if (!ts->error) {
282 log_info("%s: (groupid=%d, jobs=%d): err=%2d: pid=%d\n",
283 ts->name, ts->groupid, ts->members,
Jens Axboe5921e802008-05-30 15:02:38 +0200284 ts->error, (int) ts->pid);
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100285 } else {
286 log_info("%s: (groupid=%d, jobs=%d): err=%2d (%s): pid=%d\n",
287 ts->name, ts->groupid, ts->members,
Jens Axboe5921e802008-05-30 15:02:38 +0200288 ts->error, ts->verror, (int) ts->pid);
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100289 }
Jens Axboe3c39a372006-06-06 20:56:12 +0200290
Jens Axboe7bdce1b2007-03-06 20:01:13 +0100291 if (ts->description)
Jens Axboe6d861442007-03-15 09:22:23 +0100292 log_info(" Description : [%s]\n", ts->description);
Jens Axboe7bdce1b2007-03-06 20:01:13 +0100293
Jens Axboe756867b2007-03-06 15:19:24 +0100294 if (ts->io_bytes[DDIR_READ])
295 show_ddir_status(rs, ts, DDIR_READ);
296 if (ts->io_bytes[DDIR_WRITE])
297 show_ddir_status(rs, ts, DDIR_WRITE);
Jens Axboe3c39a372006-06-06 20:56:12 +0200298
Jens Axboe756867b2007-03-06 15:19:24 +0100299 runtime = ts->total_run_time;
Jens Axboe69008992006-11-24 13:12:56 +0100300 if (runtime) {
Jens Axboe1e97cce2006-12-05 11:44:16 +0100301 double runt = (double) runtime;
Jens Axboe3c39a372006-06-06 20:56:12 +0200302
Jens Axboe756867b2007-03-06 15:19:24 +0100303 usr_cpu = (double) ts->usr_time * 100 / runt;
304 sys_cpu = (double) ts->sys_time * 100 / runt;
Jens Axboe3c39a372006-06-06 20:56:12 +0200305 } else {
306 usr_cpu = 0;
307 sys_cpu = 0;
308 }
309
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100310 log_info(" cpu : usr=%3.2f%%, sys=%3.2f%%, ctx=%lu, majf=%lu,"
311 " minf=%lu\n", usr_cpu, sys_cpu, ts->ctx, ts->majf, ts->minf);
Jens Axboe71619dc2007-01-13 23:56:33 +0100312
Jens Axboe838bc702008-05-22 13:08:23 +0200313 stat_calc_dist(ts->io_u_map, ts_total_io_u(ts), io_u_dist);
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100314 log_info(" IO depths : 1=%3.1f%%, 2=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%,"
315 " 16=%3.1f%%, 32=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
316 io_u_dist[1], io_u_dist[2],
317 io_u_dist[3], io_u_dist[4],
318 io_u_dist[5], io_u_dist[6]);
Jens Axboe838bc702008-05-22 13:08:23 +0200319
320 stat_calc_dist(ts->io_u_submit, ts->total_submit, io_u_dist);
321 log_info(" submit : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%,"
322 " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
323 io_u_dist[1], io_u_dist[2],
324 io_u_dist[3], io_u_dist[4],
325 io_u_dist[5], io_u_dist[6]);
326 stat_calc_dist(ts->io_u_complete, ts->total_complete, io_u_dist);
327 log_info(" complete : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%,"
328 " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
329 io_u_dist[1], io_u_dist[2],
330 io_u_dist[3], io_u_dist[4],
331 io_u_dist[5], io_u_dist[6]);
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100332 log_info(" issued r/w: total=%lu/%lu, short=%lu/%lu\n",
333 ts->total_io_u[0], ts->total_io_u[1],
334 ts->short_io_u[0], ts->short_io_u[1]);
Jens Axboe838bc702008-05-22 13:08:23 +0200335 stat_calc_lat_u(ts, io_u_lat_u);
336 stat_calc_lat_m(ts, io_u_lat_m);
Jens Axboe04a0fea2007-06-19 12:48:41 +0200337 show_latencies(io_u_lat_u, io_u_lat_m);
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200338 if (ts->continue_on_error) {
339 log_info(" errors: total=%lu, first_error=%d\n",
340 ts->total_err_count, ts->first_error);
341 }
Jens Axboe3c39a372006-06-06 20:56:12 +0200342}
343
Jens Axboe756867b2007-03-06 15:19:24 +0100344static void show_ddir_status_terse(struct thread_stat *ts,
Jens Axboec6ae0a52006-06-12 11:04:44 +0200345 struct group_run_stats *rs, int ddir)
346{
347 unsigned long min, max;
348 unsigned long long bw;
349 double mean, dev;
350
351 bw = 0;
Jens Axboe756867b2007-03-06 15:19:24 +0100352 if (ts->runtime[ddir])
353 bw = ts->io_bytes[ddir] / ts->runtime[ddir];
Jens Axboec6ae0a52006-06-12 11:04:44 +0200354
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100355 log_info(";%llu;%llu;%lu", ts->io_bytes[ddir] >> 10, bw,
356 ts->runtime[ddir]);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200357
Jens Axboe079ad092007-02-20 13:58:20 +0100358 if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev))
Jens Axboe6d861442007-03-15 09:22:23 +0100359 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200360 else
Jens Axboe6d861442007-03-15 09:22:23 +0100361 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200362
Jens Axboe079ad092007-02-20 13:58:20 +0100363 if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev))
Jens Axboe6d861442007-03-15 09:22:23 +0100364 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200365 else
Jens Axboe6d861442007-03-15 09:22:23 +0100366 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200367
Jens Axboe079ad092007-02-20 13:58:20 +0100368 if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
Jens Axboec6ae0a52006-06-12 11:04:44 +0200369 double p_of_agg;
370
371 p_of_agg = mean * 100 / (double) rs->agg[ddir];
Jens Axboe6d861442007-03-15 09:22:23 +0100372 log_info(";%lu;%lu;%f%%;%f;%f", min, max, p_of_agg, mean, dev);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200373 } else
Jens Axboe6d861442007-03-15 09:22:23 +0100374 log_info(";%lu;%lu;%f%%;%f;%f", 0UL, 0UL, 0.0, 0.0, 0.0);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200375}
376
377
Jens Axboe756867b2007-03-06 15:19:24 +0100378static void show_thread_status_terse(struct thread_stat *ts,
Jens Axboec6ae0a52006-06-12 11:04:44 +0200379 struct group_run_stats *rs)
380{
Jens Axboe22708902007-03-06 17:05:32 +0100381 double io_u_dist[FIO_IO_U_MAP_NR];
Jens Axboe04a0fea2007-06-19 12:48:41 +0200382 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
383 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
Jens Axboec6ae0a52006-06-12 11:04:44 +0200384 double usr_cpu, sys_cpu;
Jens Axboe04a0fea2007-06-19 12:48:41 +0200385 int i;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200386
Jens Axboe6d861442007-03-15 09:22:23 +0100387 log_info("%s;%d;%d", ts->name, ts->groupid, ts->error);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200388
Jens Axboe756867b2007-03-06 15:19:24 +0100389 show_ddir_status_terse(ts, rs, 0);
390 show_ddir_status_terse(ts, rs, 1);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200391
Jens Axboe756867b2007-03-06 15:19:24 +0100392 if (ts->total_run_time) {
393 double runt = (double) ts->total_run_time;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200394
Jens Axboe756867b2007-03-06 15:19:24 +0100395 usr_cpu = (double) ts->usr_time * 100 / runt;
396 sys_cpu = (double) ts->sys_time * 100 / runt;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200397 } else {
398 usr_cpu = 0;
399 sys_cpu = 0;
400 }
401
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100402 log_info(";%f%%;%f%%;%lu;%lu;%lu", usr_cpu, sys_cpu, ts->ctx, ts->majf,
403 ts->minf);
Jens Axboe22708902007-03-06 17:05:32 +0100404
Jens Axboe838bc702008-05-22 13:08:23 +0200405 stat_calc_dist(ts->io_u_map, ts_total_io_u(ts), io_u_dist);
Jens Axboe04a0fea2007-06-19 12:48:41 +0200406 stat_calc_lat_u(ts, io_u_lat_u);
407 stat_calc_lat_m(ts, io_u_lat_m);
Jens Axboe22708902007-03-06 17:05:32 +0100408
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100409 log_info(";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%",
410 io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3],
411 io_u_dist[4], io_u_dist[5], io_u_dist[6]);
Jens Axboe22708902007-03-06 17:05:32 +0100412
Jens Axboe04a0fea2007-06-19 12:48:41 +0200413 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++)
414 log_info(";%3.2f%%", io_u_lat_u[i]);
415 for (i = 0; i < FIO_IO_U_LAT_M_NR; i++)
416 log_info(";%3.2f%%", io_u_lat_m[i]);
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200417 if (ts->continue_on_error)
418 log_info(";%lu;%d", ts->total_err_count, ts->first_error);
Jens Axboe04a0fea2007-06-19 12:48:41 +0200419 log_info("\n");
Jens Axboe22708902007-03-06 17:05:32 +0100420
421 if (ts->description)
Jens Axboe6d861442007-03-15 09:22:23 +0100422 log_info(";%s", ts->description);
Jens Axboe22708902007-03-06 17:05:32 +0100423
Jens Axboe6d861442007-03-15 09:22:23 +0100424 log_info("\n");
Jens Axboe756867b2007-03-06 15:19:24 +0100425}
426
Jens Axboe197574e2007-03-08 15:35:11 +0100427static void sum_stat(struct io_stat *dst, struct io_stat *src, int nr)
Jens Axboe756867b2007-03-06 15:19:24 +0100428{
429 double mean, S;
430
431 dst->min_val = min(dst->min_val, src->min_val);
432 dst->max_val = max(dst->max_val, src->max_val);
433 dst->samples += src->samples;
434
435 /*
436 * Needs a new method for calculating stddev, we cannot just
437 * average them we do below for nr > 1
438 */
439 if (nr == 1) {
440 mean = src->mean;
441 S = src->S;
442 } else {
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100443 mean = ((src->mean * (double) (nr - 1))
444 + dst->mean) / ((double) nr);
Jens Axboec39cced2007-03-06 15:37:00 +0100445 S = ((src->S * (double) (nr - 1)) + dst->S) / ((double) nr);
Jens Axboe756867b2007-03-06 15:19:24 +0100446 }
447
448 dst->mean = mean;
449 dst->S = S;
450}
451
Jens Axboe3c39a372006-06-06 20:56:12 +0200452void show_run_stats(void)
453{
454 struct group_run_stats *runstats, *rs;
455 struct thread_data *td;
Jens Axboe756867b2007-03-06 15:19:24 +0100456 struct thread_stat *threadstats, *ts;
Jens Axboe197574e2007-03-08 15:35:11 +0100457 int i, j, k, l, nr_ts, last_ts, idx;
Jens Axboe3c39a372006-06-06 20:56:12 +0200458
459 runstats = malloc(sizeof(struct group_run_stats) * (groupid + 1));
460
461 for (i = 0; i < groupid + 1; i++) {
462 rs = &runstats[i];
463
464 memset(rs, 0, sizeof(*rs));
465 rs->min_bw[0] = rs->min_run[0] = ~0UL;
466 rs->min_bw[1] = rs->min_run[1] = ~0UL;
467 }
468
Jens Axboe756867b2007-03-06 15:19:24 +0100469 /*
470 * find out how many threads stats we need. if group reporting isn't
471 * enabled, it's one-per-td.
472 */
473 nr_ts = 0;
474 last_ts = -1;
Jens Axboe34572e22006-10-20 09:33:18 +0200475 for_each_td(td, i) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100476 if (!td->o.group_reporting) {
Jens Axboe756867b2007-03-06 15:19:24 +0100477 nr_ts++;
478 continue;
479 }
480 if (last_ts == td->groupid)
481 continue;
482
483 last_ts = td->groupid;
484 nr_ts++;
485 }
486
487 threadstats = malloc(nr_ts * sizeof(struct thread_stat));
488
489 for (i = 0; i < nr_ts; i++) {
490 ts = &threadstats[i];
491
492 memset(ts, 0, sizeof(*ts));
Jens Axboede64df02007-03-08 19:09:49 +0100493 for (j = 0; j <= DDIR_WRITE; j++) {
Jens Axboe197574e2007-03-08 15:35:11 +0100494 ts->clat_stat[j].min_val = -1UL;
495 ts->slat_stat[j].min_val = -1UL;
496 ts->bw_stat[j].min_val = -1UL;
497 }
Jens Axboe7abd0e32007-03-12 15:24:43 +0100498 ts->groupid = -1;
Jens Axboe756867b2007-03-06 15:19:24 +0100499 }
500
501 j = 0;
502 last_ts = -1;
Jens Axboe197574e2007-03-08 15:35:11 +0100503 idx = 0;
Jens Axboe756867b2007-03-06 15:19:24 +0100504 for_each_td(td, i) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100505 if (idx && (!td->o.group_reporting ||
506 (td->o.group_reporting && last_ts != td->groupid))) {
Jens Axboe7abd0e32007-03-12 15:24:43 +0100507 idx = 0;
508 j++;
509 }
510
511 last_ts = td->groupid;
512
Jens Axboe756867b2007-03-06 15:19:24 +0100513 ts = &threadstats[j];
514
Jens Axboe197574e2007-03-08 15:35:11 +0100515 idx++;
Jens Axboe6586ee82007-03-06 19:46:09 +0100516 ts->members++;
Jens Axboe756867b2007-03-06 15:19:24 +0100517
Jens Axboe7abd0e32007-03-12 15:24:43 +0100518 if (ts->groupid == -1) {
Jens Axboe2dc84ba2007-03-06 15:46:33 +0100519 /*
520 * These are per-group shared already
521 */
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100522 ts->name = td->o.name;
523 ts->description = td->o.description;
Jens Axboe756867b2007-03-06 15:19:24 +0100524 ts->groupid = td->groupid;
Jens Axboe2dc84ba2007-03-06 15:46:33 +0100525
526 /*
527 * first pid in group, not very useful...
528 */
Jens Axboe756867b2007-03-06 15:19:24 +0100529 ts->pid = td->pid;
Jens Axboe2dc84ba2007-03-06 15:46:33 +0100530 }
531
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200532 ts->continue_on_error = td->o.continue_on_error;
533 ts->total_err_count += td->total_err_count;
534 ts->first_error = td->first_error;
535 if (!ts->error) {
536 if (!td->error && td->o.continue_on_error &&
537 td->first_error) {
538 ts->error = td->first_error;
539 ts->verror = td->verror;
540 } else if (td->error) {
541 ts->error = td->error;
542 ts->verror = td->verror;
543 }
Jens Axboe756867b2007-03-06 15:19:24 +0100544 }
545
Jens Axboede64df02007-03-08 19:09:49 +0100546 for (l = 0; l <= DDIR_WRITE; l++) {
Jens Axboe197574e2007-03-08 15:35:11 +0100547 sum_stat(&ts->clat_stat[l], &td->ts.clat_stat[l], idx);
548 sum_stat(&ts->slat_stat[l], &td->ts.slat_stat[l], idx);
549 sum_stat(&ts->bw_stat[l], &td->ts.bw_stat[l], idx);
Jens Axboe756867b2007-03-06 15:19:24 +0100550
Jens Axboe197574e2007-03-08 15:35:11 +0100551 ts->stat_io_bytes[l] += td->ts.stat_io_bytes[l];
552 ts->io_bytes[l] += td->ts.io_bytes[l];
553
554 if (ts->runtime[l] < td->ts.runtime[l])
555 ts->runtime[l] = td->ts.runtime[l];
556 }
Jens Axboe756867b2007-03-06 15:19:24 +0100557
558 ts->usr_time += td->ts.usr_time;
559 ts->sys_time += td->ts.sys_time;
560 ts->ctx += td->ts.ctx;
Jens Axboee7823a92007-09-07 20:33:33 +0200561 ts->majf += td->ts.majf;
562 ts->minf += td->ts.minf;
Jens Axboe756867b2007-03-06 15:19:24 +0100563
564 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
565 ts->io_u_map[k] += td->ts.io_u_map[k];
Jens Axboe838bc702008-05-22 13:08:23 +0200566 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
567 ts->io_u_submit[k] += td->ts.io_u_submit[k];
568 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
569 ts->io_u_complete[k] += td->ts.io_u_complete[k];
Jens Axboe04a0fea2007-06-19 12:48:41 +0200570 for (k = 0; k < FIO_IO_U_LAT_U_NR; k++)
571 ts->io_u_lat_u[k] += td->ts.io_u_lat_u[k];
572 for (k = 0; k < FIO_IO_U_LAT_M_NR; k++)
573 ts->io_u_lat_m[k] += td->ts.io_u_lat_m[k];
574
Jens Axboe756867b2007-03-06 15:19:24 +0100575
Jens Axboe30061b92007-04-17 13:31:34 +0200576 for (k = 0; k <= DDIR_WRITE; k++) {
Jens Axboeb3605062007-03-12 14:19:47 +0100577 ts->total_io_u[k] += td->ts.total_io_u[k];
Jens Axboe30061b92007-04-17 13:31:34 +0200578 ts->short_io_u[k] += td->ts.short_io_u[k];
579 }
Jens Axboe756867b2007-03-06 15:19:24 +0100580
581 ts->total_run_time += td->ts.total_run_time;
Jens Axboe838bc702008-05-22 13:08:23 +0200582 ts->total_submit += td->ts.total_submit;
583 ts->total_complete += td->ts.total_complete;
Jens Axboe756867b2007-03-06 15:19:24 +0100584 }
585
586 for (i = 0; i < nr_ts; i++) {
Jens Axboe94370ac2007-03-08 15:28:10 +0100587 unsigned long long bw;
Jens Axboe3c39a372006-06-06 20:56:12 +0200588
Jens Axboe756867b2007-03-06 15:19:24 +0100589 ts = &threadstats[i];
590 rs = &runstats[ts->groupid];
Jens Axboe3c39a372006-06-06 20:56:12 +0200591
Jens Axboede64df02007-03-08 19:09:49 +0100592 for (j = 0; j <= DDIR_WRITE; j++) {
Jens Axboe94370ac2007-03-08 15:28:10 +0100593 if (!ts->runtime[j])
594 continue;
595 if (ts->runtime[j] < rs->min_run[j] || !rs->min_run[j])
596 rs->min_run[j] = ts->runtime[j];
597 if (ts->runtime[j] > rs->max_run[j])
598 rs->max_run[j] = ts->runtime[j];
Jens Axboe3c39a372006-06-06 20:56:12 +0200599
Jens Axboe94370ac2007-03-08 15:28:10 +0100600 bw = 0;
Jens Axboe8879fd12009-04-20 10:06:02 +0200601 if (ts->runtime[j]) {
602 unsigned long runt;
603
604 runt = ts->runtime[j] * 1024 / 1000;
605 bw = ts->io_bytes[j] / runt;
606 }
Jens Axboe94370ac2007-03-08 15:28:10 +0100607 if (bw < rs->min_bw[j])
608 rs->min_bw[j] = bw;
609 if (bw > rs->max_bw[j])
610 rs->max_bw[j] = bw;
Jens Axboe3c39a372006-06-06 20:56:12 +0200611
Jens Axboe94370ac2007-03-08 15:28:10 +0100612 rs->io_kb[j] += ts->io_bytes[j] >> 10;
613 }
Jens Axboe3c39a372006-06-06 20:56:12 +0200614 }
615
616 for (i = 0; i < groupid + 1; i++) {
Jens Axboe8879fd12009-04-20 10:06:02 +0200617 unsigned long max_run[2];
618
Jens Axboe3c39a372006-06-06 20:56:12 +0200619 rs = &runstats[i];
Jens Axboe8879fd12009-04-20 10:06:02 +0200620 max_run[0] = rs->max_run[0] * 1024 / 1000;
621 max_run[1] = rs->max_run[1] * 1024 / 1000;
Jens Axboe3c39a372006-06-06 20:56:12 +0200622
623 if (rs->max_run[0])
Jens Axboe8879fd12009-04-20 10:06:02 +0200624 rs->agg[0] = (rs->io_kb[0]*1024) / max_run[0];
Jens Axboe3c39a372006-06-06 20:56:12 +0200625 if (rs->max_run[1])
Jens Axboe8879fd12009-04-20 10:06:02 +0200626 rs->agg[1] = (rs->io_kb[1]*1024) / max_run[1];
Jens Axboe3c39a372006-06-06 20:56:12 +0200627 }
628
629 /*
630 * don't overwrite last signal output
631 */
Jens Axboec6ae0a52006-06-12 11:04:44 +0200632 if (!terse_output)
633 printf("\n");
Jens Axboe3c39a372006-06-06 20:56:12 +0200634
Jens Axboe756867b2007-03-06 15:19:24 +0100635 for (i = 0; i < nr_ts; i++) {
636 ts = &threadstats[i];
637 rs = &runstats[ts->groupid];
Jens Axboe3c39a372006-06-06 20:56:12 +0200638
Jens Axboec6ae0a52006-06-12 11:04:44 +0200639 if (terse_output)
Jens Axboe756867b2007-03-06 15:19:24 +0100640 show_thread_status_terse(ts, rs);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200641 else
Jens Axboe756867b2007-03-06 15:19:24 +0100642 show_thread_status(ts, rs);
Jens Axboe3c39a372006-06-06 20:56:12 +0200643 }
644
Jens Axboec6ae0a52006-06-12 11:04:44 +0200645 if (!terse_output) {
646 for (i = 0; i < groupid + 1; i++)
647 show_group_stats(&runstats[i], i);
Jens Axboe3c39a372006-06-06 20:56:12 +0200648
Jens Axboec6ae0a52006-06-12 11:04:44 +0200649 show_disk_util();
650 }
Jens Axboeeecf2722006-10-20 14:00:36 +0200651
652 free(runstats);
Jens Axboe756867b2007-03-06 15:19:24 +0100653 free(threadstats);
Jens Axboe3c39a372006-06-06 20:56:12 +0200654}
655
Jens Axboe68704082007-01-10 19:56:37 +0100656static inline void add_stat_sample(struct io_stat *is, unsigned long data)
Jens Axboe3c39a372006-06-06 20:56:12 +0200657{
Jens Axboe68704082007-01-10 19:56:37 +0100658 double val = data;
Jens Axboe6660cc62007-03-06 15:48:38 +0100659 double delta;
Jens Axboe3c39a372006-06-06 20:56:12 +0200660
Jens Axboe68704082007-01-10 19:56:37 +0100661 if (data > is->max_val)
662 is->max_val = data;
663 if (data < is->min_val)
664 is->min_val = data;
665
666 delta = val - is->mean;
Jens Axboeef11d732007-03-29 15:36:29 +0200667 if (delta) {
668 is->mean += delta / (is->samples + 1.0);
669 is->S += delta * (val - is->mean);
670 }
Jens Axboe68704082007-01-10 19:56:37 +0100671
Jens Axboe3c39a372006-06-06 20:56:12 +0200672 is->samples++;
673}
674
Jens Axboebb3884d2007-01-17 17:23:11 +1100675static void __add_log_sample(struct io_log *iolog, unsigned long val,
Jens Axboe306ddc92009-05-18 13:08:12 +0200676 enum fio_ddir ddir, unsigned int bs,
677 unsigned long time)
Jens Axboe3c39a372006-06-06 20:56:12 +0200678{
Jens Axboe306ddc92009-05-18 13:08:12 +0200679 const int nr_samples = iolog->nr_samples;
680
Jens Axboe3c39a372006-06-06 20:56:12 +0200681 if (iolog->nr_samples == iolog->max_samples) {
682 int new_size = sizeof(struct io_sample) * iolog->max_samples*2;
683
684 iolog->log = realloc(iolog->log, new_size);
685 iolog->max_samples <<= 1;
686 }
687
Jens Axboe306ddc92009-05-18 13:08:12 +0200688 iolog->log[nr_samples].val = val;
689 iolog->log[nr_samples].time = time;
690 iolog->log[nr_samples].ddir = ddir;
691 iolog->log[nr_samples].bs = bs;
Jens Axboe3c39a372006-06-06 20:56:12 +0200692 iolog->nr_samples++;
693}
694
Jens Axboebb3884d2007-01-17 17:23:11 +1100695static void add_log_sample(struct thread_data *td, struct io_log *iolog,
Jens Axboe306ddc92009-05-18 13:08:12 +0200696 unsigned long val, enum fio_ddir ddir,
697 unsigned int bs)
Jens Axboebb3884d2007-01-17 17:23:11 +1100698{
Jens Axboe306ddc92009-05-18 13:08:12 +0200699 __add_log_sample(iolog, val, ddir, bs, mtime_since_now(&td->epoch));
Jens Axboebb3884d2007-01-17 17:23:11 +1100700}
701
Jens Axboe306ddc92009-05-18 13:08:12 +0200702void add_agg_sample(unsigned long val, enum fio_ddir ddir, unsigned int bs)
Jens Axboebb3884d2007-01-17 17:23:11 +1100703{
704 struct io_log *iolog = agg_io_log[ddir];
705
Jens Axboe306ddc92009-05-18 13:08:12 +0200706 __add_log_sample(iolog, val, ddir, bs, mtime_since_genesis());
Jens Axboebb3884d2007-01-17 17:23:11 +1100707}
708
Jens Axboe1e97cce2006-12-05 11:44:16 +0100709void add_clat_sample(struct thread_data *td, enum fio_ddir ddir,
Jens Axboe306ddc92009-05-18 13:08:12 +0200710 unsigned long usec, unsigned int bs)
Jens Axboe3c39a372006-06-06 20:56:12 +0200711{
Jens Axboe756867b2007-03-06 15:19:24 +0100712 struct thread_stat *ts = &td->ts;
Jens Axboe3c39a372006-06-06 20:56:12 +0200713
Jens Axboed85f5112007-06-18 09:41:23 +0200714 add_stat_sample(&ts->clat_stat[ddir], usec);
Jens Axboe079ad092007-02-20 13:58:20 +0100715
716 if (ts->clat_log)
Jens Axboe306ddc92009-05-18 13:08:12 +0200717 add_log_sample(td, ts->clat_log, usec, ddir, bs);
Jens Axboe3c39a372006-06-06 20:56:12 +0200718}
719
Jens Axboe1e97cce2006-12-05 11:44:16 +0100720void add_slat_sample(struct thread_data *td, enum fio_ddir ddir,
Jens Axboe306ddc92009-05-18 13:08:12 +0200721 unsigned long usec, unsigned int bs)
Jens Axboe3c39a372006-06-06 20:56:12 +0200722{
Jens Axboe756867b2007-03-06 15:19:24 +0100723 struct thread_stat *ts = &td->ts;
Jens Axboe3c39a372006-06-06 20:56:12 +0200724
Jens Axboed85f5112007-06-18 09:41:23 +0200725 add_stat_sample(&ts->slat_stat[ddir], usec);
Jens Axboe079ad092007-02-20 13:58:20 +0100726
727 if (ts->slat_log)
Jens Axboe306ddc92009-05-18 13:08:12 +0200728 add_log_sample(td, ts->slat_log, usec, ddir, bs);
Jens Axboe3c39a372006-06-06 20:56:12 +0200729}
730
Jens Axboe306ddc92009-05-18 13:08:12 +0200731void add_bw_sample(struct thread_data *td, enum fio_ddir ddir, unsigned int bs,
Jens Axboe1e97cce2006-12-05 11:44:16 +0100732 struct timeval *t)
Jens Axboe3c39a372006-06-06 20:56:12 +0200733{
Jens Axboe756867b2007-03-06 15:19:24 +0100734 struct thread_stat *ts = &td->ts;
Jens Axboe079ad092007-02-20 13:58:20 +0100735 unsigned long spent = mtime_since(&ts->stat_sample_time[ddir], t);
Jens Axboe3c39a372006-06-06 20:56:12 +0200736 unsigned long rate;
737
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100738 if (spent < td->o.bw_avg_time)
Jens Axboe3c39a372006-06-06 20:56:12 +0200739 return;
740
Jens Axboe8879fd12009-04-20 10:06:02 +0200741 rate = (td->this_io_bytes[ddir] - ts->stat_io_bytes[ddir]) * 1000 / spent / 1024;
Jens Axboe079ad092007-02-20 13:58:20 +0100742 add_stat_sample(&ts->bw_stat[ddir], rate);
Jens Axboe3c39a372006-06-06 20:56:12 +0200743
Jens Axboe079ad092007-02-20 13:58:20 +0100744 if (ts->bw_log)
Jens Axboe306ddc92009-05-18 13:08:12 +0200745 add_log_sample(td, ts->bw_log, rate, ddir, bs);
Jens Axboe3c39a372006-06-06 20:56:12 +0200746
Jens Axboe079ad092007-02-20 13:58:20 +0100747 fio_gettime(&ts->stat_sample_time[ddir], NULL);
748 ts->stat_io_bytes[ddir] = td->this_io_bytes[ddir];
Jens Axboe3c39a372006-06-06 20:56:12 +0200749}