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