Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <string.h> |
| 3 | #include <sys/time.h> |
| 4 | #include <sys/types.h> |
Jens Axboe | 5c4e1db | 2006-06-07 14:17:08 +0200 | [diff] [blame] | 5 | #include <sys/stat.h> |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 6 | #include <dirent.h> |
| 7 | #include <libgen.h> |
| 8 | #include <math.h> |
| 9 | |
| 10 | #include "fio.h" |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 11 | |
| 12 | static struct itimerval itimer; |
Jens Axboe | 5c4e1db | 2006-06-07 14:17:08 +0200 | [diff] [blame] | 13 | static struct list_head disk_list = LIST_HEAD_INIT(disk_list); |
Jens Axboe | c0a6b0d | 2007-02-26 12:28:58 +0100 | [diff] [blame] | 14 | static dev_t last_dev; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 15 | |
Jens Axboe | dbe1125 | 2007-02-11 00:19:51 +0100 | [diff] [blame] | 16 | /* |
Jens Axboe | 34403fb | 2007-03-02 21:43:25 +0100 | [diff] [blame] | 17 | * Cheesy number->string conversion, complete with carry rounding error. |
Jens Axboe | dbe1125 | 2007-02-11 00:19:51 +0100 | [diff] [blame] | 18 | */ |
| 19 | static char *num2str(unsigned long num, int maxlen, int base) |
| 20 | { |
| 21 | /* |
| 22 | * could be passed in for 10^3 base, but every caller expects |
| 23 | * 2^10 base right now. |
| 24 | */ |
Jens Axboe | c8c51ef | 2007-02-11 05:02:48 +0100 | [diff] [blame] | 25 | const unsigned int thousand = 1024; |
Jens Axboe | f3502ba | 2007-02-14 01:27:09 +0100 | [diff] [blame] | 26 | char postfix[] = { 'K', 'M', 'G', 'P', 'E' }; |
Jens Axboe | dbe1125 | 2007-02-11 00:19:51 +0100 | [diff] [blame] | 27 | char *buf; |
| 28 | int i; |
| 29 | |
| 30 | buf = malloc(128); |
| 31 | |
| 32 | for (i = 0; base > 1; i++) |
| 33 | base /= thousand; |
| 34 | |
| 35 | do { |
| 36 | int len, carry = 0; |
| 37 | |
| 38 | len = sprintf(buf, "%'lu", num); |
| 39 | if (len <= maxlen) { |
| 40 | buf[len] = postfix[i]; |
| 41 | buf[len + 1] = '\0'; |
| 42 | return buf; |
| 43 | } |
| 44 | |
| 45 | if ((num % thousand) >= (thousand / 2)) |
| 46 | carry = 1; |
| 47 | |
| 48 | num /= thousand; |
| 49 | num += carry; |
| 50 | i++; |
Jens Axboe | f3502ba | 2007-02-14 01:27:09 +0100 | [diff] [blame] | 51 | } while (i <= 5); |
Jens Axboe | dbe1125 | 2007-02-11 00:19:51 +0100 | [diff] [blame] | 52 | |
| 53 | return buf; |
| 54 | } |
| 55 | |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 56 | static int get_io_ticks(struct disk_util *du, struct disk_util_stat *dus) |
| 57 | { |
| 58 | unsigned in_flight; |
| 59 | char line[256]; |
| 60 | FILE *f; |
| 61 | char *p; |
| 62 | |
| 63 | f = fopen(du->path, "r"); |
| 64 | if (!f) |
| 65 | return 1; |
| 66 | |
| 67 | p = fgets(line, sizeof(line), f); |
| 68 | if (!p) { |
| 69 | fclose(f); |
| 70 | return 1; |
| 71 | } |
| 72 | |
| 73 | 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) { |
| 74 | fclose(f); |
| 75 | return 1; |
| 76 | } |
| 77 | |
| 78 | fclose(f); |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | static void update_io_tick_disk(struct disk_util *du) |
| 83 | { |
| 84 | struct disk_util_stat __dus, *dus, *ldus; |
| 85 | struct timeval t; |
| 86 | |
| 87 | if (get_io_ticks(du, &__dus)) |
| 88 | return; |
| 89 | |
| 90 | dus = &du->dus; |
| 91 | ldus = &du->last_dus; |
| 92 | |
| 93 | dus->sectors[0] += (__dus.sectors[0] - ldus->sectors[0]); |
| 94 | dus->sectors[1] += (__dus.sectors[1] - ldus->sectors[1]); |
| 95 | dus->ios[0] += (__dus.ios[0] - ldus->ios[0]); |
| 96 | dus->ios[1] += (__dus.ios[1] - ldus->ios[1]); |
| 97 | dus->merges[0] += (__dus.merges[0] - ldus->merges[0]); |
| 98 | dus->merges[1] += (__dus.merges[1] - ldus->merges[1]); |
| 99 | dus->ticks[0] += (__dus.ticks[0] - ldus->ticks[0]); |
| 100 | dus->ticks[1] += (__dus.ticks[1] - ldus->ticks[1]); |
| 101 | dus->io_ticks += (__dus.io_ticks - ldus->io_ticks); |
| 102 | dus->time_in_queue += (__dus.time_in_queue - ldus->time_in_queue); |
| 103 | |
Jens Axboe | 02bcaa8 | 2006-11-24 10:42:00 +0100 | [diff] [blame] | 104 | fio_gettime(&t, NULL); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 105 | du->msec += mtime_since(&du->time, &t); |
| 106 | memcpy(&du->time, &t, sizeof(t)); |
| 107 | memcpy(ldus, &__dus, sizeof(__dus)); |
| 108 | } |
| 109 | |
| 110 | void update_io_ticks(void) |
| 111 | { |
| 112 | struct list_head *entry; |
| 113 | struct disk_util *du; |
| 114 | |
| 115 | list_for_each(entry, &disk_list) { |
| 116 | du = list_entry(entry, struct disk_util, list); |
| 117 | update_io_tick_disk(du); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | static int disk_util_exists(dev_t dev) |
| 122 | { |
| 123 | struct list_head *entry; |
| 124 | struct disk_util *du; |
| 125 | |
| 126 | list_for_each(entry, &disk_list) { |
| 127 | du = list_entry(entry, struct disk_util, list); |
| 128 | |
| 129 | if (du->dev == dev) |
| 130 | return 1; |
| 131 | } |
| 132 | |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | static void disk_util_add(dev_t dev, char *path) |
| 137 | { |
Jens Axboe | 1188caf | 2007-01-08 10:57:27 +0100 | [diff] [blame] | 138 | struct disk_util *du, *__du; |
| 139 | struct list_head *entry; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 140 | |
Jens Axboe | 1188caf | 2007-01-08 10:57:27 +0100 | [diff] [blame] | 141 | du = malloc(sizeof(*du)); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 142 | memset(du, 0, sizeof(*du)); |
| 143 | INIT_LIST_HEAD(&du->list); |
| 144 | sprintf(du->path, "%s/stat", path); |
| 145 | du->name = strdup(basename(path)); |
| 146 | du->dev = dev; |
| 147 | |
Jens Axboe | 1188caf | 2007-01-08 10:57:27 +0100 | [diff] [blame] | 148 | list_for_each(entry, &disk_list) { |
| 149 | __du = list_entry(entry, struct disk_util, list); |
| 150 | |
| 151 | if (!strcmp(du->name, __du->name)) { |
| 152 | free(du->name); |
| 153 | free(du); |
| 154 | return; |
| 155 | } |
| 156 | } |
| 157 | |
Jens Axboe | 02bcaa8 | 2006-11-24 10:42:00 +0100 | [diff] [blame] | 158 | fio_gettime(&du->time, NULL); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 159 | get_io_ticks(du, &du->last_dus); |
| 160 | |
| 161 | list_add_tail(&du->list, &disk_list); |
| 162 | } |
| 163 | |
| 164 | static int check_dev_match(dev_t dev, char *path) |
| 165 | { |
| 166 | unsigned int major, minor; |
| 167 | char line[256], *p; |
| 168 | FILE *f; |
| 169 | |
| 170 | f = fopen(path, "r"); |
| 171 | if (!f) { |
| 172 | perror("open path"); |
| 173 | return 1; |
| 174 | } |
| 175 | |
| 176 | p = fgets(line, sizeof(line), f); |
| 177 | if (!p) { |
| 178 | fclose(f); |
| 179 | return 1; |
| 180 | } |
| 181 | |
| 182 | if (sscanf(p, "%u:%u", &major, &minor) != 2) { |
| 183 | fclose(f); |
| 184 | return 1; |
| 185 | } |
| 186 | |
| 187 | if (((major << 8) | minor) == dev) { |
| 188 | fclose(f); |
| 189 | return 0; |
| 190 | } |
| 191 | |
| 192 | fclose(f); |
| 193 | return 1; |
| 194 | } |
| 195 | |
| 196 | static int find_block_dir(dev_t dev, char *path) |
| 197 | { |
| 198 | struct dirent *dir; |
| 199 | struct stat st; |
| 200 | int found = 0; |
| 201 | DIR *D; |
| 202 | |
| 203 | D = opendir(path); |
| 204 | if (!D) |
| 205 | return 0; |
| 206 | |
| 207 | while ((dir = readdir(D)) != NULL) { |
| 208 | char full_path[256]; |
| 209 | |
| 210 | if (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, "..")) |
| 211 | continue; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 212 | |
| 213 | sprintf(full_path, "%s/%s", path, dir->d_name); |
| 214 | |
| 215 | if (!strcmp(dir->d_name, "dev")) { |
| 216 | if (!check_dev_match(dev, full_path)) { |
| 217 | found = 1; |
| 218 | break; |
| 219 | } |
| 220 | } |
| 221 | |
Jens Axboe | 3307d65 | 2006-07-17 18:15:41 +0200 | [diff] [blame] | 222 | if (lstat(full_path, &st) == -1) { |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 223 | perror("stat"); |
| 224 | break; |
| 225 | } |
| 226 | |
| 227 | if (!S_ISDIR(st.st_mode) || S_ISLNK(st.st_mode)) |
| 228 | continue; |
| 229 | |
| 230 | found = find_block_dir(dev, full_path); |
| 231 | if (found) { |
| 232 | strcpy(path, full_path); |
| 233 | break; |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | closedir(D); |
| 238 | return found; |
| 239 | } |
| 240 | |
| 241 | void init_disk_util(struct thread_data *td) |
| 242 | { |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 243 | struct fio_file *f; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 244 | struct stat st; |
Jens Axboe | 0bbab0e | 2006-11-02 09:18:36 +0100 | [diff] [blame] | 245 | char foo[PATH_MAX], tmp[PATH_MAX]; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 246 | dev_t dev; |
| 247 | char *p; |
| 248 | |
Jens Axboe | 138502a | 2007-03-01 08:27:42 +0100 | [diff] [blame] | 249 | if (!td->do_disk_util || (td->io_ops->flags & FIO_DISKLESSIO)) |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 250 | return; |
| 251 | |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 252 | /* |
| 253 | * Just use the same file, they are on the same device. |
| 254 | */ |
| 255 | f = &td->files[0]; |
| 256 | if (!stat(f->file_name, &st)) { |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 257 | if (S_ISBLK(st.st_mode)) |
| 258 | dev = st.st_rdev; |
| 259 | else |
| 260 | dev = st.st_dev; |
| 261 | } else { |
| 262 | /* |
| 263 | * must be a file, open "." in that path |
| 264 | */ |
Jens Axboe | 0bbab0e | 2006-11-02 09:18:36 +0100 | [diff] [blame] | 265 | strncpy(foo, f->file_name, PATH_MAX - 1); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 266 | p = dirname(foo); |
| 267 | if (stat(p, &st)) { |
| 268 | perror("disk util stat"); |
| 269 | return; |
| 270 | } |
| 271 | |
| 272 | dev = st.st_dev; |
| 273 | } |
| 274 | |
| 275 | if (disk_util_exists(dev)) |
| 276 | return; |
Jens Axboe | c0a6b0d | 2007-02-26 12:28:58 +0100 | [diff] [blame] | 277 | |
| 278 | /* |
| 279 | * for an fs without a device, we will repeatedly stat through |
| 280 | * sysfs which can take oodles of time for thousands of files. so |
| 281 | * cache the last lookup and compare with that before going through |
| 282 | * everything again. |
| 283 | */ |
| 284 | if (dev == last_dev) |
| 285 | return; |
| 286 | |
| 287 | last_dev = dev; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 288 | |
| 289 | sprintf(foo, "/sys/block"); |
| 290 | if (!find_block_dir(dev, foo)) |
| 291 | return; |
| 292 | |
| 293 | /* |
| 294 | * If there's a ../queue/ directory there, we are inside a partition. |
| 295 | * Check if that is the case and jump back. For loop/md/dm etc we |
| 296 | * are already in the right spot. |
| 297 | */ |
| 298 | sprintf(tmp, "%s/../queue", foo); |
| 299 | if (!stat(tmp, &st)) { |
| 300 | p = dirname(foo); |
| 301 | sprintf(tmp, "%s/queue", p); |
| 302 | if (stat(tmp, &st)) { |
Jens Axboe | 3b70d7e | 2006-06-08 21:48:46 +0200 | [diff] [blame] | 303 | log_err("unknown sysfs layout\n"); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 304 | return; |
| 305 | } |
Jens Axboe | 0bbab0e | 2006-11-02 09:18:36 +0100 | [diff] [blame] | 306 | strncpy(tmp, p, PATH_MAX - 1); |
Jens Axboe | 8458500 | 2006-10-19 20:26:22 +0200 | [diff] [blame] | 307 | sprintf(foo, "%s", tmp); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 308 | } |
| 309 | |
Jens Axboe | eecf272 | 2006-10-20 14:00:36 +0200 | [diff] [blame] | 310 | if (td->ioscheduler) |
| 311 | td->sysfs_root = strdup(foo); |
| 312 | |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 313 | disk_util_add(dev, foo); |
| 314 | } |
| 315 | |
| 316 | void disk_util_timer_arm(void) |
| 317 | { |
| 318 | itimer.it_value.tv_sec = 0; |
| 319 | itimer.it_value.tv_usec = DISK_UTIL_MSEC * 1000; |
| 320 | setitimer(ITIMER_REAL, &itimer, NULL); |
| 321 | } |
| 322 | |
| 323 | void update_rusage_stat(struct thread_data *td) |
| 324 | { |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 325 | struct thread_stat *ts = &td->ts; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 326 | |
Jens Axboe | 079ad09 | 2007-02-20 13:58:20 +0100 | [diff] [blame] | 327 | getrusage(RUSAGE_SELF, &ts->ru_end); |
| 328 | |
| 329 | ts->usr_time += mtime_since(&ts->ru_start.ru_utime, &ts->ru_end.ru_utime); |
| 330 | ts->sys_time += mtime_since(&ts->ru_start.ru_stime, &ts->ru_end.ru_stime); |
| 331 | ts->ctx += ts->ru_end.ru_nvcsw + ts->ru_end.ru_nivcsw - (ts->ru_start.ru_nvcsw + ts->ru_start.ru_nivcsw); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 332 | |
Jens Axboe | 079ad09 | 2007-02-20 13:58:20 +0100 | [diff] [blame] | 333 | memcpy(&ts->ru_start, &ts->ru_end, sizeof(ts->ru_end)); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | static int calc_lat(struct io_stat *is, unsigned long *min, unsigned long *max, |
| 337 | double *mean, double *dev) |
| 338 | { |
Jens Axboe | 6870408 | 2007-01-10 19:56:37 +0100 | [diff] [blame] | 339 | double n = is->samples; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 340 | |
| 341 | if (is->samples == 0) |
| 342 | return 0; |
| 343 | |
| 344 | *min = is->min_val; |
| 345 | *max = is->max_val; |
| 346 | |
| 347 | n = (double) is->samples; |
Jens Axboe | 6870408 | 2007-01-10 19:56:37 +0100 | [diff] [blame] | 348 | *mean = is->mean; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 349 | |
Jens Axboe | 6870408 | 2007-01-10 19:56:37 +0100 | [diff] [blame] | 350 | if (n > 1.0) |
| 351 | *dev = sqrt(is->S / (n - 1.0)); |
Jens Axboe | ef9c5c4 | 2007-01-03 14:21:13 +0100 | [diff] [blame] | 352 | else |
Jens Axboe | 6870408 | 2007-01-10 19:56:37 +0100 | [diff] [blame] | 353 | *dev = -1.0; |
Jens Axboe | ef9c5c4 | 2007-01-03 14:21:13 +0100 | [diff] [blame] | 354 | |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 355 | return 1; |
| 356 | } |
| 357 | |
| 358 | static void show_group_stats(struct group_run_stats *rs, int id) |
| 359 | { |
Jens Axboe | dbe1125 | 2007-02-11 00:19:51 +0100 | [diff] [blame] | 360 | char *p1, *p2, *p3, *p4; |
| 361 | const char *ddir_str[] = { " READ", " WRITE" }; |
| 362 | int i; |
| 363 | |
Jens Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 364 | fprintf(f_out, "\nRun status group %d (all jobs):\n", id); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 365 | |
Jens Axboe | dbe1125 | 2007-02-11 00:19:51 +0100 | [diff] [blame] | 366 | for (i = 0; i <= DDIR_WRITE; i++) { |
| 367 | if (!rs->max_run[i]) |
| 368 | continue; |
| 369 | |
| 370 | p1 = num2str(rs->io_kb[i], 6, 1); |
| 371 | p2 = num2str(rs->agg[i], 6, 1); |
| 372 | p3 = num2str(rs->min_bw[i], 6, 1); |
| 373 | p4 = num2str(rs->max_bw[i], 6, 1); |
| 374 | |
Jens Axboe | 197574e | 2007-03-08 15:35:11 +0100 | [diff] [blame] | 375 | fprintf(f_out, "%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 Axboe | dbe1125 | 2007-02-11 00:19:51 +0100 | [diff] [blame] | 376 | |
| 377 | free(p1); |
| 378 | free(p2); |
| 379 | free(p3); |
| 380 | free(p4); |
| 381 | } |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | static void show_disk_util(void) |
| 385 | { |
| 386 | struct disk_util_stat *dus; |
Jens Axboe | b4a6a59 | 2006-10-20 13:54:47 +0200 | [diff] [blame] | 387 | struct list_head *entry, *next; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 388 | struct disk_util *du; |
| 389 | double util; |
| 390 | |
Jens Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 391 | fprintf(f_out, "\nDisk stats (read/write):\n"); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 392 | |
| 393 | list_for_each(entry, &disk_list) { |
| 394 | du = list_entry(entry, struct disk_util, list); |
| 395 | dus = &du->dus; |
| 396 | |
| 397 | util = (double) 100 * du->dus.io_ticks / (double) du->msec; |
| 398 | if (util > 100.0) |
| 399 | util = 100.0; |
| 400 | |
Jens Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 401 | 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 Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 402 | } |
Jens Axboe | b4a6a59 | 2006-10-20 13:54:47 +0200 | [diff] [blame] | 403 | |
| 404 | /* |
| 405 | * now free the list |
| 406 | */ |
| 407 | list_for_each_safe(entry, next, &disk_list) { |
| 408 | list_del(entry); |
| 409 | du = list_entry(entry, struct disk_util, list); |
| 410 | free(du->name); |
| 411 | free(du); |
| 412 | } |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 413 | } |
| 414 | |
Jens Axboe | 2270890 | 2007-03-06 17:05:32 +0100 | [diff] [blame] | 415 | static void stat_calc_dist(struct thread_stat *ts, double *io_u_dist) |
| 416 | { |
| 417 | int i; |
| 418 | |
| 419 | /* |
| 420 | * Do depth distribution calculations |
| 421 | */ |
| 422 | for (i = 0; i < FIO_IO_U_MAP_NR; i++) { |
| 423 | io_u_dist[i] = (double) ts->io_u_map[i] / (double) ts->total_io_u; |
| 424 | io_u_dist[i] *= 100.0; |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | static void stat_calc_lat(struct thread_stat *ts, double *io_u_lat) |
| 429 | { |
| 430 | int i; |
| 431 | |
| 432 | /* |
| 433 | * Do latency distribution calculations |
| 434 | */ |
| 435 | for (i = 0; i < FIO_IO_U_LAT_NR; i++) { |
| 436 | io_u_lat[i] = (double) ts->io_u_lat[i] / (double) ts->total_io_u; |
| 437 | io_u_lat[i] *= 100.0; |
| 438 | } |
| 439 | } |
| 440 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 441 | static void show_ddir_status(struct group_run_stats *rs, struct thread_stat *ts, |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 442 | int ddir) |
| 443 | { |
Jens Axboe | 3c9b60c | 2006-11-07 08:36:14 +0100 | [diff] [blame] | 444 | const char *ddir_str[] = { "read ", "write" }; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 445 | unsigned long min, max; |
| 446 | unsigned long long bw; |
| 447 | double mean, dev; |
Jens Axboe | dbe1125 | 2007-02-11 00:19:51 +0100 | [diff] [blame] | 448 | char *io_p, *bw_p; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 449 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 450 | if (!ts->runtime[ddir]) |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 451 | return; |
| 452 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 453 | bw = ts->io_bytes[ddir] / ts->runtime[ddir]; |
| 454 | io_p = num2str(ts->io_bytes[ddir] >> 10, 6, 1); |
Jens Axboe | dbe1125 | 2007-02-11 00:19:51 +0100 | [diff] [blame] | 455 | bw_p = num2str(bw, 6, 1); |
| 456 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 457 | fprintf(f_out, " %s: io=%siB, bw=%siB/s, runt=%6lumsec\n", ddir_str[ddir], io_p, bw_p, ts->runtime[ddir]); |
Jens Axboe | dbe1125 | 2007-02-11 00:19:51 +0100 | [diff] [blame] | 458 | |
| 459 | free(io_p); |
| 460 | free(bw_p); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 461 | |
Jens Axboe | 079ad09 | 2007-02-20 13:58:20 +0100 | [diff] [blame] | 462 | if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) |
Jens Axboe | 6104ddb | 2007-01-11 14:24:29 +0100 | [diff] [blame] | 463 | fprintf(f_out, " slat (msec): min=%5lu, max=%5lu, avg=%5.02f, stdev=%5.02f\n", min, max, mean, dev); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 464 | |
Jens Axboe | 079ad09 | 2007-02-20 13:58:20 +0100 | [diff] [blame] | 465 | if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) |
Jens Axboe | 6104ddb | 2007-01-11 14:24:29 +0100 | [diff] [blame] | 466 | fprintf(f_out, " clat (msec): min=%5lu, max=%5lu, avg=%5.02f, stdev=%5.02f\n", min, max, mean, dev); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 467 | |
Jens Axboe | 079ad09 | 2007-02-20 13:58:20 +0100 | [diff] [blame] | 468 | if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) { |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 469 | double p_of_agg; |
| 470 | |
| 471 | p_of_agg = mean * 100 / (double) rs->agg[ddir]; |
Jens Axboe | 6104ddb | 2007-01-11 14:24:29 +0100 | [diff] [blame] | 472 | fprintf(f_out, " 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 Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 473 | } |
| 474 | } |
| 475 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 476 | static void show_thread_status(struct thread_stat *ts, |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 477 | struct group_run_stats *rs) |
| 478 | { |
| 479 | double usr_cpu, sys_cpu; |
Jens Axboe | 6900899 | 2006-11-24 13:12:56 +0100 | [diff] [blame] | 480 | unsigned long runtime; |
Jens Axboe | 71619dc | 2007-01-13 23:56:33 +0100 | [diff] [blame] | 481 | double io_u_dist[FIO_IO_U_MAP_NR]; |
Jens Axboe | ec11830 | 2007-02-17 04:38:20 +0100 | [diff] [blame] | 482 | double io_u_lat[FIO_IO_U_LAT_NR]; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 483 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 484 | if (!(ts->io_bytes[0] + ts->io_bytes[1])) |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 485 | return; |
| 486 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 487 | if (!ts->error) |
Jens Axboe | 6586ee8 | 2007-03-06 19:46:09 +0100 | [diff] [blame] | 488 | fprintf(f_out, "%s: (groupid=%d, jobs=%d): err=%2d: pid=%d\n", ts->name, ts->groupid, ts->members, ts->error, ts->pid); |
Jens Axboe | 6d66307 | 2007-02-11 00:57:13 +0100 | [diff] [blame] | 489 | else |
Jens Axboe | 6586ee8 | 2007-03-06 19:46:09 +0100 | [diff] [blame] | 490 | fprintf(f_out, "%s: (groupid=%d, jobs=%d): err=%2d (%s): pid=%d\n", ts->name, ts->groupid, ts->members, ts->error, ts->verror, ts->pid); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 491 | |
Jens Axboe | 7bdce1b | 2007-03-06 20:01:13 +0100 | [diff] [blame] | 492 | if (ts->description) |
| 493 | fprintf(f_out, " Description : [%s]\n", ts->description); |
| 494 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 495 | if (ts->io_bytes[DDIR_READ]) |
| 496 | show_ddir_status(rs, ts, DDIR_READ); |
| 497 | if (ts->io_bytes[DDIR_WRITE]) |
| 498 | show_ddir_status(rs, ts, DDIR_WRITE); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 499 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 500 | runtime = ts->total_run_time; |
Jens Axboe | 6900899 | 2006-11-24 13:12:56 +0100 | [diff] [blame] | 501 | if (runtime) { |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 502 | double runt = (double) runtime; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 503 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 504 | usr_cpu = (double) ts->usr_time * 100 / runt; |
| 505 | sys_cpu = (double) ts->sys_time * 100 / runt; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 506 | } else { |
| 507 | usr_cpu = 0; |
| 508 | sys_cpu = 0; |
| 509 | } |
| 510 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 511 | fprintf(f_out, " cpu : usr=%3.2f%%, sys=%3.2f%%, ctx=%lu\n", usr_cpu, sys_cpu, ts->ctx); |
Jens Axboe | 71619dc | 2007-01-13 23:56:33 +0100 | [diff] [blame] | 512 | |
Jens Axboe | 2270890 | 2007-03-06 17:05:32 +0100 | [diff] [blame] | 513 | stat_calc_dist(ts, io_u_dist); |
| 514 | stat_calc_lat(ts, io_u_lat); |
Jens Axboe | 71619dc | 2007-01-13 23:56:33 +0100 | [diff] [blame] | 515 | |
Jens Axboe | 5d45807 | 2007-01-13 23:59:00 +0100 | [diff] [blame] | 516 | fprintf(f_out, " 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 Axboe | 61697c3 | 2007-02-05 15:04:46 +0100 | [diff] [blame] | 517 | |
Jens Axboe | 8abdce6 | 2007-02-21 10:22:55 +0100 | [diff] [blame] | 518 | fprintf(f_out, " lat (msec): 2=%3.1f%%, 4=%3.1f%%, 10=%3.1f%%, 20=%3.1f%%, 50=%3.1f%%, 100=%3.1f%%\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]); |
| 519 | fprintf(f_out, " lat (msec): 250=%3.1f%%, 500=%3.1f%%, 750=%3.1f%%, 1000=%3.1f%%, >=2000=%3.1f%%\n", io_u_lat[6], io_u_lat[7], io_u_lat[8], io_u_lat[9], io_u_lat[10]); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 520 | } |
| 521 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 522 | static void show_ddir_status_terse(struct thread_stat *ts, |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 523 | struct group_run_stats *rs, int ddir) |
| 524 | { |
| 525 | unsigned long min, max; |
| 526 | unsigned long long bw; |
| 527 | double mean, dev; |
| 528 | |
| 529 | bw = 0; |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 530 | if (ts->runtime[ddir]) |
| 531 | bw = ts->io_bytes[ddir] / ts->runtime[ddir]; |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 532 | |
Jens Axboe | 6af019c | 2007-03-06 19:50:58 +0100 | [diff] [blame] | 533 | fprintf(f_out, ";%llu;%llu;%lu", ts->io_bytes[ddir] >> 10, bw, ts->runtime[ddir]); |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 534 | |
Jens Axboe | 079ad09 | 2007-02-20 13:58:20 +0100 | [diff] [blame] | 535 | if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) |
Jens Axboe | 6af019c | 2007-03-06 19:50:58 +0100 | [diff] [blame] | 536 | fprintf(f_out, ";%lu;%lu;%f;%f", min, max, mean, dev); |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 537 | else |
Jens Axboe | 6af019c | 2007-03-06 19:50:58 +0100 | [diff] [blame] | 538 | fprintf(f_out, ";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0); |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 539 | |
Jens Axboe | 079ad09 | 2007-02-20 13:58:20 +0100 | [diff] [blame] | 540 | if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) |
Jens Axboe | 6af019c | 2007-03-06 19:50:58 +0100 | [diff] [blame] | 541 | fprintf(f_out, ";%lu;%lu;%f;%f", min, max, mean, dev); |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 542 | else |
Jens Axboe | 6af019c | 2007-03-06 19:50:58 +0100 | [diff] [blame] | 543 | fprintf(f_out, ";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0); |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 544 | |
Jens Axboe | 079ad09 | 2007-02-20 13:58:20 +0100 | [diff] [blame] | 545 | if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) { |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 546 | double p_of_agg; |
| 547 | |
| 548 | p_of_agg = mean * 100 / (double) rs->agg[ddir]; |
Jens Axboe | 6af019c | 2007-03-06 19:50:58 +0100 | [diff] [blame] | 549 | fprintf(f_out, ";%lu;%lu;%f%%;%f;%f", min, max, p_of_agg, mean, dev); |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 550 | } else |
Jens Axboe | 6af019c | 2007-03-06 19:50:58 +0100 | [diff] [blame] | 551 | fprintf(f_out, ";%lu;%lu;%f%%;%f;%f", 0UL, 0UL, 0.0, 0.0, 0.0); |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 555 | static void show_thread_status_terse(struct thread_stat *ts, |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 556 | struct group_run_stats *rs) |
| 557 | { |
Jens Axboe | 2270890 | 2007-03-06 17:05:32 +0100 | [diff] [blame] | 558 | double io_u_dist[FIO_IO_U_MAP_NR]; |
| 559 | double io_u_lat[FIO_IO_U_LAT_NR]; |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 560 | double usr_cpu, sys_cpu; |
| 561 | |
Jens Axboe | 6af019c | 2007-03-06 19:50:58 +0100 | [diff] [blame] | 562 | fprintf(f_out, "%s;%d;%d", ts->name, ts->groupid, ts->error); |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 563 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 564 | show_ddir_status_terse(ts, rs, 0); |
| 565 | show_ddir_status_terse(ts, rs, 1); |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 566 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 567 | if (ts->total_run_time) { |
| 568 | double runt = (double) ts->total_run_time; |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 569 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 570 | usr_cpu = (double) ts->usr_time * 100 / runt; |
| 571 | sys_cpu = (double) ts->sys_time * 100 / runt; |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 572 | } else { |
| 573 | usr_cpu = 0; |
| 574 | sys_cpu = 0; |
| 575 | } |
| 576 | |
Jens Axboe | 6af019c | 2007-03-06 19:50:58 +0100 | [diff] [blame] | 577 | fprintf(f_out, ";%f%%;%f%%;%lu", usr_cpu, sys_cpu, ts->ctx); |
Jens Axboe | 2270890 | 2007-03-06 17:05:32 +0100 | [diff] [blame] | 578 | |
| 579 | stat_calc_dist(ts, io_u_dist); |
| 580 | stat_calc_lat(ts, io_u_lat); |
| 581 | |
Jens Axboe | 6af019c | 2007-03-06 19:50:58 +0100 | [diff] [blame] | 582 | fprintf(f_out, ";%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 Axboe | 2270890 | 2007-03-06 17:05:32 +0100 | [diff] [blame] | 583 | |
Jens Axboe | 6af019c | 2007-03-06 19:50:58 +0100 | [diff] [blame] | 584 | fprintf(f_out, ";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%\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]); |
| 585 | fprintf(f_out, ";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%", io_u_lat[6], io_u_lat[7], io_u_lat[8], io_u_lat[9], io_u_lat[10]); |
Jens Axboe | 2270890 | 2007-03-06 17:05:32 +0100 | [diff] [blame] | 586 | |
| 587 | if (ts->description) |
Jens Axboe | 6af019c | 2007-03-06 19:50:58 +0100 | [diff] [blame] | 588 | fprintf(f_out, ";%s", ts->description); |
Jens Axboe | 2270890 | 2007-03-06 17:05:32 +0100 | [diff] [blame] | 589 | |
| 590 | fprintf(f_out, "\n"); |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 591 | } |
| 592 | |
Jens Axboe | 197574e | 2007-03-08 15:35:11 +0100 | [diff] [blame] | 593 | static void sum_stat(struct io_stat *dst, struct io_stat *src, int nr) |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 594 | { |
| 595 | double mean, S; |
| 596 | |
| 597 | dst->min_val = min(dst->min_val, src->min_val); |
| 598 | dst->max_val = max(dst->max_val, src->max_val); |
| 599 | dst->samples += src->samples; |
| 600 | |
| 601 | /* |
| 602 | * Needs a new method for calculating stddev, we cannot just |
| 603 | * average them we do below for nr > 1 |
| 604 | */ |
| 605 | if (nr == 1) { |
| 606 | mean = src->mean; |
| 607 | S = src->S; |
| 608 | } else { |
Jens Axboe | c39cced | 2007-03-06 15:37:00 +0100 | [diff] [blame] | 609 | mean = ((src->mean * (double) (nr - 1)) + dst->mean) / ((double) nr); |
| 610 | S = ((src->S * (double) (nr - 1)) + dst->S) / ((double) nr); |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | dst->mean = mean; |
| 614 | dst->S = S; |
| 615 | } |
| 616 | |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 617 | void show_run_stats(void) |
| 618 | { |
| 619 | struct group_run_stats *runstats, *rs; |
| 620 | struct thread_data *td; |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 621 | struct thread_stat *threadstats, *ts; |
Jens Axboe | 197574e | 2007-03-08 15:35:11 +0100 | [diff] [blame] | 622 | int i, j, k, l, nr_ts, last_ts, idx; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 623 | |
| 624 | runstats = malloc(sizeof(struct group_run_stats) * (groupid + 1)); |
| 625 | |
| 626 | for (i = 0; i < groupid + 1; i++) { |
| 627 | rs = &runstats[i]; |
| 628 | |
| 629 | memset(rs, 0, sizeof(*rs)); |
| 630 | rs->min_bw[0] = rs->min_run[0] = ~0UL; |
| 631 | rs->min_bw[1] = rs->min_run[1] = ~0UL; |
| 632 | } |
| 633 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 634 | /* |
| 635 | * find out how many threads stats we need. if group reporting isn't |
| 636 | * enabled, it's one-per-td. |
| 637 | */ |
| 638 | nr_ts = 0; |
| 639 | last_ts = -1; |
Jens Axboe | 34572e2 | 2006-10-20 09:33:18 +0200 | [diff] [blame] | 640 | for_each_td(td, i) { |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 641 | if (!td->group_reporting) { |
| 642 | nr_ts++; |
| 643 | continue; |
| 644 | } |
| 645 | if (last_ts == td->groupid) |
| 646 | continue; |
| 647 | |
| 648 | last_ts = td->groupid; |
| 649 | nr_ts++; |
| 650 | } |
| 651 | |
| 652 | threadstats = malloc(nr_ts * sizeof(struct thread_stat)); |
| 653 | |
| 654 | for (i = 0; i < nr_ts; i++) { |
| 655 | ts = &threadstats[i]; |
| 656 | |
| 657 | memset(ts, 0, sizeof(*ts)); |
Jens Axboe | de64df0 | 2007-03-08 19:09:49 +0100 | [diff] [blame] | 658 | for (j = 0; j <= DDIR_WRITE; j++) { |
Jens Axboe | 197574e | 2007-03-08 15:35:11 +0100 | [diff] [blame] | 659 | ts->clat_stat[j].min_val = -1UL; |
| 660 | ts->slat_stat[j].min_val = -1UL; |
| 661 | ts->bw_stat[j].min_val = -1UL; |
| 662 | } |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | j = 0; |
| 666 | last_ts = -1; |
Jens Axboe | 197574e | 2007-03-08 15:35:11 +0100 | [diff] [blame] | 667 | idx = 0; |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 668 | for_each_td(td, i) { |
| 669 | ts = &threadstats[j]; |
| 670 | |
Jens Axboe | 197574e | 2007-03-08 15:35:11 +0100 | [diff] [blame] | 671 | idx++; |
Jens Axboe | 6586ee8 | 2007-03-06 19:46:09 +0100 | [diff] [blame] | 672 | ts->members++; |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 673 | |
| 674 | if (!ts->groupid) { |
Jens Axboe | 2dc84ba | 2007-03-06 15:46:33 +0100 | [diff] [blame] | 675 | /* |
| 676 | * These are per-group shared already |
| 677 | */ |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 678 | ts->name = td->name; |
| 679 | ts->description = td->description; |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 680 | ts->groupid = td->groupid; |
Jens Axboe | 2dc84ba | 2007-03-06 15:46:33 +0100 | [diff] [blame] | 681 | |
| 682 | /* |
| 683 | * first pid in group, not very useful... |
| 684 | */ |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 685 | ts->pid = td->pid; |
Jens Axboe | 2dc84ba | 2007-03-06 15:46:33 +0100 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | if (td->error && !ts->error) { |
| 689 | ts->error = td->error; |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 690 | ts->verror = td->verror; |
| 691 | } |
| 692 | |
Jens Axboe | de64df0 | 2007-03-08 19:09:49 +0100 | [diff] [blame] | 693 | for (l = 0; l <= DDIR_WRITE; l++) { |
Jens Axboe | 197574e | 2007-03-08 15:35:11 +0100 | [diff] [blame] | 694 | sum_stat(&ts->clat_stat[l], &td->ts.clat_stat[l], idx); |
| 695 | sum_stat(&ts->slat_stat[l], &td->ts.slat_stat[l], idx); |
| 696 | sum_stat(&ts->bw_stat[l], &td->ts.bw_stat[l], idx); |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 697 | |
Jens Axboe | 197574e | 2007-03-08 15:35:11 +0100 | [diff] [blame] | 698 | ts->stat_io_bytes[l] += td->ts.stat_io_bytes[l]; |
| 699 | ts->io_bytes[l] += td->ts.io_bytes[l]; |
| 700 | |
| 701 | if (ts->runtime[l] < td->ts.runtime[l]) |
| 702 | ts->runtime[l] = td->ts.runtime[l]; |
| 703 | } |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 704 | |
| 705 | ts->usr_time += td->ts.usr_time; |
| 706 | ts->sys_time += td->ts.sys_time; |
| 707 | ts->ctx += td->ts.ctx; |
| 708 | |
| 709 | for (k = 0; k < FIO_IO_U_MAP_NR; k++) |
| 710 | ts->io_u_map[k] += td->ts.io_u_map[k]; |
| 711 | for (k = 0; k < FIO_IO_U_LAT_NR; k++) |
| 712 | ts->io_u_lat[k] += td->ts.io_u_lat[k]; |
| 713 | |
| 714 | ts->total_io_u += td->ts.total_io_u; |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 715 | |
| 716 | ts->total_run_time += td->ts.total_run_time; |
| 717 | |
| 718 | if (!td->group_reporting) { |
Jens Axboe | 197574e | 2007-03-08 15:35:11 +0100 | [diff] [blame] | 719 | idx = 0; |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 720 | j++; |
| 721 | continue; |
| 722 | } |
| 723 | if (last_ts == td->groupid) |
| 724 | continue; |
| 725 | |
| 726 | if (last_ts != -1) { |
Jens Axboe | 197574e | 2007-03-08 15:35:11 +0100 | [diff] [blame] | 727 | idx = 0; |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 728 | j++; |
| 729 | } |
| 730 | |
| 731 | last_ts = td->groupid; |
| 732 | } |
| 733 | |
| 734 | for (i = 0; i < nr_ts; i++) { |
Jens Axboe | 94370ac | 2007-03-08 15:28:10 +0100 | [diff] [blame] | 735 | unsigned long long bw; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 736 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 737 | ts = &threadstats[i]; |
| 738 | rs = &runstats[ts->groupid]; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 739 | |
Jens Axboe | de64df0 | 2007-03-08 19:09:49 +0100 | [diff] [blame] | 740 | for (j = 0; j <= DDIR_WRITE; j++) { |
Jens Axboe | 94370ac | 2007-03-08 15:28:10 +0100 | [diff] [blame] | 741 | if (!ts->runtime[j]) |
| 742 | continue; |
| 743 | if (ts->runtime[j] < rs->min_run[j] || !rs->min_run[j]) |
| 744 | rs->min_run[j] = ts->runtime[j]; |
| 745 | if (ts->runtime[j] > rs->max_run[j]) |
| 746 | rs->max_run[j] = ts->runtime[j]; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 747 | |
Jens Axboe | 94370ac | 2007-03-08 15:28:10 +0100 | [diff] [blame] | 748 | bw = 0; |
| 749 | if (ts->runtime[j]) |
| 750 | bw = ts->io_bytes[j] / (unsigned long long) ts->runtime[j]; |
| 751 | if (bw < rs->min_bw[j]) |
| 752 | rs->min_bw[j] = bw; |
| 753 | if (bw > rs->max_bw[j]) |
| 754 | rs->max_bw[j] = bw; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 755 | |
Jens Axboe | 94370ac | 2007-03-08 15:28:10 +0100 | [diff] [blame] | 756 | rs->io_kb[j] += ts->io_bytes[j] >> 10; |
| 757 | } |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | for (i = 0; i < groupid + 1; i++) { |
| 761 | rs = &runstats[i]; |
| 762 | |
| 763 | if (rs->max_run[0]) |
| 764 | rs->agg[0] = (rs->io_kb[0]*1024) / rs->max_run[0]; |
| 765 | if (rs->max_run[1]) |
| 766 | rs->agg[1] = (rs->io_kb[1]*1024) / rs->max_run[1]; |
| 767 | } |
| 768 | |
| 769 | /* |
| 770 | * don't overwrite last signal output |
| 771 | */ |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 772 | if (!terse_output) |
| 773 | printf("\n"); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 774 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 775 | for (i = 0; i < nr_ts; i++) { |
| 776 | ts = &threadstats[i]; |
| 777 | rs = &runstats[ts->groupid]; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 778 | |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 779 | if (terse_output) |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 780 | show_thread_status_terse(ts, rs); |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 781 | else |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 782 | show_thread_status(ts, rs); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 783 | } |
| 784 | |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 785 | if (!terse_output) { |
| 786 | for (i = 0; i < groupid + 1; i++) |
| 787 | show_group_stats(&runstats[i], i); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 788 | |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 789 | show_disk_util(); |
| 790 | } |
Jens Axboe | eecf272 | 2006-10-20 14:00:36 +0200 | [diff] [blame] | 791 | |
| 792 | free(runstats); |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 793 | free(threadstats); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 794 | } |
| 795 | |
Jens Axboe | 6870408 | 2007-01-10 19:56:37 +0100 | [diff] [blame] | 796 | static inline void add_stat_sample(struct io_stat *is, unsigned long data) |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 797 | { |
Jens Axboe | 6870408 | 2007-01-10 19:56:37 +0100 | [diff] [blame] | 798 | double val = data; |
Jens Axboe | 6660cc6 | 2007-03-06 15:48:38 +0100 | [diff] [blame] | 799 | double delta; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 800 | |
Jens Axboe | 6870408 | 2007-01-10 19:56:37 +0100 | [diff] [blame] | 801 | if (data > is->max_val) |
| 802 | is->max_val = data; |
| 803 | if (data < is->min_val) |
| 804 | is->min_val = data; |
| 805 | |
| 806 | delta = val - is->mean; |
Jens Axboe | 6660cc6 | 2007-03-06 15:48:38 +0100 | [diff] [blame] | 807 | is->mean += delta / (is->samples + 1.0); |
Jens Axboe | 6870408 | 2007-01-10 19:56:37 +0100 | [diff] [blame] | 808 | is->S += delta * (val - is->mean); |
| 809 | |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 810 | is->samples++; |
| 811 | } |
| 812 | |
Jens Axboe | bb3884d | 2007-01-17 17:23:11 +1100 | [diff] [blame] | 813 | static void __add_log_sample(struct io_log *iolog, unsigned long val, |
| 814 | enum fio_ddir ddir, unsigned long time) |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 815 | { |
| 816 | if (iolog->nr_samples == iolog->max_samples) { |
| 817 | int new_size = sizeof(struct io_sample) * iolog->max_samples*2; |
| 818 | |
| 819 | iolog->log = realloc(iolog->log, new_size); |
| 820 | iolog->max_samples <<= 1; |
| 821 | } |
| 822 | |
| 823 | iolog->log[iolog->nr_samples].val = val; |
Jens Axboe | bb3884d | 2007-01-17 17:23:11 +1100 | [diff] [blame] | 824 | iolog->log[iolog->nr_samples].time = time; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 825 | iolog->log[iolog->nr_samples].ddir = ddir; |
| 826 | iolog->nr_samples++; |
| 827 | } |
| 828 | |
Jens Axboe | bb3884d | 2007-01-17 17:23:11 +1100 | [diff] [blame] | 829 | static void add_log_sample(struct thread_data *td, struct io_log *iolog, |
| 830 | unsigned long val, enum fio_ddir ddir) |
| 831 | { |
| 832 | __add_log_sample(iolog, val, ddir, mtime_since_now(&td->epoch)); |
| 833 | } |
| 834 | |
| 835 | void add_agg_sample(unsigned long val, enum fio_ddir ddir) |
| 836 | { |
| 837 | struct io_log *iolog = agg_io_log[ddir]; |
| 838 | |
| 839 | __add_log_sample(iolog, val, ddir, mtime_since_genesis()); |
| 840 | } |
| 841 | |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 842 | void add_clat_sample(struct thread_data *td, enum fio_ddir ddir, |
| 843 | unsigned long msec) |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 844 | { |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 845 | struct thread_stat *ts = &td->ts; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 846 | |
Jens Axboe | 079ad09 | 2007-02-20 13:58:20 +0100 | [diff] [blame] | 847 | add_stat_sample(&ts->clat_stat[ddir], msec); |
| 848 | |
| 849 | if (ts->clat_log) |
| 850 | add_log_sample(td, ts->clat_log, msec, ddir); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 851 | } |
| 852 | |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 853 | void add_slat_sample(struct thread_data *td, enum fio_ddir ddir, |
| 854 | unsigned long msec) |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 855 | { |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 856 | struct thread_stat *ts = &td->ts; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 857 | |
Jens Axboe | 079ad09 | 2007-02-20 13:58:20 +0100 | [diff] [blame] | 858 | add_stat_sample(&ts->slat_stat[ddir], msec); |
| 859 | |
| 860 | if (ts->slat_log) |
| 861 | add_log_sample(td, ts->slat_log, msec, ddir); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 862 | } |
| 863 | |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 864 | void add_bw_sample(struct thread_data *td, enum fio_ddir ddir, |
| 865 | struct timeval *t) |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 866 | { |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 867 | struct thread_stat *ts = &td->ts; |
Jens Axboe | 079ad09 | 2007-02-20 13:58:20 +0100 | [diff] [blame] | 868 | unsigned long spent = mtime_since(&ts->stat_sample_time[ddir], t); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 869 | unsigned long rate; |
| 870 | |
| 871 | if (spent < td->bw_avg_time) |
| 872 | return; |
| 873 | |
Jens Axboe | 079ad09 | 2007-02-20 13:58:20 +0100 | [diff] [blame] | 874 | rate = (td->this_io_bytes[ddir] - ts->stat_io_bytes[ddir]) / spent; |
| 875 | add_stat_sample(&ts->bw_stat[ddir], rate); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 876 | |
Jens Axboe | 079ad09 | 2007-02-20 13:58:20 +0100 | [diff] [blame] | 877 | if (ts->bw_log) |
| 878 | add_log_sample(td, ts->bw_log, rate, ddir); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 879 | |
Jens Axboe | 079ad09 | 2007-02-20 13:58:20 +0100 | [diff] [blame] | 880 | fio_gettime(&ts->stat_sample_time[ddir], NULL); |
| 881 | ts->stat_io_bytes[ddir] = td->this_io_bytes[ddir]; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 882 | } |