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 | |
| 15 | static 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 | |
| 41 | static 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 Axboe | 02bcaa8 | 2006-11-24 10:42:00 +0100 | [diff] [blame] | 63 | fio_gettime(&t, NULL); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 64 | du->msec += mtime_since(&du->time, &t); |
| 65 | memcpy(&du->time, &t, sizeof(t)); |
| 66 | memcpy(ldus, &__dus, sizeof(__dus)); |
| 67 | } |
| 68 | |
| 69 | void 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 | |
| 80 | static 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 | |
| 95 | static void disk_util_add(dev_t dev, char *path) |
| 96 | { |
Jens Axboe | 1188caf | 2007-01-08 10:57:27 +0100 | [diff] [blame] | 97 | struct disk_util *du, *__du; |
| 98 | struct list_head *entry; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 99 | |
Jens Axboe | 1188caf | 2007-01-08 10:57:27 +0100 | [diff] [blame] | 100 | du = malloc(sizeof(*du)); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 101 | 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 Axboe | 1188caf | 2007-01-08 10:57:27 +0100 | [diff] [blame] | 107 | 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 Axboe | 02bcaa8 | 2006-11-24 10:42:00 +0100 | [diff] [blame] | 117 | fio_gettime(&du->time, NULL); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 118 | get_io_ticks(du, &du->last_dus); |
| 119 | |
| 120 | list_add_tail(&du->list, &disk_list); |
| 121 | } |
| 122 | |
| 123 | static 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 | |
| 155 | static 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 Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 171 | |
| 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 Axboe | 3307d65 | 2006-07-17 18:15:41 +0200 | [diff] [blame] | 181 | if (lstat(full_path, &st) == -1) { |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 182 | 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 | |
| 200 | void init_disk_util(struct thread_data *td) |
| 201 | { |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 202 | struct fio_file *f; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 203 | struct stat st; |
Jens Axboe | 0bbab0e | 2006-11-02 09:18:36 +0100 | [diff] [blame] | 204 | char foo[PATH_MAX], tmp[PATH_MAX]; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 205 | dev_t dev; |
| 206 | char *p; |
| 207 | |
| 208 | if (!td->do_disk_util) |
| 209 | return; |
| 210 | |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 211 | /* |
| 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 Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 216 | 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 Axboe | 0bbab0e | 2006-11-02 09:18:36 +0100 | [diff] [blame] | 224 | strncpy(foo, f->file_name, PATH_MAX - 1); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 225 | 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 Axboe | 3b70d7e | 2006-06-08 21:48:46 +0200 | [diff] [blame] | 251 | log_err("unknown sysfs layout\n"); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 252 | return; |
| 253 | } |
Jens Axboe | 0bbab0e | 2006-11-02 09:18:36 +0100 | [diff] [blame] | 254 | strncpy(tmp, p, PATH_MAX - 1); |
Jens Axboe | 8458500 | 2006-10-19 20:26:22 +0200 | [diff] [blame] | 255 | sprintf(foo, "%s", tmp); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 256 | } |
| 257 | |
Jens Axboe | eecf272 | 2006-10-20 14:00:36 +0200 | [diff] [blame] | 258 | if (td->ioscheduler) |
| 259 | td->sysfs_root = strdup(foo); |
| 260 | |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 261 | disk_util_add(dev, foo); |
| 262 | } |
| 263 | |
| 264 | void 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 | |
| 271 | void update_rusage_stat(struct thread_data *td) |
| 272 | { |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 273 | 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 | |
| 283 | static int calc_lat(struct io_stat *is, unsigned long *min, unsigned long *max, |
| 284 | double *mean, double *dev) |
| 285 | { |
Jens Axboe | ef9c5c4 | 2007-01-03 14:21:13 +0100 | [diff] [blame] | 286 | double n, o; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 287 | |
| 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 Axboe | ef9c5c4 | 2007-01-03 14:21:13 +0100 | [diff] [blame] | 296 | *dev = 0.01; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 297 | |
Jens Axboe | ef9c5c4 | 2007-01-03 14:21:13 +0100 | [diff] [blame] | 298 | if (n <= 1.0) |
Jens Axboe | e6d276f | 2007-01-03 11:10:27 +0100 | [diff] [blame] | 299 | return 1; |
| 300 | |
Jens Axboe | ef9c5c4 | 2007-01-03 14:21:13 +0100 | [diff] [blame] | 301 | 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 Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 307 | return 1; |
| 308 | } |
| 309 | |
| 310 | static void show_group_stats(struct group_run_stats *rs, int id) |
| 311 | { |
Jens Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 312 | fprintf(f_out, "\nRun status group %d (all jobs):\n", id); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 313 | |
| 314 | if (rs->max_run[DDIR_READ]) |
Jens Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 315 | 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 Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 316 | if (rs->max_run[DDIR_WRITE]) |
Jens Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 317 | 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 Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | static void show_disk_util(void) |
| 321 | { |
| 322 | struct disk_util_stat *dus; |
Jens Axboe | b4a6a59 | 2006-10-20 13:54:47 +0200 | [diff] [blame] | 323 | struct list_head *entry, *next; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 324 | struct disk_util *du; |
| 325 | double util; |
| 326 | |
Jens Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 327 | fprintf(f_out, "\nDisk stats (read/write):\n"); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 328 | |
| 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 Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 337 | 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] | 338 | } |
Jens Axboe | b4a6a59 | 2006-10-20 13:54:47 +0200 | [diff] [blame] | 339 | |
| 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 Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | static void show_ddir_status(struct thread_data *td, struct group_run_stats *rs, |
| 352 | int ddir) |
| 353 | { |
Jens Axboe | 3c9b60c | 2006-11-07 08:36:14 +0100 | [diff] [blame] | 354 | const char *ddir_str[] = { "read ", "write" }; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 355 | 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 Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 363 | 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 Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 364 | |
| 365 | if (calc_lat(&td->slat_stat[ddir], &min, &max, &mean, &dev)) |
Jens Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 366 | fprintf(f_out, " slat (msec): min=%5lu, max=%5lu, avg=%5.02f, dev=%5.02f\n", min, max, mean, dev); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 367 | |
| 368 | if (calc_lat(&td->clat_stat[ddir], &min, &max, &mean, &dev)) |
Jens Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 369 | fprintf(f_out, " clat (msec): min=%5lu, max=%5lu, avg=%5.02f, dev=%5.02f\n", min, max, mean, dev); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 370 | |
| 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 Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 375 | 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 Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | |
| 379 | static void show_thread_status(struct thread_data *td, |
| 380 | struct group_run_stats *rs) |
| 381 | { |
| 382 | double usr_cpu, sys_cpu; |
Jens Axboe | 6900899 | 2006-11-24 13:12:56 +0100 | [diff] [blame] | 383 | unsigned long runtime; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 384 | |
| 385 | if (!(td->io_bytes[0] + td->io_bytes[1]) && !td->error) |
| 386 | return; |
| 387 | |
Jens Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 388 | fprintf(f_out, "%s: (groupid=%d): err=%2d:\n",td->name, td->groupid, td->error); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 389 | |
| 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 Axboe | 6900899 | 2006-11-24 13:12:56 +0100 | [diff] [blame] | 394 | runtime = mtime_since(&td->epoch, &td->end_time); |
| 395 | if (runtime) { |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 396 | double runt = (double) runtime; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 397 | |
| 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 Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 405 | fprintf(f_out, " cpu : usr=%3.2f%%, sys=%3.2f%%, ctx=%lu\n", usr_cpu, sys_cpu, td->ctx); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 406 | } |
| 407 | |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 408 | static 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 | |
| 442 | static 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 Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 453 | double runt = (double) (td->runtime[0] + td->runtime[1]); |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 454 | |
| 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 Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 465 | void 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 Axboe | 34572e2 | 2006-10-20 09:33:18 +0200 | [diff] [blame] | 481 | for_each_td(td, i) { |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 482 | unsigned long long rbw, wbw; |
| 483 | |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 484 | if (td->error) { |
Jens Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 485 | fprintf(f_out, "%s: %s\n", td->name, td->verror); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 486 | 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 Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 531 | if (!terse_output) |
| 532 | printf("\n"); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 533 | |
Jens Axboe | 34572e2 | 2006-10-20 09:33:18 +0200 | [diff] [blame] | 534 | for_each_td(td, i) { |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 535 | rs = &runstats[td->groupid]; |
| 536 | |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 537 | if (terse_output) |
| 538 | show_thread_status_terse(td, rs); |
| 539 | else |
| 540 | show_thread_status(td, rs); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 541 | } |
| 542 | |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 543 | if (!terse_output) { |
| 544 | for (i = 0; i < groupid + 1; i++) |
| 545 | show_group_stats(&runstats[i], i); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 546 | |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 547 | show_disk_util(); |
| 548 | } |
Jens Axboe | eecf272 | 2006-10-20 14:00:36 +0200 | [diff] [blame] | 549 | |
| 550 | free(runstats); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | static 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 | |
| 565 | static void add_log_sample(struct thread_data *td, struct io_log *iolog, |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 566 | unsigned long val, enum fio_ddir ddir) |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 567 | { |
| 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 Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 581 | void add_clat_sample(struct thread_data *td, enum fio_ddir ddir, |
| 582 | unsigned long msec) |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 583 | { |
| 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 Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 590 | void add_slat_sample(struct thread_data *td, enum fio_ddir ddir, |
| 591 | unsigned long msec) |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 592 | { |
| 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 Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 599 | void add_bw_sample(struct thread_data *td, enum fio_ddir ddir, |
| 600 | struct timeval *t) |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 601 | { |
Jens Axboe | 02bcaa8 | 2006-11-24 10:42:00 +0100 | [diff] [blame] | 602 | unsigned long spent = mtime_since(&td->stat_sample_time[ddir], t); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 603 | 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 Axboe | 02bcaa8 | 2006-11-24 10:42:00 +0100 | [diff] [blame] | 614 | fio_gettime(&td->stat_sample_time[ddir], NULL); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 615 | td->stat_io_bytes[ddir] = td->this_io_bytes[ddir]; |
| 616 | } |
| 617 | |
| 618 | |