10 static char run_str[REAL_MAX_JOBS + 1];
13 * Sets the status of the 'td' in the printed status map.
15 static void check_str_update(struct thread_data *td)
17 char c = run_str[td->thread_number - 1];
19 switch (td->runstate) {
35 if (td->o.rwmix[DDIR_READ] == 100)
37 else if (td->o.rwmix[DDIR_WRITE] == 100)
42 if (td->o.rwmix[DDIR_READ] == 100)
44 else if (td->o.rwmix[DDIR_WRITE] == 100)
49 } else if (td_read(td)) {
80 log_err("state %d\n", td->runstate);
83 run_str[td->thread_number - 1] = c;
87 * Convert seconds to a printable string.
89 static void eta_to_str(char *str, unsigned long eta_sec)
91 unsigned int d, h, m, s;
104 str += sprintf(str, "%02ud:", d);
108 str += sprintf(str, "%02uh:", h);
110 str += sprintf(str, "%02um:", m);
111 str += sprintf(str, "%02us", s);
115 * Best effort calculation of the estimated pending runtime of a job.
117 static int thread_eta(struct thread_data *td)
119 unsigned long long bytes_total, bytes_done;
120 unsigned long eta_sec = 0;
121 unsigned long elapsed;
123 elapsed = (mtime_since_now(&td->epoch) + 999) / 1000;
125 bytes_total = td->total_io_size;
127 if (td->o.fill_device && td->o.size == -1ULL) {
128 if (!td->fill_device_size || td->fill_device_size == -1ULL)
131 bytes_total = td->fill_device_size;
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.
138 if (td->o.do_verify && td->o.verify && td_write(td)) {
140 bytes_total = bytes_total * 3 / 2;
145 if (td->o.zone_size && td->o.zone_skip)
146 bytes_total /= (td->o.zone_skip / td->o.zone_size);
148 if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING) {
151 bytes_done = td->io_bytes[DDIR_READ] + td->io_bytes[DDIR_WRITE];
152 perc = (double) bytes_done / (double) bytes_total;
156 if (td->o.time_based) {
157 perc_t = (double) elapsed / (double) td->o.timeout;
162 eta_sec = (unsigned long) (elapsed * (1.0 / perc)) - elapsed;
165 eta_sec > (td->o.timeout + done_secs - elapsed))
166 eta_sec = td->o.timeout + done_secs - elapsed;
167 } else if (td->runstate == TD_NOT_CREATED || td->runstate == TD_CREATED
168 || td->runstate == TD_INITIALIZED
169 || td->runstate == TD_RAMP
170 || td->runstate == TD_PRE_READING) {
171 int t_eta = 0, r_eta = 0;
174 * We can only guess - assume it'll run the full timeout
175 * if given, otherwise assume it'll run at the specified rate.
178 t_eta = td->o.timeout + td->o.start_delay +
181 if (in_ramp_time(td)) {
182 unsigned long ramp_left;
184 ramp_left = mtime_since_now(&td->epoch);
185 ramp_left = (ramp_left + 999) / 1000;
186 if (ramp_left <= t_eta)
190 if (td->o.rate[0] || td->o.rate[1]) {
191 r_eta = (bytes_total / 1024) /
192 (td->o.rate[0] + td->o.rate[1]);
193 r_eta += td->o.start_delay;
197 eta_sec = min(r_eta, t_eta);
206 * thread is already done or waiting for fsync
214 static void calc_rate(unsigned long mtime, unsigned long long *io_bytes,
215 unsigned long long *prev_io_bytes, unsigned int *rate)
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];
223 static void calc_iops(unsigned long mtime, unsigned long long *io_iops,
224 unsigned long long *prev_io_iops, unsigned int *iops)
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];
233 * Print status of the jobs we know about. This includes rate estimates,
234 * ETA, thread state, etc.
236 int calc_thread_status(struct jobs_eta *je, int force)
238 struct thread_data *td;
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];
245 static unsigned long long rate_io_bytes[2];
246 static unsigned long long disp_io_bytes[2];
247 static unsigned long long disp_io_iops[2];
248 static struct timeval rate_prev_time, disp_prev_time;
252 if (temp_stall_ts || terse_output || eta_print == FIO_ETA_NEVER)
255 if (!isatty(STDOUT_FILENO) && (eta_print != FIO_ETA_ALWAYS))
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);
264 eta_secs = malloc(thread_number * sizeof(unsigned long));
265 memset(eta_secs, 0, thread_number * sizeof(unsigned long));
267 je->elapsed_sec = (mtime_since_genesis() + 999) / 1000;
269 io_bytes[0] = io_bytes[1] = 0;
270 io_iops[0] = io_iops[1] = 0;
271 bw_avg_time = ULONG_MAX;
273 if (td->o.bw_avg_time < bw_avg_time)
274 bw_avg_time = td->o.bw_avg_time;
275 if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING
276 || td->runstate == TD_FSYNCING
277 || td->runstate == TD_PRE_READING) {
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] +
283 td->o.rate_iops_min[1];
284 je->files_open += td->nr_open_files;
285 } else if (td->runstate == TD_RAMP) {
288 } else if (td->runstate < TD_RUNNING)
291 if (je->elapsed_sec >= 3)
292 eta_secs[i] = thread_eta(td);
294 eta_secs[i] = INT_MAX;
296 check_str_update(td);
298 if (td->runstate > TD_RAMP) {
299 io_bytes[0] += td->io_bytes[0];
300 io_bytes[1] += td->io_bytes[1];
301 io_iops[0] += td->io_blocks[0];
302 io_iops[1] += td->io_blocks[1];
306 if (exitall_on_terminate)
307 je->eta_sec = INT_MAX;
312 if (!i2p && is_power_of_2(td->o.kb_base))
314 if (exitall_on_terminate) {
315 if (eta_secs[i] < je->eta_sec)
316 je->eta_sec = eta_secs[i];
318 if (eta_secs[i] > je->eta_sec)
319 je->eta_sec = eta_secs[i];
325 fio_gettime(&now, NULL);
326 rate_time = mtime_since(&rate_prev_time, &now);
328 if (write_bw_log && rate_time > bw_avg_time && !in_ramp_time(td)) {
329 calc_rate(rate_time, io_bytes, rate_io_bytes, je->rate);
330 memcpy(&rate_prev_time, &now, sizeof(now));
331 add_agg_sample(je->rate[DDIR_READ], DDIR_READ, 0);
332 add_agg_sample(je->rate[DDIR_WRITE], DDIR_WRITE, 0);
335 disp_time = mtime_since(&disp_prev_time, &now);
338 * Allow a little slack, the target is to print it every 1000 msecs
340 if (!force && disp_time < 900)
343 calc_rate(disp_time, io_bytes, disp_io_bytes, je->rate);
344 calc_iops(disp_time, io_iops, disp_io_iops, je->iops);
346 memcpy(&disp_prev_time, &now, sizeof(now));
348 if (!force && !je->nr_running && !je->nr_pending)
351 je->nr_threads = thread_number;
352 memcpy(je->run_str, run_str, thread_number * sizeof(char));
357 void display_thread_status(struct jobs_eta *je)
359 static int linelen_last;
361 char output[512], *p = output;
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);
371 p += sprintf(p, "Jobs: %d (f=%d)", je->nr_running, je->files_open);
372 if (je->m_rate || je->t_rate) {
375 mr = num2str(je->m_rate, 4, 0, i2p);
376 tr = num2str(je->t_rate, 4, 0, i2p);
377 p += sprintf(p, ", CR=%s/%s KB/s", tr, mr);
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) {
388 if ((!je->eta_sec && !eta_good) || je->nr_ramp == je->nr_running)
389 strcpy(perc_str, "-.-% done");
393 sprintf(perc_str, "%3.1f%% done", perc);
396 rate_str[0] = num2str(je->rate[0], 5, 10, i2p);
397 rate_str[1] = num2str(je->rate[1], 5, 10, i2p);
399 iops_str[0] = num2str(je->iops[0], 4, 1, 0);
400 iops_str[1] = num2str(je->iops[1], 4, 1, 0);
402 l = sprintf(p, ": [%s] [%s] [%s/%s /s] [%s/%s iops] [eta %s]",
403 je->run_str, perc_str, rate_str[0],
404 rate_str[1], iops_str[0], iops_str[1], eta_str);
406 if (l >= 0 && l < linelen_last)
407 p += sprintf(p, "%*s", linelen_last - l, "");
415 p += sprintf(p, "\r");
417 printf("%s", output);
421 void print_thread_status(void)
429 size = sizeof(*je) + thread_number * sizeof(char) + 1;
433 if (calc_thread_status(je, 0))
434 display_thread_status(je);
439 void print_status_init(int thr_number)
441 run_str[thr_number] = 'P';