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