Merge branch 'smalloc-gc' of https://github.com/vincentkfu/fio
[fio.git] / eta.c
1 /*
2  * Status and ETA code
3  */
4 #include <unistd.h>
5 #include <string.h>
6 #ifdef CONFIG_VALGRIND_DEV
7 #include <valgrind/drd.h>
8 #else
9 #define DRD_IGNORE_VAR(x) do { } while (0)
10 #endif
11
12 #include "fio.h"
13 #include "lib/pow2.h"
14
15 static char __run_str[REAL_MAX_JOBS + 1];
16 static char run_str[__THREAD_RUNSTR_SZ(REAL_MAX_JOBS) + 1];
17
18 static void update_condensed_str(char *rstr, char *run_str_condensed)
19 {
20         if (*rstr) {
21                 while (*rstr) {
22                         int nr = 1;
23
24                         *run_str_condensed++ = *rstr++;
25                         while (*(rstr - 1) == *rstr) {
26                                 rstr++;
27                                 nr++;
28                         }
29                         run_str_condensed += sprintf(run_str_condensed, "(%u),", nr);
30                 }
31                 run_str_condensed--;
32         }
33         *run_str_condensed = '\0';
34 }
35
36 /*
37  * Sets the status of the 'td' in the printed status map.
38  */
39 static void check_str_update(struct thread_data *td)
40 {
41         char c = __run_str[td->thread_number - 1];
42
43         switch (td->runstate) {
44         case TD_REAPED:
45                 if (td->error)
46                         c = 'X';
47                 else if (td->sig)
48                         c = 'K';
49                 else
50                         c = '_';
51                 break;
52         case TD_EXITED:
53                 c = 'E';
54                 break;
55         case TD_RAMP:
56                 c = '/';
57                 break;
58         case TD_RUNNING:
59                 if (td_rw(td)) {
60                         if (td_random(td)) {
61                                 if (td->o.rwmix[DDIR_READ] == 100)
62                                         c = 'r';
63                                 else if (td->o.rwmix[DDIR_WRITE] == 100)
64                                         c = 'w';
65                                 else
66                                         c = 'm';
67                         } else {
68                                 if (td->o.rwmix[DDIR_READ] == 100)
69                                         c = 'R';
70                                 else if (td->o.rwmix[DDIR_WRITE] == 100)
71                                         c = 'W';
72                                 else
73                                         c = 'M';
74                         }
75                 } else if (td_read(td)) {
76                         if (td_random(td))
77                                 c = 'r';
78                         else
79                                 c = 'R';
80                 } else if (td_write(td)) {
81                         if (td_random(td))
82                                 c = 'w';
83                         else
84                                 c = 'W';
85                 } else {
86                         if (td_random(td))
87                                 c = 'd';
88                         else
89                                 c = 'D';
90                 }
91                 break;
92         case TD_PRE_READING:
93                 c = 'p';
94                 break;
95         case TD_VERIFYING:
96                 c = 'V';
97                 break;
98         case TD_FSYNCING:
99                 c = 'F';
100                 break;
101         case TD_FINISHING:
102                 c = 'f';
103                 break;
104         case TD_CREATED:
105                 c = 'C';
106                 break;
107         case TD_INITIALIZED:
108         case TD_SETTING_UP:
109                 c = 'I';
110                 break;
111         case TD_NOT_CREATED:
112                 c = 'P';
113                 break;
114         default:
115                 log_err("state %d\n", td->runstate);
116         }
117
118         __run_str[td->thread_number - 1] = c;
119         update_condensed_str(__run_str, run_str);
120 }
121
122 /*
123  * Convert seconds to a printable string.
124  */
125 void eta_to_str(char *str, unsigned long eta_sec)
126 {
127         unsigned int d, h, m, s;
128         int disp_hour = 0;
129
130         if (eta_sec == -1) {
131                 sprintf(str, "--");
132                 return;
133         }
134
135         s = eta_sec % 60;
136         eta_sec /= 60;
137         m = eta_sec % 60;
138         eta_sec /= 60;
139         h = eta_sec % 24;
140         eta_sec /= 24;
141         d = eta_sec;
142
143         if (d) {
144                 disp_hour = 1;
145                 str += sprintf(str, "%02ud:", d);
146         }
147
148         if (h || disp_hour)
149                 str += sprintf(str, "%02uh:", h);
150
151         str += sprintf(str, "%02um:", m);
152         sprintf(str, "%02us", s);
153 }
154
155 /*
156  * Best effort calculation of the estimated pending runtime of a job.
157  */
158 static unsigned long thread_eta(struct thread_data *td)
159 {
160         unsigned long long bytes_total, bytes_done;
161         unsigned long eta_sec = 0;
162         unsigned long elapsed;
163         uint64_t timeout;
164
165         elapsed = (mtime_since_now(&td->epoch) + 999) / 1000;
166         timeout = td->o.timeout / 1000000UL;
167
168         bytes_total = td->total_io_size;
169
170         if (td->flags & TD_F_NO_PROGRESS)
171                 return -1;
172
173         if (td->o.fill_device && td->o.size  == -1ULL) {
174                 if (!td->fill_device_size || td->fill_device_size == -1ULL)
175                         return 0;
176
177                 bytes_total = td->fill_device_size;
178         }
179
180         /*
181          * If io_size is set, bytes_total is an exact value that does not need
182          * adjustment.
183          */
184         if (td->o.zone_size && td->o.zone_skip && bytes_total &&
185             !fio_option_is_set(&td->o, io_size)) {
186                 unsigned int nr_zones;
187                 uint64_t zone_bytes;
188
189                 /*
190                  * Calculate the upper bound of the number of zones that will
191                  * be processed, including skipped bytes between zones. If this
192                  * is larger than total_io_size (e.g. when --io_size or --size
193                  * specify a small value), use the lower bound to avoid
194                  * adjustments to a negative value that would result in a very
195                  * large bytes_total and an incorrect eta.
196                  */
197                 zone_bytes = td->o.zone_size + td->o.zone_skip;
198                 nr_zones = (bytes_total + zone_bytes - 1) / zone_bytes;
199                 if (bytes_total < nr_zones * td->o.zone_skip)
200                         nr_zones = bytes_total / zone_bytes;
201                 bytes_total -= nr_zones * td->o.zone_skip;
202         }
203
204         /*
205          * if writing and verifying afterwards, bytes_total will be twice the
206          * size. In a mixed workload, verify phase will be the size of the
207          * first stage writes.
208          */
209         if (td->o.do_verify && td->o.verify && td_write(td)) {
210                 if (td_rw(td)) {
211                         unsigned int perc = 50;
212
213                         if (td->o.rwmix[DDIR_WRITE])
214                                 perc = td->o.rwmix[DDIR_WRITE];
215
216                         bytes_total += (bytes_total * perc) / 100;
217                 } else
218                         bytes_total <<= 1;
219         }
220
221         if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING) {
222                 double perc, perc_t;
223
224                 bytes_done = ddir_rw_sum(td->io_bytes);
225
226                 if (bytes_total) {
227                         perc = (double) bytes_done / (double) bytes_total;
228                         if (perc > 1.0)
229                                 perc = 1.0;
230                 } else
231                         perc = 0.0;
232
233                 if (td->o.time_based) {
234                         if (timeout) {
235                                 perc_t = (double) elapsed / (double) timeout;
236                                 if (perc_t < perc)
237                                         perc = perc_t;
238                         } else {
239                                 /*
240                                  * Will never hit, we can't have time_based
241                                  * without a timeout set.
242                                  */
243                                 perc = 0.0;
244                         }
245                 }
246
247                 if (perc == 0.0) {
248                         eta_sec = timeout;
249                 } else {
250                         eta_sec = (unsigned long) (elapsed * (1.0 / perc)) - elapsed;
251                 }
252
253                 if (td->o.timeout &&
254                     eta_sec > (timeout + done_secs - elapsed))
255                         eta_sec = timeout + done_secs - elapsed;
256         } else if (td->runstate == TD_NOT_CREATED || td->runstate == TD_CREATED
257                         || td->runstate == TD_INITIALIZED
258                         || td->runstate == TD_SETTING_UP
259                         || td->runstate == TD_RAMP
260                         || td->runstate == TD_PRE_READING) {
261                 int64_t t_eta = 0, r_eta = 0;
262                 unsigned long long rate_bytes;
263
264                 /*
265                  * We can only guess - assume it'll run the full timeout
266                  * if given, otherwise assume it'll run at the specified rate.
267                  */
268                 if (td->o.timeout) {
269                         uint64_t __timeout = td->o.timeout;
270                         uint64_t start_delay = td->o.start_delay;
271                         uint64_t ramp_time = td->o.ramp_time;
272
273                         t_eta = __timeout + start_delay;
274                         if (!td->ramp_time_over) {
275                                 t_eta += ramp_time;
276                         }
277                         t_eta /= 1000000ULL;
278
279                         if ((td->runstate == TD_RAMP) && in_ramp_time(td)) {
280                                 unsigned long ramp_left;
281
282                                 ramp_left = mtime_since_now(&td->epoch);
283                                 ramp_left = (ramp_left + 999) / 1000;
284                                 if (ramp_left <= t_eta)
285                                         t_eta -= ramp_left;
286                         }
287                 }
288                 rate_bytes = 0;
289                 if (td_read(td))
290                         rate_bytes  = td->o.rate[DDIR_READ];
291                 if (td_write(td))
292                         rate_bytes += td->o.rate[DDIR_WRITE];
293                 if (td_trim(td))
294                         rate_bytes += td->o.rate[DDIR_TRIM];
295
296                 if (rate_bytes) {
297                         r_eta = bytes_total / rate_bytes;
298                         r_eta += (td->o.start_delay / 1000000ULL);
299                 }
300
301                 if (r_eta && t_eta)
302                         eta_sec = min(r_eta, t_eta);
303                 else if (r_eta)
304                         eta_sec = r_eta;
305                 else if (t_eta)
306                         eta_sec = t_eta;
307                 else
308                         eta_sec = 0;
309         } else {
310                 /*
311                  * thread is already done or waiting for fsync
312                  */
313                 eta_sec = 0;
314         }
315
316         return eta_sec;
317 }
318
319 static void calc_rate(int unified_rw_rep, unsigned long mtime,
320                       unsigned long long *io_bytes,
321                       unsigned long long *prev_io_bytes, uint64_t *rate)
322 {
323         int i;
324
325         for (i = 0; i < DDIR_RWDIR_CNT; i++) {
326                 unsigned long long diff, this_rate;
327
328                 diff = io_bytes[i] - prev_io_bytes[i];
329                 if (mtime)
330                         this_rate = ((1000 * diff) / mtime) / 1024; /* KiB/s */
331                 else
332                         this_rate = 0;
333
334                 if (unified_rw_rep) {
335                         rate[i] = 0;
336                         rate[0] += this_rate;
337                 } else
338                         rate[i] = this_rate;
339
340                 prev_io_bytes[i] = io_bytes[i];
341         }
342 }
343
344 static void calc_iops(int unified_rw_rep, unsigned long mtime,
345                       unsigned long long *io_iops,
346                       unsigned long long *prev_io_iops, unsigned int *iops)
347 {
348         int i;
349
350         for (i = 0; i < DDIR_RWDIR_CNT; i++) {
351                 unsigned long long diff, this_iops;
352
353                 diff = io_iops[i] - prev_io_iops[i];
354                 if (mtime)
355                         this_iops = (diff * 1000) / mtime;
356                 else
357                         this_iops = 0;
358
359                 if (unified_rw_rep) {
360                         iops[i] = 0;
361                         iops[0] += this_iops;
362                 } else
363                         iops[i] = this_iops;
364
365                 prev_io_iops[i] = io_iops[i];
366         }
367 }
368
369 /*
370  * Allow a little slack - if we're within 95% of the time, allow ETA.
371  */
372 bool eta_time_within_slack(unsigned int time)
373 {
374         return time > ((eta_interval_msec * 95) / 100);
375 }
376
377 /*
378  * Print status of the jobs we know about. This includes rate estimates,
379  * ETA, thread state, etc.
380  */
381 bool calc_thread_status(struct jobs_eta *je, int force)
382 {
383         struct thread_data *td;
384         int i, unified_rw_rep;
385         uint64_t rate_time, disp_time, bw_avg_time, *eta_secs;
386         unsigned long long io_bytes[DDIR_RWDIR_CNT];
387         unsigned long long io_iops[DDIR_RWDIR_CNT];
388         struct timespec now;
389
390         static unsigned long long rate_io_bytes[DDIR_RWDIR_CNT];
391         static unsigned long long disp_io_bytes[DDIR_RWDIR_CNT];
392         static unsigned long long disp_io_iops[DDIR_RWDIR_CNT];
393         static struct timespec rate_prev_time, disp_prev_time;
394
395         void *je_rate = (void *) je->rate;
396         void *je_iops = (void *) je->iops;
397
398         if (!force) {
399                 if (!(output_format & FIO_OUTPUT_NORMAL) &&
400                     f_out == stdout)
401                         return false;
402                 if (temp_stall_ts || eta_print == FIO_ETA_NEVER)
403                         return false;
404
405                 if (!isatty(STDOUT_FILENO) && (eta_print != FIO_ETA_ALWAYS))
406                         return false;
407         }
408
409         if (!ddir_rw_sum(rate_io_bytes))
410                 fill_start_time(&rate_prev_time);
411         if (!ddir_rw_sum(disp_io_bytes))
412                 fill_start_time(&disp_prev_time);
413
414         eta_secs = malloc(thread_number * sizeof(uint64_t));
415         memset(eta_secs, 0, thread_number * sizeof(uint64_t));
416
417         je->elapsed_sec = (mtime_since_genesis() + 999) / 1000;
418
419         io_bytes[DDIR_READ] = io_bytes[DDIR_WRITE] = io_bytes[DDIR_TRIM] = 0;
420         io_iops[DDIR_READ] = io_iops[DDIR_WRITE] = io_iops[DDIR_TRIM] = 0;
421         bw_avg_time = ULONG_MAX;
422         unified_rw_rep = 0;
423         for_each_td(td, i) {
424                 unified_rw_rep += td->o.unified_rw_rep;
425                 if (is_power_of_2(td->o.kb_base))
426                         je->is_pow2 = 1;
427                 je->unit_base = td->o.unit_base;
428                 if (td->o.bw_avg_time < bw_avg_time)
429                         bw_avg_time = td->o.bw_avg_time;
430                 if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING
431                     || td->runstate == TD_FSYNCING
432                     || td->runstate == TD_PRE_READING
433                     || td->runstate == TD_FINISHING) {
434                         je->nr_running++;
435                         if (td_read(td)) {
436                                 je->t_rate[0] += td->o.rate[DDIR_READ];
437                                 je->t_iops[0] += td->o.rate_iops[DDIR_READ];
438                                 je->m_rate[0] += td->o.ratemin[DDIR_READ];
439                                 je->m_iops[0] += td->o.rate_iops_min[DDIR_READ];
440                         }
441                         if (td_write(td)) {
442                                 je->t_rate[1] += td->o.rate[DDIR_WRITE];
443                                 je->t_iops[1] += td->o.rate_iops[DDIR_WRITE];
444                                 je->m_rate[1] += td->o.ratemin[DDIR_WRITE];
445                                 je->m_iops[1] += td->o.rate_iops_min[DDIR_WRITE];
446                         }
447                         if (td_trim(td)) {
448                                 je->t_rate[2] += td->o.rate[DDIR_TRIM];
449                                 je->t_iops[2] += td->o.rate_iops[DDIR_TRIM];
450                                 je->m_rate[2] += td->o.ratemin[DDIR_TRIM];
451                                 je->m_iops[2] += td->o.rate_iops_min[DDIR_TRIM];
452                         }
453
454                         je->files_open += td->nr_open_files;
455                 } else if (td->runstate == TD_RAMP) {
456                         je->nr_running++;
457                         je->nr_ramp++;
458                 } else if (td->runstate == TD_SETTING_UP)
459                         je->nr_setting_up++;
460                 else if (td->runstate < TD_RUNNING)
461                         je->nr_pending++;
462
463                 if (je->elapsed_sec >= 3)
464                         eta_secs[i] = thread_eta(td);
465                 else
466                         eta_secs[i] = INT_MAX;
467
468                 check_str_update(td);
469
470                 if (td->runstate > TD_SETTING_UP) {
471                         int ddir;
472
473                         for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) {
474                                 if (unified_rw_rep) {
475                                         io_bytes[0] += td->io_bytes[ddir];
476                                         io_iops[0] += td->io_blocks[ddir];
477                                 } else {
478                                         io_bytes[ddir] += td->io_bytes[ddir];
479                                         io_iops[ddir] += td->io_blocks[ddir];
480                                 }
481                         }
482                 }
483         }
484
485         if (exitall_on_terminate) {
486                 je->eta_sec = INT_MAX;
487                 for_each_td(td, i) {
488                         if (eta_secs[i] < je->eta_sec)
489                                 je->eta_sec = eta_secs[i];
490                 }
491         } else {
492                 unsigned long eta_stone = 0;
493
494                 je->eta_sec = 0;
495                 for_each_td(td, i) {
496                         if ((td->runstate == TD_NOT_CREATED) && td->o.stonewall)
497                                 eta_stone += eta_secs[i];
498                         else {
499                                 if (eta_secs[i] > je->eta_sec)
500                                         je->eta_sec = eta_secs[i];
501                         }
502                 }
503                 je->eta_sec += eta_stone;
504         }
505
506         free(eta_secs);
507
508         fio_gettime(&now, NULL);
509         rate_time = mtime_since(&rate_prev_time, &now);
510
511         if (write_bw_log && rate_time > bw_avg_time && !in_ramp_time(td)) {
512                 calc_rate(unified_rw_rep, rate_time, io_bytes, rate_io_bytes,
513                                 je_rate);
514                 memcpy(&rate_prev_time, &now, sizeof(now));
515                 add_agg_sample(sample_val(je->rate[DDIR_READ]), DDIR_READ, 0);
516                 add_agg_sample(sample_val(je->rate[DDIR_WRITE]), DDIR_WRITE, 0);
517                 add_agg_sample(sample_val(je->rate[DDIR_TRIM]), DDIR_TRIM, 0);
518         }
519
520         disp_time = mtime_since(&disp_prev_time, &now);
521
522         if (!force && !eta_time_within_slack(disp_time))
523                 return false;
524
525         calc_rate(unified_rw_rep, disp_time, io_bytes, disp_io_bytes, je_rate);
526         calc_iops(unified_rw_rep, disp_time, io_iops, disp_io_iops, je_iops);
527
528         memcpy(&disp_prev_time, &now, sizeof(now));
529
530         if (!force && !je->nr_running && !je->nr_pending)
531                 return false;
532
533         je->nr_threads = thread_number;
534         update_condensed_str(__run_str, run_str);
535         memcpy(je->run_str, run_str, strlen(run_str));
536         return true;
537 }
538
539 static int gen_eta_str(struct jobs_eta *je, char *p, size_t left,
540                        char **rate_str, char **iops_str)
541 {
542         bool has_r = je->rate[DDIR_READ] || je->iops[DDIR_READ];
543         bool has_w = je->rate[DDIR_WRITE] || je->iops[DDIR_WRITE];
544         bool has_t = je->rate[DDIR_TRIM] || je->iops[DDIR_TRIM];
545         int l = 0;
546
547         if (!has_r && !has_w && !has_t)
548                 return 0;
549
550         if (has_r) {
551                 l += snprintf(p + l, left - l, "[r=%s", rate_str[DDIR_READ]);
552                 if (!has_w)
553                         l += snprintf(p + l, left - l, "]");
554         }
555         if (has_w) {
556                 if (has_r)
557                         l += snprintf(p + l, left - l, ",");
558                 else
559                         l += snprintf(p + l, left - l, "[");
560                 l += snprintf(p + l, left - l, "w=%s", rate_str[DDIR_WRITE]);
561                 if (!has_t)
562                         l += snprintf(p + l, left - l, "]");
563         }
564         if (has_t) {
565                 if (has_r || has_w)
566                         l += snprintf(p + l, left - l, ",");
567                 else if (!has_r && !has_w)
568                         l += snprintf(p + l, left - l, "[");
569                 l += snprintf(p + l, left - l, "t=%s]", rate_str[DDIR_TRIM]);
570         }
571         if (has_r) {
572                 l += snprintf(p + l, left - l, "[r=%s", iops_str[DDIR_READ]);
573                 if (!has_w)
574                         l += snprintf(p + l, left - l, " IOPS]");
575         }
576         if (has_w) {
577                 if (has_r)
578                         l += snprintf(p + l, left - l, ",");
579                 else
580                         l += snprintf(p + l, left - l, "[");
581                 l += snprintf(p + l, left - l, "w=%s", iops_str[DDIR_WRITE]);
582                 if (!has_t)
583                         l += snprintf(p + l, left - l, " IOPS]");
584         }
585         if (has_t) {
586                 if (has_r || has_w)
587                         l += snprintf(p + l, left - l, ",");
588                 else if (!has_r && !has_w)
589                         l += snprintf(p + l, left - l, "[");
590                 l += snprintf(p + l, left - l, "t=%s IOPS]", iops_str[DDIR_TRIM]);
591         }
592
593         return l;
594 }
595
596 void display_thread_status(struct jobs_eta *je)
597 {
598         static struct timespec disp_eta_new_line;
599         static int eta_new_line_init, eta_new_line_pending;
600         static int linelen_last;
601         static int eta_good;
602         char output[__THREAD_RUNSTR_SZ(REAL_MAX_JOBS) + 512], *p = output;
603         char eta_str[128];
604         double perc = 0.0;
605
606         if (je->eta_sec != INT_MAX && je->elapsed_sec) {
607                 perc = (double) je->elapsed_sec / (double) (je->elapsed_sec + je->eta_sec);
608                 eta_to_str(eta_str, je->eta_sec);
609         }
610
611         if (eta_new_line_pending) {
612                 eta_new_line_pending = 0;
613                 linelen_last = 0;
614                 p += sprintf(p, "\n");
615         }
616
617         p += sprintf(p, "Jobs: %d (f=%d)", je->nr_running, je->files_open);
618
619         /* rate limits, if any */
620         if (je->m_rate[0] || je->m_rate[1] || je->m_rate[2] ||
621             je->t_rate[0] || je->t_rate[1] || je->t_rate[2]) {
622                 char *tr, *mr;
623
624                 mr = num2str(je->m_rate[0] + je->m_rate[1] + je->m_rate[2],
625                                 je->sig_figs, 0, je->is_pow2, N2S_BYTEPERSEC);
626                 tr = num2str(je->t_rate[0] + je->t_rate[1] + je->t_rate[2],
627                                 je->sig_figs, 0, je->is_pow2, N2S_BYTEPERSEC);
628
629                 p += sprintf(p, ", %s-%s", mr, tr);
630                 free(tr);
631                 free(mr);
632         } else if (je->m_iops[0] || je->m_iops[1] || je->m_iops[2] ||
633                    je->t_iops[0] || je->t_iops[1] || je->t_iops[2]) {
634                 p += sprintf(p, ", %d-%d IOPS",
635                                         je->m_iops[0] + je->m_iops[1] + je->m_iops[2],
636                                         je->t_iops[0] + je->t_iops[1] + je->t_iops[2]);
637         }
638
639         /* current run string, % done, bandwidth, iops, eta */
640         if (je->eta_sec != INT_MAX && je->nr_running) {
641                 char perc_str[32];
642                 char *iops_str[DDIR_RWDIR_CNT];
643                 char *rate_str[DDIR_RWDIR_CNT];
644                 size_t left;
645                 int l;
646                 int ddir;
647                 int linelen;
648
649                 if ((!je->eta_sec && !eta_good) || je->nr_ramp == je->nr_running ||
650                     je->eta_sec == -1)
651                         strcpy(perc_str, "-.-%");
652                 else {
653                         double mult = 100.0;
654
655                         if (je->nr_setting_up && je->nr_running)
656                                 mult *= (1.0 - (double) je->nr_setting_up / (double) je->nr_running);
657
658                         eta_good = 1;
659                         perc *= mult;
660                         sprintf(perc_str, "%3.1f%%", perc);
661                 }
662
663                 for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) {
664                         rate_str[ddir] = num2str(je->rate[ddir], 4,
665                                                 1024, je->is_pow2, je->unit_base);
666                         iops_str[ddir] = num2str(je->iops[ddir], 4, 1, 0, N2S_NONE);
667                 }
668
669                 left = sizeof(output) - (p - output) - 1;
670                 l = snprintf(p, left, ": [%s][%s]", je->run_str, perc_str);
671                 l += gen_eta_str(je, p + l, left - l, rate_str, iops_str);
672                 l += snprintf(p + l, left - l, "[eta %s]", eta_str);
673
674                 /* If truncation occurred adjust l so p is on the null */
675                 if (l >= left)
676                         l = left - 1;
677                 p += l;
678                 linelen = p - output;
679                 if (l >= 0 && linelen < linelen_last)
680                         p += sprintf(p, "%*s", linelen_last - linelen, "");
681                 linelen_last = linelen;
682
683                 for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) {
684                         free(rate_str[ddir]);
685                         free(iops_str[ddir]);
686                 }
687         }
688         sprintf(p, "\r");
689
690         printf("%s", output);
691
692         if (!eta_new_line_init) {
693                 fio_gettime(&disp_eta_new_line, NULL);
694                 eta_new_line_init = 1;
695         } else if (eta_new_line && mtime_since_now(&disp_eta_new_line) > eta_new_line) {
696                 fio_gettime(&disp_eta_new_line, NULL);
697                 eta_new_line_pending = 1;
698         }
699
700         fflush(stdout);
701 }
702
703 struct jobs_eta *get_jobs_eta(bool force, size_t *size)
704 {
705         struct jobs_eta *je;
706
707         if (!thread_number)
708                 return NULL;
709
710         *size = sizeof(*je) + THREAD_RUNSTR_SZ + 8;
711         je = malloc(*size);
712         if (!je)
713                 return NULL;
714         memset(je, 0, *size);
715
716         if (!calc_thread_status(je, force)) {
717                 free(je);
718                 return NULL;
719         }
720
721         *size = sizeof(*je) + strlen((char *) je->run_str) + 1;
722         return je;
723 }
724
725 void print_thread_status(void)
726 {
727         struct jobs_eta *je;
728         size_t size;
729
730         je = get_jobs_eta(false, &size);
731         if (je)
732                 display_thread_status(je);
733
734         free(je);
735 }
736
737 void print_status_init(int thr_number)
738 {
739         DRD_IGNORE_VAR(__run_str);
740         __run_str[thr_number] = 'P';
741         update_condensed_str(__run_str, run_str);
742 }