blob: adf7f94c658607009c85ad49b8348f9160e33fa1 [file] [log] [blame]
Jens Axboe263e5292006-10-18 15:37:01 +02001/*
2 * Status and ETA code
3 */
4#include <unistd.h>
5#include <fcntl.h>
6#include <string.h>
7
8#include "fio.h"
Elliott Hugheseda3a602017-05-19 18:53:02 -07009#include "lib/pow2.h"
Jens Axboe263e5292006-10-18 15:37:01 +020010
Jens Axboef9ce7c02014-06-16 14:42:05 -060011static char __run_str[REAL_MAX_JOBS + 1];
Jens Axboe18148762014-06-23 19:07:12 -060012static char run_str[__THREAD_RUNSTR_SZ(REAL_MAX_JOBS)];
Jens Axboef9ce7c02014-06-16 14:42:05 -060013
Jens Axboe0f7f9a92014-11-06 09:21:10 -070014static void update_condensed_str(char *rstr, char *run_str_condensed)
Jens Axboef9ce7c02014-06-16 14:42:05 -060015{
Jens Axboe0f7f9a92014-11-06 09:21:10 -070016 if (*rstr) {
17 while (*rstr) {
Andreas Gruenbacherc5be4452014-06-24 13:09:07 +020018 int nr = 1;
Jens Axboef9ce7c02014-06-16 14:42:05 -060019
Jens Axboe0f7f9a92014-11-06 09:21:10 -070020 *run_str_condensed++ = *rstr++;
21 while (*(rstr - 1) == *rstr) {
22 rstr++;
Andreas Gruenbacherc5be4452014-06-24 13:09:07 +020023 nr++;
24 }
25 run_str_condensed += sprintf(run_str_condensed, "(%u),", nr);
Jens Axboef9ce7c02014-06-16 14:42:05 -060026 }
Andreas Gruenbacherc5be4452014-06-24 13:09:07 +020027 run_str_condensed--;
Jens Axboef9ce7c02014-06-16 14:42:05 -060028 }
Andreas Gruenbacherc5be4452014-06-24 13:09:07 +020029 *run_str_condensed = '\0';
Jens Axboecdd2bfa2014-06-17 09:22:34 -060030}
Jens Axboe263e5292006-10-18 15:37:01 +020031
32/*
33 * Sets the status of the 'td' in the printed status map.
34 */
35static void check_str_update(struct thread_data *td)
36{
Jens Axboef9ce7c02014-06-16 14:42:05 -060037 char c = __run_str[td->thread_number - 1];
Jens Axboe263e5292006-10-18 15:37:01 +020038
39 switch (td->runstate) {
Jens Axboe5ec10ea2008-03-06 15:42:00 +010040 case TD_REAPED:
Jens Axboe4f7e57a2012-03-30 21:21:20 +020041 if (td->error)
42 c = 'X';
Jens Axboea5e371a2012-04-02 09:47:09 -070043 else if (td->sig)
44 c = 'K';
Jens Axboe4f7e57a2012-03-30 21:21:20 +020045 else
46 c = '_';
Jens Axboe5ec10ea2008-03-06 15:42:00 +010047 break;
48 case TD_EXITED:
49 c = 'E';
50 break;
Jens Axboeb29ee5b2008-09-11 10:17:26 +020051 case TD_RAMP:
52 c = '/';
53 break;
Jens Axboe5ec10ea2008-03-06 15:42:00 +010054 case TD_RUNNING:
55 if (td_rw(td)) {
Jens Axboee3b3f812011-09-01 09:58:11 -060056 if (td_random(td)) {
57 if (td->o.rwmix[DDIR_READ] == 100)
58 c = 'r';
59 else if (td->o.rwmix[DDIR_WRITE] == 100)
60 c = 'w';
61 else
62 c = 'm';
63 } else {
64 if (td->o.rwmix[DDIR_READ] == 100)
65 c = 'R';
66 else if (td->o.rwmix[DDIR_WRITE] == 100)
67 c = 'W';
68 else
69 c = 'M';
70 }
Jens Axboe5ec10ea2008-03-06 15:42:00 +010071 } else if (td_read(td)) {
72 if (td_random(td))
73 c = 'r';
74 else
75 c = 'R';
Shaohua Li6eaf09d2012-09-14 08:49:43 +020076 } else if (td_write(td)) {
Jens Axboe5ec10ea2008-03-06 15:42:00 +010077 if (td_random(td))
78 c = 'w';
79 else
80 c = 'W';
Shaohua Li6eaf09d2012-09-14 08:49:43 +020081 } else {
82 if (td_random(td))
83 c = 'd';
84 else
85 c = 'D';
Jens Axboe5ec10ea2008-03-06 15:42:00 +010086 }
87 break;
Jens Axboeb0f65862009-05-20 11:52:15 +020088 case TD_PRE_READING:
89 c = 'p';
90 break;
Jens Axboe5ec10ea2008-03-06 15:42:00 +010091 case TD_VERIFYING:
92 c = 'V';
93 break;
94 case TD_FSYNCING:
95 c = 'F';
96 break;
Jens Axboe3d434052014-04-02 15:46:22 -060097 case TD_FINISHING:
98 c = 'f';
99 break;
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100100 case TD_CREATED:
101 c = 'C';
102 break;
103 case TD_INITIALIZED:
Jens Axboe9c6f6312012-11-07 09:15:45 +0100104 case TD_SETTING_UP:
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100105 c = 'I';
106 break;
107 case TD_NOT_CREATED:
108 c = 'P';
109 break;
110 default:
111 log_err("state %d\n", td->runstate);
Jens Axboe263e5292006-10-18 15:37:01 +0200112 }
113
Jens Axboef9ce7c02014-06-16 14:42:05 -0600114 __run_str[td->thread_number - 1] = c;
115 update_condensed_str(__run_str, run_str);
Jens Axboe263e5292006-10-18 15:37:01 +0200116}
117
118/*
119 * Convert seconds to a printable string.
120 */
Jens Axboe3e47bd22012-02-29 13:45:02 +0100121void eta_to_str(char *str, unsigned long eta_sec)
Jens Axboe263e5292006-10-18 15:37:01 +0200122{
123 unsigned int d, h, m, s;
Jens Axboe165faf12007-02-07 11:30:37 +0100124 int disp_hour = 0;
Jens Axboe263e5292006-10-18 15:37:01 +0200125
Elliott Hugheseda3a602017-05-19 18:53:02 -0700126 if (eta_sec == -1) {
127 sprintf(str, "--");
128 return;
129 }
130
Jens Axboe263e5292006-10-18 15:37:01 +0200131 s = eta_sec % 60;
132 eta_sec /= 60;
133 m = eta_sec % 60;
134 eta_sec /= 60;
135 h = eta_sec % 24;
136 eta_sec /= 24;
137 d = eta_sec;
138
Jens Axboe165faf12007-02-07 11:30:37 +0100139 if (d) {
140 disp_hour = 1;
Jens Axboe1e97cce2006-12-05 11:44:16 +0100141 str += sprintf(str, "%02ud:", d);
Jens Axboe263e5292006-10-18 15:37:01 +0200142 }
Jens Axboe165faf12007-02-07 11:30:37 +0100143
144 if (h || disp_hour)
Jens Axboe1e97cce2006-12-05 11:44:16 +0100145 str += sprintf(str, "%02uh:", h);
Jens Axboe263e5292006-10-18 15:37:01 +0200146
Jens Axboe1e97cce2006-12-05 11:44:16 +0100147 str += sprintf(str, "%02um:", m);
148 str += sprintf(str, "%02us", s);
Jens Axboe263e5292006-10-18 15:37:01 +0200149}
150
151/*
152 * Best effort calculation of the estimated pending runtime of a job.
153 */
Elliott Hugheseda3a602017-05-19 18:53:02 -0700154static unsigned long thread_eta(struct thread_data *td)
Jens Axboe263e5292006-10-18 15:37:01 +0200155{
156 unsigned long long bytes_total, bytes_done;
Jens Axboe1e97cce2006-12-05 11:44:16 +0100157 unsigned long eta_sec = 0;
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200158 unsigned long elapsed;
Jens Axboe0de5b262014-02-21 15:26:01 -0800159 uint64_t timeout;
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200160
161 elapsed = (mtime_since_now(&td->epoch) + 999) / 1000;
Jens Axboe0de5b262014-02-21 15:26:01 -0800162 timeout = td->o.timeout / 1000000UL;
Jens Axboe263e5292006-10-18 15:37:01 +0200163
164 bytes_total = td->total_io_size;
165
Elliott Hugheseda3a602017-05-19 18:53:02 -0700166 if (td->flags & TD_F_NO_PROGRESS)
167 return -1;
168
Jens Axboe2e3bd4c2010-05-17 12:29:57 +0200169 if (td->o.fill_device && td->o.size == -1ULL) {
170 if (!td->fill_device_size || td->fill_device_size == -1ULL)
171 return 0;
172
173 bytes_total = td->fill_device_size;
174 }
175
Jens Axboe0d73a2f2013-02-07 12:54:10 +0100176 if (td->o.zone_size && td->o.zone_skip && bytes_total) {
177 unsigned int nr_zones;
178 uint64_t zone_bytes;
179
180 zone_bytes = bytes_total + td->o.zone_size + td->o.zone_skip;
181 nr_zones = (zone_bytes - 1) / (td->o.zone_size + td->o.zone_skip);
182 bytes_total -= nr_zones * td->o.zone_skip;
183 }
184
Jens Axboe74939e32006-10-19 20:37:12 +0200185 /*
Jens Axboe165eb052013-01-23 08:40:11 -0700186 * if writing and verifying afterwards, bytes_total will be twice the
187 * size. In a mixed workload, verify phase will be the size of the
188 * first stage writes.
Jens Axboe74939e32006-10-19 20:37:12 +0200189 */
Jens Axboe0dd83772007-09-04 12:38:28 +0200190 if (td->o.do_verify && td->o.verify && td_write(td)) {
Jens Axboe165eb052013-01-23 08:40:11 -0700191 if (td_rw(td)) {
192 unsigned int perc = 50;
193
194 if (td->o.rwmix[DDIR_WRITE])
195 perc = td->o.rwmix[DDIR_WRITE];
196
197 bytes_total += (bytes_total * perc) / 100;
198 } else
Jens Axboe74939e32006-10-19 20:37:12 +0200199 bytes_total <<= 1;
200 }
201
Jens Axboe263e5292006-10-18 15:37:01 +0200202 if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING) {
Jens Axboecf4464c2007-04-17 20:14:42 +0200203 double perc, perc_t;
Jens Axboe263e5292006-10-18 15:37:01 +0200204
Jens Axboe342f4be2012-09-14 08:59:20 +0200205 bytes_done = ddir_rw_sum(td->io_bytes);
Jens Axboe476882d2014-04-14 09:45:19 -0600206
207 if (bytes_total) {
208 perc = (double) bytes_done / (double) bytes_total;
209 if (perc > 1.0)
210 perc = 1.0;
211 } else
212 perc = 0.0;
Jens Axboe263e5292006-10-18 15:37:01 +0200213
Jens Axboecf4464c2007-04-17 20:14:42 +0200214 if (td->o.time_based) {
Jens Axboe476882d2014-04-14 09:45:19 -0600215 if (timeout) {
216 perc_t = (double) elapsed / (double) timeout;
217 if (perc_t < perc)
218 perc = perc_t;
219 } else {
220 /*
221 * Will never hit, we can't have time_based
222 * without a timeout set.
223 */
224 perc = 0.0;
225 }
Jens Axboecf4464c2007-04-17 20:14:42 +0200226 }
227
Elliott Hugheseda3a602017-05-19 18:53:02 -0700228 if (perc == 0.0) {
229 eta_sec = timeout;
230 } else {
231 eta_sec = (unsigned long) (elapsed * (1.0 / perc)) - elapsed;
232 }
Jens Axboe263e5292006-10-18 15:37:01 +0200233
Jens Axboed3eeeab2008-04-06 12:19:05 +0200234 if (td->o.timeout &&
Jens Axboe0de5b262014-02-21 15:26:01 -0800235 eta_sec > (timeout + done_secs - elapsed))
236 eta_sec = timeout + done_secs - elapsed;
Jens Axboe263e5292006-10-18 15:37:01 +0200237 } else if (td->runstate == TD_NOT_CREATED || td->runstate == TD_CREATED
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200238 || td->runstate == TD_INITIALIZED
Jens Axboe714e85f2013-04-15 10:21:56 +0200239 || td->runstate == TD_SETTING_UP
Jens Axboeb0f65862009-05-20 11:52:15 +0200240 || td->runstate == TD_RAMP
241 || td->runstate == TD_PRE_READING) {
Elliott Hugheseda3a602017-05-19 18:53:02 -0700242 int64_t t_eta = 0, r_eta = 0;
Jens Axboe342f4be2012-09-14 08:59:20 +0200243 unsigned long long rate_bytes;
Jens Axboe263e5292006-10-18 15:37:01 +0200244
245 /*
246 * We can only guess - assume it'll run the full timeout
247 * if given, otherwise assume it'll run at the specified rate.
248 */
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200249 if (td->o.timeout) {
Jens Axboe0f7f9a92014-11-06 09:21:10 -0700250 uint64_t __timeout = td->o.timeout;
Jens Axboe0de5b262014-02-21 15:26:01 -0800251 uint64_t start_delay = td->o.start_delay;
252 uint64_t ramp_time = td->o.ramp_time;
253
Elliott Hugheseda3a602017-05-19 18:53:02 -0700254 t_eta = __timeout + start_delay;
255 if (!td->ramp_time_over) {
256 t_eta += ramp_time;
257 }
Jens Axboe0de5b262014-02-21 15:26:01 -0800258 t_eta /= 1000000ULL;
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200259
Elliott Hugheseda3a602017-05-19 18:53:02 -0700260 if ((td->runstate == TD_RAMP) && in_ramp_time(td)) {
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200261 unsigned long ramp_left;
262
Signed-off-by Steven Prattcda99fa2010-12-14 08:31:36 +0100263 ramp_left = mtime_since_now(&td->epoch);
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200264 ramp_left = (ramp_left + 999) / 1000;
265 if (ramp_left <= t_eta)
266 t_eta -= ramp_left;
267 }
268 }
Elliott Hugheseda3a602017-05-19 18:53:02 -0700269 rate_bytes = 0;
270 if (td_read(td))
271 rate_bytes = td->o.rate[DDIR_READ];
272 if (td_write(td))
273 rate_bytes += td->o.rate[DDIR_WRITE];
274 if (td_trim(td))
275 rate_bytes += td->o.rate[DDIR_TRIM];
276
Jens Axboe342f4be2012-09-14 08:59:20 +0200277 if (rate_bytes) {
Elliott Hugheseda3a602017-05-19 18:53:02 -0700278 r_eta = bytes_total / rate_bytes;
Jens Axboe0de5b262014-02-21 15:26:01 -0800279 r_eta += (td->o.start_delay / 1000000ULL);
Jens Axboe263e5292006-10-18 15:37:01 +0200280 }
281
282 if (r_eta && t_eta)
283 eta_sec = min(r_eta, t_eta);
284 else if (r_eta)
285 eta_sec = r_eta;
286 else if (t_eta)
287 eta_sec = t_eta;
288 else
289 eta_sec = 0;
290 } else {
291 /*
292 * thread is already done or waiting for fsync
293 */
294 eta_sec = 0;
295 }
296
297 return eta_sec;
298}
299
Jens Axboe771e58b2013-01-30 12:56:23 +0100300static void calc_rate(int unified_rw_rep, unsigned long mtime,
301 unsigned long long *io_bytes,
Elliott Hugheseda3a602017-05-19 18:53:02 -0700302 unsigned long long *prev_io_bytes, uint64_t *rate)
Jens Axboe46fda8d2007-02-11 00:49:30 +0100303{
Jens Axboeb7f05eb2012-05-11 20:33:02 +0200304 int i;
305
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200306 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Elliott Hugheseda3a602017-05-19 18:53:02 -0700307 unsigned long long diff, this_rate;
Jens Axboeb7f05eb2012-05-11 20:33:02 +0200308
309 diff = io_bytes[i] - prev_io_bytes[i];
Elliott Hugheseda3a602017-05-19 18:53:02 -0700310 if (mtime)
311 this_rate = ((1000 * diff) / mtime) / 1024; /* KiB/s */
312 else
313 this_rate = 0;
314
Jens Axboe771e58b2013-01-30 12:56:23 +0100315 if (unified_rw_rep) {
316 rate[i] = 0;
Elliott Hugheseda3a602017-05-19 18:53:02 -0700317 rate[0] += this_rate;
Jens Axboe771e58b2013-01-30 12:56:23 +0100318 } else
Elliott Hugheseda3a602017-05-19 18:53:02 -0700319 rate[i] = this_rate;
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200320
321 prev_io_bytes[i] = io_bytes[i];
Jens Axboeb7f05eb2012-05-11 20:33:02 +0200322 }
Jens Axboe46fda8d2007-02-11 00:49:30 +0100323}
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100324
Jens Axboe771e58b2013-01-30 12:56:23 +0100325static void calc_iops(int unified_rw_rep, unsigned long mtime,
326 unsigned long long *io_iops,
Jens Axboeadb02ba2009-06-03 10:47:44 +0200327 unsigned long long *prev_io_iops, unsigned int *iops)
328{
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200329 int i;
330
331 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Elliott Hugheseda3a602017-05-19 18:53:02 -0700332 unsigned long long diff, this_iops;
Jens Axboe771e58b2013-01-30 12:56:23 +0100333
334 diff = io_iops[i] - prev_io_iops[i];
Elliott Hugheseda3a602017-05-19 18:53:02 -0700335 if (mtime)
336 this_iops = (diff * 1000) / mtime;
337 else
338 this_iops = 0;
339
Jens Axboe771e58b2013-01-30 12:56:23 +0100340 if (unified_rw_rep) {
341 iops[i] = 0;
Elliott Hugheseda3a602017-05-19 18:53:02 -0700342 iops[0] += this_iops;
Jens Axboe771e58b2013-01-30 12:56:23 +0100343 } else
Elliott Hugheseda3a602017-05-19 18:53:02 -0700344 iops[i] = this_iops;
Jens Axboe771e58b2013-01-30 12:56:23 +0100345
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200346 prev_io_iops[i] = io_iops[i];
347 }
Jens Axboeadb02ba2009-06-03 10:47:44 +0200348}
349
Jens Axboe263e5292006-10-18 15:37:01 +0200350/*
351 * Print status of the jobs we know about. This includes rate estimates,
352 * ETA, thread state, etc.
353 */
Elliott Hugheseda3a602017-05-19 18:53:02 -0700354bool calc_thread_status(struct jobs_eta *je, int force)
Jens Axboe263e5292006-10-18 15:37:01 +0200355{
Jens Axboe34572e22006-10-20 09:33:18 +0200356 struct thread_data *td;
Jens Axboe771e58b2013-01-30 12:56:23 +0100357 int i, unified_rw_rep;
Elliott Hugheseda3a602017-05-19 18:53:02 -0700358 uint64_t rate_time, disp_time, bw_avg_time, *eta_secs;
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200359 unsigned long long io_bytes[DDIR_RWDIR_CNT];
360 unsigned long long io_iops[DDIR_RWDIR_CNT];
Jens Axboe46fda8d2007-02-11 00:49:30 +0100361 struct timeval now;
362
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200363 static unsigned long long rate_io_bytes[DDIR_RWDIR_CNT];
364 static unsigned long long disp_io_bytes[DDIR_RWDIR_CNT];
365 static unsigned long long disp_io_iops[DDIR_RWDIR_CNT];
Jens Axboe46fda8d2007-02-11 00:49:30 +0100366 static struct timeval rate_prev_time, disp_prev_time;
Jens Axboe6043c572006-11-03 11:37:47 +0100367
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200368 if (!force) {
Elliott Hugheseda3a602017-05-19 18:53:02 -0700369 if (!(output_format & FIO_OUTPUT_NORMAL) &&
Jens Axboefc475592013-01-31 15:24:34 +0100370 f_out == stdout)
Elliott Hugheseda3a602017-05-19 18:53:02 -0700371 return false;
Jens Axboef3afa572012-09-17 13:34:16 +0200372 if (temp_stall_ts || eta_print == FIO_ETA_NEVER)
Elliott Hugheseda3a602017-05-19 18:53:02 -0700373 return false;
Aaron Carrolle592a062007-09-14 09:49:41 +0200374
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200375 if (!isatty(STDOUT_FILENO) && (eta_print != FIO_ETA_ALWAYS))
Elliott Hugheseda3a602017-05-19 18:53:02 -0700376 return false;
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200377 }
Jens Axboe263e5292006-10-18 15:37:01 +0200378
Jens Axboe342f4be2012-09-14 08:59:20 +0200379 if (!ddir_rw_sum(rate_io_bytes))
Jens Axboe46fda8d2007-02-11 00:49:30 +0100380 fill_start_time(&rate_prev_time);
Jens Axboe342f4be2012-09-14 08:59:20 +0200381 if (!ddir_rw_sum(disp_io_bytes))
Jens Axboe46fda8d2007-02-11 00:49:30 +0100382 fill_start_time(&disp_prev_time);
Jens Axboe6043c572006-11-03 11:37:47 +0100383
Elliott Hugheseda3a602017-05-19 18:53:02 -0700384 eta_secs = malloc(thread_number * sizeof(uint64_t));
385 memset(eta_secs, 0, thread_number * sizeof(uint64_t));
Jens Axboe263e5292006-10-18 15:37:01 +0200386
Jens Axboeb75a3942011-10-03 16:03:43 +0200387 je->elapsed_sec = (mtime_since_genesis() + 999) / 1000;
388
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200389 io_bytes[DDIR_READ] = io_bytes[DDIR_WRITE] = io_bytes[DDIR_TRIM] = 0;
390 io_iops[DDIR_READ] = io_iops[DDIR_WRITE] = io_iops[DDIR_TRIM] = 0;
Jens Axboebb3884d2007-01-17 17:23:11 +1100391 bw_avg_time = ULONG_MAX;
Jens Axboe771e58b2013-01-30 12:56:23 +0100392 unified_rw_rep = 0;
Jens Axboe34572e22006-10-20 09:33:18 +0200393 for_each_td(td, i) {
Jens Axboe771e58b2013-01-30 12:56:23 +0100394 unified_rw_rep += td->o.unified_rw_rep;
Jens Axboeb7f05eb2012-05-11 20:33:02 +0200395 if (is_power_of_2(td->o.kb_base))
396 je->is_pow2 = 1;
Steven Noonanad705bc2013-04-08 15:05:25 -0700397 je->unit_base = td->o.unit_base;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100398 if (td->o.bw_avg_time < bw_avg_time)
399 bw_avg_time = td->o.bw_avg_time;
Jens Axboe46fda8d2007-02-11 00:49:30 +0100400 if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING
Jens Axboeb0f65862009-05-20 11:52:15 +0200401 || td->runstate == TD_FSYNCING
Jens Axboe3d434052014-04-02 15:46:22 -0600402 || td->runstate == TD_PRE_READING
403 || td->runstate == TD_FINISHING) {
Jens Axboeb75a3942011-10-03 16:03:43 +0200404 je->nr_running++;
Jens Axboe242c38d2012-08-20 14:44:22 +0200405 if (td_read(td)) {
Jens Axboec2e9cc42012-08-21 15:34:13 +0200406 je->t_rate[0] += td->o.rate[DDIR_READ];
407 je->t_iops[0] += td->o.rate_iops[DDIR_READ];
408 je->m_rate[0] += td->o.ratemin[DDIR_READ];
409 je->m_iops[0] += td->o.rate_iops_min[DDIR_READ];
Jens Axboe242c38d2012-08-20 14:44:22 +0200410 }
411 if (td_write(td)) {
Jens Axboec2e9cc42012-08-21 15:34:13 +0200412 je->t_rate[1] += td->o.rate[DDIR_WRITE];
413 je->t_iops[1] += td->o.rate_iops[DDIR_WRITE];
414 je->m_rate[1] += td->o.ratemin[DDIR_WRITE];
415 je->m_iops[1] += td->o.rate_iops_min[DDIR_WRITE];
Jens Axboe242c38d2012-08-20 14:44:22 +0200416 }
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200417 if (td_trim(td)) {
Jens Axboed79db122012-09-24 08:51:24 +0200418 je->t_rate[2] += td->o.rate[DDIR_TRIM];
419 je->t_iops[2] += td->o.rate_iops[DDIR_TRIM];
420 je->m_rate[2] += td->o.ratemin[DDIR_TRIM];
421 je->m_iops[2] += td->o.rate_iops_min[DDIR_TRIM];
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200422 }
423
Jens Axboeb75a3942011-10-03 16:03:43 +0200424 je->files_open += td->nr_open_files;
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200425 } else if (td->runstate == TD_RAMP) {
Jens Axboeb75a3942011-10-03 16:03:43 +0200426 je->nr_running++;
427 je->nr_ramp++;
Jens Axboe7bc24f62014-10-09 18:06:15 -0600428 } else if (td->runstate == TD_SETTING_UP)
Jens Axboe714e85f2013-04-15 10:21:56 +0200429 je->nr_setting_up++;
Jens Axboe7bc24f62014-10-09 18:06:15 -0600430 else if (td->runstate < TD_RUNNING)
Jens Axboeb75a3942011-10-03 16:03:43 +0200431 je->nr_pending++;
Jens Axboe263e5292006-10-18 15:37:01 +0200432
Jens Axboeb75a3942011-10-03 16:03:43 +0200433 if (je->elapsed_sec >= 3)
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200434 eta_secs[i] = thread_eta(td);
Jens Axboe263e5292006-10-18 15:37:01 +0200435 else
436 eta_secs[i] = INT_MAX;
437
438 check_str_update(td);
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200439
Jens Axboe714e85f2013-04-15 10:21:56 +0200440 if (td->runstate > TD_SETTING_UP) {
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200441 int ddir;
Jens Axboe771e58b2013-01-30 12:56:23 +0100442
Elliott Hugheseda3a602017-05-19 18:53:02 -0700443 for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) {
Jens Axboe771e58b2013-01-30 12:56:23 +0100444 if (unified_rw_rep) {
445 io_bytes[0] += td->io_bytes[ddir];
446 io_iops[0] += td->io_blocks[ddir];
447 } else {
448 io_bytes[ddir] += td->io_bytes[ddir];
449 io_iops[ddir] += td->io_blocks[ddir];
450 }
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200451 }
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200452 }
Jens Axboe263e5292006-10-18 15:37:01 +0200453 }
454
Elliott Hugheseda3a602017-05-19 18:53:02 -0700455 if (exitall_on_terminate) {
Jens Axboeb75a3942011-10-03 16:03:43 +0200456 je->eta_sec = INT_MAX;
Elliott Hugheseda3a602017-05-19 18:53:02 -0700457 for_each_td(td, i) {
Jens Axboeb75a3942011-10-03 16:03:43 +0200458 if (eta_secs[i] < je->eta_sec)
459 je->eta_sec = eta_secs[i];
Shaozhi Shawn Ye9c5a3852008-09-10 09:09:37 +0200460 }
Elliott Hugheseda3a602017-05-19 18:53:02 -0700461 } else {
462 unsigned long eta_stone = 0;
463
464 je->eta_sec = 0;
465 for_each_td(td, i) {
466 if ((td->runstate == TD_NOT_CREATED) && td->o.stonewall)
467 eta_stone += eta_secs[i];
468 else {
469 if (eta_secs[i] > je->eta_sec)
470 je->eta_sec = eta_secs[i];
471 }
472 }
473 je->eta_sec += eta_stone;
Jens Axboe263e5292006-10-18 15:37:01 +0200474 }
475
Jens Axboeeecf2722006-10-20 14:00:36 +0200476 free(eta_secs);
477
Jens Axboe46fda8d2007-02-11 00:49:30 +0100478 fio_gettime(&now, NULL);
479 rate_time = mtime_since(&rate_prev_time, &now);
480
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200481 if (write_bw_log && rate_time > bw_avg_time && !in_ramp_time(td)) {
Jens Axboe771e58b2013-01-30 12:56:23 +0100482 calc_rate(unified_rw_rep, rate_time, io_bytes, rate_io_bytes,
483 je->rate);
Jens Axboe46fda8d2007-02-11 00:49:30 +0100484 memcpy(&rate_prev_time, &now, sizeof(now));
Elliott Hugheseda3a602017-05-19 18:53:02 -0700485 add_agg_sample(sample_val(je->rate[DDIR_READ]), DDIR_READ, 0);
486 add_agg_sample(sample_val(je->rate[DDIR_WRITE]), DDIR_WRITE, 0);
487 add_agg_sample(sample_val(je->rate[DDIR_TRIM]), DDIR_TRIM, 0);
Jens Axboe6043c572006-11-03 11:37:47 +0100488 }
489
Jens Axboe46fda8d2007-02-11 00:49:30 +0100490 disp_time = mtime_since(&disp_prev_time, &now);
Jens Axboea5b01f12010-11-11 09:19:49 +0100491
492 /*
493 * Allow a little slack, the target is to print it every 1000 msecs
494 */
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200495 if (!force && disp_time < 900)
Elliott Hugheseda3a602017-05-19 18:53:02 -0700496 return false;
Jens Axboe46fda8d2007-02-11 00:49:30 +0100497
Jens Axboe771e58b2013-01-30 12:56:23 +0100498 calc_rate(unified_rw_rep, disp_time, io_bytes, disp_io_bytes, je->rate);
499 calc_iops(unified_rw_rep, disp_time, io_iops, disp_io_iops, je->iops);
Jens Axboeadb02ba2009-06-03 10:47:44 +0200500
Jens Axboe46fda8d2007-02-11 00:49:30 +0100501 memcpy(&disp_prev_time, &now, sizeof(now));
502
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200503 if (!force && !je->nr_running && !je->nr_pending)
Elliott Hugheseda3a602017-05-19 18:53:02 -0700504 return false;
Jens Axboeb75a3942011-10-03 16:03:43 +0200505
Jens Axboe1d1f45a2011-10-03 19:44:41 +0200506 je->nr_threads = thread_number;
Jens Axboecdd2bfa2014-06-17 09:22:34 -0600507 update_condensed_str(__run_str, run_str);
508 memcpy(je->run_str, run_str, strlen(run_str));
Elliott Hugheseda3a602017-05-19 18:53:02 -0700509 return true;
Jens Axboeb75a3942011-10-03 16:03:43 +0200510}
511
Jens Axboecf451d12011-10-03 16:48:30 +0200512void display_thread_status(struct jobs_eta *je)
Jens Axboeb75a3942011-10-03 16:03:43 +0200513{
Jens Axboee382e662013-02-22 20:48:56 +0100514 static struct timeval disp_eta_new_line;
515 static int eta_new_line_init, eta_new_line_pending;
Jens Axboeb75a3942011-10-03 16:03:43 +0200516 static int linelen_last;
517 static int eta_good;
Jens Axboe79074e72012-04-18 20:39:48 +0200518 char output[REAL_MAX_JOBS + 512], *p = output;
Jens Axboeb75a3942011-10-03 16:03:43 +0200519 char eta_str[128];
520 double perc = 0.0;
Jens Axboeb75a3942011-10-03 16:03:43 +0200521
Jens Axboecf451d12011-10-03 16:48:30 +0200522 if (je->eta_sec != INT_MAX && je->elapsed_sec) {
523 perc = (double) je->elapsed_sec / (double) (je->elapsed_sec + je->eta_sec);
524 eta_to_str(eta_str, je->eta_sec);
Jens Axboeb75a3942011-10-03 16:03:43 +0200525 }
526
Jens Axboee382e662013-02-22 20:48:56 +0100527 if (eta_new_line_pending) {
528 eta_new_line_pending = 0;
529 p += sprintf(p, "\n");
530 }
531
Jens Axboecf451d12011-10-03 16:48:30 +0200532 p += sprintf(p, "Jobs: %d (f=%d)", je->nr_running, je->files_open);
Elliott Hugheseda3a602017-05-19 18:53:02 -0700533
534 /* rate limits, if any */
535 if (je->m_rate[0] || je->m_rate[1] || je->m_rate[2] ||
536 je->t_rate[0] || je->t_rate[1] || je->t_rate[2]) {
Jens Axboe581e7142009-06-09 12:47:16 +0200537 char *tr, *mr;
538
Elliott Hugheseda3a602017-05-19 18:53:02 -0700539 mr = num2str(je->m_rate[0] + je->m_rate[1] + je->m_rate[2],
540 4, 0, je->is_pow2, N2S_BYTEPERSEC);
541 tr = num2str(je->t_rate[0] + je->t_rate[1] + je->t_rate[2],
542 4, 0, je->is_pow2, N2S_BYTEPERSEC);
543
544 p += sprintf(p, ", %s-%s", mr, tr);
Jens Axboe581e7142009-06-09 12:47:16 +0200545 free(tr);
546 free(mr);
Elliott Hugheseda3a602017-05-19 18:53:02 -0700547 } else if (je->m_iops[0] || je->m_iops[1] || je->m_iops[2] ||
548 je->t_iops[0] || je->t_iops[1] || je->t_iops[2]) {
549 p += sprintf(p, ", %d-%d IOPS",
550 je->m_iops[0] + je->m_iops[1] + je->m_iops[2],
551 je->t_iops[0] + je->t_iops[1] + je->t_iops[2]);
Jens Axboe3e47bd22012-02-29 13:45:02 +0100552 }
Elliott Hugheseda3a602017-05-19 18:53:02 -0700553
554 /* current run string, % done, bandwidth, iops, eta */
Jens Axboecf451d12011-10-03 16:48:30 +0200555 if (je->eta_sec != INT_MAX && je->nr_running) {
Jens Axboe0721d112008-06-05 09:03:05 +0200556 char perc_str[32];
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200557 char *iops_str[DDIR_RWDIR_CNT];
558 char *rate_str[DDIR_RWDIR_CNT];
Jens Axboe79074e72012-04-18 20:39:48 +0200559 size_t left;
Jens Axboeadb02ba2009-06-03 10:47:44 +0200560 int l;
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200561 int ddir;
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100562
Elliott Hugheseda3a602017-05-19 18:53:02 -0700563 if ((!je->eta_sec && !eta_good) || je->nr_ramp == je->nr_running ||
564 je->eta_sec == -1)
565 strcpy(perc_str, "-.-%");
Jens Axboecac58fd2008-06-06 01:17:03 +0200566 else {
Jens Axboe714e85f2013-04-15 10:21:56 +0200567 double mult = 100.0;
568
569 if (je->nr_setting_up && je->nr_running)
570 mult *= (1.0 - (double) je->nr_setting_up / (double) je->nr_running);
571
Jens Axboecac58fd2008-06-06 01:17:03 +0200572 eta_good = 1;
Jens Axboe714e85f2013-04-15 10:21:56 +0200573 perc *= mult;
Elliott Hugheseda3a602017-05-19 18:53:02 -0700574 sprintf(perc_str, "%3.1f%%", perc);
Jens Axboecac58fd2008-06-06 01:17:03 +0200575 }
Jens Axboe0721d112008-06-05 09:03:05 +0200576
Elliott Hugheseda3a602017-05-19 18:53:02 -0700577 for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) {
578 rate_str[ddir] = num2str(je->rate[ddir], 4,
Steven Noonanad705bc2013-04-08 15:05:25 -0700579 1024, je->is_pow2, je->unit_base);
Elliott Hugheseda3a602017-05-19 18:53:02 -0700580 iops_str[ddir] = num2str(je->iops[ddir], 4, 1, 0, N2S_NONE);
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200581 }
Jens Axboeadb02ba2009-06-03 10:47:44 +0200582
Jens Axboe79074e72012-04-18 20:39:48 +0200583 left = sizeof(output) - (p - output) - 1;
584
Elliott Hugheseda3a602017-05-19 18:53:02 -0700585 if (je->rate[DDIR_TRIM] || je->iops[DDIR_TRIM])
586 l = snprintf(p, left,
587 ": [%s][%s][r=%s,w=%s,t=%s][r=%s,w=%s,t=%s IOPS][eta %s]",
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200588 je->run_str, perc_str, rate_str[DDIR_READ],
589 rate_str[DDIR_WRITE], rate_str[DDIR_TRIM],
590 iops_str[DDIR_READ], iops_str[DDIR_WRITE],
591 iops_str[DDIR_TRIM], eta_str);
Elliott Hugheseda3a602017-05-19 18:53:02 -0700592 else
593 l = snprintf(p, left,
594 ": [%s][%s][r=%s,w=%s][r=%s,w=%s IOPS][eta %s]",
595 je->run_str, perc_str,
596 rate_str[DDIR_READ], rate_str[DDIR_WRITE],
597 iops_str[DDIR_READ], iops_str[DDIR_WRITE],
598 eta_str);
Jens Axboe37db14f2011-09-30 17:00:42 -0600599 p += l;
Jens Axboeadb02ba2009-06-03 10:47:44 +0200600 if (l >= 0 && l < linelen_last)
Jens Axboe37db14f2011-09-30 17:00:42 -0600601 p += sprintf(p, "%*s", linelen_last - l, "");
Jens Axboeadb02ba2009-06-03 10:47:44 +0200602 linelen_last = l;
Jens Axboed1bd7212009-06-03 10:53:45 +0200603
Elliott Hugheseda3a602017-05-19 18:53:02 -0700604 for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) {
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200605 free(rate_str[ddir]);
606 free(iops_str[ddir]);
607 }
Jens Axboe263e5292006-10-18 15:37:01 +0200608 }
Jens Axboe37db14f2011-09-30 17:00:42 -0600609 p += sprintf(p, "\r");
610
Jens Axboe3e47bd22012-02-29 13:45:02 +0100611 printf("%s", output);
Jens Axboee382e662013-02-22 20:48:56 +0100612
613 if (!eta_new_line_init) {
614 fio_gettime(&disp_eta_new_line, NULL);
615 eta_new_line_init = 1;
Stephen M. Cameron79dc9142014-11-10 20:31:26 -0700616 } else if (eta_new_line && mtime_since_now(&disp_eta_new_line) > eta_new_line) {
Jens Axboee382e662013-02-22 20:48:56 +0100617 fio_gettime(&disp_eta_new_line, NULL);
618 eta_new_line_pending = 1;
619 }
620
Jens Axboe3e47bd22012-02-29 13:45:02 +0100621 fflush(stdout);
Jens Axboe263e5292006-10-18 15:37:01 +0200622}
623
Elliott Hugheseda3a602017-05-19 18:53:02 -0700624struct jobs_eta *get_jobs_eta(bool force, size_t *size)
Jens Axboe61f6cce2014-06-24 08:40:21 -0600625{
626 struct jobs_eta *je;
627
628 if (!thread_number)
629 return NULL;
630
Elliott Hugheseda3a602017-05-19 18:53:02 -0700631 *size = sizeof(*je) + THREAD_RUNSTR_SZ + 8;
Jens Axboe61f6cce2014-06-24 08:40:21 -0600632 je = malloc(*size);
Robert Elliott106a06b2014-12-12 21:50:30 -0700633 if (!je)
634 return NULL;
Jens Axboe61f6cce2014-06-24 08:40:21 -0600635 memset(je, 0, *size);
636
Jens Axboe18dbbb92014-11-19 09:34:01 -0700637 if (!calc_thread_status(je, force)) {
Jens Axboe61f6cce2014-06-24 08:40:21 -0600638 free(je);
639 return NULL;
640 }
641
Jens Axboed6756e52014-06-27 15:15:23 -0600642 *size = sizeof(*je) + strlen((char *) je->run_str) + 1;
Jens Axboe61f6cce2014-06-24 08:40:21 -0600643 return je;
644}
645
Jens Axboecf451d12011-10-03 16:48:30 +0200646void print_thread_status(void)
647{
Jens Axboe1d1f45a2011-10-03 19:44:41 +0200648 struct jobs_eta *je;
Jens Axboeb814fb22011-10-12 09:20:34 +0200649 size_t size;
Jens Axboecf451d12011-10-03 16:48:30 +0200650
Elliott Hugheseda3a602017-05-19 18:53:02 -0700651 je = get_jobs_eta(false, &size);
Jens Axboe61f6cce2014-06-24 08:40:21 -0600652 if (je)
Jens Axboe1d1f45a2011-10-03 19:44:41 +0200653 display_thread_status(je);
654
655 free(je);
Jens Axboecf451d12011-10-03 16:48:30 +0200656}
Jens Axboeb75a3942011-10-03 16:03:43 +0200657
Jens Axboe2b13e712011-01-19 14:04:16 -0700658void print_status_init(int thr_number)
Jens Axboe263e5292006-10-18 15:37:01 +0200659{
Jens Axboef9ce7c02014-06-16 14:42:05 -0600660 __run_str[thr_number] = 'P';
661 update_condensed_str(__run_str, run_str);
Jens Axboe263e5292006-10-18 15:37:01 +0200662}