blob: 34c8fceefc2982199ada1a613e535f4cae54343f [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 Axboe3c39a372006-06-06 20:56:12 +020011
Jens Axboedbe11252007-02-11 00:19:51 +010012/*
Jens Axboe34403fb2007-03-02 21:43:25 +010013 * Cheesy number->string conversion, complete with carry rounding error.
Jens Axboedbe11252007-02-11 00:19:51 +010014 */
Jens Axboeb3605062007-03-12 14:19:47 +010015static char *num2str(unsigned long num, int maxlen, int base, int pow2)
Jens Axboedbe11252007-02-11 00:19:51 +010016{
Jens Axboeb3605062007-03-12 14:19:47 +010017 char postfix[] = { ' ', 'K', 'M', 'G', 'P', 'E' };
18 unsigned int thousand;
Jens Axboedbe11252007-02-11 00:19:51 +010019 char *buf;
20 int i;
21
Jens Axboeb3605062007-03-12 14:19:47 +010022 if (pow2)
23 thousand = 1024;
24 else
25 thousand = 1000;
26
Jens Axboedbe11252007-02-11 00:19:51 +010027 buf = malloc(128);
28
29 for (i = 0; base > 1; i++)
30 base /= thousand;
31
32 do {
33 int len, carry = 0;
34
35 len = sprintf(buf, "%'lu", num);
36 if (len <= maxlen) {
Jens Axboeb3605062007-03-12 14:19:47 +010037 if (i >= 1) {
38 buf[len] = postfix[i];
39 buf[len + 1] = '\0';
40 }
Jens Axboedbe11252007-02-11 00:19:51 +010041 return buf;
42 }
43
44 if ((num % thousand) >= (thousand / 2))
45 carry = 1;
46
47 num /= thousand;
48 num += carry;
49 i++;
Jens Axboef3502ba2007-02-14 01:27:09 +010050 } while (i <= 5);
Jens Axboedbe11252007-02-11 00:19:51 +010051
52 return buf;
53}
54
Jens Axboe3c39a372006-06-06 20:56:12 +020055void update_rusage_stat(struct thread_data *td)
56{
Jens Axboe756867b2007-03-06 15:19:24 +010057 struct thread_stat *ts = &td->ts;
Jens Axboe3c39a372006-06-06 20:56:12 +020058
Jens Axboe079ad092007-02-20 13:58:20 +010059 getrusage(RUSAGE_SELF, &ts->ru_end);
60
61 ts->usr_time += mtime_since(&ts->ru_start.ru_utime, &ts->ru_end.ru_utime);
62 ts->sys_time += mtime_since(&ts->ru_start.ru_stime, &ts->ru_end.ru_stime);
63 ts->ctx += ts->ru_end.ru_nvcsw + ts->ru_end.ru_nivcsw - (ts->ru_start.ru_nvcsw + ts->ru_start.ru_nivcsw);
Jens Axboe3c39a372006-06-06 20:56:12 +020064
Jens Axboe079ad092007-02-20 13:58:20 +010065 memcpy(&ts->ru_start, &ts->ru_end, sizeof(ts->ru_end));
Jens Axboe3c39a372006-06-06 20:56:12 +020066}
67
68static int calc_lat(struct io_stat *is, unsigned long *min, unsigned long *max,
69 double *mean, double *dev)
70{
Jens Axboe68704082007-01-10 19:56:37 +010071 double n = is->samples;
Jens Axboe3c39a372006-06-06 20:56:12 +020072
73 if (is->samples == 0)
74 return 0;
75
76 *min = is->min_val;
77 *max = is->max_val;
78
79 n = (double) is->samples;
Jens Axboe68704082007-01-10 19:56:37 +010080 *mean = is->mean;
Jens Axboe3c39a372006-06-06 20:56:12 +020081
Jens Axboe68704082007-01-10 19:56:37 +010082 if (n > 1.0)
83 *dev = sqrt(is->S / (n - 1.0));
Jens Axboeef9c5c42007-01-03 14:21:13 +010084 else
Jens Axboe68704082007-01-10 19:56:37 +010085 *dev = -1.0;
Jens Axboeef9c5c42007-01-03 14:21:13 +010086
Jens Axboe3c39a372006-06-06 20:56:12 +020087 return 1;
88}
89
90static void show_group_stats(struct group_run_stats *rs, int id)
91{
Jens Axboedbe11252007-02-11 00:19:51 +010092 char *p1, *p2, *p3, *p4;
93 const char *ddir_str[] = { " READ", " WRITE" };
94 int i;
95
Jens Axboe6d861442007-03-15 09:22:23 +010096 log_info("\nRun status group %d (all jobs):\n", id);
Jens Axboe3c39a372006-06-06 20:56:12 +020097
Jens Axboedbe11252007-02-11 00:19:51 +010098 for (i = 0; i <= DDIR_WRITE; i++) {
99 if (!rs->max_run[i])
100 continue;
101
Jens Axboeb3605062007-03-12 14:19:47 +0100102 p1 = num2str(rs->io_kb[i], 6, 1000, 1);
103 p2 = num2str(rs->agg[i], 6, 1000, 1);
104 p3 = num2str(rs->min_bw[i], 6, 1000, 1);
105 p4 = num2str(rs->max_bw[i], 6, 1000, 1);
Jens Axboedbe11252007-02-11 00:19:51 +0100106
Jens Axboe6d861442007-03-15 09:22:23 +0100107 log_info("%s: io=%siB, aggrb=%siB/s, minb=%siB/s, maxb=%siB/s, mint=%llumsec, maxt=%llumsec\n", ddir_str[i], p1, p2, p3, p4, rs->min_run[i], rs->max_run[i]);
Jens Axboedbe11252007-02-11 00:19:51 +0100108
109 free(p1);
110 free(p2);
111 free(p3);
112 free(p4);
113 }
Jens Axboe3c39a372006-06-06 20:56:12 +0200114}
115
Jens Axboeb3605062007-03-12 14:19:47 +0100116#define ts_total_io_u(ts) \
117 ((ts)->total_io_u[0] + (ts)->total_io_u[1])
118
Jens Axboe22708902007-03-06 17:05:32 +0100119static void stat_calc_dist(struct thread_stat *ts, double *io_u_dist)
120{
121 int i;
122
123 /*
124 * Do depth distribution calculations
125 */
126 for (i = 0; i < FIO_IO_U_MAP_NR; i++) {
Jens Axboeb3605062007-03-12 14:19:47 +0100127 io_u_dist[i] = (double) ts->io_u_map[i] / (double) ts_total_io_u(ts);
Jens Axboe22708902007-03-06 17:05:32 +0100128 io_u_dist[i] *= 100.0;
Jens Axboed0f62ba2007-03-29 12:55:58 -0800129 if (io_u_dist[i] < 0.1 && ts->io_u_map[i])
130 io_u_dist[i] = 0.1;
Jens Axboe22708902007-03-06 17:05:32 +0100131 }
132}
133
134static void stat_calc_lat(struct thread_stat *ts, double *io_u_lat)
135{
136 int i;
137
138 /*
139 * Do latency distribution calculations
140 */
141 for (i = 0; i < FIO_IO_U_LAT_NR; i++) {
Jens Axboeb3605062007-03-12 14:19:47 +0100142 io_u_lat[i] = (double) ts->io_u_lat[i] / (double) ts_total_io_u(ts);
Jens Axboe22708902007-03-06 17:05:32 +0100143 io_u_lat[i] *= 100.0;
Jens Axboed0f62ba2007-03-29 12:55:58 -0800144 if (io_u_lat[i] < 0.01 && ts->io_u_lat[i])
145 io_u_lat[i] = 0.01;
Jens Axboe22708902007-03-06 17:05:32 +0100146 }
147}
148
Jens Axboeea2accc2007-06-19 09:48:44 +0200149static int usec_to_msec(unsigned long *min, unsigned long *max, double *mean,
150 double *dev)
151{
152 if (*min > 1000 && *max > 1000 && *mean > 1000.0 && *dev > 1000.0) {
153 *min /= 1000;
154 *max /= 1000;
155 *mean /= 1000.0;
156 *dev /= 1000.0;
157 return 0;
158 }
159
160 return 1;
161}
162
Jens Axboe756867b2007-03-06 15:19:24 +0100163static void show_ddir_status(struct group_run_stats *rs, struct thread_stat *ts,
Jens Axboe3c39a372006-06-06 20:56:12 +0200164 int ddir)
165{
Jens Axboe3c9b60c2006-11-07 08:36:14 +0100166 const char *ddir_str[] = { "read ", "write" };
Jens Axboe3c39a372006-06-06 20:56:12 +0200167 unsigned long min, max;
Jens Axboeb3605062007-03-12 14:19:47 +0100168 unsigned long long bw, iops;
Jens Axboe3c39a372006-06-06 20:56:12 +0200169 double mean, dev;
Jens Axboeb3605062007-03-12 14:19:47 +0100170 char *io_p, *bw_p, *iops_p;
Jens Axboe3c39a372006-06-06 20:56:12 +0200171
Jens Axboe756867b2007-03-06 15:19:24 +0100172 if (!ts->runtime[ddir])
Jens Axboe3c39a372006-06-06 20:56:12 +0200173 return;
174
Jens Axboe756867b2007-03-06 15:19:24 +0100175 bw = ts->io_bytes[ddir] / ts->runtime[ddir];
Jens Axboeb3605062007-03-12 14:19:47 +0100176 iops = (1000 * ts->total_io_u[ddir]) / ts->runtime[ddir];
177 io_p = num2str(ts->io_bytes[ddir] >> 10, 6, 1000, 1);
178 bw_p = num2str(bw, 6, 1000, 1);
179 iops_p = num2str(iops, 6, 1, 0);
Jens Axboedbe11252007-02-11 00:19:51 +0100180
Jens Axboe6d861442007-03-15 09:22:23 +0100181 log_info(" %s: io=%siB, bw=%siB/s, iops=%s, runt=%6lumsec\n", ddir_str[ddir], io_p, bw_p, iops_p, ts->runtime[ddir]);
Jens Axboedbe11252007-02-11 00:19:51 +0100182
183 free(io_p);
184 free(bw_p);
Jens Axboeb3605062007-03-12 14:19:47 +0100185 free(iops_p);
Jens Axboe3c39a372006-06-06 20:56:12 +0200186
Jens Axboed85f5112007-06-18 09:41:23 +0200187 if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) {
188 const char *base = "(usec)";
Jens Axboe3c39a372006-06-06 20:56:12 +0200189
Jens Axboeea2accc2007-06-19 09:48:44 +0200190 if (!usec_to_msec(&min, &max, &mean, &dev))
Jens Axboed85f5112007-06-18 09:41:23 +0200191 base = "(msec)";
Jens Axboeea2accc2007-06-19 09:48:44 +0200192
Jens Axboed85f5112007-06-18 09:41:23 +0200193 log_info(" slat %s: min=%5lu, max=%5lu, avg=%5.02f, stdev=%5.02f\n", base, min, max, mean, dev);
194 }
195 if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) {
196 const char *base = "(usec)";
Jens Axboe3c39a372006-06-06 20:56:12 +0200197
Jens Axboeea2accc2007-06-19 09:48:44 +0200198 if (!usec_to_msec(&min, &max, &mean, &dev))
199 base = "(msec)";
200
Jens Axboed85f5112007-06-18 09:41:23 +0200201 log_info(" clat %s: min=%5lu, max=%5lu, avg=%5.02f, stdev=%5.02f\n", base, min, max, mean, dev);
202 }
Jens Axboe079ad092007-02-20 13:58:20 +0100203 if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
Jens Axboe3c39a372006-06-06 20:56:12 +0200204 double p_of_agg;
205
206 p_of_agg = mean * 100 / (double) rs->agg[ddir];
Jens Axboe6d861442007-03-15 09:22:23 +0100207 log_info(" bw (KiB/s) : min=%5lu, max=%5lu, per=%3.2f%%, avg=%5.02f, stdev=%5.02f\n", min, max, p_of_agg, mean, dev);
Jens Axboe3c39a372006-06-06 20:56:12 +0200208 }
209}
210
Jens Axboe756867b2007-03-06 15:19:24 +0100211static void show_thread_status(struct thread_stat *ts,
Jens Axboe3c39a372006-06-06 20:56:12 +0200212 struct group_run_stats *rs)
213{
214 double usr_cpu, sys_cpu;
Jens Axboe69008992006-11-24 13:12:56 +0100215 unsigned long runtime;
Jens Axboe71619dc2007-01-13 23:56:33 +0100216 double io_u_dist[FIO_IO_U_MAP_NR];
Jens Axboeec118302007-02-17 04:38:20 +0100217 double io_u_lat[FIO_IO_U_LAT_NR];
Jens Axboe3c39a372006-06-06 20:56:12 +0200218
Jens Axboe756867b2007-03-06 15:19:24 +0100219 if (!(ts->io_bytes[0] + ts->io_bytes[1]))
Jens Axboe3c39a372006-06-06 20:56:12 +0200220 return;
221
Jens Axboe756867b2007-03-06 15:19:24 +0100222 if (!ts->error)
Jens Axboe6d861442007-03-15 09:22:23 +0100223 log_info("%s: (groupid=%d, jobs=%d): err=%2d: pid=%d\n", ts->name, ts->groupid, ts->members, ts->error, ts->pid);
Jens Axboe6d663072007-02-11 00:57:13 +0100224 else
Jens Axboe6d861442007-03-15 09:22:23 +0100225 log_info("%s: (groupid=%d, jobs=%d): err=%2d (%s): pid=%d\n", ts->name, ts->groupid, ts->members, ts->error, ts->verror, ts->pid);
Jens Axboe3c39a372006-06-06 20:56:12 +0200226
Jens Axboe7bdce1b2007-03-06 20:01:13 +0100227 if (ts->description)
Jens Axboe6d861442007-03-15 09:22:23 +0100228 log_info(" Description : [%s]\n", ts->description);
Jens Axboe7bdce1b2007-03-06 20:01:13 +0100229
Jens Axboe756867b2007-03-06 15:19:24 +0100230 if (ts->io_bytes[DDIR_READ])
231 show_ddir_status(rs, ts, DDIR_READ);
232 if (ts->io_bytes[DDIR_WRITE])
233 show_ddir_status(rs, ts, DDIR_WRITE);
Jens Axboe3c39a372006-06-06 20:56:12 +0200234
Jens Axboe756867b2007-03-06 15:19:24 +0100235 runtime = ts->total_run_time;
Jens Axboe69008992006-11-24 13:12:56 +0100236 if (runtime) {
Jens Axboe1e97cce2006-12-05 11:44:16 +0100237 double runt = (double) runtime;
Jens Axboe3c39a372006-06-06 20:56:12 +0200238
Jens Axboe756867b2007-03-06 15:19:24 +0100239 usr_cpu = (double) ts->usr_time * 100 / runt;
240 sys_cpu = (double) ts->sys_time * 100 / runt;
Jens Axboe3c39a372006-06-06 20:56:12 +0200241 } else {
242 usr_cpu = 0;
243 sys_cpu = 0;
244 }
245
Jens Axboe6d861442007-03-15 09:22:23 +0100246 log_info(" cpu : usr=%3.2f%%, sys=%3.2f%%, ctx=%lu\n", usr_cpu, sys_cpu, ts->ctx);
Jens Axboe71619dc2007-01-13 23:56:33 +0100247
Jens Axboe22708902007-03-06 17:05:32 +0100248 stat_calc_dist(ts, io_u_dist);
249 stat_calc_lat(ts, io_u_lat);
Jens Axboe71619dc2007-01-13 23:56:33 +0100250
Jens Axboe6d861442007-03-15 09:22:23 +0100251 log_info(" IO depths : 1=%3.1f%%, 2=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%, 32=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3], io_u_dist[4], io_u_dist[5], io_u_dist[6]);
Jens Axboe30061b92007-04-17 13:31:34 +0200252 log_info(" issued r/w: total=%lu/%lu, short=%lu/%lu\n", ts->total_io_u[0], ts->total_io_u[1], ts->short_io_u[0], ts->short_io_u[1]);
Jens Axboe61697c32007-02-05 15:04:46 +0100253
Jens Axboed85f5112007-06-18 09:41:23 +0200254 log_info(" lat (msec): 2=%3.2f%%, 4=%3.2f%%, 10=%3.2f%%, 20=%3.2f%%, 50=%3.2f%%\n", io_u_lat[0], io_u_lat[1], io_u_lat[2], io_u_lat[3], io_u_lat[4]);
255 log_info(" lat (msec): 100=%3.2f%%, 250=%3.2f%%, 500=%3.2f%%, 750=%3.2f%%\n", io_u_lat[5], io_u_lat[6], io_u_lat[7], io_u_lat[8]);
256 log_info(" lat (msec): 1000=%3.2f%%, 2000=%3.2f%%, >=2000=%3.2f%%\n", io_u_lat[9], io_u_lat[10], io_u_lat[11]);
Jens Axboe3c39a372006-06-06 20:56:12 +0200257}
258
Jens Axboe756867b2007-03-06 15:19:24 +0100259static void show_ddir_status_terse(struct thread_stat *ts,
Jens Axboec6ae0a52006-06-12 11:04:44 +0200260 struct group_run_stats *rs, int ddir)
261{
262 unsigned long min, max;
263 unsigned long long bw;
264 double mean, dev;
265
266 bw = 0;
Jens Axboe756867b2007-03-06 15:19:24 +0100267 if (ts->runtime[ddir])
268 bw = ts->io_bytes[ddir] / ts->runtime[ddir];
Jens Axboec6ae0a52006-06-12 11:04:44 +0200269
Jens Axboe6d861442007-03-15 09:22:23 +0100270 log_info(";%llu;%llu;%lu", ts->io_bytes[ddir] >> 10, bw, ts->runtime[ddir]);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200271
Jens Axboe079ad092007-02-20 13:58:20 +0100272 if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev))
Jens Axboe6d861442007-03-15 09:22:23 +0100273 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200274 else
Jens Axboe6d861442007-03-15 09:22:23 +0100275 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200276
Jens Axboe079ad092007-02-20 13:58:20 +0100277 if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev))
Jens Axboe6d861442007-03-15 09:22:23 +0100278 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200279 else
Jens Axboe6d861442007-03-15 09:22:23 +0100280 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200281
Jens Axboe079ad092007-02-20 13:58:20 +0100282 if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
Jens Axboec6ae0a52006-06-12 11:04:44 +0200283 double p_of_agg;
284
285 p_of_agg = mean * 100 / (double) rs->agg[ddir];
Jens Axboe6d861442007-03-15 09:22:23 +0100286 log_info(";%lu;%lu;%f%%;%f;%f", min, max, p_of_agg, mean, dev);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200287 } else
Jens Axboe6d861442007-03-15 09:22:23 +0100288 log_info(";%lu;%lu;%f%%;%f;%f", 0UL, 0UL, 0.0, 0.0, 0.0);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200289}
290
291
Jens Axboe756867b2007-03-06 15:19:24 +0100292static void show_thread_status_terse(struct thread_stat *ts,
Jens Axboec6ae0a52006-06-12 11:04:44 +0200293 struct group_run_stats *rs)
294{
Jens Axboe22708902007-03-06 17:05:32 +0100295 double io_u_dist[FIO_IO_U_MAP_NR];
296 double io_u_lat[FIO_IO_U_LAT_NR];
Jens Axboec6ae0a52006-06-12 11:04:44 +0200297 double usr_cpu, sys_cpu;
298
Jens Axboe6d861442007-03-15 09:22:23 +0100299 log_info("%s;%d;%d", ts->name, ts->groupid, ts->error);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200300
Jens Axboe756867b2007-03-06 15:19:24 +0100301 show_ddir_status_terse(ts, rs, 0);
302 show_ddir_status_terse(ts, rs, 1);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200303
Jens Axboe756867b2007-03-06 15:19:24 +0100304 if (ts->total_run_time) {
305 double runt = (double) ts->total_run_time;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200306
Jens Axboe756867b2007-03-06 15:19:24 +0100307 usr_cpu = (double) ts->usr_time * 100 / runt;
308 sys_cpu = (double) ts->sys_time * 100 / runt;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200309 } else {
310 usr_cpu = 0;
311 sys_cpu = 0;
312 }
313
Jens Axboe6d861442007-03-15 09:22:23 +0100314 log_info(";%f%%;%f%%;%lu", usr_cpu, sys_cpu, ts->ctx);
Jens Axboe22708902007-03-06 17:05:32 +0100315
316 stat_calc_dist(ts, io_u_dist);
317 stat_calc_lat(ts, io_u_lat);
318
Jens Axboe6d861442007-03-15 09:22:23 +0100319 log_info(";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%", io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3], io_u_dist[4], io_u_dist[5], io_u_dist[6]);
Jens Axboe22708902007-03-06 17:05:32 +0100320
Jens Axboed0f62ba2007-03-29 12:55:58 -0800321 log_info(";%3.2f%%;%3.2f%%;%3.2f%%;%3.2f%%;%3.2f%%;%3.2f%%\n", io_u_lat[0], io_u_lat[1], io_u_lat[2], io_u_lat[3], io_u_lat[4], io_u_lat[5]);
322 log_info(";%3.2f%%;%3.2f%%;%3.2f%%;%3.2f%%;%3.2f%%", io_u_lat[6], io_u_lat[7], io_u_lat[8], io_u_lat[9], io_u_lat[10]);
Jens Axboe22708902007-03-06 17:05:32 +0100323
324 if (ts->description)
Jens Axboe6d861442007-03-15 09:22:23 +0100325 log_info(";%s", ts->description);
Jens Axboe22708902007-03-06 17:05:32 +0100326
Jens Axboe6d861442007-03-15 09:22:23 +0100327 log_info("\n");
Jens Axboe756867b2007-03-06 15:19:24 +0100328}
329
Jens Axboe197574e2007-03-08 15:35:11 +0100330static void sum_stat(struct io_stat *dst, struct io_stat *src, int nr)
Jens Axboe756867b2007-03-06 15:19:24 +0100331{
332 double mean, S;
333
334 dst->min_val = min(dst->min_val, src->min_val);
335 dst->max_val = max(dst->max_val, src->max_val);
336 dst->samples += src->samples;
337
338 /*
339 * Needs a new method for calculating stddev, we cannot just
340 * average them we do below for nr > 1
341 */
342 if (nr == 1) {
343 mean = src->mean;
344 S = src->S;
345 } else {
Jens Axboec39cced2007-03-06 15:37:00 +0100346 mean = ((src->mean * (double) (nr - 1)) + dst->mean) / ((double) nr);
347 S = ((src->S * (double) (nr - 1)) + dst->S) / ((double) nr);
Jens Axboe756867b2007-03-06 15:19:24 +0100348 }
349
350 dst->mean = mean;
351 dst->S = S;
352}
353
Jens Axboe3c39a372006-06-06 20:56:12 +0200354void show_run_stats(void)
355{
356 struct group_run_stats *runstats, *rs;
357 struct thread_data *td;
Jens Axboe756867b2007-03-06 15:19:24 +0100358 struct thread_stat *threadstats, *ts;
Jens Axboe197574e2007-03-08 15:35:11 +0100359 int i, j, k, l, nr_ts, last_ts, idx;
Jens Axboe3c39a372006-06-06 20:56:12 +0200360
361 runstats = malloc(sizeof(struct group_run_stats) * (groupid + 1));
362
363 for (i = 0; i < groupid + 1; i++) {
364 rs = &runstats[i];
365
366 memset(rs, 0, sizeof(*rs));
367 rs->min_bw[0] = rs->min_run[0] = ~0UL;
368 rs->min_bw[1] = rs->min_run[1] = ~0UL;
369 }
370
Jens Axboe756867b2007-03-06 15:19:24 +0100371 /*
372 * find out how many threads stats we need. if group reporting isn't
373 * enabled, it's one-per-td.
374 */
375 nr_ts = 0;
376 last_ts = -1;
Jens Axboe34572e22006-10-20 09:33:18 +0200377 for_each_td(td, i) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100378 if (!td->o.group_reporting) {
Jens Axboe756867b2007-03-06 15:19:24 +0100379 nr_ts++;
380 continue;
381 }
382 if (last_ts == td->groupid)
383 continue;
384
385 last_ts = td->groupid;
386 nr_ts++;
387 }
388
389 threadstats = malloc(nr_ts * sizeof(struct thread_stat));
390
391 for (i = 0; i < nr_ts; i++) {
392 ts = &threadstats[i];
393
394 memset(ts, 0, sizeof(*ts));
Jens Axboede64df02007-03-08 19:09:49 +0100395 for (j = 0; j <= DDIR_WRITE; j++) {
Jens Axboe197574e2007-03-08 15:35:11 +0100396 ts->clat_stat[j].min_val = -1UL;
397 ts->slat_stat[j].min_val = -1UL;
398 ts->bw_stat[j].min_val = -1UL;
399 }
Jens Axboe7abd0e32007-03-12 15:24:43 +0100400 ts->groupid = -1;
Jens Axboe756867b2007-03-06 15:19:24 +0100401 }
402
403 j = 0;
404 last_ts = -1;
Jens Axboe197574e2007-03-08 15:35:11 +0100405 idx = 0;
Jens Axboe756867b2007-03-06 15:19:24 +0100406 for_each_td(td, i) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100407 if (idx && (!td->o.group_reporting ||
408 (td->o.group_reporting && last_ts != td->groupid))) {
Jens Axboe7abd0e32007-03-12 15:24:43 +0100409 idx = 0;
410 j++;
411 }
412
413 last_ts = td->groupid;
414
Jens Axboe756867b2007-03-06 15:19:24 +0100415 ts = &threadstats[j];
416
Jens Axboe197574e2007-03-08 15:35:11 +0100417 idx++;
Jens Axboe6586ee82007-03-06 19:46:09 +0100418 ts->members++;
Jens Axboe756867b2007-03-06 15:19:24 +0100419
Jens Axboe7abd0e32007-03-12 15:24:43 +0100420 if (ts->groupid == -1) {
Jens Axboe2dc84ba2007-03-06 15:46:33 +0100421 /*
422 * These are per-group shared already
423 */
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100424 ts->name = td->o.name;
425 ts->description = td->o.description;
Jens Axboe756867b2007-03-06 15:19:24 +0100426 ts->groupid = td->groupid;
Jens Axboe2dc84ba2007-03-06 15:46:33 +0100427
428 /*
429 * first pid in group, not very useful...
430 */
Jens Axboe756867b2007-03-06 15:19:24 +0100431 ts->pid = td->pid;
Jens Axboe2dc84ba2007-03-06 15:46:33 +0100432 }
433
434 if (td->error && !ts->error) {
435 ts->error = td->error;
Jens Axboe756867b2007-03-06 15:19:24 +0100436 ts->verror = td->verror;
437 }
438
Jens Axboede64df02007-03-08 19:09:49 +0100439 for (l = 0; l <= DDIR_WRITE; l++) {
Jens Axboe197574e2007-03-08 15:35:11 +0100440 sum_stat(&ts->clat_stat[l], &td->ts.clat_stat[l], idx);
441 sum_stat(&ts->slat_stat[l], &td->ts.slat_stat[l], idx);
442 sum_stat(&ts->bw_stat[l], &td->ts.bw_stat[l], idx);
Jens Axboe756867b2007-03-06 15:19:24 +0100443
Jens Axboe197574e2007-03-08 15:35:11 +0100444 ts->stat_io_bytes[l] += td->ts.stat_io_bytes[l];
445 ts->io_bytes[l] += td->ts.io_bytes[l];
446
447 if (ts->runtime[l] < td->ts.runtime[l])
448 ts->runtime[l] = td->ts.runtime[l];
449 }
Jens Axboe756867b2007-03-06 15:19:24 +0100450
451 ts->usr_time += td->ts.usr_time;
452 ts->sys_time += td->ts.sys_time;
453 ts->ctx += td->ts.ctx;
454
455 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
456 ts->io_u_map[k] += td->ts.io_u_map[k];
457 for (k = 0; k < FIO_IO_U_LAT_NR; k++)
458 ts->io_u_lat[k] += td->ts.io_u_lat[k];
459
Jens Axboe30061b92007-04-17 13:31:34 +0200460 for (k = 0; k <= DDIR_WRITE; k++) {
Jens Axboeb3605062007-03-12 14:19:47 +0100461 ts->total_io_u[k] += td->ts.total_io_u[k];
Jens Axboe30061b92007-04-17 13:31:34 +0200462 ts->short_io_u[k] += td->ts.short_io_u[k];
463 }
Jens Axboe756867b2007-03-06 15:19:24 +0100464
465 ts->total_run_time += td->ts.total_run_time;
Jens Axboe756867b2007-03-06 15:19:24 +0100466 }
467
468 for (i = 0; i < nr_ts; i++) {
Jens Axboe94370ac2007-03-08 15:28:10 +0100469 unsigned long long bw;
Jens Axboe3c39a372006-06-06 20:56:12 +0200470
Jens Axboe756867b2007-03-06 15:19:24 +0100471 ts = &threadstats[i];
472 rs = &runstats[ts->groupid];
Jens Axboe3c39a372006-06-06 20:56:12 +0200473
Jens Axboede64df02007-03-08 19:09:49 +0100474 for (j = 0; j <= DDIR_WRITE; j++) {
Jens Axboe94370ac2007-03-08 15:28:10 +0100475 if (!ts->runtime[j])
476 continue;
477 if (ts->runtime[j] < rs->min_run[j] || !rs->min_run[j])
478 rs->min_run[j] = ts->runtime[j];
479 if (ts->runtime[j] > rs->max_run[j])
480 rs->max_run[j] = ts->runtime[j];
Jens Axboe3c39a372006-06-06 20:56:12 +0200481
Jens Axboe94370ac2007-03-08 15:28:10 +0100482 bw = 0;
483 if (ts->runtime[j])
484 bw = ts->io_bytes[j] / (unsigned long long) ts->runtime[j];
485 if (bw < rs->min_bw[j])
486 rs->min_bw[j] = bw;
487 if (bw > rs->max_bw[j])
488 rs->max_bw[j] = bw;
Jens Axboe3c39a372006-06-06 20:56:12 +0200489
Jens Axboe94370ac2007-03-08 15:28:10 +0100490 rs->io_kb[j] += ts->io_bytes[j] >> 10;
491 }
Jens Axboe3c39a372006-06-06 20:56:12 +0200492 }
493
494 for (i = 0; i < groupid + 1; i++) {
495 rs = &runstats[i];
496
497 if (rs->max_run[0])
498 rs->agg[0] = (rs->io_kb[0]*1024) / rs->max_run[0];
499 if (rs->max_run[1])
500 rs->agg[1] = (rs->io_kb[1]*1024) / rs->max_run[1];
501 }
502
503 /*
504 * don't overwrite last signal output
505 */
Jens Axboec6ae0a52006-06-12 11:04:44 +0200506 if (!terse_output)
507 printf("\n");
Jens Axboe3c39a372006-06-06 20:56:12 +0200508
Jens Axboe756867b2007-03-06 15:19:24 +0100509 for (i = 0; i < nr_ts; i++) {
510 ts = &threadstats[i];
511 rs = &runstats[ts->groupid];
Jens Axboe3c39a372006-06-06 20:56:12 +0200512
Jens Axboec6ae0a52006-06-12 11:04:44 +0200513 if (terse_output)
Jens Axboe756867b2007-03-06 15:19:24 +0100514 show_thread_status_terse(ts, rs);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200515 else
Jens Axboe756867b2007-03-06 15:19:24 +0100516 show_thread_status(ts, rs);
Jens Axboe3c39a372006-06-06 20:56:12 +0200517 }
518
Jens Axboec6ae0a52006-06-12 11:04:44 +0200519 if (!terse_output) {
520 for (i = 0; i < groupid + 1; i++)
521 show_group_stats(&runstats[i], i);
Jens Axboe3c39a372006-06-06 20:56:12 +0200522
Jens Axboec6ae0a52006-06-12 11:04:44 +0200523 show_disk_util();
524 }
Jens Axboeeecf2722006-10-20 14:00:36 +0200525
526 free(runstats);
Jens Axboe756867b2007-03-06 15:19:24 +0100527 free(threadstats);
Jens Axboe3c39a372006-06-06 20:56:12 +0200528}
529
Jens Axboe68704082007-01-10 19:56:37 +0100530static inline void add_stat_sample(struct io_stat *is, unsigned long data)
Jens Axboe3c39a372006-06-06 20:56:12 +0200531{
Jens Axboe68704082007-01-10 19:56:37 +0100532 double val = data;
Jens Axboe6660cc62007-03-06 15:48:38 +0100533 double delta;
Jens Axboe3c39a372006-06-06 20:56:12 +0200534
Jens Axboe68704082007-01-10 19:56:37 +0100535 if (data > is->max_val)
536 is->max_val = data;
537 if (data < is->min_val)
538 is->min_val = data;
539
540 delta = val - is->mean;
Jens Axboeef11d732007-03-29 15:36:29 +0200541 if (delta) {
542 is->mean += delta / (is->samples + 1.0);
543 is->S += delta * (val - is->mean);
544 }
Jens Axboe68704082007-01-10 19:56:37 +0100545
Jens Axboe3c39a372006-06-06 20:56:12 +0200546 is->samples++;
547}
548
Jens Axboebb3884d2007-01-17 17:23:11 +1100549static void __add_log_sample(struct io_log *iolog, unsigned long val,
550 enum fio_ddir ddir, unsigned long time)
Jens Axboe3c39a372006-06-06 20:56:12 +0200551{
552 if (iolog->nr_samples == iolog->max_samples) {
553 int new_size = sizeof(struct io_sample) * iolog->max_samples*2;
554
555 iolog->log = realloc(iolog->log, new_size);
556 iolog->max_samples <<= 1;
557 }
558
559 iolog->log[iolog->nr_samples].val = val;
Jens Axboebb3884d2007-01-17 17:23:11 +1100560 iolog->log[iolog->nr_samples].time = time;
Jens Axboe3c39a372006-06-06 20:56:12 +0200561 iolog->log[iolog->nr_samples].ddir = ddir;
562 iolog->nr_samples++;
563}
564
Jens Axboebb3884d2007-01-17 17:23:11 +1100565static void add_log_sample(struct thread_data *td, struct io_log *iolog,
566 unsigned long val, enum fio_ddir ddir)
567{
568 __add_log_sample(iolog, val, ddir, mtime_since_now(&td->epoch));
569}
570
571void add_agg_sample(unsigned long val, enum fio_ddir ddir)
572{
573 struct io_log *iolog = agg_io_log[ddir];
574
575 __add_log_sample(iolog, val, ddir, mtime_since_genesis());
576}
577
Jens Axboe1e97cce2006-12-05 11:44:16 +0100578void add_clat_sample(struct thread_data *td, enum fio_ddir ddir,
Jens Axboed85f5112007-06-18 09:41:23 +0200579 unsigned long usec)
Jens Axboe3c39a372006-06-06 20:56:12 +0200580{
Jens Axboe756867b2007-03-06 15:19:24 +0100581 struct thread_stat *ts = &td->ts;
Jens Axboe3c39a372006-06-06 20:56:12 +0200582
Jens Axboed85f5112007-06-18 09:41:23 +0200583 add_stat_sample(&ts->clat_stat[ddir], usec);
Jens Axboe079ad092007-02-20 13:58:20 +0100584
585 if (ts->clat_log)
Jens Axboed85f5112007-06-18 09:41:23 +0200586 add_log_sample(td, ts->clat_log, usec, ddir);
Jens Axboe3c39a372006-06-06 20:56:12 +0200587}
588
Jens Axboe1e97cce2006-12-05 11:44:16 +0100589void add_slat_sample(struct thread_data *td, enum fio_ddir ddir,
Jens Axboed85f5112007-06-18 09:41:23 +0200590 unsigned long usec)
Jens Axboe3c39a372006-06-06 20:56:12 +0200591{
Jens Axboe756867b2007-03-06 15:19:24 +0100592 struct thread_stat *ts = &td->ts;
Jens Axboe3c39a372006-06-06 20:56:12 +0200593
Jens Axboed85f5112007-06-18 09:41:23 +0200594 add_stat_sample(&ts->slat_stat[ddir], usec);
Jens Axboe079ad092007-02-20 13:58:20 +0100595
596 if (ts->slat_log)
Jens Axboed85f5112007-06-18 09:41:23 +0200597 add_log_sample(td, ts->slat_log, usec, ddir);
Jens Axboe3c39a372006-06-06 20:56:12 +0200598}
599
Jens Axboe1e97cce2006-12-05 11:44:16 +0100600void add_bw_sample(struct thread_data *td, enum fio_ddir ddir,
601 struct timeval *t)
Jens Axboe3c39a372006-06-06 20:56:12 +0200602{
Jens Axboe756867b2007-03-06 15:19:24 +0100603 struct thread_stat *ts = &td->ts;
Jens Axboe079ad092007-02-20 13:58:20 +0100604 unsigned long spent = mtime_since(&ts->stat_sample_time[ddir], t);
Jens Axboe3c39a372006-06-06 20:56:12 +0200605 unsigned long rate;
606
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100607 if (spent < td->o.bw_avg_time)
Jens Axboe3c39a372006-06-06 20:56:12 +0200608 return;
609
Jens Axboe079ad092007-02-20 13:58:20 +0100610 rate = (td->this_io_bytes[ddir] - ts->stat_io_bytes[ddir]) / spent;
611 add_stat_sample(&ts->bw_stat[ddir], rate);
Jens Axboe3c39a372006-06-06 20:56:12 +0200612
Jens Axboe079ad092007-02-20 13:58:20 +0100613 if (ts->bw_log)
614 add_log_sample(td, ts->bw_log, rate, ddir);
Jens Axboe3c39a372006-06-06 20:56:12 +0200615
Jens Axboe079ad092007-02-20 13:58:20 +0100616 fio_gettime(&ts->stat_sample_time[ddir], NULL);
617 ts->stat_io_bytes[ddir] = td->this_io_bytes[ddir];
Jens Axboe3c39a372006-06-06 20:56:12 +0200618}