X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=stat.c;h=29a5f912d26d597ded5142842e34e1ad39405599;hp=8d391a35d4dec7058e0670bde73685d3fa176937;hb=07e5b2646f673a56c05a53c6a84bf5d0c949d290;hpb=b3605062146bce0136918763bb8eb584478ae042 diff --git a/stat.c b/stat.c index 8d391a35..29a5f912 100644 --- a/stat.c +++ b/stat.c @@ -11,7 +11,7 @@ static struct itimerval itimer; static struct list_head disk_list = LIST_HEAD_INIT(disk_list); -static dev_t last_dev; +static int last_majdev, last_mindev; /* * Cheesy number->string conversion, complete with carry rounding error. @@ -121,7 +121,7 @@ void update_io_ticks(void) } } -static int disk_util_exists(dev_t dev) +static int disk_util_exists(int major, int minor) { struct list_head *entry; struct disk_util *du; @@ -129,14 +129,14 @@ static int disk_util_exists(dev_t dev) list_for_each(entry, &disk_list) { du = list_entry(entry, struct disk_util, list); - if (du->dev == dev) + if (major == du->major && minor == du->minor) return 1; } return 0; } -static void disk_util_add(dev_t dev, char *path) +static void disk_util_add(int majdev, int mindev, char *path) { struct disk_util *du, *__du; struct list_head *entry; @@ -146,7 +146,8 @@ static void disk_util_add(dev_t dev, char *path) INIT_LIST_HEAD(&du->list); sprintf(du->path, "%s/stat", path); du->name = strdup(basename(path)); - du->dev = dev; + du->major = majdev; + du->minor = mindev; list_for_each(entry, &disk_list) { __du = list_entry(entry, struct disk_util, list); @@ -164,9 +165,9 @@ static void disk_util_add(dev_t dev, char *path) list_add_tail(&du->list, &disk_list); } -static int check_dev_match(dev_t dev, char *path) +static int check_dev_match(int majdev, int mindev, char *path) { - unsigned int major, minor; + int major, minor; char line[256], *p; FILE *f; @@ -187,7 +188,7 @@ static int check_dev_match(dev_t dev, char *path) return 1; } - if (((major << 8) | minor) == dev) { + if (majdev == major && mindev == minor) { fclose(f); return 0; } @@ -196,7 +197,7 @@ static int check_dev_match(dev_t dev, char *path) return 1; } -static int find_block_dir(dev_t dev, char *path) +static int find_block_dir(int majdev, int mindev, char *path) { struct dirent *dir; struct stat st; @@ -216,7 +217,7 @@ static int find_block_dir(dev_t dev, char *path) sprintf(full_path, "%s/%s", path, dir->d_name); if (!strcmp(dir->d_name, "dev")) { - if (!check_dev_match(dev, full_path)) { + if (!check_dev_match(majdev, mindev, full_path)) { found = 1; break; } @@ -230,7 +231,7 @@ static int find_block_dir(dev_t dev, char *path) if (!S_ISDIR(st.st_mode) || S_ISLNK(st.st_mode)) continue; - found = find_block_dir(dev, full_path); + found = find_block_dir(majdev, mindev, full_path); if (found) { strcpy(path, full_path); break; @@ -241,26 +242,25 @@ static int find_block_dir(dev_t dev, char *path) return found; } -void init_disk_util(struct thread_data *td) +static void __init_disk_util(struct thread_data *td, struct fio_file *f) { - struct fio_file *f; struct stat st; char foo[PATH_MAX], tmp[PATH_MAX]; - dev_t dev; + int mindev, majdev; char *p; - if (!td->do_disk_util || (td->io_ops->flags & FIO_DISKLESSIO)) - return; - - /* - * Just use the same file, they are on the same device. - */ - f = &td->files[0]; if (!stat(f->file_name, &st)) { - if (S_ISBLK(st.st_mode)) - dev = st.st_rdev; - else - dev = st.st_dev; + if (S_ISBLK(st.st_mode)) { + majdev = major(st.st_rdev); + mindev = minor(st.st_rdev); + } else if (S_ISCHR(st.st_mode)) { + majdev = major(st.st_rdev); + mindev = minor(st.st_rdev); + fio_lookup_raw(st.st_rdev, &majdev, &mindev); + } else { + majdev = major(st.st_dev); + mindev = minor(st.st_dev); + } } else { /* * must be a file, open "." in that path @@ -272,10 +272,11 @@ void init_disk_util(struct thread_data *td) return; } - dev = st.st_dev; + majdev = major(st.st_dev); + mindev = minor(st.st_dev); } - if (disk_util_exists(dev)) + if (disk_util_exists(majdev, mindev)) return; /* @@ -284,13 +285,14 @@ void init_disk_util(struct thread_data *td) * cache the last lookup and compare with that before going through * everything again. */ - if (dev == last_dev) + if (mindev == last_mindev && majdev == last_majdev) return; - last_dev = dev; + last_mindev = mindev; + last_majdev = majdev; sprintf(foo, "/sys/block"); - if (!find_block_dir(dev, foo)) + if (!find_block_dir(majdev, mindev, foo)) return; /* @@ -310,10 +312,23 @@ void init_disk_util(struct thread_data *td) sprintf(foo, "%s", tmp); } - if (td->ioscheduler) + if (td->o.ioscheduler && !td->sysfs_root) td->sysfs_root = strdup(foo); - disk_util_add(dev, foo); + disk_util_add(majdev, mindev, foo); +} + +void init_disk_util(struct thread_data *td) +{ + struct fio_file *f; + unsigned int i; + + if (!td->o.do_disk_util || + (td->io_ops->flags & (FIO_DISKLESSIO | FIO_NODISKUTIL))) + return; + + for_each_file(td, f, i) + __init_disk_util(td, f); } void disk_util_timer_arm(void) @@ -364,7 +379,7 @@ static void show_group_stats(struct group_run_stats *rs, int id) const char *ddir_str[] = { " READ", " WRITE" }; int i; - fprintf(f_out, "\nRun status group %d (all jobs):\n", id); + log_info("\nRun status group %d (all jobs):\n", id); for (i = 0; i <= DDIR_WRITE; i++) { if (!rs->max_run[i]) @@ -375,7 +390,7 @@ static void show_group_stats(struct group_run_stats *rs, int id) p3 = num2str(rs->min_bw[i], 6, 1000, 1); p4 = num2str(rs->max_bw[i], 6, 1000, 1); - 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]); + log_info("%s: io=%siB, aggrb=%siB/s, minb=%siB/s, maxb=%siB/s, mint=%llumsec, maxt=%llumsec\n", ddir_str[i], p1, p2, p3, p4, rs->min_run[i], rs->max_run[i]); free(p1); free(p2); @@ -391,7 +406,7 @@ static void show_disk_util(void) struct disk_util *du; double util; - fprintf(f_out, "\nDisk stats (read/write):\n"); + log_info("\nDisk stats (read/write):\n"); list_for_each(entry, &disk_list) { du = list_entry(entry, struct disk_util, list); @@ -401,7 +416,7 @@ static void show_disk_util(void) if (util > 100.0) util = 100.0; - 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); + log_info(" %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); } /* @@ -428,6 +443,8 @@ static void stat_calc_dist(struct thread_stat *ts, double *io_u_dist) for (i = 0; i < FIO_IO_U_MAP_NR; i++) { io_u_dist[i] = (double) ts->io_u_map[i] / (double) ts_total_io_u(ts); io_u_dist[i] *= 100.0; + if (io_u_dist[i] < 0.1 && ts->io_u_map[i]) + io_u_dist[i] = 0.1; } } @@ -441,6 +458,8 @@ static void stat_calc_lat(struct thread_stat *ts, double *io_u_lat) for (i = 0; i < FIO_IO_U_LAT_NR; i++) { io_u_lat[i] = (double) ts->io_u_lat[i] / (double) ts_total_io_u(ts); io_u_lat[i] *= 100.0; + if (io_u_lat[i] < 0.01 && ts->io_u_lat[i]) + io_u_lat[i] = 0.01; } } @@ -462,23 +481,23 @@ static void show_ddir_status(struct group_run_stats *rs, struct thread_stat *ts, bw_p = num2str(bw, 6, 1000, 1); iops_p = num2str(iops, 6, 1, 0); - fprintf(f_out, " %s: io=%siB, bw=%siB/s, iops=%s, runt=%6lumsec\n", ddir_str[ddir], io_p, bw_p, iops_p, ts->runtime[ddir]); + log_info(" %s: io=%siB, bw=%siB/s, iops=%s, runt=%6lumsec\n", ddir_str[ddir], io_p, bw_p, iops_p, ts->runtime[ddir]); free(io_p); free(bw_p); free(iops_p); if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) - fprintf(f_out, " slat (msec): min=%5lu, max=%5lu, avg=%5.02f, stdev=%5.02f\n", min, max, mean, dev); + log_info(" slat (msec): min=%5lu, max=%5lu, avg=%5.02f, stdev=%5.02f\n", min, max, mean, dev); if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) - fprintf(f_out, " clat (msec): min=%5lu, max=%5lu, avg=%5.02f, stdev=%5.02f\n", min, max, mean, dev); + log_info(" clat (msec): min=%5lu, max=%5lu, avg=%5.02f, stdev=%5.02f\n", min, max, mean, dev); if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) { double p_of_agg; p_of_agg = mean * 100 / (double) rs->agg[ddir]; - 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); + log_info(" bw (KiB/s) : min=%5lu, max=%5lu, per=%3.2f%%, avg=%5.02f, stdev=%5.02f\n", min, max, p_of_agg, mean, dev); } } @@ -494,12 +513,12 @@ static void show_thread_status(struct thread_stat *ts, return; if (!ts->error) - fprintf(f_out, "%s: (groupid=%d, jobs=%d): err=%2d: pid=%d\n", ts->name, ts->groupid, ts->members, ts->error, ts->pid); + log_info("%s: (groupid=%d, jobs=%d): err=%2d: pid=%d\n", ts->name, ts->groupid, ts->members, ts->error, ts->pid); else - 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); + log_info("%s: (groupid=%d, jobs=%d): err=%2d (%s): pid=%d\n", ts->name, ts->groupid, ts->members, ts->error, ts->verror, ts->pid); if (ts->description) - fprintf(f_out, " Description : [%s]\n", ts->description); + log_info(" Description : [%s]\n", ts->description); if (ts->io_bytes[DDIR_READ]) show_ddir_status(rs, ts, DDIR_READ); @@ -517,15 +536,15 @@ static void show_thread_status(struct thread_stat *ts, sys_cpu = 0; } - fprintf(f_out, " cpu : usr=%3.2f%%, sys=%3.2f%%, ctx=%lu\n", usr_cpu, sys_cpu, ts->ctx); + log_info(" cpu : usr=%3.2f%%, sys=%3.2f%%, ctx=%lu\n", usr_cpu, sys_cpu, ts->ctx); stat_calc_dist(ts, io_u_dist); stat_calc_lat(ts, io_u_lat); - 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]); + log_info(" IO depths : 1=%3.1f%%, 2=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%, 32=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3], io_u_dist[4], io_u_dist[5], io_u_dist[6]); - 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]); - 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]); + log_info(" lat (msec): 2=%3.2f%%, 4=%3.2f%%, 10=%3.2f%%, 20=%3.2f%%, 50=%3.2f%%, 100=%3.2f%%\n", io_u_lat[0], io_u_lat[1], io_u_lat[2], io_u_lat[3], io_u_lat[4], io_u_lat[5]); + log_info(" lat (msec): 250=%3.2f%%, 500=%3.2f%%, 750=%3.2f%%, 1000=%3.2f%%, >=2000=%3.2f%%\n", io_u_lat[6], io_u_lat[7], io_u_lat[8], io_u_lat[9], io_u_lat[10]); } static void show_ddir_status_terse(struct thread_stat *ts, @@ -539,25 +558,25 @@ static void show_ddir_status_terse(struct thread_stat *ts, if (ts->runtime[ddir]) bw = ts->io_bytes[ddir] / ts->runtime[ddir]; - fprintf(f_out, ";%llu;%llu;%lu", ts->io_bytes[ddir] >> 10, bw, ts->runtime[ddir]); + log_info(";%llu;%llu;%lu", ts->io_bytes[ddir] >> 10, bw, ts->runtime[ddir]); if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) - fprintf(f_out, ";%lu;%lu;%f;%f", min, max, mean, dev); + log_info(";%lu;%lu;%f;%f", min, max, mean, dev); else - fprintf(f_out, ";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0); + log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0); if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) - fprintf(f_out, ";%lu;%lu;%f;%f", min, max, mean, dev); + log_info(";%lu;%lu;%f;%f", min, max, mean, dev); else - fprintf(f_out, ";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0); + log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0); if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) { double p_of_agg; p_of_agg = mean * 100 / (double) rs->agg[ddir]; - fprintf(f_out, ";%lu;%lu;%f%%;%f;%f", min, max, p_of_agg, mean, dev); + log_info(";%lu;%lu;%f%%;%f;%f", min, max, p_of_agg, mean, dev); } else - fprintf(f_out, ";%lu;%lu;%f%%;%f;%f", 0UL, 0UL, 0.0, 0.0, 0.0); + log_info(";%lu;%lu;%f%%;%f;%f", 0UL, 0UL, 0.0, 0.0, 0.0); } @@ -568,7 +587,7 @@ static void show_thread_status_terse(struct thread_stat *ts, double io_u_lat[FIO_IO_U_LAT_NR]; double usr_cpu, sys_cpu; - fprintf(f_out, "%s;%d;%d", ts->name, ts->groupid, ts->error); + log_info("%s;%d;%d", ts->name, ts->groupid, ts->error); show_ddir_status_terse(ts, rs, 0); show_ddir_status_terse(ts, rs, 1); @@ -583,20 +602,20 @@ static void show_thread_status_terse(struct thread_stat *ts, sys_cpu = 0; } - fprintf(f_out, ";%f%%;%f%%;%lu", usr_cpu, sys_cpu, ts->ctx); + log_info(";%f%%;%f%%;%lu", usr_cpu, sys_cpu, ts->ctx); stat_calc_dist(ts, io_u_dist); stat_calc_lat(ts, io_u_lat); - 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]); + log_info(";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%", io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3], io_u_dist[4], io_u_dist[5], io_u_dist[6]); - 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]); - 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]); + log_info(";%3.2f%%;%3.2f%%;%3.2f%%;%3.2f%%;%3.2f%%;%3.2f%%\n", io_u_lat[0], io_u_lat[1], io_u_lat[2], io_u_lat[3], io_u_lat[4], io_u_lat[5]); + log_info(";%3.2f%%;%3.2f%%;%3.2f%%;%3.2f%%;%3.2f%%", io_u_lat[6], io_u_lat[7], io_u_lat[8], io_u_lat[9], io_u_lat[10]); if (ts->description) - fprintf(f_out, ";%s", ts->description); + log_info(";%s", ts->description); - fprintf(f_out, "\n"); + log_info("\n"); } static void sum_stat(struct io_stat *dst, struct io_stat *src, int nr) @@ -647,7 +666,7 @@ void show_run_stats(void) nr_ts = 0; last_ts = -1; for_each_td(td, i) { - if (!td->group_reporting) { + if (!td->o.group_reporting) { nr_ts++; continue; } @@ -669,23 +688,32 @@ void show_run_stats(void) ts->slat_stat[j].min_val = -1UL; ts->bw_stat[j].min_val = -1UL; } + ts->groupid = -1; } j = 0; last_ts = -1; idx = 0; for_each_td(td, i) { + if (idx && (!td->o.group_reporting || + (td->o.group_reporting && last_ts != td->groupid))) { + idx = 0; + j++; + } + + last_ts = td->groupid; + ts = &threadstats[j]; idx++; ts->members++; - if (!ts->groupid) { + if (ts->groupid == -1) { /* * These are per-group shared already */ - ts->name = td->name; - ts->description = td->description; + ts->name = td->o.name; + ts->description = td->o.description; ts->groupid = td->groupid; /* @@ -724,21 +752,6 @@ void show_run_stats(void) ts->total_io_u[k] += td->ts.total_io_u[k]; ts->total_run_time += td->ts.total_run_time; - - if (!td->group_reporting) { - idx = 0; - j++; - continue; - } - if (last_ts == td->groupid) - continue; - - if (last_ts != -1) { - idx = 0; - j++; - } - - last_ts = td->groupid; } for (i = 0; i < nr_ts; i++) { @@ -814,8 +827,10 @@ static inline void add_stat_sample(struct io_stat *is, unsigned long data) is->min_val = data; delta = val - is->mean; - is->mean += delta / (is->samples + 1.0); - is->S += delta * (val - is->mean); + if (delta) { + is->mean += delta / (is->samples + 1.0); + is->S += delta * (val - is->mean); + } is->samples++; } @@ -878,7 +893,7 @@ void add_bw_sample(struct thread_data *td, enum fio_ddir ddir, unsigned long spent = mtime_since(&ts->stat_sample_time[ddir], t); unsigned long rate; - if (spent < td->bw_avg_time) + if (spent < td->o.bw_avg_time) return; rate = (td->this_io_bytes[ddir] - ts->stat_io_bytes[ddir]) / spent;