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 | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 14 | |
Jens Axboe | dbe1125 | 2007-02-11 00:19:51 +0100 | [diff] [blame] | 15 | /* |
| 16 | * Cheasy number->string conversion, complete with carry rounding error. |
| 17 | */ |
| 18 | static char *num2str(unsigned long num, int maxlen, int base) |
| 19 | { |
| 20 | /* |
| 21 | * could be passed in for 10^3 base, but every caller expects |
| 22 | * 2^10 base right now. |
| 23 | */ |
| 24 | const int thousand = 1024; |
| 25 | char postfix[] = { 'K', 'M', 'G', 'P' }; |
| 26 | char *buf; |
| 27 | int i; |
| 28 | |
| 29 | buf = malloc(128); |
| 30 | |
| 31 | for (i = 0; base > 1; i++) |
| 32 | base /= thousand; |
| 33 | |
| 34 | do { |
| 35 | int len, carry = 0; |
| 36 | |
| 37 | len = sprintf(buf, "%'lu", num); |
| 38 | if (len <= maxlen) { |
| 39 | buf[len] = postfix[i]; |
| 40 | buf[len + 1] = '\0'; |
| 41 | return buf; |
| 42 | } |
| 43 | |
| 44 | if ((num % thousand) >= (thousand / 2)) |
| 45 | carry = 1; |
| 46 | |
| 47 | num /= thousand; |
| 48 | num += carry; |
| 49 | i++; |
| 50 | } while (i <= 4); |
| 51 | |
| 52 | return buf; |
| 53 | } |
| 54 | |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 55 | static int get_io_ticks(struct disk_util *du, struct disk_util_stat *dus) |
| 56 | { |
| 57 | unsigned in_flight; |
| 58 | char line[256]; |
| 59 | FILE *f; |
| 60 | char *p; |
| 61 | |
| 62 | f = fopen(du->path, "r"); |
| 63 | if (!f) |
| 64 | return 1; |
| 65 | |
| 66 | p = fgets(line, sizeof(line), f); |
| 67 | if (!p) { |
| 68 | fclose(f); |
| 69 | return 1; |
| 70 | } |
| 71 | |
| 72 | 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) { |
| 73 | fclose(f); |
| 74 | return 1; |
| 75 | } |
| 76 | |
| 77 | fclose(f); |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | static void update_io_tick_disk(struct disk_util *du) |
| 82 | { |
| 83 | struct disk_util_stat __dus, *dus, *ldus; |
| 84 | struct timeval t; |
| 85 | |
| 86 | if (get_io_ticks(du, &__dus)) |
| 87 | return; |
| 88 | |
| 89 | dus = &du->dus; |
| 90 | ldus = &du->last_dus; |
| 91 | |
| 92 | dus->sectors[0] += (__dus.sectors[0] - ldus->sectors[0]); |
| 93 | dus->sectors[1] += (__dus.sectors[1] - ldus->sectors[1]); |
| 94 | dus->ios[0] += (__dus.ios[0] - ldus->ios[0]); |
| 95 | dus->ios[1] += (__dus.ios[1] - ldus->ios[1]); |
| 96 | dus->merges[0] += (__dus.merges[0] - ldus->merges[0]); |
| 97 | dus->merges[1] += (__dus.merges[1] - ldus->merges[1]); |
| 98 | dus->ticks[0] += (__dus.ticks[0] - ldus->ticks[0]); |
| 99 | dus->ticks[1] += (__dus.ticks[1] - ldus->ticks[1]); |
| 100 | dus->io_ticks += (__dus.io_ticks - ldus->io_ticks); |
| 101 | dus->time_in_queue += (__dus.time_in_queue - ldus->time_in_queue); |
| 102 | |
Jens Axboe | 02bcaa8 | 2006-11-24 10:42:00 +0100 | [diff] [blame] | 103 | fio_gettime(&t, NULL); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 104 | du->msec += mtime_since(&du->time, &t); |
| 105 | memcpy(&du->time, &t, sizeof(t)); |
| 106 | memcpy(ldus, &__dus, sizeof(__dus)); |
| 107 | } |
| 108 | |
| 109 | void update_io_ticks(void) |
| 110 | { |
| 111 | struct list_head *entry; |
| 112 | struct disk_util *du; |
| 113 | |
| 114 | list_for_each(entry, &disk_list) { |
| 115 | du = list_entry(entry, struct disk_util, list); |
| 116 | update_io_tick_disk(du); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | static int disk_util_exists(dev_t dev) |
| 121 | { |
| 122 | struct list_head *entry; |
| 123 | struct disk_util *du; |
| 124 | |
| 125 | list_for_each(entry, &disk_list) { |
| 126 | du = list_entry(entry, struct disk_util, list); |
| 127 | |
| 128 | if (du->dev == dev) |
| 129 | return 1; |
| 130 | } |
| 131 | |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | static void disk_util_add(dev_t dev, char *path) |
| 136 | { |
Jens Axboe | 1188caf | 2007-01-08 10:57:27 +0100 | [diff] [blame] | 137 | struct disk_util *du, *__du; |
| 138 | struct list_head *entry; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 139 | |
Jens Axboe | 1188caf | 2007-01-08 10:57:27 +0100 | [diff] [blame] | 140 | du = malloc(sizeof(*du)); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 141 | memset(du, 0, sizeof(*du)); |
| 142 | INIT_LIST_HEAD(&du->list); |
| 143 | sprintf(du->path, "%s/stat", path); |
| 144 | du->name = strdup(basename(path)); |
| 145 | du->dev = dev; |
| 146 | |
Jens Axboe | 1188caf | 2007-01-08 10:57:27 +0100 | [diff] [blame] | 147 | list_for_each(entry, &disk_list) { |
| 148 | __du = list_entry(entry, struct disk_util, list); |
| 149 | |
| 150 | if (!strcmp(du->name, __du->name)) { |
| 151 | free(du->name); |
| 152 | free(du); |
| 153 | return; |
| 154 | } |
| 155 | } |
| 156 | |
Jens Axboe | 02bcaa8 | 2006-11-24 10:42:00 +0100 | [diff] [blame] | 157 | fio_gettime(&du->time, NULL); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 158 | get_io_ticks(du, &du->last_dus); |
| 159 | |
| 160 | list_add_tail(&du->list, &disk_list); |
| 161 | } |
| 162 | |
| 163 | static int check_dev_match(dev_t dev, char *path) |
| 164 | { |
| 165 | unsigned int major, minor; |
| 166 | char line[256], *p; |
| 167 | FILE *f; |
| 168 | |
| 169 | f = fopen(path, "r"); |
| 170 | if (!f) { |
| 171 | perror("open path"); |
| 172 | return 1; |
| 173 | } |
| 174 | |
| 175 | p = fgets(line, sizeof(line), f); |
| 176 | if (!p) { |
| 177 | fclose(f); |
| 178 | return 1; |
| 179 | } |
| 180 | |
| 181 | if (sscanf(p, "%u:%u", &major, &minor) != 2) { |
| 182 | fclose(f); |
| 183 | return 1; |
| 184 | } |
| 185 | |
| 186 | if (((major << 8) | minor) == dev) { |
| 187 | fclose(f); |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | fclose(f); |
| 192 | return 1; |
| 193 | } |
| 194 | |
| 195 | static int find_block_dir(dev_t dev, char *path) |
| 196 | { |
| 197 | struct dirent *dir; |
| 198 | struct stat st; |
| 199 | int found = 0; |
| 200 | DIR *D; |
| 201 | |
| 202 | D = opendir(path); |
| 203 | if (!D) |
| 204 | return 0; |
| 205 | |
| 206 | while ((dir = readdir(D)) != NULL) { |
| 207 | char full_path[256]; |
| 208 | |
| 209 | if (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, "..")) |
| 210 | continue; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 211 | |
| 212 | sprintf(full_path, "%s/%s", path, dir->d_name); |
| 213 | |
| 214 | if (!strcmp(dir->d_name, "dev")) { |
| 215 | if (!check_dev_match(dev, full_path)) { |
| 216 | found = 1; |
| 217 | break; |
| 218 | } |
| 219 | } |
| 220 | |
Jens Axboe | 3307d65 | 2006-07-17 18:15:41 +0200 | [diff] [blame] | 221 | if (lstat(full_path, &st) == -1) { |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 222 | perror("stat"); |
| 223 | break; |
| 224 | } |
| 225 | |
| 226 | if (!S_ISDIR(st.st_mode) || S_ISLNK(st.st_mode)) |
| 227 | continue; |
| 228 | |
| 229 | found = find_block_dir(dev, full_path); |
| 230 | if (found) { |
| 231 | strcpy(path, full_path); |
| 232 | break; |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | closedir(D); |
| 237 | return found; |
| 238 | } |
| 239 | |
| 240 | void init_disk_util(struct thread_data *td) |
| 241 | { |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 242 | struct fio_file *f; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 243 | struct stat st; |
Jens Axboe | 0bbab0e | 2006-11-02 09:18:36 +0100 | [diff] [blame] | 244 | char foo[PATH_MAX], tmp[PATH_MAX]; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 245 | dev_t dev; |
| 246 | char *p; |
| 247 | |
Jens Axboe | 4d9345a | 2007-02-07 13:14:57 +0100 | [diff] [blame] | 248 | if (!td->do_disk_util || (td->io_ops->flags & (FIO_NETIO | FIO_NULLIO))) |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 249 | return; |
| 250 | |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 251 | /* |
| 252 | * Just use the same file, they are on the same device. |
| 253 | */ |
| 254 | f = &td->files[0]; |
| 255 | if (!stat(f->file_name, &st)) { |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 256 | if (S_ISBLK(st.st_mode)) |
| 257 | dev = st.st_rdev; |
| 258 | else |
| 259 | dev = st.st_dev; |
| 260 | } else { |
| 261 | /* |
| 262 | * must be a file, open "." in that path |
| 263 | */ |
Jens Axboe | 0bbab0e | 2006-11-02 09:18:36 +0100 | [diff] [blame] | 264 | strncpy(foo, f->file_name, PATH_MAX - 1); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 265 | p = dirname(foo); |
| 266 | if (stat(p, &st)) { |
| 267 | perror("disk util stat"); |
| 268 | return; |
| 269 | } |
| 270 | |
| 271 | dev = st.st_dev; |
| 272 | } |
| 273 | |
| 274 | if (disk_util_exists(dev)) |
| 275 | return; |
| 276 | |
| 277 | sprintf(foo, "/sys/block"); |
| 278 | if (!find_block_dir(dev, foo)) |
| 279 | return; |
| 280 | |
| 281 | /* |
| 282 | * If there's a ../queue/ directory there, we are inside a partition. |
| 283 | * Check if that is the case and jump back. For loop/md/dm etc we |
| 284 | * are already in the right spot. |
| 285 | */ |
| 286 | sprintf(tmp, "%s/../queue", foo); |
| 287 | if (!stat(tmp, &st)) { |
| 288 | p = dirname(foo); |
| 289 | sprintf(tmp, "%s/queue", p); |
| 290 | if (stat(tmp, &st)) { |
Jens Axboe | 3b70d7e | 2006-06-08 21:48:46 +0200 | [diff] [blame] | 291 | log_err("unknown sysfs layout\n"); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 292 | return; |
| 293 | } |
Jens Axboe | 0bbab0e | 2006-11-02 09:18:36 +0100 | [diff] [blame] | 294 | strncpy(tmp, p, PATH_MAX - 1); |
Jens Axboe | 8458500 | 2006-10-19 20:26:22 +0200 | [diff] [blame] | 295 | sprintf(foo, "%s", tmp); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 296 | } |
| 297 | |
Jens Axboe | eecf272 | 2006-10-20 14:00:36 +0200 | [diff] [blame] | 298 | if (td->ioscheduler) |
| 299 | td->sysfs_root = strdup(foo); |
| 300 | |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 301 | disk_util_add(dev, foo); |
| 302 | } |
| 303 | |
| 304 | void disk_util_timer_arm(void) |
| 305 | { |
| 306 | itimer.it_value.tv_sec = 0; |
| 307 | itimer.it_value.tv_usec = DISK_UTIL_MSEC * 1000; |
| 308 | setitimer(ITIMER_REAL, &itimer, NULL); |
| 309 | } |
| 310 | |
| 311 | void update_rusage_stat(struct thread_data *td) |
| 312 | { |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 313 | getrusage(RUSAGE_SELF, &td->ru_end); |
| 314 | |
| 315 | td->usr_time += mtime_since(&td->ru_start.ru_utime, &td->ru_end.ru_utime); |
| 316 | td->sys_time += mtime_since(&td->ru_start.ru_stime, &td->ru_end.ru_stime); |
| 317 | td->ctx += td->ru_end.ru_nvcsw + td->ru_end.ru_nivcsw - (td->ru_start.ru_nvcsw + td->ru_start.ru_nivcsw); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 318 | |
| 319 | memcpy(&td->ru_start, &td->ru_end, sizeof(td->ru_end)); |
| 320 | } |
| 321 | |
| 322 | static int calc_lat(struct io_stat *is, unsigned long *min, unsigned long *max, |
| 323 | double *mean, double *dev) |
| 324 | { |
Jens Axboe | 6870408 | 2007-01-10 19:56:37 +0100 | [diff] [blame] | 325 | double n = is->samples; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 326 | |
| 327 | if (is->samples == 0) |
| 328 | return 0; |
| 329 | |
| 330 | *min = is->min_val; |
| 331 | *max = is->max_val; |
| 332 | |
| 333 | n = (double) is->samples; |
Jens Axboe | 6870408 | 2007-01-10 19:56:37 +0100 | [diff] [blame] | 334 | *mean = is->mean; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 335 | |
Jens Axboe | 6870408 | 2007-01-10 19:56:37 +0100 | [diff] [blame] | 336 | if (n > 1.0) |
| 337 | *dev = sqrt(is->S / (n - 1.0)); |
Jens Axboe | ef9c5c4 | 2007-01-03 14:21:13 +0100 | [diff] [blame] | 338 | else |
Jens Axboe | 6870408 | 2007-01-10 19:56:37 +0100 | [diff] [blame] | 339 | *dev = -1.0; |
Jens Axboe | ef9c5c4 | 2007-01-03 14:21:13 +0100 | [diff] [blame] | 340 | |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 341 | return 1; |
| 342 | } |
| 343 | |
| 344 | static void show_group_stats(struct group_run_stats *rs, int id) |
| 345 | { |
Jens Axboe | dbe1125 | 2007-02-11 00:19:51 +0100 | [diff] [blame] | 346 | char *p1, *p2, *p3, *p4; |
| 347 | const char *ddir_str[] = { " READ", " WRITE" }; |
| 348 | int i; |
| 349 | |
Jens Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 350 | fprintf(f_out, "\nRun status group %d (all jobs):\n", id); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 351 | |
Jens Axboe | dbe1125 | 2007-02-11 00:19:51 +0100 | [diff] [blame] | 352 | for (i = 0; i <= DDIR_WRITE; i++) { |
| 353 | if (!rs->max_run[i]) |
| 354 | continue; |
| 355 | |
| 356 | p1 = num2str(rs->io_kb[i], 6, 1); |
| 357 | p2 = num2str(rs->agg[i], 6, 1); |
| 358 | p3 = num2str(rs->min_bw[i], 6, 1); |
| 359 | p4 = num2str(rs->max_bw[i], 6, 1); |
| 360 | |
| 361 | 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[0], rs->max_run[0]); |
| 362 | |
| 363 | free(p1); |
| 364 | free(p2); |
| 365 | free(p3); |
| 366 | free(p4); |
| 367 | } |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | static void show_disk_util(void) |
| 371 | { |
| 372 | struct disk_util_stat *dus; |
Jens Axboe | b4a6a59 | 2006-10-20 13:54:47 +0200 | [diff] [blame] | 373 | struct list_head *entry, *next; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 374 | struct disk_util *du; |
| 375 | double util; |
| 376 | |
Jens Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 377 | fprintf(f_out, "\nDisk stats (read/write):\n"); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 378 | |
| 379 | list_for_each(entry, &disk_list) { |
| 380 | du = list_entry(entry, struct disk_util, list); |
| 381 | dus = &du->dus; |
| 382 | |
| 383 | util = (double) 100 * du->dus.io_ticks / (double) du->msec; |
| 384 | if (util > 100.0) |
| 385 | util = 100.0; |
| 386 | |
Jens Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 387 | 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] | 388 | } |
Jens Axboe | b4a6a59 | 2006-10-20 13:54:47 +0200 | [diff] [blame] | 389 | |
| 390 | /* |
| 391 | * now free the list |
| 392 | */ |
| 393 | list_for_each_safe(entry, next, &disk_list) { |
| 394 | list_del(entry); |
| 395 | du = list_entry(entry, struct disk_util, list); |
| 396 | free(du->name); |
| 397 | free(du); |
| 398 | } |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | static void show_ddir_status(struct thread_data *td, struct group_run_stats *rs, |
| 402 | int ddir) |
| 403 | { |
Jens Axboe | 3c9b60c | 2006-11-07 08:36:14 +0100 | [diff] [blame] | 404 | const char *ddir_str[] = { "read ", "write" }; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 405 | unsigned long min, max; |
| 406 | unsigned long long bw; |
| 407 | double mean, dev; |
Jens Axboe | dbe1125 | 2007-02-11 00:19:51 +0100 | [diff] [blame] | 408 | char *io_p, *bw_p; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 409 | |
| 410 | if (!td->runtime[ddir]) |
| 411 | return; |
| 412 | |
| 413 | bw = td->io_bytes[ddir] / td->runtime[ddir]; |
Jens Axboe | dbe1125 | 2007-02-11 00:19:51 +0100 | [diff] [blame] | 414 | io_p = num2str(td->io_bytes[ddir] >> 10, 6, 1); |
| 415 | bw_p = num2str(bw, 6, 1); |
| 416 | |
| 417 | fprintf(f_out, " %s: io=%siB, bw=%siB/s, runt=%6lumsec\n", ddir_str[ddir], io_p, bw_p, td->runtime[ddir]); |
| 418 | |
| 419 | free(io_p); |
| 420 | free(bw_p); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 421 | |
| 422 | if (calc_lat(&td->slat_stat[ddir], &min, &max, &mean, &dev)) |
Jens Axboe | 6104ddb | 2007-01-11 14:24:29 +0100 | [diff] [blame] | 423 | 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] | 424 | |
| 425 | if (calc_lat(&td->clat_stat[ddir], &min, &max, &mean, &dev)) |
Jens Axboe | 6104ddb | 2007-01-11 14:24:29 +0100 | [diff] [blame] | 426 | 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] | 427 | |
| 428 | if (calc_lat(&td->bw_stat[ddir], &min, &max, &mean, &dev)) { |
| 429 | double p_of_agg; |
| 430 | |
| 431 | p_of_agg = mean * 100 / (double) rs->agg[ddir]; |
Jens Axboe | 6104ddb | 2007-01-11 14:24:29 +0100 | [diff] [blame] | 432 | 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] | 433 | } |
| 434 | } |
| 435 | |
| 436 | static void show_thread_status(struct thread_data *td, |
| 437 | struct group_run_stats *rs) |
| 438 | { |
| 439 | double usr_cpu, sys_cpu; |
Jens Axboe | 6900899 | 2006-11-24 13:12:56 +0100 | [diff] [blame] | 440 | unsigned long runtime; |
Jens Axboe | 71619dc | 2007-01-13 23:56:33 +0100 | [diff] [blame] | 441 | double io_u_dist[FIO_IO_U_MAP_NR]; |
| 442 | int i; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 443 | |
| 444 | if (!(td->io_bytes[0] + td->io_bytes[1]) && !td->error) |
| 445 | return; |
| 446 | |
Jens Axboe | bb3884d | 2007-01-17 17:23:11 +1100 | [diff] [blame] | 447 | fprintf(f_out, "%s: (groupid=%d): err=%2d: pid=%d\n",td->name, td->groupid, td->error, td->pid); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 448 | |
| 449 | show_ddir_status(td, rs, td->ddir); |
| 450 | if (td->io_bytes[td->ddir ^ 1]) |
| 451 | show_ddir_status(td, rs, td->ddir ^ 1); |
| 452 | |
Jens Axboe | 6900899 | 2006-11-24 13:12:56 +0100 | [diff] [blame] | 453 | runtime = mtime_since(&td->epoch, &td->end_time); |
| 454 | if (runtime) { |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 455 | double runt = (double) runtime; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 456 | |
| 457 | usr_cpu = (double) td->usr_time * 100 / runt; |
| 458 | sys_cpu = (double) td->sys_time * 100 / runt; |
| 459 | } else { |
| 460 | usr_cpu = 0; |
| 461 | sys_cpu = 0; |
| 462 | } |
| 463 | |
Jens Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 464 | fprintf(f_out, " cpu : usr=%3.2f%%, sys=%3.2f%%, ctx=%lu\n", usr_cpu, sys_cpu, td->ctx); |
Jens Axboe | 71619dc | 2007-01-13 23:56:33 +0100 | [diff] [blame] | 465 | |
| 466 | /* |
| 467 | * Do depth distribution calculations |
| 468 | */ |
| 469 | for (i = 0; i < FIO_IO_U_MAP_NR; i++) { |
| 470 | io_u_dist[i] = (double) td->io_u_map[i] / (double) td->total_io_u; |
| 471 | io_u_dist[i] *= 100.0; |
| 472 | } |
| 473 | |
Jens Axboe | 5d45807 | 2007-01-13 23:59:00 +0100 | [diff] [blame] | 474 | 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] | 475 | |
| 476 | if (td->description) |
| 477 | fprintf(f_out, "%s\n", td->description); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 478 | } |
| 479 | |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 480 | static void show_ddir_status_terse(struct thread_data *td, |
| 481 | struct group_run_stats *rs, int ddir) |
| 482 | { |
| 483 | unsigned long min, max; |
| 484 | unsigned long long bw; |
| 485 | double mean, dev; |
| 486 | |
| 487 | bw = 0; |
| 488 | if (td->runtime[ddir]) |
| 489 | bw = td->io_bytes[ddir] / td->runtime[ddir]; |
| 490 | |
| 491 | fprintf(f_out, ",%llu,%llu,%lu", td->io_bytes[ddir] >> 10, bw, td->runtime[ddir]); |
| 492 | |
| 493 | if (calc_lat(&td->slat_stat[ddir], &min, &max, &mean, &dev)) |
| 494 | fprintf(f_out, ",%lu,%lu,%f,%f", min, max, mean, dev); |
| 495 | else |
| 496 | fprintf(f_out, ",%lu,%lu,%f,%f", 0UL, 0UL, 0.0, 0.0); |
| 497 | |
| 498 | if (calc_lat(&td->clat_stat[ddir], &min, &max, &mean, &dev)) |
| 499 | fprintf(f_out, ",%lu,%lu,%f,%f", min, max, mean, dev); |
| 500 | else |
| 501 | fprintf(f_out, ",%lu,%lu,%f,%f", 0UL, 0UL, 0.0, 0.0); |
| 502 | |
| 503 | if (calc_lat(&td->bw_stat[ddir], &min, &max, &mean, &dev)) { |
| 504 | double p_of_agg; |
| 505 | |
| 506 | p_of_agg = mean * 100 / (double) rs->agg[ddir]; |
| 507 | fprintf(f_out, ",%lu,%lu,%f%%,%f,%f", min, max, p_of_agg, mean, dev); |
| 508 | } else |
| 509 | fprintf(f_out, ",%lu,%lu,%f%%,%f,%f", 0UL, 0UL, 0.0, 0.0, 0.0); |
| 510 | |
| 511 | } |
| 512 | |
| 513 | |
| 514 | static void show_thread_status_terse(struct thread_data *td, |
| 515 | struct group_run_stats *rs) |
| 516 | { |
| 517 | double usr_cpu, sys_cpu; |
| 518 | |
| 519 | fprintf(f_out, "%s,%d,%d",td->name, td->groupid, td->error); |
| 520 | |
| 521 | show_ddir_status_terse(td, rs, 0); |
| 522 | show_ddir_status_terse(td, rs, 1); |
| 523 | |
| 524 | if (td->runtime[0] + td->runtime[1]) { |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 525 | double runt = (double) (td->runtime[0] + td->runtime[1]); |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 526 | |
| 527 | usr_cpu = (double) td->usr_time * 100 / runt; |
| 528 | sys_cpu = (double) td->sys_time * 100 / runt; |
| 529 | } else { |
| 530 | usr_cpu = 0; |
| 531 | sys_cpu = 0; |
| 532 | } |
| 533 | |
| 534 | fprintf(f_out, ",%f%%,%f%%,%lu\n", usr_cpu, sys_cpu, td->ctx); |
| 535 | } |
| 536 | |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 537 | void show_run_stats(void) |
| 538 | { |
| 539 | struct group_run_stats *runstats, *rs; |
| 540 | struct thread_data *td; |
| 541 | int i; |
| 542 | |
| 543 | runstats = malloc(sizeof(struct group_run_stats) * (groupid + 1)); |
| 544 | |
| 545 | for (i = 0; i < groupid + 1; i++) { |
| 546 | rs = &runstats[i]; |
| 547 | |
| 548 | memset(rs, 0, sizeof(*rs)); |
| 549 | rs->min_bw[0] = rs->min_run[0] = ~0UL; |
| 550 | rs->min_bw[1] = rs->min_run[1] = ~0UL; |
| 551 | } |
| 552 | |
Jens Axboe | 34572e2 | 2006-10-20 09:33:18 +0200 | [diff] [blame] | 553 | for_each_td(td, i) { |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 554 | unsigned long long rbw, wbw; |
| 555 | |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 556 | if (td->error) { |
Jens Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 557 | fprintf(f_out, "%s: %s\n", td->name, td->verror); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 558 | continue; |
| 559 | } |
| 560 | |
| 561 | rs = &runstats[td->groupid]; |
| 562 | |
| 563 | if (td->runtime[0] < rs->min_run[0] || !rs->min_run[0]) |
| 564 | rs->min_run[0] = td->runtime[0]; |
| 565 | if (td->runtime[0] > rs->max_run[0]) |
| 566 | rs->max_run[0] = td->runtime[0]; |
| 567 | if (td->runtime[1] < rs->min_run[1] || !rs->min_run[1]) |
| 568 | rs->min_run[1] = td->runtime[1]; |
| 569 | if (td->runtime[1] > rs->max_run[1]) |
| 570 | rs->max_run[1] = td->runtime[1]; |
| 571 | |
| 572 | rbw = wbw = 0; |
| 573 | if (td->runtime[0]) |
| 574 | rbw = td->io_bytes[0] / (unsigned long long) td->runtime[0]; |
| 575 | if (td->runtime[1]) |
| 576 | wbw = td->io_bytes[1] / (unsigned long long) td->runtime[1]; |
| 577 | |
| 578 | if (rbw < rs->min_bw[0]) |
| 579 | rs->min_bw[0] = rbw; |
| 580 | if (wbw < rs->min_bw[1]) |
| 581 | rs->min_bw[1] = wbw; |
| 582 | if (rbw > rs->max_bw[0]) |
| 583 | rs->max_bw[0] = rbw; |
| 584 | if (wbw > rs->max_bw[1]) |
| 585 | rs->max_bw[1] = wbw; |
| 586 | |
| 587 | rs->io_kb[0] += td->io_bytes[0] >> 10; |
| 588 | rs->io_kb[1] += td->io_bytes[1] >> 10; |
| 589 | } |
| 590 | |
| 591 | for (i = 0; i < groupid + 1; i++) { |
| 592 | rs = &runstats[i]; |
| 593 | |
| 594 | if (rs->max_run[0]) |
| 595 | rs->agg[0] = (rs->io_kb[0]*1024) / rs->max_run[0]; |
| 596 | if (rs->max_run[1]) |
| 597 | rs->agg[1] = (rs->io_kb[1]*1024) / rs->max_run[1]; |
| 598 | } |
| 599 | |
| 600 | /* |
| 601 | * don't overwrite last signal output |
| 602 | */ |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 603 | if (!terse_output) |
| 604 | printf("\n"); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 605 | |
Jens Axboe | 34572e2 | 2006-10-20 09:33:18 +0200 | [diff] [blame] | 606 | for_each_td(td, i) { |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 607 | rs = &runstats[td->groupid]; |
| 608 | |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 609 | if (terse_output) |
| 610 | show_thread_status_terse(td, rs); |
| 611 | else |
| 612 | show_thread_status(td, rs); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 613 | } |
| 614 | |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 615 | if (!terse_output) { |
| 616 | for (i = 0; i < groupid + 1; i++) |
| 617 | show_group_stats(&runstats[i], i); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 618 | |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 619 | show_disk_util(); |
| 620 | } |
Jens Axboe | eecf272 | 2006-10-20 14:00:36 +0200 | [diff] [blame] | 621 | |
| 622 | free(runstats); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 623 | } |
| 624 | |
Jens Axboe | 6870408 | 2007-01-10 19:56:37 +0100 | [diff] [blame] | 625 | 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] | 626 | { |
Jens Axboe | 6870408 | 2007-01-10 19:56:37 +0100 | [diff] [blame] | 627 | double val = data; |
| 628 | double delta, n; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 629 | |
Jens Axboe | 6870408 | 2007-01-10 19:56:37 +0100 | [diff] [blame] | 630 | if (data > is->max_val) |
| 631 | is->max_val = data; |
| 632 | if (data < is->min_val) |
| 633 | is->min_val = data; |
| 634 | |
| 635 | delta = val - is->mean; |
| 636 | n = is->samples + 1.0; |
| 637 | is->mean += delta / n; |
| 638 | is->S += delta * (val - is->mean); |
| 639 | |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 640 | is->samples++; |
| 641 | } |
| 642 | |
Jens Axboe | bb3884d | 2007-01-17 17:23:11 +1100 | [diff] [blame] | 643 | static void __add_log_sample(struct io_log *iolog, unsigned long val, |
| 644 | enum fio_ddir ddir, unsigned long time) |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 645 | { |
| 646 | if (iolog->nr_samples == iolog->max_samples) { |
| 647 | int new_size = sizeof(struct io_sample) * iolog->max_samples*2; |
| 648 | |
| 649 | iolog->log = realloc(iolog->log, new_size); |
| 650 | iolog->max_samples <<= 1; |
| 651 | } |
| 652 | |
| 653 | iolog->log[iolog->nr_samples].val = val; |
Jens Axboe | bb3884d | 2007-01-17 17:23:11 +1100 | [diff] [blame] | 654 | iolog->log[iolog->nr_samples].time = time; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 655 | iolog->log[iolog->nr_samples].ddir = ddir; |
| 656 | iolog->nr_samples++; |
| 657 | } |
| 658 | |
Jens Axboe | bb3884d | 2007-01-17 17:23:11 +1100 | [diff] [blame] | 659 | static void add_log_sample(struct thread_data *td, struct io_log *iolog, |
| 660 | unsigned long val, enum fio_ddir ddir) |
| 661 | { |
| 662 | __add_log_sample(iolog, val, ddir, mtime_since_now(&td->epoch)); |
| 663 | } |
| 664 | |
| 665 | void add_agg_sample(unsigned long val, enum fio_ddir ddir) |
| 666 | { |
| 667 | struct io_log *iolog = agg_io_log[ddir]; |
| 668 | |
| 669 | __add_log_sample(iolog, val, ddir, mtime_since_genesis()); |
| 670 | } |
| 671 | |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 672 | void add_clat_sample(struct thread_data *td, enum fio_ddir ddir, |
| 673 | unsigned long msec) |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 674 | { |
| 675 | add_stat_sample(&td->clat_stat[ddir], msec); |
| 676 | |
| 677 | if (td->clat_log) |
| 678 | add_log_sample(td, td->clat_log, msec, ddir); |
| 679 | } |
| 680 | |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 681 | void add_slat_sample(struct thread_data *td, enum fio_ddir ddir, |
| 682 | unsigned long msec) |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 683 | { |
| 684 | add_stat_sample(&td->slat_stat[ddir], msec); |
| 685 | |
| 686 | if (td->slat_log) |
| 687 | add_log_sample(td, td->slat_log, msec, ddir); |
| 688 | } |
| 689 | |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 690 | void add_bw_sample(struct thread_data *td, enum fio_ddir ddir, |
| 691 | struct timeval *t) |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 692 | { |
Jens Axboe | 02bcaa8 | 2006-11-24 10:42:00 +0100 | [diff] [blame] | 693 | unsigned long spent = mtime_since(&td->stat_sample_time[ddir], t); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 694 | unsigned long rate; |
| 695 | |
| 696 | if (spent < td->bw_avg_time) |
| 697 | return; |
| 698 | |
| 699 | rate = (td->this_io_bytes[ddir] - td->stat_io_bytes[ddir]) / spent; |
| 700 | add_stat_sample(&td->bw_stat[ddir], rate); |
| 701 | |
| 702 | if (td->bw_log) |
| 703 | add_log_sample(td, td->bw_log, rate, ddir); |
| 704 | |
Jens Axboe | 02bcaa8 | 2006-11-24 10:42:00 +0100 | [diff] [blame] | 705 | fio_gettime(&td->stat_sample_time[ddir], NULL); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 706 | td->stat_io_bytes[ddir] = td->this_io_bytes[ddir]; |
| 707 | } |
| 708 | |
| 709 | |