blob: a84f28a58edf4069091bccf25ffc9801426ce3fb [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
12static struct itimerval itimer;
Jens Axboe5c4e1db2006-06-07 14:17:08 +020013static struct list_head disk_list = LIST_HEAD_INIT(disk_list);
Jens Axboe3c39a372006-06-06 20:56:12 +020014
15static int get_io_ticks(struct disk_util *du, struct disk_util_stat *dus)
16{
17 unsigned in_flight;
18 char line[256];
19 FILE *f;
20 char *p;
21
22 f = fopen(du->path, "r");
23 if (!f)
24 return 1;
25
26 p = fgets(line, sizeof(line), f);
27 if (!p) {
28 fclose(f);
29 return 1;
30 }
31
32 if (sscanf(p, "%u %u %llu %u %u %u %llu %u %u %u %u\n", &dus->ios[0], &dus->merges[0], &dus->sectors[0], &dus->ticks[0], &dus->ios[1], &dus->merges[1], &dus->sectors[1], &dus->ticks[1], &in_flight, &dus->io_ticks, &dus->time_in_queue) != 11) {
33 fclose(f);
34 return 1;
35 }
36
37 fclose(f);
38 return 0;
39}
40
41static void update_io_tick_disk(struct disk_util *du)
42{
43 struct disk_util_stat __dus, *dus, *ldus;
44 struct timeval t;
45
46 if (get_io_ticks(du, &__dus))
47 return;
48
49 dus = &du->dus;
50 ldus = &du->last_dus;
51
52 dus->sectors[0] += (__dus.sectors[0] - ldus->sectors[0]);
53 dus->sectors[1] += (__dus.sectors[1] - ldus->sectors[1]);
54 dus->ios[0] += (__dus.ios[0] - ldus->ios[0]);
55 dus->ios[1] += (__dus.ios[1] - ldus->ios[1]);
56 dus->merges[0] += (__dus.merges[0] - ldus->merges[0]);
57 dus->merges[1] += (__dus.merges[1] - ldus->merges[1]);
58 dus->ticks[0] += (__dus.ticks[0] - ldus->ticks[0]);
59 dus->ticks[1] += (__dus.ticks[1] - ldus->ticks[1]);
60 dus->io_ticks += (__dus.io_ticks - ldus->io_ticks);
61 dus->time_in_queue += (__dus.time_in_queue - ldus->time_in_queue);
62
Jens Axboe02bcaa82006-11-24 10:42:00 +010063 fio_gettime(&t, NULL);
Jens Axboe3c39a372006-06-06 20:56:12 +020064 du->msec += mtime_since(&du->time, &t);
65 memcpy(&du->time, &t, sizeof(t));
66 memcpy(ldus, &__dus, sizeof(__dus));
67}
68
69void update_io_ticks(void)
70{
71 struct list_head *entry;
72 struct disk_util *du;
73
74 list_for_each(entry, &disk_list) {
75 du = list_entry(entry, struct disk_util, list);
76 update_io_tick_disk(du);
77 }
78}
79
80static int disk_util_exists(dev_t dev)
81{
82 struct list_head *entry;
83 struct disk_util *du;
84
85 list_for_each(entry, &disk_list) {
86 du = list_entry(entry, struct disk_util, list);
87
88 if (du->dev == dev)
89 return 1;
90 }
91
92 return 0;
93}
94
95static void disk_util_add(dev_t dev, char *path)
96{
Jens Axboe1188caf2007-01-08 10:57:27 +010097 struct disk_util *du, *__du;
98 struct list_head *entry;
Jens Axboe3c39a372006-06-06 20:56:12 +020099
Jens Axboe1188caf2007-01-08 10:57:27 +0100100 du = malloc(sizeof(*du));
Jens Axboe3c39a372006-06-06 20:56:12 +0200101 memset(du, 0, sizeof(*du));
102 INIT_LIST_HEAD(&du->list);
103 sprintf(du->path, "%s/stat", path);
104 du->name = strdup(basename(path));
105 du->dev = dev;
106
Jens Axboe1188caf2007-01-08 10:57:27 +0100107 list_for_each(entry, &disk_list) {
108 __du = list_entry(entry, struct disk_util, list);
109
110 if (!strcmp(du->name, __du->name)) {
111 free(du->name);
112 free(du);
113 return;
114 }
115 }
116
Jens Axboe02bcaa82006-11-24 10:42:00 +0100117 fio_gettime(&du->time, NULL);
Jens Axboe3c39a372006-06-06 20:56:12 +0200118 get_io_ticks(du, &du->last_dus);
119
120 list_add_tail(&du->list, &disk_list);
121}
122
123static int check_dev_match(dev_t dev, char *path)
124{
125 unsigned int major, minor;
126 char line[256], *p;
127 FILE *f;
128
129 f = fopen(path, "r");
130 if (!f) {
131 perror("open path");
132 return 1;
133 }
134
135 p = fgets(line, sizeof(line), f);
136 if (!p) {
137 fclose(f);
138 return 1;
139 }
140
141 if (sscanf(p, "%u:%u", &major, &minor) != 2) {
142 fclose(f);
143 return 1;
144 }
145
146 if (((major << 8) | minor) == dev) {
147 fclose(f);
148 return 0;
149 }
150
151 fclose(f);
152 return 1;
153}
154
155static int find_block_dir(dev_t dev, char *path)
156{
157 struct dirent *dir;
158 struct stat st;
159 int found = 0;
160 DIR *D;
161
162 D = opendir(path);
163 if (!D)
164 return 0;
165
166 while ((dir = readdir(D)) != NULL) {
167 char full_path[256];
168
169 if (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, ".."))
170 continue;
Jens Axboe3c39a372006-06-06 20:56:12 +0200171
172 sprintf(full_path, "%s/%s", path, dir->d_name);
173
174 if (!strcmp(dir->d_name, "dev")) {
175 if (!check_dev_match(dev, full_path)) {
176 found = 1;
177 break;
178 }
179 }
180
Jens Axboe3307d652006-07-17 18:15:41 +0200181 if (lstat(full_path, &st) == -1) {
Jens Axboe3c39a372006-06-06 20:56:12 +0200182 perror("stat");
183 break;
184 }
185
186 if (!S_ISDIR(st.st_mode) || S_ISLNK(st.st_mode))
187 continue;
188
189 found = find_block_dir(dev, full_path);
190 if (found) {
191 strcpy(path, full_path);
192 break;
193 }
194 }
195
196 closedir(D);
197 return found;
198}
199
200void init_disk_util(struct thread_data *td)
201{
Jens Axboe53cdc682006-10-18 11:50:58 +0200202 struct fio_file *f;
Jens Axboe3c39a372006-06-06 20:56:12 +0200203 struct stat st;
Jens Axboe0bbab0e2006-11-02 09:18:36 +0100204 char foo[PATH_MAX], tmp[PATH_MAX];
Jens Axboe3c39a372006-06-06 20:56:12 +0200205 dev_t dev;
206 char *p;
207
208 if (!td->do_disk_util)
209 return;
210
Jens Axboe53cdc682006-10-18 11:50:58 +0200211 /*
212 * Just use the same file, they are on the same device.
213 */
214 f = &td->files[0];
215 if (!stat(f->file_name, &st)) {
Jens Axboe3c39a372006-06-06 20:56:12 +0200216 if (S_ISBLK(st.st_mode))
217 dev = st.st_rdev;
218 else
219 dev = st.st_dev;
220 } else {
221 /*
222 * must be a file, open "." in that path
223 */
Jens Axboe0bbab0e2006-11-02 09:18:36 +0100224 strncpy(foo, f->file_name, PATH_MAX - 1);
Jens Axboe3c39a372006-06-06 20:56:12 +0200225 p = dirname(foo);
226 if (stat(p, &st)) {
227 perror("disk util stat");
228 return;
229 }
230
231 dev = st.st_dev;
232 }
233
234 if (disk_util_exists(dev))
235 return;
236
237 sprintf(foo, "/sys/block");
238 if (!find_block_dir(dev, foo))
239 return;
240
241 /*
242 * If there's a ../queue/ directory there, we are inside a partition.
243 * Check if that is the case and jump back. For loop/md/dm etc we
244 * are already in the right spot.
245 */
246 sprintf(tmp, "%s/../queue", foo);
247 if (!stat(tmp, &st)) {
248 p = dirname(foo);
249 sprintf(tmp, "%s/queue", p);
250 if (stat(tmp, &st)) {
Jens Axboe3b70d7e2006-06-08 21:48:46 +0200251 log_err("unknown sysfs layout\n");
Jens Axboe3c39a372006-06-06 20:56:12 +0200252 return;
253 }
Jens Axboe0bbab0e2006-11-02 09:18:36 +0100254 strncpy(tmp, p, PATH_MAX - 1);
Jens Axboe84585002006-10-19 20:26:22 +0200255 sprintf(foo, "%s", tmp);
Jens Axboe3c39a372006-06-06 20:56:12 +0200256 }
257
Jens Axboeeecf2722006-10-20 14:00:36 +0200258 if (td->ioscheduler)
259 td->sysfs_root = strdup(foo);
260
Jens Axboe3c39a372006-06-06 20:56:12 +0200261 disk_util_add(dev, foo);
262}
263
264void disk_util_timer_arm(void)
265{
266 itimer.it_value.tv_sec = 0;
267 itimer.it_value.tv_usec = DISK_UTIL_MSEC * 1000;
268 setitimer(ITIMER_REAL, &itimer, NULL);
269}
270
271void update_rusage_stat(struct thread_data *td)
272{
Jens Axboe3c39a372006-06-06 20:56:12 +0200273 getrusage(RUSAGE_SELF, &td->ru_end);
274
275 td->usr_time += mtime_since(&td->ru_start.ru_utime, &td->ru_end.ru_utime);
276 td->sys_time += mtime_since(&td->ru_start.ru_stime, &td->ru_end.ru_stime);
277 td->ctx += td->ru_end.ru_nvcsw + td->ru_end.ru_nivcsw - (td->ru_start.ru_nvcsw + td->ru_start.ru_nivcsw);
278
279
280 memcpy(&td->ru_start, &td->ru_end, sizeof(td->ru_end));
281}
282
283static int calc_lat(struct io_stat *is, unsigned long *min, unsigned long *max,
284 double *mean, double *dev)
285{
Jens Axboeef9c5c42007-01-03 14:21:13 +0100286 double n, o;
Jens Axboe3c39a372006-06-06 20:56:12 +0200287
288 if (is->samples == 0)
289 return 0;
290
291 *min = is->min_val;
292 *max = is->max_val;
293
294 n = (double) is->samples;
295 *mean = (double) is->val / n;
Jens Axboeef9c5c42007-01-03 14:21:13 +0100296 *dev = 0.01;
Jens Axboe3c39a372006-06-06 20:56:12 +0200297
Jens Axboeef9c5c42007-01-03 14:21:13 +0100298 if (n <= 1.0)
Jens Axboee6d276f2007-01-03 11:10:27 +0100299 return 1;
300
Jens Axboeef9c5c42007-01-03 14:21:13 +0100301 o = (double) is->val_sq - ((*mean * *mean) / n);
302 if (o < 0.0)
303 *dev = -1.0;
304 else
305 *dev = sqrt(o / (n - 1.0));
306
Jens Axboe3c39a372006-06-06 20:56:12 +0200307 return 1;
308}
309
310static void show_group_stats(struct group_run_stats *rs, int id)
311{
Jens Axboeeb8bbf42006-06-08 21:40:11 +0200312 fprintf(f_out, "\nRun status group %d (all jobs):\n", id);
Jens Axboe3c39a372006-06-06 20:56:12 +0200313
314 if (rs->max_run[DDIR_READ])
Jens Axboeeb8bbf42006-06-08 21:40:11 +0200315 fprintf(f_out, " READ: io=%lluMiB, aggrb=%llu, minb=%llu, maxb=%llu, mint=%llumsec, maxt=%llumsec\n", rs->io_kb[0] >> 10, rs->agg[0], rs->min_bw[0], rs->max_bw[0], rs->min_run[0], rs->max_run[0]);
Jens Axboe3c39a372006-06-06 20:56:12 +0200316 if (rs->max_run[DDIR_WRITE])
Jens Axboeeb8bbf42006-06-08 21:40:11 +0200317 fprintf(f_out, " WRITE: io=%lluMiB, aggrb=%llu, minb=%llu, maxb=%llu, mint=%llumsec, maxt=%llumsec\n", rs->io_kb[1] >> 10, rs->agg[1], rs->min_bw[1], rs->max_bw[1], rs->min_run[1], rs->max_run[1]);
Jens Axboe3c39a372006-06-06 20:56:12 +0200318}
319
320static void show_disk_util(void)
321{
322 struct disk_util_stat *dus;
Jens Axboeb4a6a592006-10-20 13:54:47 +0200323 struct list_head *entry, *next;
Jens Axboe3c39a372006-06-06 20:56:12 +0200324 struct disk_util *du;
325 double util;
326
Jens Axboeeb8bbf42006-06-08 21:40:11 +0200327 fprintf(f_out, "\nDisk stats (read/write):\n");
Jens Axboe3c39a372006-06-06 20:56:12 +0200328
329 list_for_each(entry, &disk_list) {
330 du = list_entry(entry, struct disk_util, list);
331 dus = &du->dus;
332
333 util = (double) 100 * du->dus.io_ticks / (double) du->msec;
334 if (util > 100.0)
335 util = 100.0;
336
Jens Axboeeb8bbf42006-06-08 21:40:11 +0200337 fprintf(f_out, " %s: ios=%u/%u, merge=%u/%u, ticks=%u/%u, in_queue=%u, util=%3.2f%%\n", du->name, dus->ios[0], dus->ios[1], dus->merges[0], dus->merges[1], dus->ticks[0], dus->ticks[1], dus->time_in_queue, util);
Jens Axboe3c39a372006-06-06 20:56:12 +0200338 }
Jens Axboeb4a6a592006-10-20 13:54:47 +0200339
340 /*
341 * now free the list
342 */
343 list_for_each_safe(entry, next, &disk_list) {
344 list_del(entry);
345 du = list_entry(entry, struct disk_util, list);
346 free(du->name);
347 free(du);
348 }
Jens Axboe3c39a372006-06-06 20:56:12 +0200349}
350
351static void show_ddir_status(struct thread_data *td, struct group_run_stats *rs,
352 int ddir)
353{
Jens Axboe3c9b60c2006-11-07 08:36:14 +0100354 const char *ddir_str[] = { "read ", "write" };
Jens Axboe3c39a372006-06-06 20:56:12 +0200355 unsigned long min, max;
356 unsigned long long bw;
357 double mean, dev;
358
359 if (!td->runtime[ddir])
360 return;
361
362 bw = td->io_bytes[ddir] / td->runtime[ddir];
Jens Axboeeb8bbf42006-06-08 21:40:11 +0200363 fprintf(f_out, " %s: io=%6lluMiB, bw=%6lluKiB/s, runt=%6lumsec\n", ddir_str[ddir], td->io_bytes[ddir] >> 20, bw, td->runtime[ddir]);
Jens Axboe3c39a372006-06-06 20:56:12 +0200364
365 if (calc_lat(&td->slat_stat[ddir], &min, &max, &mean, &dev))
Jens Axboeeb8bbf42006-06-08 21:40:11 +0200366 fprintf(f_out, " slat (msec): min=%5lu, max=%5lu, avg=%5.02f, dev=%5.02f\n", min, max, mean, dev);
Jens Axboe3c39a372006-06-06 20:56:12 +0200367
368 if (calc_lat(&td->clat_stat[ddir], &min, &max, &mean, &dev))
Jens Axboeeb8bbf42006-06-08 21:40:11 +0200369 fprintf(f_out, " clat (msec): min=%5lu, max=%5lu, avg=%5.02f, dev=%5.02f\n", min, max, mean, dev);
Jens Axboe3c39a372006-06-06 20:56:12 +0200370
371 if (calc_lat(&td->bw_stat[ddir], &min, &max, &mean, &dev)) {
372 double p_of_agg;
373
374 p_of_agg = mean * 100 / (double) rs->agg[ddir];
Jens Axboeeb8bbf42006-06-08 21:40:11 +0200375 fprintf(f_out, " bw (KiB/s) : min=%5lu, max=%5lu, per=%3.2f%%, avg=%5.02f, dev=%5.02f\n", min, max, p_of_agg, mean, dev);
Jens Axboe3c39a372006-06-06 20:56:12 +0200376 }
377}
378
379static void show_thread_status(struct thread_data *td,
380 struct group_run_stats *rs)
381{
382 double usr_cpu, sys_cpu;
Jens Axboe69008992006-11-24 13:12:56 +0100383 unsigned long runtime;
Jens Axboe3c39a372006-06-06 20:56:12 +0200384
385 if (!(td->io_bytes[0] + td->io_bytes[1]) && !td->error)
386 return;
387
Jens Axboeeb8bbf42006-06-08 21:40:11 +0200388 fprintf(f_out, "%s: (groupid=%d): err=%2d:\n",td->name, td->groupid, td->error);
Jens Axboe3c39a372006-06-06 20:56:12 +0200389
390 show_ddir_status(td, rs, td->ddir);
391 if (td->io_bytes[td->ddir ^ 1])
392 show_ddir_status(td, rs, td->ddir ^ 1);
393
Jens Axboe69008992006-11-24 13:12:56 +0100394 runtime = mtime_since(&td->epoch, &td->end_time);
395 if (runtime) {
Jens Axboe1e97cce2006-12-05 11:44:16 +0100396 double runt = (double) runtime;
Jens Axboe3c39a372006-06-06 20:56:12 +0200397
398 usr_cpu = (double) td->usr_time * 100 / runt;
399 sys_cpu = (double) td->sys_time * 100 / runt;
400 } else {
401 usr_cpu = 0;
402 sys_cpu = 0;
403 }
404
Jens Axboeeb8bbf42006-06-08 21:40:11 +0200405 fprintf(f_out, " cpu : usr=%3.2f%%, sys=%3.2f%%, ctx=%lu\n", usr_cpu, sys_cpu, td->ctx);
Jens Axboe3c39a372006-06-06 20:56:12 +0200406}
407
Jens Axboec6ae0a52006-06-12 11:04:44 +0200408static void show_ddir_status_terse(struct thread_data *td,
409 struct group_run_stats *rs, int ddir)
410{
411 unsigned long min, max;
412 unsigned long long bw;
413 double mean, dev;
414
415 bw = 0;
416 if (td->runtime[ddir])
417 bw = td->io_bytes[ddir] / td->runtime[ddir];
418
419 fprintf(f_out, ",%llu,%llu,%lu", td->io_bytes[ddir] >> 10, bw, td->runtime[ddir]);
420
421 if (calc_lat(&td->slat_stat[ddir], &min, &max, &mean, &dev))
422 fprintf(f_out, ",%lu,%lu,%f,%f", min, max, mean, dev);
423 else
424 fprintf(f_out, ",%lu,%lu,%f,%f", 0UL, 0UL, 0.0, 0.0);
425
426 if (calc_lat(&td->clat_stat[ddir], &min, &max, &mean, &dev))
427 fprintf(f_out, ",%lu,%lu,%f,%f", min, max, mean, dev);
428 else
429 fprintf(f_out, ",%lu,%lu,%f,%f", 0UL, 0UL, 0.0, 0.0);
430
431 if (calc_lat(&td->bw_stat[ddir], &min, &max, &mean, &dev)) {
432 double p_of_agg;
433
434 p_of_agg = mean * 100 / (double) rs->agg[ddir];
435 fprintf(f_out, ",%lu,%lu,%f%%,%f,%f", min, max, p_of_agg, mean, dev);
436 } else
437 fprintf(f_out, ",%lu,%lu,%f%%,%f,%f", 0UL, 0UL, 0.0, 0.0, 0.0);
438
439}
440
441
442static void show_thread_status_terse(struct thread_data *td,
443 struct group_run_stats *rs)
444{
445 double usr_cpu, sys_cpu;
446
447 fprintf(f_out, "%s,%d,%d",td->name, td->groupid, td->error);
448
449 show_ddir_status_terse(td, rs, 0);
450 show_ddir_status_terse(td, rs, 1);
451
452 if (td->runtime[0] + td->runtime[1]) {
Jens Axboe1e97cce2006-12-05 11:44:16 +0100453 double runt = (double) (td->runtime[0] + td->runtime[1]);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200454
455 usr_cpu = (double) td->usr_time * 100 / runt;
456 sys_cpu = (double) td->sys_time * 100 / runt;
457 } else {
458 usr_cpu = 0;
459 sys_cpu = 0;
460 }
461
462 fprintf(f_out, ",%f%%,%f%%,%lu\n", usr_cpu, sys_cpu, td->ctx);
463}
464
Jens Axboe3c39a372006-06-06 20:56:12 +0200465void show_run_stats(void)
466{
467 struct group_run_stats *runstats, *rs;
468 struct thread_data *td;
469 int i;
470
471 runstats = malloc(sizeof(struct group_run_stats) * (groupid + 1));
472
473 for (i = 0; i < groupid + 1; i++) {
474 rs = &runstats[i];
475
476 memset(rs, 0, sizeof(*rs));
477 rs->min_bw[0] = rs->min_run[0] = ~0UL;
478 rs->min_bw[1] = rs->min_run[1] = ~0UL;
479 }
480
Jens Axboe34572e22006-10-20 09:33:18 +0200481 for_each_td(td, i) {
Jens Axboe3c39a372006-06-06 20:56:12 +0200482 unsigned long long rbw, wbw;
483
Jens Axboe3c39a372006-06-06 20:56:12 +0200484 if (td->error) {
Jens Axboeeb8bbf42006-06-08 21:40:11 +0200485 fprintf(f_out, "%s: %s\n", td->name, td->verror);
Jens Axboe3c39a372006-06-06 20:56:12 +0200486 continue;
487 }
488
489 rs = &runstats[td->groupid];
490
491 if (td->runtime[0] < rs->min_run[0] || !rs->min_run[0])
492 rs->min_run[0] = td->runtime[0];
493 if (td->runtime[0] > rs->max_run[0])
494 rs->max_run[0] = td->runtime[0];
495 if (td->runtime[1] < rs->min_run[1] || !rs->min_run[1])
496 rs->min_run[1] = td->runtime[1];
497 if (td->runtime[1] > rs->max_run[1])
498 rs->max_run[1] = td->runtime[1];
499
500 rbw = wbw = 0;
501 if (td->runtime[0])
502 rbw = td->io_bytes[0] / (unsigned long long) td->runtime[0];
503 if (td->runtime[1])
504 wbw = td->io_bytes[1] / (unsigned long long) td->runtime[1];
505
506 if (rbw < rs->min_bw[0])
507 rs->min_bw[0] = rbw;
508 if (wbw < rs->min_bw[1])
509 rs->min_bw[1] = wbw;
510 if (rbw > rs->max_bw[0])
511 rs->max_bw[0] = rbw;
512 if (wbw > rs->max_bw[1])
513 rs->max_bw[1] = wbw;
514
515 rs->io_kb[0] += td->io_bytes[0] >> 10;
516 rs->io_kb[1] += td->io_bytes[1] >> 10;
517 }
518
519 for (i = 0; i < groupid + 1; i++) {
520 rs = &runstats[i];
521
522 if (rs->max_run[0])
523 rs->agg[0] = (rs->io_kb[0]*1024) / rs->max_run[0];
524 if (rs->max_run[1])
525 rs->agg[1] = (rs->io_kb[1]*1024) / rs->max_run[1];
526 }
527
528 /*
529 * don't overwrite last signal output
530 */
Jens Axboec6ae0a52006-06-12 11:04:44 +0200531 if (!terse_output)
532 printf("\n");
Jens Axboe3c39a372006-06-06 20:56:12 +0200533
Jens Axboe34572e22006-10-20 09:33:18 +0200534 for_each_td(td, i) {
Jens Axboe3c39a372006-06-06 20:56:12 +0200535 rs = &runstats[td->groupid];
536
Jens Axboec6ae0a52006-06-12 11:04:44 +0200537 if (terse_output)
538 show_thread_status_terse(td, rs);
539 else
540 show_thread_status(td, rs);
Jens Axboe3c39a372006-06-06 20:56:12 +0200541 }
542
Jens Axboec6ae0a52006-06-12 11:04:44 +0200543 if (!terse_output) {
544 for (i = 0; i < groupid + 1; i++)
545 show_group_stats(&runstats[i], i);
Jens Axboe3c39a372006-06-06 20:56:12 +0200546
Jens Axboec6ae0a52006-06-12 11:04:44 +0200547 show_disk_util();
548 }
Jens Axboeeecf2722006-10-20 14:00:36 +0200549
550 free(runstats);
Jens Axboe3c39a372006-06-06 20:56:12 +0200551}
552
553static inline void add_stat_sample(struct io_stat *is, unsigned long val)
554{
555 if (val > is->max_val)
556 is->max_val = val;
557 if (val < is->min_val)
558 is->min_val = val;
559
560 is->val += val;
561 is->val_sq += val * val;
562 is->samples++;
563}
564
565static void add_log_sample(struct thread_data *td, struct io_log *iolog,
Jens Axboe1e97cce2006-12-05 11:44:16 +0100566 unsigned long val, enum fio_ddir ddir)
Jens Axboe3c39a372006-06-06 20:56:12 +0200567{
568 if (iolog->nr_samples == iolog->max_samples) {
569 int new_size = sizeof(struct io_sample) * iolog->max_samples*2;
570
571 iolog->log = realloc(iolog->log, new_size);
572 iolog->max_samples <<= 1;
573 }
574
575 iolog->log[iolog->nr_samples].val = val;
576 iolog->log[iolog->nr_samples].time = mtime_since_now(&td->epoch);
577 iolog->log[iolog->nr_samples].ddir = ddir;
578 iolog->nr_samples++;
579}
580
Jens Axboe1e97cce2006-12-05 11:44:16 +0100581void add_clat_sample(struct thread_data *td, enum fio_ddir ddir,
582 unsigned long msec)
Jens Axboe3c39a372006-06-06 20:56:12 +0200583{
584 add_stat_sample(&td->clat_stat[ddir], msec);
585
586 if (td->clat_log)
587 add_log_sample(td, td->clat_log, msec, ddir);
588}
589
Jens Axboe1e97cce2006-12-05 11:44:16 +0100590void add_slat_sample(struct thread_data *td, enum fio_ddir ddir,
591 unsigned long msec)
Jens Axboe3c39a372006-06-06 20:56:12 +0200592{
593 add_stat_sample(&td->slat_stat[ddir], msec);
594
595 if (td->slat_log)
596 add_log_sample(td, td->slat_log, msec, ddir);
597}
598
Jens Axboe1e97cce2006-12-05 11:44:16 +0100599void add_bw_sample(struct thread_data *td, enum fio_ddir ddir,
600 struct timeval *t)
Jens Axboe3c39a372006-06-06 20:56:12 +0200601{
Jens Axboe02bcaa82006-11-24 10:42:00 +0100602 unsigned long spent = mtime_since(&td->stat_sample_time[ddir], t);
Jens Axboe3c39a372006-06-06 20:56:12 +0200603 unsigned long rate;
604
605 if (spent < td->bw_avg_time)
606 return;
607
608 rate = (td->this_io_bytes[ddir] - td->stat_io_bytes[ddir]) / spent;
609 add_stat_sample(&td->bw_stat[ddir], rate);
610
611 if (td->bw_log)
612 add_log_sample(td, td->bw_log, rate, ddir);
613
Jens Axboe02bcaa82006-11-24 10:42:00 +0100614 fio_gettime(&td->stat_sample_time[ddir], NULL);
Jens Axboe3c39a372006-06-06 20:56:12 +0200615 td->stat_io_bytes[ddir] = td->this_io_bytes[ddir];
616}
617
618