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 | |
| 10 | static char run_str[MAX_JOBS + 1]; |
| 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: |
| 21 | c = '_'; |
| 22 | break; |
| 23 | case TD_EXITED: |
| 24 | c = 'E'; |
| 25 | break; |
| 26 | case TD_RUNNING: |
| 27 | if (td_rw(td)) { |
| 28 | if (td_random(td)) |
| 29 | c = 'm'; |
| 30 | else |
| 31 | c = 'M'; |
| 32 | } else if (td_read(td)) { |
| 33 | if (td_random(td)) |
| 34 | c = 'r'; |
| 35 | else |
| 36 | c = 'R'; |
| 37 | } else { |
| 38 | if (td_random(td)) |
| 39 | c = 'w'; |
| 40 | else |
| 41 | c = 'W'; |
| 42 | } |
| 43 | break; |
| 44 | case TD_VERIFYING: |
| 45 | c = 'V'; |
| 46 | break; |
| 47 | case TD_FSYNCING: |
| 48 | c = 'F'; |
| 49 | break; |
| 50 | case TD_CREATED: |
| 51 | c = 'C'; |
| 52 | break; |
| 53 | case TD_INITIALIZED: |
| 54 | c = 'I'; |
| 55 | break; |
| 56 | case TD_NOT_CREATED: |
| 57 | c = 'P'; |
| 58 | break; |
| 59 | default: |
| 60 | log_err("state %d\n", td->runstate); |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | run_str[td->thread_number - 1] = c; |
| 64 | } |
| 65 | |
| 66 | /* |
| 67 | * Convert seconds to a printable string. |
| 68 | */ |
| 69 | static void eta_to_str(char *str, int eta_sec) |
| 70 | { |
| 71 | unsigned int d, h, m, s; |
Jens Axboe | 165faf1 | 2007-02-07 11:30:37 +0100 | [diff] [blame] | 72 | int disp_hour = 0; |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 73 | |
| 74 | d = h = m = s = 0; |
| 75 | |
| 76 | s = eta_sec % 60; |
| 77 | eta_sec /= 60; |
| 78 | m = eta_sec % 60; |
| 79 | eta_sec /= 60; |
| 80 | h = eta_sec % 24; |
| 81 | eta_sec /= 24; |
| 82 | d = eta_sec; |
| 83 | |
Jens Axboe | 165faf1 | 2007-02-07 11:30:37 +0100 | [diff] [blame] | 84 | if (d) { |
| 85 | disp_hour = 1; |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 86 | str += sprintf(str, "%02ud:", d); |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 87 | } |
Jens Axboe | 165faf1 | 2007-02-07 11:30:37 +0100 | [diff] [blame] | 88 | |
| 89 | if (h || disp_hour) |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 90 | str += sprintf(str, "%02uh:", h); |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 91 | |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 92 | str += sprintf(str, "%02um:", m); |
| 93 | str += sprintf(str, "%02us", s); |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | /* |
| 97 | * Best effort calculation of the estimated pending runtime of a job. |
| 98 | */ |
| 99 | static int thread_eta(struct thread_data *td, unsigned long elapsed) |
| 100 | { |
| 101 | unsigned long long bytes_total, bytes_done; |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 102 | unsigned long eta_sec = 0; |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 103 | |
| 104 | bytes_total = td->total_io_size; |
| 105 | |
Jens Axboe | 74939e3 | 2006-10-19 20:37:12 +0200 | [diff] [blame] | 106 | /* |
| 107 | * if writing, bytes_total will be twice the size. If mixing, |
| 108 | * assume a 50/50 split and thus bytes_total will be 50% larger. |
| 109 | */ |
Jens Axboe | 0dd8377 | 2007-09-04 12:38:28 +0200 | [diff] [blame] | 110 | if (td->o.do_verify && td->o.verify && td_write(td)) { |
Jens Axboe | 74939e3 | 2006-10-19 20:37:12 +0200 | [diff] [blame] | 111 | if (td_rw(td)) |
| 112 | bytes_total = bytes_total * 3 / 2; |
| 113 | else |
| 114 | bytes_total <<= 1; |
| 115 | } |
| 116 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 117 | if (td->o.zone_size && td->o.zone_skip) |
| 118 | bytes_total /= (td->o.zone_skip / td->o.zone_size); |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 119 | |
| 120 | if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING) { |
Jens Axboe | cf4464c | 2007-04-17 20:14:42 +0200 | [diff] [blame] | 121 | double perc, perc_t; |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 122 | |
| 123 | bytes_done = td->io_bytes[DDIR_READ] + td->io_bytes[DDIR_WRITE]; |
| 124 | perc = (double) bytes_done / (double) bytes_total; |
| 125 | if (perc > 1.0) |
| 126 | perc = 1.0; |
| 127 | |
Jens Axboe | cf4464c | 2007-04-17 20:14:42 +0200 | [diff] [blame] | 128 | if (td->o.time_based) { |
| 129 | perc_t = (double) elapsed / (double) td->o.timeout; |
| 130 | if (perc_t < perc) |
| 131 | perc = perc_t; |
| 132 | } |
| 133 | |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 134 | eta_sec = (unsigned long) (elapsed * (1.0 / perc)) - elapsed; |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 135 | |
Jens Axboe | d3eeeab | 2008-04-06 12:19:05 +0200 | [diff] [blame] | 136 | if (td->o.timeout && |
| 137 | eta_sec > (td->o.timeout + done_secs - elapsed)) |
| 138 | eta_sec = td->o.timeout + done_secs - elapsed; |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 139 | } else if (td->runstate == TD_NOT_CREATED || td->runstate == TD_CREATED |
| 140 | || td->runstate == TD_INITIALIZED) { |
| 141 | int t_eta = 0, r_eta = 0; |
| 142 | |
| 143 | /* |
| 144 | * We can only guess - assume it'll run the full timeout |
| 145 | * if given, otherwise assume it'll run at the specified rate. |
| 146 | */ |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 147 | if (td->o.timeout) |
Jens Axboe | d3eeeab | 2008-04-06 12:19:05 +0200 | [diff] [blame] | 148 | t_eta = td->o.timeout + td->o.start_delay; |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 149 | if (td->o.rate) { |
| 150 | r_eta = (bytes_total / 1024) / td->o.rate; |
Jens Axboe | d3eeeab | 2008-04-06 12:19:05 +0200 | [diff] [blame] | 151 | r_eta += td->o.start_delay; |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | if (r_eta && t_eta) |
| 155 | eta_sec = min(r_eta, t_eta); |
| 156 | else if (r_eta) |
| 157 | eta_sec = r_eta; |
| 158 | else if (t_eta) |
| 159 | eta_sec = t_eta; |
| 160 | else |
| 161 | eta_sec = 0; |
| 162 | } else { |
| 163 | /* |
| 164 | * thread is already done or waiting for fsync |
| 165 | */ |
| 166 | eta_sec = 0; |
| 167 | } |
| 168 | |
| 169 | return eta_sec; |
| 170 | } |
| 171 | |
Jens Axboe | 46fda8d | 2007-02-11 00:49:30 +0100 | [diff] [blame] | 172 | static void calc_rate(unsigned long mtime, unsigned long long *io_bytes, |
| 173 | unsigned long long *prev_io_bytes, unsigned int *rate) |
| 174 | { |
| 175 | rate[0] = (io_bytes[0] - prev_io_bytes[0]) / mtime; |
| 176 | rate[1] = (io_bytes[1] - prev_io_bytes[1]) / mtime; |
| 177 | prev_io_bytes[0] = io_bytes[0]; |
| 178 | prev_io_bytes[1] = io_bytes[1]; |
| 179 | } |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 180 | |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 181 | /* |
| 182 | * Print status of the jobs we know about. This includes rate estimates, |
| 183 | * ETA, thread state, etc. |
| 184 | */ |
| 185 | void print_thread_status(void) |
| 186 | { |
| 187 | unsigned long elapsed = mtime_since_genesis() / 1000; |
Jens Axboe | d3eeeab | 2008-04-06 12:19:05 +0200 | [diff] [blame] | 188 | int i, nr_running, nr_pending, t_rate, m_rate; |
Jens Axboe | e6e4160 | 2007-03-27 20:20:36 +0200 | [diff] [blame] | 189 | int t_iops, m_iops, files_open; |
Jens Axboe | 34572e2 | 2006-10-20 09:33:18 +0200 | [diff] [blame] | 190 | struct thread_data *td; |
Jens Axboe | 2eaa41c | 2007-02-11 00:51:30 +0100 | [diff] [blame] | 191 | char eta_str[128]; |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 192 | double perc = 0.0; |
Jens Axboe | 6043c57 | 2006-11-03 11:37:47 +0100 | [diff] [blame] | 193 | unsigned long long io_bytes[2]; |
Jens Axboe | d3eeeab | 2008-04-06 12:19:05 +0200 | [diff] [blame] | 194 | unsigned long rate_time, disp_time, bw_avg_time, *eta_secs, eta_sec; |
Jens Axboe | 46fda8d | 2007-02-11 00:49:30 +0100 | [diff] [blame] | 195 | struct timeval now; |
| 196 | |
| 197 | static unsigned long long rate_io_bytes[2]; |
| 198 | static unsigned long long disp_io_bytes[2]; |
| 199 | static struct timeval rate_prev_time, disp_prev_time; |
| 200 | static unsigned int rate[2]; |
Aaron Carroll | 4381960 | 2007-10-26 11:10:28 +0200 | [diff] [blame] | 201 | static int linelen_last; |
Jens Axboe | 6043c57 | 2006-11-03 11:37:47 +0100 | [diff] [blame] | 202 | |
Aaron Carroll | e592a06 | 2007-09-14 09:49:41 +0200 | [diff] [blame] | 203 | if (temp_stall_ts || terse_output || eta_print == FIO_ETA_NEVER) |
| 204 | return; |
| 205 | |
| 206 | if (!isatty(STDOUT_FILENO) && (eta_print != FIO_ETA_ALWAYS)) |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 207 | return; |
| 208 | |
Jens Axboe | 46fda8d | 2007-02-11 00:49:30 +0100 | [diff] [blame] | 209 | if (!rate_io_bytes[0] && !rate_io_bytes[1]) |
| 210 | fill_start_time(&rate_prev_time); |
| 211 | if (!disp_io_bytes[0] && !disp_io_bytes[1]) |
| 212 | fill_start_time(&disp_prev_time); |
Jens Axboe | 6043c57 | 2006-11-03 11:37:47 +0100 | [diff] [blame] | 213 | |
Jens Axboe | d3eeeab | 2008-04-06 12:19:05 +0200 | [diff] [blame] | 214 | eta_secs = malloc(thread_number * sizeof(unsigned long)); |
| 215 | memset(eta_secs, 0, thread_number * sizeof(unsigned long)); |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 216 | |
Jens Axboe | 6043c57 | 2006-11-03 11:37:47 +0100 | [diff] [blame] | 217 | io_bytes[0] = io_bytes[1] = 0; |
Jens Axboe | ac71feb | 2007-03-16 10:24:07 +0100 | [diff] [blame] | 218 | nr_pending = nr_running = t_rate = m_rate = t_iops = m_iops = 0; |
Jens Axboe | bb3884d | 2007-01-17 17:23:11 +1100 | [diff] [blame] | 219 | bw_avg_time = ULONG_MAX; |
Jens Axboe | e6e4160 | 2007-03-27 20:20:36 +0200 | [diff] [blame] | 220 | files_open = 0; |
Jens Axboe | 34572e2 | 2006-10-20 09:33:18 +0200 | [diff] [blame] | 221 | for_each_td(td, i) { |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 222 | if (td->o.bw_avg_time < bw_avg_time) |
| 223 | bw_avg_time = td->o.bw_avg_time; |
Jens Axboe | 46fda8d | 2007-02-11 00:49:30 +0100 | [diff] [blame] | 224 | if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING |
| 225 | || td->runstate == TD_FSYNCING) { |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 226 | nr_running++; |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 227 | t_rate += td->o.rate; |
| 228 | m_rate += td->o.ratemin; |
Jens Axboe | ac71feb | 2007-03-16 10:24:07 +0100 | [diff] [blame] | 229 | t_iops += td->o.rate_iops; |
| 230 | m_iops += td->o.rate_iops_min; |
Jens Axboe | e6e4160 | 2007-03-27 20:20:36 +0200 | [diff] [blame] | 231 | files_open += td->nr_open_files; |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 232 | } else if (td->runstate < TD_RUNNING) |
| 233 | nr_pending++; |
| 234 | |
| 235 | if (elapsed >= 3) |
| 236 | eta_secs[i] = thread_eta(td, elapsed); |
| 237 | else |
| 238 | eta_secs[i] = INT_MAX; |
| 239 | |
| 240 | check_str_update(td); |
Jens Axboe | 6043c57 | 2006-11-03 11:37:47 +0100 | [diff] [blame] | 241 | io_bytes[0] += td->io_bytes[0]; |
| 242 | io_bytes[1] += td->io_bytes[1]; |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | if (exitall_on_terminate) |
| 246 | eta_sec = INT_MAX; |
| 247 | else |
| 248 | eta_sec = 0; |
| 249 | |
Jens Axboe | 34572e2 | 2006-10-20 09:33:18 +0200 | [diff] [blame] | 250 | for_each_td(td, i) { |
Jens Axboe | d3eeeab | 2008-04-06 12:19:05 +0200 | [diff] [blame] | 251 | if (eta_secs[i] != INT_MAX) |
| 252 | eta_sec += eta_secs[i]; |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 253 | } |
| 254 | |
Jens Axboe | eecf272 | 2006-10-20 14:00:36 +0200 | [diff] [blame] | 255 | free(eta_secs); |
| 256 | |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 257 | if (eta_sec != INT_MAX && elapsed) { |
| 258 | perc = (double) elapsed / (double) (elapsed + eta_sec); |
| 259 | eta_to_str(eta_str, eta_sec); |
| 260 | } |
| 261 | |
Jens Axboe | 46fda8d | 2007-02-11 00:49:30 +0100 | [diff] [blame] | 262 | fio_gettime(&now, NULL); |
| 263 | rate_time = mtime_since(&rate_prev_time, &now); |
| 264 | |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 265 | if (write_bw_log && rate_time > bw_avg_time) { |
Jens Axboe | 46fda8d | 2007-02-11 00:49:30 +0100 | [diff] [blame] | 266 | calc_rate(rate_time, io_bytes, rate_io_bytes, rate); |
| 267 | memcpy(&rate_prev_time, &now, sizeof(now)); |
| 268 | add_agg_sample(rate[DDIR_READ], DDIR_READ); |
| 269 | add_agg_sample(rate[DDIR_WRITE], DDIR_WRITE); |
Jens Axboe | 6043c57 | 2006-11-03 11:37:47 +0100 | [diff] [blame] | 270 | } |
| 271 | |
Jens Axboe | 46fda8d | 2007-02-11 00:49:30 +0100 | [diff] [blame] | 272 | disp_time = mtime_since(&disp_prev_time, &now); |
| 273 | if (disp_time < 1000) |
| 274 | return; |
| 275 | |
| 276 | calc_rate(disp_time, io_bytes, disp_io_bytes, rate); |
| 277 | memcpy(&disp_prev_time, &now, sizeof(now)); |
| 278 | |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 279 | if (!nr_running && !nr_pending) |
| 280 | return; |
| 281 | |
Jens Axboe | e6e4160 | 2007-03-27 20:20:36 +0200 | [diff] [blame] | 282 | printf("Jobs: %d (f=%d)", nr_running, files_open); |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 283 | if (m_rate || t_rate) |
Jens Axboe | 2cb8d96 | 2007-01-13 15:15:47 +0100 | [diff] [blame] | 284 | printf(", CR=%d/%d KiB/s", t_rate, m_rate); |
Jens Axboe | ac71feb | 2007-03-16 10:24:07 +0100 | [diff] [blame] | 285 | else if (m_iops || t_iops) |
| 286 | printf(", CR=%d/%d IOPS", t_iops, m_iops); |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 287 | if (eta_sec != INT_MAX && nr_running) { |
Jens Axboe | 0721d11 | 2008-06-05 09:03:05 +0200 | [diff] [blame] | 288 | char perc_str[32]; |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 289 | int ll; |
| 290 | |
Jens Axboe | 0721d11 | 2008-06-05 09:03:05 +0200 | [diff] [blame] | 291 | if (!eta_sec) |
| 292 | strcpy(perc_str, "--- done"); |
| 293 | else |
| 294 | sprintf(perc_str, "%3.1f%% done", perc); |
| 295 | |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 296 | perc *= 100.0; |
Jens Axboe | 0721d11 | 2008-06-05 09:03:05 +0200 | [diff] [blame] | 297 | ll = printf(": [%s] [%s] [%6u/%6u kb/s] [eta %s]", |
| 298 | run_str, perc_str, rate[0], rate[1], eta_str); |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 299 | if (ll >= 0 && ll < linelen_last) |
| 300 | printf("%*s", linelen_last - ll, ""); |
| 301 | linelen_last = ll; |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 302 | } |
| 303 | printf("\r"); |
| 304 | fflush(stdout); |
Jens Axboe | 263e529 | 2006-10-18 15:37:01 +0200 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | void print_status_init(int thread_number) |
| 308 | { |
| 309 | run_str[thread_number] = 'P'; |
| 310 | } |