Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Status and ETA code |
| 3 | */ |
| 4 | #include <unistd.h> |
| 5 | #include <fcntl.h> |
| 6 | #include <string.h> |
| 7 | |
| 8 | #include "fio.h" |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 9 | |
Jens Axboe | fca7035 | 2011-07-06 20:12:54 +0200 | [diff] [blame] | 10 | static char run_str[REAL_MAX_JOBS + 1]; |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 11 | |
| 12 | /* |
| 13 | * Sets the status of the 'td' in the printed status map. |
| 14 | */ |
| 15 | static void check_str_update(struct thread_data *td) |
| 16 | { |
| 17 | char c = run_str[td->thread_number - 1]; |
| 18 | |
| 19 | switch (td->runstate) { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 20 | case TD_REAPED: |
Jens Axboe | 4f7e57a | 2012-03-30 21:21:20 +0200 | [diff] [blame] | 21 | if (td->error) |
| 22 | c = 'X'; |
Jens Axboe | a5e371a | 2012-04-02 09:47:09 -0700 | [diff] [blame] | 23 | else if (td->sig) |
| 24 | c = 'K'; |
Jens Axboe | 4f7e57a | 2012-03-30 21:21:20 +0200 | [diff] [blame] | 25 | else |
| 26 | c = '_'; |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 27 | break; |
| 28 | case TD_EXITED: |
| 29 | c = 'E'; |
| 30 | break; |
Jens Axboe | b29ee5b | 2008-09-11 10:17:26 +0200 | [diff] [blame] | 31 | case TD_RAMP: |
| 32 | c = '/'; |
| 33 | break; |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 34 | case TD_RUNNING: |
| 35 | if (td_rw(td)) { |
Jens Axboe | e3b3f81 | 2011-09-01 09:58:11 -0600 | [diff] [blame] | 36 | if (td_random(td)) { |
| 37 | if (td->o.rwmix[DDIR_READ] == 100) |
| 38 | c = 'r'; |
| 39 | else if (td->o.rwmix[DDIR_WRITE] == 100) |
| 40 | c = 'w'; |
| 41 | else |
| 42 | c = 'm'; |
| 43 | } else { |
| 44 | if (td->o.rwmix[DDIR_READ] == 100) |
| 45 | c = 'R'; |
| 46 | else if (td->o.rwmix[DDIR_WRITE] == 100) |
| 47 | c = 'W'; |
| 48 | else |
| 49 | c = 'M'; |
| 50 | } |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 51 | } else if (td_read(td)) { |
| 52 | if (td_random(td)) |
| 53 | c = 'r'; |
| 54 | else |
| 55 | c = 'R'; |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 56 | } else if (td_write(td)) { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 57 | if (td_random(td)) |
| 58 | c = 'w'; |
| 59 | else |
| 60 | c = 'W'; |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 61 | } else { |
| 62 | if (td_random(td)) |
| 63 | c = 'd'; |
| 64 | else |
| 65 | c = 'D'; |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 66 | } |
| 67 | break; |
Jens Axboe | b0f6586 | 2009-05-20 11:52:15 +0200 | [diff] [blame] | 68 | case TD_PRE_READING: |
| 69 | c = 'p'; |
| 70 | break; |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 71 | case TD_VERIFYING: |
| 72 | c = 'V'; |
| 73 | break; |
| 74 | case TD_FSYNCING: |
| 75 | c = 'F'; |
| 76 | break; |
| 77 | case TD_CREATED: |
| 78 | c = 'C'; |
| 79 | break; |
| 80 | case TD_INITIALIZED: |
Jens Axboe | 9c6f631 | 2012-11-07 09:15:45 +0100 | [diff] [blame] | 81 | case TD_SETTING_UP: |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 82 | c = 'I'; |
| 83 | break; |
| 84 | case TD_NOT_CREATED: |
| 85 | c = 'P'; |
| 86 | break; |
| 87 | default: |
| 88 | log_err("state %d\n", td->runstate); |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | run_str[td->thread_number - 1] = c; |
| 92 | } |
| 93 | |
| 94 | /* |
| 95 | * Convert seconds to a printable string. |
| 96 | */ |
Gurudas Pai | 9c02f6e | 2008-06-13 08:40:11 +0200 | [diff] [blame] | 97 | static void eta_to_str(char *str, unsigned long eta_sec) |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 98 | { |
| 99 | unsigned int d, h, m, s; |
Jens Axboe | 165faf1 | 2007-02-07 11:30:37 +0100 | [diff] [blame] | 100 | int disp_hour = 0; |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 101 | |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 102 | s = eta_sec % 60; |
| 103 | eta_sec /= 60; |
| 104 | m = eta_sec % 60; |
| 105 | eta_sec /= 60; |
| 106 | h = eta_sec % 24; |
| 107 | eta_sec /= 24; |
| 108 | d = eta_sec; |
| 109 | |
Jens Axboe | 165faf1 | 2007-02-07 11:30:37 +0100 | [diff] [blame] | 110 | if (d) { |
| 111 | disp_hour = 1; |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 112 | str += sprintf(str, "%02ud:", d); |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 113 | } |
Jens Axboe | 165faf1 | 2007-02-07 11:30:37 +0100 | [diff] [blame] | 114 | |
| 115 | if (h || disp_hour) |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 116 | str += sprintf(str, "%02uh:", h); |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 117 | |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 118 | str += sprintf(str, "%02um:", m); |
| 119 | str += sprintf(str, "%02us", s); |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | /* |
| 123 | * Best effort calculation of the estimated pending runtime of a job. |
| 124 | */ |
Jens Axboe | b29ee5b | 2008-09-11 10:17:26 +0200 | [diff] [blame] | 125 | static int thread_eta(struct thread_data *td) |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 126 | { |
| 127 | unsigned long long bytes_total, bytes_done; |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 128 | unsigned long eta_sec = 0; |
Jens Axboe | b29ee5b | 2008-09-11 10:17:26 +0200 | [diff] [blame] | 129 | unsigned long elapsed; |
| 130 | |
| 131 | elapsed = (mtime_since_now(&td->epoch) + 999) / 1000; |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 132 | |
| 133 | bytes_total = td->total_io_size; |
| 134 | |
Jens Axboe | 2e3bd4c | 2010-05-17 12:29:57 +0200 | [diff] [blame] | 135 | if (td->o.fill_device && td->o.size == -1ULL) { |
| 136 | if (!td->fill_device_size || td->fill_device_size == -1ULL) |
| 137 | return 0; |
| 138 | |
| 139 | bytes_total = td->fill_device_size; |
| 140 | } |
| 141 | |
Jens Axboe | 74939e3 | 2006-10-19 20:37:12 +0200 | [diff] [blame] | 142 | /* |
Jens Axboe | 165eb05 | 2013-01-23 08:40:11 -0700 | [diff] [blame] | 143 | * if writing and verifying afterwards, bytes_total will be twice the |
| 144 | * size. In a mixed workload, verify phase will be the size of the |
| 145 | * first stage writes. |
Jens Axboe | 74939e3 | 2006-10-19 20:37:12 +0200 | [diff] [blame] | 146 | */ |
Jens Axboe | 0dd8377 | 2007-09-04 12:38:28 +0200 | [diff] [blame] | 147 | if (td->o.do_verify && td->o.verify && td_write(td)) { |
Jens Axboe | 165eb05 | 2013-01-23 08:40:11 -0700 | [diff] [blame] | 148 | if (td_rw(td)) { |
| 149 | unsigned int perc = 50; |
| 150 | |
| 151 | if (td->o.rwmix[DDIR_WRITE]) |
| 152 | perc = td->o.rwmix[DDIR_WRITE]; |
| 153 | |
| 154 | bytes_total += (bytes_total * perc) / 100; |
| 155 | } else |
Jens Axboe | 74939e3 | 2006-10-19 20:37:12 +0200 | [diff] [blame] | 156 | bytes_total <<= 1; |
| 157 | } |
| 158 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 159 | if (td->o.zone_size && td->o.zone_skip) |
| 160 | bytes_total /= (td->o.zone_skip / td->o.zone_size); |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 161 | |
| 162 | if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING) { |
Jens Axboe | cf4464c | 2007-04-17 20:14:42 +0200 | [diff] [blame] | 163 | double perc, perc_t; |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 164 | |
Jens Axboe | 342f4be | 2012-09-14 08:59:20 +0200 | [diff] [blame] | 165 | bytes_done = ddir_rw_sum(td->io_bytes); |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 166 | perc = (double) bytes_done / (double) bytes_total; |
| 167 | if (perc > 1.0) |
| 168 | perc = 1.0; |
| 169 | |
Jens Axboe | cf4464c | 2007-04-17 20:14:42 +0200 | [diff] [blame] | 170 | if (td->o.time_based) { |
| 171 | perc_t = (double) elapsed / (double) td->o.timeout; |
| 172 | if (perc_t < perc) |
| 173 | perc = perc_t; |
| 174 | } |
| 175 | |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 176 | eta_sec = (unsigned long) (elapsed * (1.0 / perc)) - elapsed; |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 177 | |
Jens Axboe | d3eeeab | 2008-04-06 12:19:05 +0200 | [diff] [blame] | 178 | if (td->o.timeout && |
| 179 | eta_sec > (td->o.timeout + done_secs - elapsed)) |
| 180 | eta_sec = td->o.timeout + done_secs - elapsed; |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 181 | } else if (td->runstate == TD_NOT_CREATED || td->runstate == TD_CREATED |
Jens Axboe | b29ee5b | 2008-09-11 10:17:26 +0200 | [diff] [blame] | 182 | || td->runstate == TD_INITIALIZED |
Jens Axboe | b0f6586 | 2009-05-20 11:52:15 +0200 | [diff] [blame] | 183 | || td->runstate == TD_RAMP |
| 184 | || td->runstate == TD_PRE_READING) { |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 185 | int t_eta = 0, r_eta = 0; |
Jens Axboe | 342f4be | 2012-09-14 08:59:20 +0200 | [diff] [blame] | 186 | unsigned long long rate_bytes; |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 187 | |
| 188 | /* |
| 189 | * We can only guess - assume it'll run the full timeout |
| 190 | * if given, otherwise assume it'll run at the specified rate. |
| 191 | */ |
Jens Axboe | b29ee5b | 2008-09-11 10:17:26 +0200 | [diff] [blame] | 192 | if (td->o.timeout) { |
Signed-off-by Steven Pratt | cda99fa | 2010-12-14 08:31:36 +0100 | [diff] [blame] | 193 | t_eta = td->o.timeout + td->o.start_delay + |
| 194 | td->o.ramp_time; |
Jens Axboe | b29ee5b | 2008-09-11 10:17:26 +0200 | [diff] [blame] | 195 | |
| 196 | if (in_ramp_time(td)) { |
| 197 | unsigned long ramp_left; |
| 198 | |
Signed-off-by Steven Pratt | cda99fa | 2010-12-14 08:31:36 +0100 | [diff] [blame] | 199 | ramp_left = mtime_since_now(&td->epoch); |
Jens Axboe | b29ee5b | 2008-09-11 10:17:26 +0200 | [diff] [blame] | 200 | ramp_left = (ramp_left + 999) / 1000; |
| 201 | if (ramp_left <= t_eta) |
| 202 | t_eta -= ramp_left; |
| 203 | } |
| 204 | } |
Jens Axboe | 342f4be | 2012-09-14 08:59:20 +0200 | [diff] [blame] | 205 | rate_bytes = ddir_rw_sum(td->o.rate); |
| 206 | if (rate_bytes) { |
| 207 | r_eta = (bytes_total / 1024) / rate_bytes; |
Jens Axboe | d3eeeab | 2008-04-06 12:19:05 +0200 | [diff] [blame] | 208 | r_eta += td->o.start_delay; |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | if (r_eta && t_eta) |
| 212 | eta_sec = min(r_eta, t_eta); |
| 213 | else if (r_eta) |
| 214 | eta_sec = r_eta; |
| 215 | else if (t_eta) |
| 216 | eta_sec = t_eta; |
| 217 | else |
| 218 | eta_sec = 0; |
| 219 | } else { |
| 220 | /* |
| 221 | * thread is already done or waiting for fsync |
| 222 | */ |
| 223 | eta_sec = 0; |
| 224 | } |
| 225 | |
| 226 | return eta_sec; |
| 227 | } |
| 228 | |
Jens Axboe | 771e58b | 2013-01-30 12:56:23 +0100 | [diff] [blame] | 229 | static void calc_rate(int unified_rw_rep, unsigned long mtime, |
| 230 | unsigned long long *io_bytes, |
Jens Axboe | 46fda8d | 2007-02-11 00:49:30 +0100 | [diff] [blame] | 231 | unsigned long long *prev_io_bytes, unsigned int *rate) |
| 232 | { |
Jens Axboe | b7f05eb | 2012-05-11 20:33:02 +0200 | [diff] [blame] | 233 | int i; |
| 234 | |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 235 | for (i = 0; i < DDIR_RWDIR_CNT; i++) { |
Jens Axboe | b7f05eb | 2012-05-11 20:33:02 +0200 | [diff] [blame] | 236 | unsigned long long diff; |
| 237 | |
| 238 | diff = io_bytes[i] - prev_io_bytes[i]; |
Jens Axboe | 771e58b | 2013-01-30 12:56:23 +0100 | [diff] [blame] | 239 | if (unified_rw_rep) { |
| 240 | rate[i] = 0; |
| 241 | rate[0] += ((1000 * diff) / mtime) / 1024; |
| 242 | } else |
| 243 | rate[i] = ((1000 * diff) / mtime) / 1024; |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 244 | |
| 245 | prev_io_bytes[i] = io_bytes[i]; |
Jens Axboe | b7f05eb | 2012-05-11 20:33:02 +0200 | [diff] [blame] | 246 | } |
Jens Axboe | 46fda8d | 2007-02-11 00:49:30 +0100 | [diff] [blame] | 247 | } |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 248 | |
Jens Axboe | 771e58b | 2013-01-30 12:56:23 +0100 | [diff] [blame] | 249 | static void calc_iops(int unified_rw_rep, unsigned long mtime, |
| 250 | unsigned long long *io_iops, |
Jens Axboe | adb02ba | 2009-06-03 10:47:44 +0200 | [diff] [blame] | 251 | unsigned long long *prev_io_iops, unsigned int *iops) |
| 252 | { |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 253 | int i; |
| 254 | |
| 255 | for (i = 0; i < DDIR_RWDIR_CNT; i++) { |
Jens Axboe | 771e58b | 2013-01-30 12:56:23 +0100 | [diff] [blame] | 256 | unsigned long long diff; |
| 257 | |
| 258 | diff = io_iops[i] - prev_io_iops[i]; |
| 259 | if (unified_rw_rep) { |
| 260 | iops[i] = 0; |
| 261 | iops[0] += (diff * 1000) / mtime; |
| 262 | } else |
| 263 | iops[i] = (diff * 1000) / mtime; |
| 264 | |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 265 | prev_io_iops[i] = io_iops[i]; |
| 266 | } |
Jens Axboe | adb02ba | 2009-06-03 10:47:44 +0200 | [diff] [blame] | 267 | } |
| 268 | |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 269 | /* |
| 270 | * Print status of the jobs we know about. This includes rate estimates, |
| 271 | * ETA, thread state, etc. |
| 272 | */ |
Jens Axboe | af9c9fb | 2011-10-09 21:54:10 +0200 | [diff] [blame] | 273 | int calc_thread_status(struct jobs_eta *je, int force) |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 274 | { |
Jens Axboe | 34572e2 | 2006-10-20 09:33:18 +0200 | [diff] [blame] | 275 | struct thread_data *td; |
Jens Axboe | 771e58b | 2013-01-30 12:56:23 +0100 | [diff] [blame] | 276 | int i, unified_rw_rep; |
Jens Axboe | b75a394 | 2011-10-03 16:03:43 +0200 | [diff] [blame] | 277 | unsigned long rate_time, disp_time, bw_avg_time, *eta_secs; |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 278 | unsigned long long io_bytes[DDIR_RWDIR_CNT]; |
| 279 | unsigned long long io_iops[DDIR_RWDIR_CNT]; |
Jens Axboe | 46fda8d | 2007-02-11 00:49:30 +0100 | [diff] [blame] | 280 | struct timeval now; |
| 281 | |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 282 | static unsigned long long rate_io_bytes[DDIR_RWDIR_CNT]; |
| 283 | static unsigned long long disp_io_bytes[DDIR_RWDIR_CNT]; |
| 284 | static unsigned long long disp_io_iops[DDIR_RWDIR_CNT]; |
Jens Axboe | 46fda8d | 2007-02-11 00:49:30 +0100 | [diff] [blame] | 285 | static struct timeval rate_prev_time, disp_prev_time; |
Jens Axboe | 6043c57 | 2006-11-03 11:37:47 +0100 | [diff] [blame] | 286 | |
Jens Axboe | af9c9fb | 2011-10-09 21:54:10 +0200 | [diff] [blame] | 287 | if (!force) { |
Jens Axboe | fc47559 | 2013-01-31 15:24:34 +0100 | [diff] [blame^] | 288 | if (output_format != FIO_OUTPUT_NORMAL && |
| 289 | f_out == stdout) |
Jens Axboe | f3afa57 | 2012-09-17 13:34:16 +0200 | [diff] [blame] | 290 | return 0; |
| 291 | if (temp_stall_ts || eta_print == FIO_ETA_NEVER) |
Jens Axboe | af9c9fb | 2011-10-09 21:54:10 +0200 | [diff] [blame] | 292 | return 0; |
Aaron Carroll | e592a06 | 2007-09-14 09:49:41 +0200 | [diff] [blame] | 293 | |
Jens Axboe | af9c9fb | 2011-10-09 21:54:10 +0200 | [diff] [blame] | 294 | if (!isatty(STDOUT_FILENO) && (eta_print != FIO_ETA_ALWAYS)) |
| 295 | return 0; |
| 296 | } |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 297 | |
Jens Axboe | 342f4be | 2012-09-14 08:59:20 +0200 | [diff] [blame] | 298 | if (!ddir_rw_sum(rate_io_bytes)) |
Jens Axboe | 46fda8d | 2007-02-11 00:49:30 +0100 | [diff] [blame] | 299 | fill_start_time(&rate_prev_time); |
Jens Axboe | 342f4be | 2012-09-14 08:59:20 +0200 | [diff] [blame] | 300 | if (!ddir_rw_sum(disp_io_bytes)) |
Jens Axboe | 46fda8d | 2007-02-11 00:49:30 +0100 | [diff] [blame] | 301 | fill_start_time(&disp_prev_time); |
Jens Axboe | 6043c57 | 2006-11-03 11:37:47 +0100 | [diff] [blame] | 302 | |
Jens Axboe | d3eeeab | 2008-04-06 12:19:05 +0200 | [diff] [blame] | 303 | eta_secs = malloc(thread_number * sizeof(unsigned long)); |
| 304 | memset(eta_secs, 0, thread_number * sizeof(unsigned long)); |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 305 | |
Jens Axboe | b75a394 | 2011-10-03 16:03:43 +0200 | [diff] [blame] | 306 | je->elapsed_sec = (mtime_since_genesis() + 999) / 1000; |
| 307 | |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 308 | io_bytes[DDIR_READ] = io_bytes[DDIR_WRITE] = io_bytes[DDIR_TRIM] = 0; |
| 309 | io_iops[DDIR_READ] = io_iops[DDIR_WRITE] = io_iops[DDIR_TRIM] = 0; |
Jens Axboe | bb3884d | 2007-01-17 17:23:11 +1100 | [diff] [blame] | 310 | bw_avg_time = ULONG_MAX; |
Jens Axboe | 771e58b | 2013-01-30 12:56:23 +0100 | [diff] [blame] | 311 | unified_rw_rep = 0; |
Jens Axboe | 34572e2 | 2006-10-20 09:33:18 +0200 | [diff] [blame] | 312 | for_each_td(td, i) { |
Jens Axboe | 771e58b | 2013-01-30 12:56:23 +0100 | [diff] [blame] | 313 | unified_rw_rep += td->o.unified_rw_rep; |
Jens Axboe | b7f05eb | 2012-05-11 20:33:02 +0200 | [diff] [blame] | 314 | if (is_power_of_2(td->o.kb_base)) |
| 315 | je->is_pow2 = 1; |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 316 | if (td->o.bw_avg_time < bw_avg_time) |
| 317 | bw_avg_time = td->o.bw_avg_time; |
Jens Axboe | 46fda8d | 2007-02-11 00:49:30 +0100 | [diff] [blame] | 318 | if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING |
Jens Axboe | b0f6586 | 2009-05-20 11:52:15 +0200 | [diff] [blame] | 319 | || td->runstate == TD_FSYNCING |
| 320 | || td->runstate == TD_PRE_READING) { |
Jens Axboe | b75a394 | 2011-10-03 16:03:43 +0200 | [diff] [blame] | 321 | je->nr_running++; |
Jens Axboe | 242c38d | 2012-08-20 14:44:22 +0200 | [diff] [blame] | 322 | if (td_read(td)) { |
| 323 | je->t_rate += td->o.rate[DDIR_READ]; |
| 324 | je->t_iops += td->o.rate_iops[DDIR_READ]; |
| 325 | je->m_rate += td->o.ratemin[DDIR_READ]; |
| 326 | je->m_iops += td->o.rate_iops_min[DDIR_READ]; |
| 327 | } |
| 328 | if (td_write(td)) { |
| 329 | je->t_rate += td->o.rate[DDIR_WRITE]; |
| 330 | je->t_iops += td->o.rate_iops[DDIR_WRITE]; |
| 331 | je->m_rate += td->o.ratemin[DDIR_WRITE]; |
| 332 | je->m_iops += td->o.rate_iops_min[DDIR_WRITE]; |
| 333 | } |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 334 | if (td_trim(td)) { |
| 335 | je->t_rate += td->o.rate[DDIR_TRIM]; |
| 336 | je->t_iops += td->o.rate_iops[DDIR_TRIM]; |
| 337 | je->m_rate += td->o.ratemin[DDIR_TRIM]; |
| 338 | je->m_iops += td->o.rate_iops_min[DDIR_TRIM]; |
| 339 | } |
| 340 | |
Jens Axboe | b75a394 | 2011-10-03 16:03:43 +0200 | [diff] [blame] | 341 | je->files_open += td->nr_open_files; |
Jens Axboe | b29ee5b | 2008-09-11 10:17:26 +0200 | [diff] [blame] | 342 | } else if (td->runstate == TD_RAMP) { |
Jens Axboe | b75a394 | 2011-10-03 16:03:43 +0200 | [diff] [blame] | 343 | je->nr_running++; |
| 344 | je->nr_ramp++; |
Jens Axboe | 9c6f631 | 2012-11-07 09:15:45 +0100 | [diff] [blame] | 345 | } else if (td->runstate == TD_SETTING_UP) |
| 346 | je->nr_running++; |
| 347 | else if (td->runstate < TD_RUNNING) |
Jens Axboe | b75a394 | 2011-10-03 16:03:43 +0200 | [diff] [blame] | 348 | je->nr_pending++; |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 349 | |
Jens Axboe | b75a394 | 2011-10-03 16:03:43 +0200 | [diff] [blame] | 350 | if (je->elapsed_sec >= 3) |
Jens Axboe | b29ee5b | 2008-09-11 10:17:26 +0200 | [diff] [blame] | 351 | eta_secs[i] = thread_eta(td); |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 352 | else |
| 353 | eta_secs[i] = INT_MAX; |
| 354 | |
| 355 | check_str_update(td); |
Jens Axboe | b29ee5b | 2008-09-11 10:17:26 +0200 | [diff] [blame] | 356 | |
| 357 | if (td->runstate > TD_RAMP) { |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 358 | int ddir; |
Jens Axboe | 771e58b | 2013-01-30 12:56:23 +0100 | [diff] [blame] | 359 | |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 360 | for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) { |
Jens Axboe | 771e58b | 2013-01-30 12:56:23 +0100 | [diff] [blame] | 361 | if (unified_rw_rep) { |
| 362 | io_bytes[0] += td->io_bytes[ddir]; |
| 363 | io_iops[0] += td->io_blocks[ddir]; |
| 364 | } else { |
| 365 | io_bytes[ddir] += td->io_bytes[ddir]; |
| 366 | io_iops[ddir] += td->io_blocks[ddir]; |
| 367 | } |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 368 | } |
Jens Axboe | b29ee5b | 2008-09-11 10:17:26 +0200 | [diff] [blame] | 369 | } |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | if (exitall_on_terminate) |
Jens Axboe | b75a394 | 2011-10-03 16:03:43 +0200 | [diff] [blame] | 373 | je->eta_sec = INT_MAX; |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 374 | else |
Jens Axboe | b75a394 | 2011-10-03 16:03:43 +0200 | [diff] [blame] | 375 | je->eta_sec = 0; |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 376 | |
Jens Axboe | 34572e2 | 2006-10-20 09:33:18 +0200 | [diff] [blame] | 377 | for_each_td(td, i) { |
Shaozhi Shawn Ye | 9c5a385 | 2008-09-10 09:09:37 +0200 | [diff] [blame] | 378 | if (exitall_on_terminate) { |
Jens Axboe | b75a394 | 2011-10-03 16:03:43 +0200 | [diff] [blame] | 379 | if (eta_secs[i] < je->eta_sec) |
| 380 | je->eta_sec = eta_secs[i]; |
Shaozhi Shawn Ye | 9c5a385 | 2008-09-10 09:09:37 +0200 | [diff] [blame] | 381 | } else { |
Jens Axboe | b75a394 | 2011-10-03 16:03:43 +0200 | [diff] [blame] | 382 | if (eta_secs[i] > je->eta_sec) |
| 383 | je->eta_sec = eta_secs[i]; |
Shaozhi Shawn Ye | 9c5a385 | 2008-09-10 09:09:37 +0200 | [diff] [blame] | 384 | } |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 385 | } |
| 386 | |
Jens Axboe | eecf272 | 2006-10-20 14:00:36 +0200 | [diff] [blame] | 387 | free(eta_secs); |
| 388 | |
Jens Axboe | 46fda8d | 2007-02-11 00:49:30 +0100 | [diff] [blame] | 389 | fio_gettime(&now, NULL); |
| 390 | rate_time = mtime_since(&rate_prev_time, &now); |
| 391 | |
Jens Axboe | b29ee5b | 2008-09-11 10:17:26 +0200 | [diff] [blame] | 392 | if (write_bw_log && rate_time > bw_avg_time && !in_ramp_time(td)) { |
Jens Axboe | 771e58b | 2013-01-30 12:56:23 +0100 | [diff] [blame] | 393 | calc_rate(unified_rw_rep, rate_time, io_bytes, rate_io_bytes, |
| 394 | je->rate); |
Jens Axboe | 46fda8d | 2007-02-11 00:49:30 +0100 | [diff] [blame] | 395 | memcpy(&rate_prev_time, &now, sizeof(now)); |
Jens Axboe | b75a394 | 2011-10-03 16:03:43 +0200 | [diff] [blame] | 396 | add_agg_sample(je->rate[DDIR_READ], DDIR_READ, 0); |
| 397 | add_agg_sample(je->rate[DDIR_WRITE], DDIR_WRITE, 0); |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 398 | add_agg_sample(je->rate[DDIR_TRIM], DDIR_TRIM, 0); |
Jens Axboe | 6043c57 | 2006-11-03 11:37:47 +0100 | [diff] [blame] | 399 | } |
| 400 | |
Jens Axboe | 46fda8d | 2007-02-11 00:49:30 +0100 | [diff] [blame] | 401 | disp_time = mtime_since(&disp_prev_time, &now); |
Jens Axboe | a5b01f1 | 2010-11-11 09:19:49 +0100 | [diff] [blame] | 402 | |
| 403 | /* |
| 404 | * Allow a little slack, the target is to print it every 1000 msecs |
| 405 | */ |
Jens Axboe | af9c9fb | 2011-10-09 21:54:10 +0200 | [diff] [blame] | 406 | if (!force && disp_time < 900) |
Jens Axboe | b75a394 | 2011-10-03 16:03:43 +0200 | [diff] [blame] | 407 | return 0; |
Jens Axboe | 46fda8d | 2007-02-11 00:49:30 +0100 | [diff] [blame] | 408 | |
Jens Axboe | 771e58b | 2013-01-30 12:56:23 +0100 | [diff] [blame] | 409 | calc_rate(unified_rw_rep, disp_time, io_bytes, disp_io_bytes, je->rate); |
| 410 | calc_iops(unified_rw_rep, disp_time, io_iops, disp_io_iops, je->iops); |
Jens Axboe | adb02ba | 2009-06-03 10:47:44 +0200 | [diff] [blame] | 411 | |
Jens Axboe | 46fda8d | 2007-02-11 00:49:30 +0100 | [diff] [blame] | 412 | memcpy(&disp_prev_time, &now, sizeof(now)); |
| 413 | |
Jens Axboe | af9c9fb | 2011-10-09 21:54:10 +0200 | [diff] [blame] | 414 | if (!force && !je->nr_running && !je->nr_pending) |
Jens Axboe | b75a394 | 2011-10-03 16:03:43 +0200 | [diff] [blame] | 415 | return 0; |
| 416 | |
Jens Axboe | 1d1f45a | 2011-10-03 19:44:41 +0200 | [diff] [blame] | 417 | je->nr_threads = thread_number; |
| 418 | memcpy(je->run_str, run_str, thread_number * sizeof(char)); |
| 419 | |
Jens Axboe | b75a394 | 2011-10-03 16:03:43 +0200 | [diff] [blame] | 420 | return 1; |
| 421 | } |
| 422 | |
Jens Axboe | cf451d1 | 2011-10-03 16:48:30 +0200 | [diff] [blame] | 423 | void display_thread_status(struct jobs_eta *je) |
Jens Axboe | b75a394 | 2011-10-03 16:03:43 +0200 | [diff] [blame] | 424 | { |
Jens Axboe | b75a394 | 2011-10-03 16:03:43 +0200 | [diff] [blame] | 425 | static int linelen_last; |
| 426 | static int eta_good; |
Jens Axboe | 79074e7 | 2012-04-18 20:39:48 +0200 | [diff] [blame] | 427 | char output[REAL_MAX_JOBS + 512], *p = output; |
Jens Axboe | b75a394 | 2011-10-03 16:03:43 +0200 | [diff] [blame] | 428 | char eta_str[128]; |
| 429 | double perc = 0.0; |
Jens Axboe | b75a394 | 2011-10-03 16:03:43 +0200 | [diff] [blame] | 430 | |
Jens Axboe | cf451d1 | 2011-10-03 16:48:30 +0200 | [diff] [blame] | 431 | if (je->eta_sec != INT_MAX && je->elapsed_sec) { |
| 432 | perc = (double) je->elapsed_sec / (double) (je->elapsed_sec + je->eta_sec); |
| 433 | eta_to_str(eta_str, je->eta_sec); |
Jens Axboe | b75a394 | 2011-10-03 16:03:43 +0200 | [diff] [blame] | 434 | } |
| 435 | |
Jens Axboe | cf451d1 | 2011-10-03 16:48:30 +0200 | [diff] [blame] | 436 | p += sprintf(p, "Jobs: %d (f=%d)", je->nr_running, je->files_open); |
| 437 | if (je->m_rate || je->t_rate) { |
Jens Axboe | 581e714 | 2009-06-09 12:47:16 +0200 | [diff] [blame] | 438 | char *tr, *mr; |
| 439 | |
Jens Axboe | b7f05eb | 2012-05-11 20:33:02 +0200 | [diff] [blame] | 440 | mr = num2str(je->m_rate, 4, 0, je->is_pow2); |
| 441 | tr = num2str(je->t_rate, 4, 0, je->is_pow2); |
Jens Axboe | 37db14f | 2011-09-30 17:00:42 -0600 | [diff] [blame] | 442 | p += sprintf(p, ", CR=%s/%s KB/s", tr, mr); |
Jens Axboe | 581e714 | 2009-06-09 12:47:16 +0200 | [diff] [blame] | 443 | free(tr); |
| 444 | free(mr); |
Jens Axboe | cf451d1 | 2011-10-03 16:48:30 +0200 | [diff] [blame] | 445 | } else if (je->m_iops || je->t_iops) |
| 446 | p += sprintf(p, ", CR=%d/%d IOPS", je->t_iops, je->m_iops); |
| 447 | if (je->eta_sec != INT_MAX && je->nr_running) { |
Jens Axboe | 0721d11 | 2008-06-05 09:03:05 +0200 | [diff] [blame] | 448 | char perc_str[32]; |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 449 | char *iops_str[DDIR_RWDIR_CNT]; |
| 450 | char *rate_str[DDIR_RWDIR_CNT]; |
Jens Axboe | 79074e7 | 2012-04-18 20:39:48 +0200 | [diff] [blame] | 451 | size_t left; |
Jens Axboe | adb02ba | 2009-06-03 10:47:44 +0200 | [diff] [blame] | 452 | int l; |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 453 | int ddir; |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 454 | |
Jens Axboe | cf451d1 | 2011-10-03 16:48:30 +0200 | [diff] [blame] | 455 | if ((!je->eta_sec && !eta_good) || je->nr_ramp == je->nr_running) |
Jens Axboe | cac58fd | 2008-06-06 01:17:03 +0200 | [diff] [blame] | 456 | strcpy(perc_str, "-.-% done"); |
| 457 | else { |
| 458 | eta_good = 1; |
| 459 | perc *= 100.0; |
Jens Axboe | 0721d11 | 2008-06-05 09:03:05 +0200 | [diff] [blame] | 460 | sprintf(perc_str, "%3.1f%% done", perc); |
Jens Axboe | cac58fd | 2008-06-06 01:17:03 +0200 | [diff] [blame] | 461 | } |
Jens Axboe | 0721d11 | 2008-06-05 09:03:05 +0200 | [diff] [blame] | 462 | |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 463 | for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) { |
| 464 | rate_str[ddir] = num2str(je->rate[ddir], 5, |
| 465 | 1024, je->is_pow2); |
| 466 | iops_str[ddir] = num2str(je->iops[ddir], 4, 1, 0); |
| 467 | } |
Jens Axboe | adb02ba | 2009-06-03 10:47:44 +0200 | [diff] [blame] | 468 | |
Jens Axboe | 79074e7 | 2012-04-18 20:39:48 +0200 | [diff] [blame] | 469 | left = sizeof(output) - (p - output) - 1; |
| 470 | |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 471 | l = snprintf(p, left, ": [%s] [%s] [%s/%s/%s /s] [%s/%s/%s iops] [eta %s]", |
| 472 | je->run_str, perc_str, rate_str[DDIR_READ], |
| 473 | rate_str[DDIR_WRITE], rate_str[DDIR_TRIM], |
| 474 | iops_str[DDIR_READ], iops_str[DDIR_WRITE], |
| 475 | iops_str[DDIR_TRIM], eta_str); |
Jens Axboe | 37db14f | 2011-09-30 17:00:42 -0600 | [diff] [blame] | 476 | p += l; |
Jens Axboe | adb02ba | 2009-06-03 10:47:44 +0200 | [diff] [blame] | 477 | if (l >= 0 && l < linelen_last) |
Jens Axboe | 37db14f | 2011-09-30 17:00:42 -0600 | [diff] [blame] | 478 | p += sprintf(p, "%*s", linelen_last - l, ""); |
Jens Axboe | adb02ba | 2009-06-03 10:47:44 +0200 | [diff] [blame] | 479 | linelen_last = l; |
Jens Axboe | d1bd721 | 2009-06-03 10:53:45 +0200 | [diff] [blame] | 480 | |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 481 | for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) { |
| 482 | free(rate_str[ddir]); |
| 483 | free(iops_str[ddir]); |
| 484 | } |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 485 | } |
Jens Axboe | 37db14f | 2011-09-30 17:00:42 -0600 | [diff] [blame] | 486 | p += sprintf(p, "\r"); |
| 487 | |
Jens Axboe | cf451d1 | 2011-10-03 16:48:30 +0200 | [diff] [blame] | 488 | printf("%s", output); |
| 489 | fflush(stdout); |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 490 | } |
| 491 | |
Jens Axboe | cf451d1 | 2011-10-03 16:48:30 +0200 | [diff] [blame] | 492 | void print_thread_status(void) |
| 493 | { |
Jens Axboe | 1d1f45a | 2011-10-03 19:44:41 +0200 | [diff] [blame] | 494 | struct jobs_eta *je; |
Jens Axboe | b814fb2 | 2011-10-12 09:20:34 +0200 | [diff] [blame] | 495 | size_t size; |
Jens Axboe | cf451d1 | 2011-10-03 16:48:30 +0200 | [diff] [blame] | 496 | |
Jens Axboe | b814fb2 | 2011-10-12 09:20:34 +0200 | [diff] [blame] | 497 | if (!thread_number) |
| 498 | return; |
Jens Axboe | cf451d1 | 2011-10-03 16:48:30 +0200 | [diff] [blame] | 499 | |
Jens Axboe | b814fb2 | 2011-10-12 09:20:34 +0200 | [diff] [blame] | 500 | size = sizeof(*je) + thread_number * sizeof(char) + 1; |
| 501 | je = malloc(size); |
| 502 | memset(je, 0, size); |
Jens Axboe | cf451d1 | 2011-10-03 16:48:30 +0200 | [diff] [blame] | 503 | |
Jens Axboe | af9c9fb | 2011-10-09 21:54:10 +0200 | [diff] [blame] | 504 | if (calc_thread_status(je, 0)) |
Jens Axboe | 1d1f45a | 2011-10-03 19:44:41 +0200 | [diff] [blame] | 505 | display_thread_status(je); |
| 506 | |
| 507 | free(je); |
Jens Axboe | cf451d1 | 2011-10-03 16:48:30 +0200 | [diff] [blame] | 508 | } |
Jens Axboe | b75a394 | 2011-10-03 16:03:43 +0200 | [diff] [blame] | 509 | |
Jens Axboe | 2b13e71 | 2011-01-19 14:04:16 -0700 | [diff] [blame] | 510 | void print_status_init(int thr_number) |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 511 | { |
Jens Axboe | 2b13e71 | 2011-01-19 14:04:16 -0700 | [diff] [blame] | 512 | run_str[thr_number] = 'P'; |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 513 | } |