blob: 0dd04be8d7a6506443a369233718bbea7937a5a3 [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"
Jens Axboe263e5292006-10-18 15:37:01 +02009
Jens Axboef9ce7c02014-06-16 14:42:05 -060010static char __run_str[REAL_MAX_JOBS + 1];
11
12/*
13 * Worst level condensing would be 1:4, so allow enough room for that
14 */
15static char run_str[(4 * REAL_MAX_JOBS) + 1];
16
17static void update_condensed_str(char *run_str, char *run_str_condensed)
18{
19 int i, ci, last, nr;
20 size_t len;
21
22 len = strlen(run_str);
23 if (!len)
24 return;
25
26 last = 0;
27 nr = 0;
28 ci = 0;
29 for (i = 0; i < len; i++) {
30 if (!last) {
31new:
32 run_str_condensed[ci] = run_str[i];
33 last = run_str[i];
34 nr = 1;
35 ci++;
36 } else if (last == run_str[i]) {
37 nr++;
38 } else {
Jens Axboecdd2bfa2014-06-17 09:22:34 -060039 ci += sprintf(&run_str_condensed[ci], "(%u),", nr);
Jens Axboef9ce7c02014-06-16 14:42:05 -060040 goto new;
41 }
42 }
43
44 if (nr)
Jens Axboecdd2bfa2014-06-17 09:22:34 -060045 ci += sprintf(&run_str_condensed[ci], "(%u)", nr);
Jens Axboef9ce7c02014-06-16 14:42:05 -060046
Jens Axboecdd2bfa2014-06-17 09:22:34 -060047 run_str_condensed[ci + 1] = '\0';
48}
Jens Axboe263e5292006-10-18 15:37:01 +020049
50/*
51 * Sets the status of the 'td' in the printed status map.
52 */
53static void check_str_update(struct thread_data *td)
54{
Jens Axboef9ce7c02014-06-16 14:42:05 -060055 char c = __run_str[td->thread_number - 1];
Jens Axboe263e5292006-10-18 15:37:01 +020056
57 switch (td->runstate) {
Jens Axboe5ec10ea2008-03-06 15:42:00 +010058 case TD_REAPED:
Jens Axboe4f7e57a2012-03-30 21:21:20 +020059 if (td->error)
60 c = 'X';
Jens Axboea5e371a2012-04-02 09:47:09 -070061 else if (td->sig)
62 c = 'K';
Jens Axboe4f7e57a2012-03-30 21:21:20 +020063 else
64 c = '_';
Jens Axboe5ec10ea2008-03-06 15:42:00 +010065 break;
66 case TD_EXITED:
67 c = 'E';
68 break;
Jens Axboeb29ee5b2008-09-11 10:17:26 +020069 case TD_RAMP:
70 c = '/';
71 break;
Jens Axboe5ec10ea2008-03-06 15:42:00 +010072 case TD_RUNNING:
73 if (td_rw(td)) {
Jens Axboee3b3f812011-09-01 09:58:11 -060074 if (td_random(td)) {
75 if (td->o.rwmix[DDIR_READ] == 100)
76 c = 'r';
77 else if (td->o.rwmix[DDIR_WRITE] == 100)
78 c = 'w';
79 else
80 c = 'm';
81 } else {
82 if (td->o.rwmix[DDIR_READ] == 100)
83 c = 'R';
84 else if (td->o.rwmix[DDIR_WRITE] == 100)
85 c = 'W';
86 else
87 c = 'M';
88 }
Jens Axboe5ec10ea2008-03-06 15:42:00 +010089 } else if (td_read(td)) {
90 if (td_random(td))
91 c = 'r';
92 else
93 c = 'R';
Shaohua Li6eaf09d2012-09-14 08:49:43 +020094 } else if (td_write(td)) {
Jens Axboe5ec10ea2008-03-06 15:42:00 +010095 if (td_random(td))
96 c = 'w';
97 else
98 c = 'W';
Shaohua Li6eaf09d2012-09-14 08:49:43 +020099 } else {
100 if (td_random(td))
101 c = 'd';
102 else
103 c = 'D';
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100104 }
105 break;
Jens Axboeb0f65862009-05-20 11:52:15 +0200106 case TD_PRE_READING:
107 c = 'p';
108 break;
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100109 case TD_VERIFYING:
110 c = 'V';
111 break;
112 case TD_FSYNCING:
113 c = 'F';
114 break;
Jens Axboe3d434052014-04-02 15:46:22 -0600115 case TD_FINISHING:
116 c = 'f';
117 break;
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100118 case TD_CREATED:
119 c = 'C';
120 break;
121 case TD_INITIALIZED:
Jens Axboe9c6f6312012-11-07 09:15:45 +0100122 case TD_SETTING_UP:
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100123 c = 'I';
124 break;
125 case TD_NOT_CREATED:
126 c = 'P';
127 break;
128 default:
129 log_err("state %d\n", td->runstate);
Jens Axboe263e5292006-10-18 15:37:01 +0200130 }
131
Jens Axboef9ce7c02014-06-16 14:42:05 -0600132 __run_str[td->thread_number - 1] = c;
133 update_condensed_str(__run_str, run_str);
Jens Axboe263e5292006-10-18 15:37:01 +0200134}
135
136/*
137 * Convert seconds to a printable string.
138 */
Jens Axboe3e47bd22012-02-29 13:45:02 +0100139void eta_to_str(char *str, unsigned long eta_sec)
Jens Axboe263e5292006-10-18 15:37:01 +0200140{
141 unsigned int d, h, m, s;
Jens Axboe165faf12007-02-07 11:30:37 +0100142 int disp_hour = 0;
Jens Axboe263e5292006-10-18 15:37:01 +0200143
Jens Axboe263e5292006-10-18 15:37:01 +0200144 s = eta_sec % 60;
145 eta_sec /= 60;
146 m = eta_sec % 60;
147 eta_sec /= 60;
148 h = eta_sec % 24;
149 eta_sec /= 24;
150 d = eta_sec;
151
Jens Axboe165faf12007-02-07 11:30:37 +0100152 if (d) {
153 disp_hour = 1;
Jens Axboe1e97cce2006-12-05 11:44:16 +0100154 str += sprintf(str, "%02ud:", d);
Jens Axboe263e5292006-10-18 15:37:01 +0200155 }
Jens Axboe165faf12007-02-07 11:30:37 +0100156
157 if (h || disp_hour)
Jens Axboe1e97cce2006-12-05 11:44:16 +0100158 str += sprintf(str, "%02uh:", h);
Jens Axboe263e5292006-10-18 15:37:01 +0200159
Jens Axboe1e97cce2006-12-05 11:44:16 +0100160 str += sprintf(str, "%02um:", m);
161 str += sprintf(str, "%02us", s);
Jens Axboe263e5292006-10-18 15:37:01 +0200162}
163
164/*
165 * Best effort calculation of the estimated pending runtime of a job.
166 */
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200167static int thread_eta(struct thread_data *td)
Jens Axboe263e5292006-10-18 15:37:01 +0200168{
169 unsigned long long bytes_total, bytes_done;
Jens Axboe1e97cce2006-12-05 11:44:16 +0100170 unsigned long eta_sec = 0;
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200171 unsigned long elapsed;
Jens Axboe0de5b262014-02-21 15:26:01 -0800172 uint64_t timeout;
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200173
174 elapsed = (mtime_since_now(&td->epoch) + 999) / 1000;
Jens Axboe0de5b262014-02-21 15:26:01 -0800175 timeout = td->o.timeout / 1000000UL;
Jens Axboe263e5292006-10-18 15:37:01 +0200176
177 bytes_total = td->total_io_size;
178
Jens Axboe2e3bd4c2010-05-17 12:29:57 +0200179 if (td->o.fill_device && td->o.size == -1ULL) {
180 if (!td->fill_device_size || td->fill_device_size == -1ULL)
181 return 0;
182
183 bytes_total = td->fill_device_size;
184 }
185
Jens Axboe0d73a2f2013-02-07 12:54:10 +0100186 if (td->o.zone_size && td->o.zone_skip && bytes_total) {
187 unsigned int nr_zones;
188 uint64_t zone_bytes;
189
190 zone_bytes = bytes_total + td->o.zone_size + td->o.zone_skip;
191 nr_zones = (zone_bytes - 1) / (td->o.zone_size + td->o.zone_skip);
192 bytes_total -= nr_zones * td->o.zone_skip;
193 }
194
Jens Axboe74939e32006-10-19 20:37:12 +0200195 /*
Jens Axboe165eb052013-01-23 08:40:11 -0700196 * if writing and verifying afterwards, bytes_total will be twice the
197 * size. In a mixed workload, verify phase will be the size of the
198 * first stage writes.
Jens Axboe74939e32006-10-19 20:37:12 +0200199 */
Jens Axboe0dd83772007-09-04 12:38:28 +0200200 if (td->o.do_verify && td->o.verify && td_write(td)) {
Jens Axboe165eb052013-01-23 08:40:11 -0700201 if (td_rw(td)) {
202 unsigned int perc = 50;
203
204 if (td->o.rwmix[DDIR_WRITE])
205 perc = td->o.rwmix[DDIR_WRITE];
206
207 bytes_total += (bytes_total * perc) / 100;
208 } else
Jens Axboe74939e32006-10-19 20:37:12 +0200209 bytes_total <<= 1;
210 }
211
Jens Axboe263e5292006-10-18 15:37:01 +0200212 if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING) {
Jens Axboecf4464c2007-04-17 20:14:42 +0200213 double perc, perc_t;
Jens Axboe263e5292006-10-18 15:37:01 +0200214
Jens Axboe342f4be2012-09-14 08:59:20 +0200215 bytes_done = ddir_rw_sum(td->io_bytes);
Jens Axboe476882d2014-04-14 09:45:19 -0600216
217 if (bytes_total) {
218 perc = (double) bytes_done / (double) bytes_total;
219 if (perc > 1.0)
220 perc = 1.0;
221 } else
222 perc = 0.0;
Jens Axboe263e5292006-10-18 15:37:01 +0200223
Jens Axboecf4464c2007-04-17 20:14:42 +0200224 if (td->o.time_based) {
Jens Axboe476882d2014-04-14 09:45:19 -0600225 if (timeout) {
226 perc_t = (double) elapsed / (double) timeout;
227 if (perc_t < perc)
228 perc = perc_t;
229 } else {
230 /*
231 * Will never hit, we can't have time_based
232 * without a timeout set.
233 */
234 perc = 0.0;
235 }
Jens Axboecf4464c2007-04-17 20:14:42 +0200236 }
237
Jens Axboe1e97cce2006-12-05 11:44:16 +0100238 eta_sec = (unsigned long) (elapsed * (1.0 / perc)) - elapsed;
Jens Axboe263e5292006-10-18 15:37:01 +0200239
Jens Axboed3eeeab2008-04-06 12:19:05 +0200240 if (td->o.timeout &&
Jens Axboe0de5b262014-02-21 15:26:01 -0800241 eta_sec > (timeout + done_secs - elapsed))
242 eta_sec = timeout + done_secs - elapsed;
Jens Axboe263e5292006-10-18 15:37:01 +0200243 } else if (td->runstate == TD_NOT_CREATED || td->runstate == TD_CREATED
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200244 || td->runstate == TD_INITIALIZED
Jens Axboe714e85f2013-04-15 10:21:56 +0200245 || td->runstate == TD_SETTING_UP
Jens Axboeb0f65862009-05-20 11:52:15 +0200246 || td->runstate == TD_RAMP
247 || td->runstate == TD_PRE_READING) {
Jens Axboe263e5292006-10-18 15:37:01 +0200248 int t_eta = 0, r_eta = 0;
Jens Axboe342f4be2012-09-14 08:59:20 +0200249 unsigned long long rate_bytes;
Jens Axboe263e5292006-10-18 15:37:01 +0200250
251 /*
252 * We can only guess - assume it'll run the full timeout
253 * if given, otherwise assume it'll run at the specified rate.
254 */
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200255 if (td->o.timeout) {
Jens Axboe0de5b262014-02-21 15:26:01 -0800256 uint64_t timeout = td->o.timeout;
257 uint64_t start_delay = td->o.start_delay;
258 uint64_t ramp_time = td->o.ramp_time;
259
260 t_eta = timeout + start_delay + ramp_time;
261 t_eta /= 1000000ULL;
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200262
263 if (in_ramp_time(td)) {
264 unsigned long ramp_left;
265
Signed-off-by Steven Prattcda99fa2010-12-14 08:31:36 +0100266 ramp_left = mtime_since_now(&td->epoch);
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200267 ramp_left = (ramp_left + 999) / 1000;
268 if (ramp_left <= t_eta)
269 t_eta -= ramp_left;
270 }
271 }
Jens Axboe342f4be2012-09-14 08:59:20 +0200272 rate_bytes = ddir_rw_sum(td->o.rate);
273 if (rate_bytes) {
274 r_eta = (bytes_total / 1024) / rate_bytes;
Jens Axboe0de5b262014-02-21 15:26:01 -0800275 r_eta += (td->o.start_delay / 1000000ULL);
Jens Axboe263e5292006-10-18 15:37:01 +0200276 }
277
278 if (r_eta && t_eta)
279 eta_sec = min(r_eta, t_eta);
280 else if (r_eta)
281 eta_sec = r_eta;
282 else if (t_eta)
283 eta_sec = t_eta;
284 else
285 eta_sec = 0;
286 } else {
287 /*
288 * thread is already done or waiting for fsync
289 */
290 eta_sec = 0;
291 }
292
293 return eta_sec;
294}
295
Jens Axboe771e58b2013-01-30 12:56:23 +0100296static void calc_rate(int unified_rw_rep, unsigned long mtime,
297 unsigned long long *io_bytes,
Jens Axboe46fda8d2007-02-11 00:49:30 +0100298 unsigned long long *prev_io_bytes, unsigned int *rate)
299{
Jens Axboeb7f05eb2012-05-11 20:33:02 +0200300 int i;
301
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200302 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboeb7f05eb2012-05-11 20:33:02 +0200303 unsigned long long diff;
304
305 diff = io_bytes[i] - prev_io_bytes[i];
Jens Axboe771e58b2013-01-30 12:56:23 +0100306 if (unified_rw_rep) {
307 rate[i] = 0;
308 rate[0] += ((1000 * diff) / mtime) / 1024;
309 } else
310 rate[i] = ((1000 * diff) / mtime) / 1024;
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200311
312 prev_io_bytes[i] = io_bytes[i];
Jens Axboeb7f05eb2012-05-11 20:33:02 +0200313 }
Jens Axboe46fda8d2007-02-11 00:49:30 +0100314}
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100315
Jens Axboe771e58b2013-01-30 12:56:23 +0100316static void calc_iops(int unified_rw_rep, unsigned long mtime,
317 unsigned long long *io_iops,
Jens Axboeadb02ba2009-06-03 10:47:44 +0200318 unsigned long long *prev_io_iops, unsigned int *iops)
319{
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200320 int i;
321
322 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboe771e58b2013-01-30 12:56:23 +0100323 unsigned long long diff;
324
325 diff = io_iops[i] - prev_io_iops[i];
326 if (unified_rw_rep) {
327 iops[i] = 0;
328 iops[0] += (diff * 1000) / mtime;
329 } else
330 iops[i] = (diff * 1000) / mtime;
331
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200332 prev_io_iops[i] = io_iops[i];
333 }
Jens Axboeadb02ba2009-06-03 10:47:44 +0200334}
335
Jens Axboe263e5292006-10-18 15:37:01 +0200336/*
337 * Print status of the jobs we know about. This includes rate estimates,
338 * ETA, thread state, etc.
339 */
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200340int calc_thread_status(struct jobs_eta *je, int force)
Jens Axboe263e5292006-10-18 15:37:01 +0200341{
Jens Axboe34572e22006-10-20 09:33:18 +0200342 struct thread_data *td;
Jens Axboe771e58b2013-01-30 12:56:23 +0100343 int i, unified_rw_rep;
Jens Axboeb75a3942011-10-03 16:03:43 +0200344 unsigned long rate_time, disp_time, bw_avg_time, *eta_secs;
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200345 unsigned long long io_bytes[DDIR_RWDIR_CNT];
346 unsigned long long io_iops[DDIR_RWDIR_CNT];
Jens Axboe46fda8d2007-02-11 00:49:30 +0100347 struct timeval now;
348
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200349 static unsigned long long rate_io_bytes[DDIR_RWDIR_CNT];
350 static unsigned long long disp_io_bytes[DDIR_RWDIR_CNT];
351 static unsigned long long disp_io_iops[DDIR_RWDIR_CNT];
Jens Axboe46fda8d2007-02-11 00:49:30 +0100352 static struct timeval rate_prev_time, disp_prev_time;
Jens Axboe6043c572006-11-03 11:37:47 +0100353
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200354 if (!force) {
Jens Axboefc475592013-01-31 15:24:34 +0100355 if (output_format != FIO_OUTPUT_NORMAL &&
356 f_out == stdout)
Jens Axboef3afa572012-09-17 13:34:16 +0200357 return 0;
358 if (temp_stall_ts || eta_print == FIO_ETA_NEVER)
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200359 return 0;
Aaron Carrolle592a062007-09-14 09:49:41 +0200360
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200361 if (!isatty(STDOUT_FILENO) && (eta_print != FIO_ETA_ALWAYS))
362 return 0;
363 }
Jens Axboe263e5292006-10-18 15:37:01 +0200364
Jens Axboe342f4be2012-09-14 08:59:20 +0200365 if (!ddir_rw_sum(rate_io_bytes))
Jens Axboe46fda8d2007-02-11 00:49:30 +0100366 fill_start_time(&rate_prev_time);
Jens Axboe342f4be2012-09-14 08:59:20 +0200367 if (!ddir_rw_sum(disp_io_bytes))
Jens Axboe46fda8d2007-02-11 00:49:30 +0100368 fill_start_time(&disp_prev_time);
Jens Axboe6043c572006-11-03 11:37:47 +0100369
Jens Axboed3eeeab2008-04-06 12:19:05 +0200370 eta_secs = malloc(thread_number * sizeof(unsigned long));
371 memset(eta_secs, 0, thread_number * sizeof(unsigned long));
Jens Axboe263e5292006-10-18 15:37:01 +0200372
Jens Axboeb75a3942011-10-03 16:03:43 +0200373 je->elapsed_sec = (mtime_since_genesis() + 999) / 1000;
374
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200375 io_bytes[DDIR_READ] = io_bytes[DDIR_WRITE] = io_bytes[DDIR_TRIM] = 0;
376 io_iops[DDIR_READ] = io_iops[DDIR_WRITE] = io_iops[DDIR_TRIM] = 0;
Jens Axboebb3884d2007-01-17 17:23:11 +1100377 bw_avg_time = ULONG_MAX;
Jens Axboe771e58b2013-01-30 12:56:23 +0100378 unified_rw_rep = 0;
Jens Axboe34572e22006-10-20 09:33:18 +0200379 for_each_td(td, i) {
Jens Axboe771e58b2013-01-30 12:56:23 +0100380 unified_rw_rep += td->o.unified_rw_rep;
Jens Axboeb7f05eb2012-05-11 20:33:02 +0200381 if (is_power_of_2(td->o.kb_base))
382 je->is_pow2 = 1;
Steven Noonanad705bc2013-04-08 15:05:25 -0700383 je->unit_base = td->o.unit_base;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100384 if (td->o.bw_avg_time < bw_avg_time)
385 bw_avg_time = td->o.bw_avg_time;
Jens Axboe46fda8d2007-02-11 00:49:30 +0100386 if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING
Jens Axboeb0f65862009-05-20 11:52:15 +0200387 || td->runstate == TD_FSYNCING
Jens Axboe3d434052014-04-02 15:46:22 -0600388 || td->runstate == TD_PRE_READING
389 || td->runstate == TD_FINISHING) {
Jens Axboeb75a3942011-10-03 16:03:43 +0200390 je->nr_running++;
Jens Axboe242c38d2012-08-20 14:44:22 +0200391 if (td_read(td)) {
Jens Axboec2e9cc42012-08-21 15:34:13 +0200392 je->t_rate[0] += td->o.rate[DDIR_READ];
393 je->t_iops[0] += td->o.rate_iops[DDIR_READ];
394 je->m_rate[0] += td->o.ratemin[DDIR_READ];
395 je->m_iops[0] += td->o.rate_iops_min[DDIR_READ];
Jens Axboe242c38d2012-08-20 14:44:22 +0200396 }
397 if (td_write(td)) {
Jens Axboec2e9cc42012-08-21 15:34:13 +0200398 je->t_rate[1] += td->o.rate[DDIR_WRITE];
399 je->t_iops[1] += td->o.rate_iops[DDIR_WRITE];
400 je->m_rate[1] += td->o.ratemin[DDIR_WRITE];
401 je->m_iops[1] += td->o.rate_iops_min[DDIR_WRITE];
Jens Axboe242c38d2012-08-20 14:44:22 +0200402 }
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200403 if (td_trim(td)) {
Jens Axboed79db122012-09-24 08:51:24 +0200404 je->t_rate[2] += td->o.rate[DDIR_TRIM];
405 je->t_iops[2] += td->o.rate_iops[DDIR_TRIM];
406 je->m_rate[2] += td->o.ratemin[DDIR_TRIM];
407 je->m_iops[2] += td->o.rate_iops_min[DDIR_TRIM];
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200408 }
409
Jens Axboeb75a3942011-10-03 16:03:43 +0200410 je->files_open += td->nr_open_files;
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200411 } else if (td->runstate == TD_RAMP) {
Jens Axboeb75a3942011-10-03 16:03:43 +0200412 je->nr_running++;
413 je->nr_ramp++;
Jens Axboe714e85f2013-04-15 10:21:56 +0200414 } else if (td->runstate == TD_SETTING_UP) {
Jens Axboe9c6f6312012-11-07 09:15:45 +0100415 je->nr_running++;
Jens Axboe714e85f2013-04-15 10:21:56 +0200416 je->nr_setting_up++;
417 } else if (td->runstate < TD_RUNNING)
Jens Axboeb75a3942011-10-03 16:03:43 +0200418 je->nr_pending++;
Jens Axboe263e5292006-10-18 15:37:01 +0200419
Jens Axboeb75a3942011-10-03 16:03:43 +0200420 if (je->elapsed_sec >= 3)
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200421 eta_secs[i] = thread_eta(td);
Jens Axboe263e5292006-10-18 15:37:01 +0200422 else
423 eta_secs[i] = INT_MAX;
424
425 check_str_update(td);
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200426
Jens Axboe714e85f2013-04-15 10:21:56 +0200427 if (td->runstate > TD_SETTING_UP) {
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200428 int ddir;
Jens Axboe771e58b2013-01-30 12:56:23 +0100429
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200430 for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) {
Jens Axboe771e58b2013-01-30 12:56:23 +0100431 if (unified_rw_rep) {
432 io_bytes[0] += td->io_bytes[ddir];
433 io_iops[0] += td->io_blocks[ddir];
434 } else {
435 io_bytes[ddir] += td->io_bytes[ddir];
436 io_iops[ddir] += td->io_blocks[ddir];
437 }
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200438 }
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200439 }
Jens Axboe263e5292006-10-18 15:37:01 +0200440 }
441
442 if (exitall_on_terminate)
Jens Axboeb75a3942011-10-03 16:03:43 +0200443 je->eta_sec = INT_MAX;
Jens Axboe263e5292006-10-18 15:37:01 +0200444 else
Jens Axboeb75a3942011-10-03 16:03:43 +0200445 je->eta_sec = 0;
Jens Axboe263e5292006-10-18 15:37:01 +0200446
Jens Axboe34572e22006-10-20 09:33:18 +0200447 for_each_td(td, i) {
Shaozhi Shawn Ye9c5a3852008-09-10 09:09:37 +0200448 if (exitall_on_terminate) {
Jens Axboeb75a3942011-10-03 16:03:43 +0200449 if (eta_secs[i] < je->eta_sec)
450 je->eta_sec = eta_secs[i];
Shaozhi Shawn Ye9c5a3852008-09-10 09:09:37 +0200451 } else {
Jens Axboeb75a3942011-10-03 16:03:43 +0200452 if (eta_secs[i] > je->eta_sec)
453 je->eta_sec = eta_secs[i];
Shaozhi Shawn Ye9c5a3852008-09-10 09:09:37 +0200454 }
Jens Axboe263e5292006-10-18 15:37:01 +0200455 }
456
Jens Axboeeecf2722006-10-20 14:00:36 +0200457 free(eta_secs);
458
Jens Axboe46fda8d2007-02-11 00:49:30 +0100459 fio_gettime(&now, NULL);
460 rate_time = mtime_since(&rate_prev_time, &now);
461
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200462 if (write_bw_log && rate_time > bw_avg_time && !in_ramp_time(td)) {
Jens Axboe771e58b2013-01-30 12:56:23 +0100463 calc_rate(unified_rw_rep, rate_time, io_bytes, rate_io_bytes,
464 je->rate);
Jens Axboe46fda8d2007-02-11 00:49:30 +0100465 memcpy(&rate_prev_time, &now, sizeof(now));
Jens Axboeb75a3942011-10-03 16:03:43 +0200466 add_agg_sample(je->rate[DDIR_READ], DDIR_READ, 0);
467 add_agg_sample(je->rate[DDIR_WRITE], DDIR_WRITE, 0);
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200468 add_agg_sample(je->rate[DDIR_TRIM], DDIR_TRIM, 0);
Jens Axboe6043c572006-11-03 11:37:47 +0100469 }
470
Jens Axboe46fda8d2007-02-11 00:49:30 +0100471 disp_time = mtime_since(&disp_prev_time, &now);
Jens Axboea5b01f12010-11-11 09:19:49 +0100472
473 /*
474 * Allow a little slack, the target is to print it every 1000 msecs
475 */
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200476 if (!force && disp_time < 900)
Jens Axboeb75a3942011-10-03 16:03:43 +0200477 return 0;
Jens Axboe46fda8d2007-02-11 00:49:30 +0100478
Jens Axboe771e58b2013-01-30 12:56:23 +0100479 calc_rate(unified_rw_rep, disp_time, io_bytes, disp_io_bytes, je->rate);
480 calc_iops(unified_rw_rep, disp_time, io_iops, disp_io_iops, je->iops);
Jens Axboeadb02ba2009-06-03 10:47:44 +0200481
Jens Axboe46fda8d2007-02-11 00:49:30 +0100482 memcpy(&disp_prev_time, &now, sizeof(now));
483
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200484 if (!force && !je->nr_running && !je->nr_pending)
Jens Axboeb75a3942011-10-03 16:03:43 +0200485 return 0;
486
Jens Axboe1d1f45a2011-10-03 19:44:41 +0200487 je->nr_threads = thread_number;
Jens Axboecdd2bfa2014-06-17 09:22:34 -0600488 update_condensed_str(__run_str, run_str);
489 memcpy(je->run_str, run_str, strlen(run_str));
Jens Axboeb75a3942011-10-03 16:03:43 +0200490 return 1;
491}
492
Jens Axboecf451d12011-10-03 16:48:30 +0200493void display_thread_status(struct jobs_eta *je)
Jens Axboeb75a3942011-10-03 16:03:43 +0200494{
Jens Axboee382e662013-02-22 20:48:56 +0100495 static struct timeval disp_eta_new_line;
496 static int eta_new_line_init, eta_new_line_pending;
Jens Axboeb75a3942011-10-03 16:03:43 +0200497 static int linelen_last;
498 static int eta_good;
Jens Axboe79074e72012-04-18 20:39:48 +0200499 char output[REAL_MAX_JOBS + 512], *p = output;
Jens Axboeb75a3942011-10-03 16:03:43 +0200500 char eta_str[128];
501 double perc = 0.0;
Jens Axboeb75a3942011-10-03 16:03:43 +0200502
Jens Axboecf451d12011-10-03 16:48:30 +0200503 if (je->eta_sec != INT_MAX && je->elapsed_sec) {
504 perc = (double) je->elapsed_sec / (double) (je->elapsed_sec + je->eta_sec);
505 eta_to_str(eta_str, je->eta_sec);
Jens Axboeb75a3942011-10-03 16:03:43 +0200506 }
507
Jens Axboee382e662013-02-22 20:48:56 +0100508 if (eta_new_line_pending) {
509 eta_new_line_pending = 0;
510 p += sprintf(p, "\n");
511 }
512
Jens Axboecf451d12011-10-03 16:48:30 +0200513 p += sprintf(p, "Jobs: %d (f=%d)", je->nr_running, je->files_open);
Jens Axboe3e47bd22012-02-29 13:45:02 +0100514 if (je->m_rate[0] || je->m_rate[1] || je->t_rate[0] || je->t_rate[1]) {
Jens Axboe581e7142009-06-09 12:47:16 +0200515 char *tr, *mr;
516
Jens Axboe22f80452013-04-09 20:29:16 +0200517 mr = num2str(je->m_rate[0] + je->m_rate[1], 4, 0, je->is_pow2, 8);
518 tr = num2str(je->t_rate[0] + je->t_rate[1], 4, 0, je->is_pow2, 8);
Jens Axboe37db14f2011-09-30 17:00:42 -0600519 p += sprintf(p, ", CR=%s/%s KB/s", tr, mr);
Jens Axboe581e7142009-06-09 12:47:16 +0200520 free(tr);
521 free(mr);
Jens Axboe3e47bd22012-02-29 13:45:02 +0100522 } else if (je->m_iops[0] || je->m_iops[1] || je->t_iops[0] || je->t_iops[1]) {
523 p += sprintf(p, ", CR=%d/%d IOPS",
524 je->t_iops[0] + je->t_iops[1],
Jens Axboe88e4bea2012-08-21 15:34:36 +0200525 je->m_iops[0] + je->m_iops[1]);
Jens Axboe3e47bd22012-02-29 13:45:02 +0100526 }
Jens Axboecf451d12011-10-03 16:48:30 +0200527 if (je->eta_sec != INT_MAX && je->nr_running) {
Jens Axboe0721d112008-06-05 09:03:05 +0200528 char perc_str[32];
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200529 char *iops_str[DDIR_RWDIR_CNT];
530 char *rate_str[DDIR_RWDIR_CNT];
Jens Axboe79074e72012-04-18 20:39:48 +0200531 size_t left;
Jens Axboeadb02ba2009-06-03 10:47:44 +0200532 int l;
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200533 int ddir;
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100534
Jens Axboecf451d12011-10-03 16:48:30 +0200535 if ((!je->eta_sec && !eta_good) || je->nr_ramp == je->nr_running)
Jens Axboecac58fd2008-06-06 01:17:03 +0200536 strcpy(perc_str, "-.-% done");
537 else {
Jens Axboe714e85f2013-04-15 10:21:56 +0200538 double mult = 100.0;
539
540 if (je->nr_setting_up && je->nr_running)
541 mult *= (1.0 - (double) je->nr_setting_up / (double) je->nr_running);
542
Jens Axboecac58fd2008-06-06 01:17:03 +0200543 eta_good = 1;
Jens Axboe714e85f2013-04-15 10:21:56 +0200544 perc *= mult;
Jens Axboe0721d112008-06-05 09:03:05 +0200545 sprintf(perc_str, "%3.1f%% done", perc);
Jens Axboecac58fd2008-06-06 01:17:03 +0200546 }
Jens Axboe0721d112008-06-05 09:03:05 +0200547
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200548 for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) {
549 rate_str[ddir] = num2str(je->rate[ddir], 5,
Steven Noonanad705bc2013-04-08 15:05:25 -0700550 1024, je->is_pow2, je->unit_base);
Steven Noonan73798eb2013-04-05 16:57:38 -0700551 iops_str[ddir] = num2str(je->iops[ddir], 4, 1, 0, 0);
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200552 }
Jens Axboeadb02ba2009-06-03 10:47:44 +0200553
Jens Axboe79074e72012-04-18 20:39:48 +0200554 left = sizeof(output) - (p - output) - 1;
555
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200556 l = snprintf(p, left, ": [%s] [%s] [%s/%s/%s /s] [%s/%s/%s iops] [eta %s]",
557 je->run_str, perc_str, rate_str[DDIR_READ],
558 rate_str[DDIR_WRITE], rate_str[DDIR_TRIM],
559 iops_str[DDIR_READ], iops_str[DDIR_WRITE],
560 iops_str[DDIR_TRIM], eta_str);
Jens Axboe37db14f2011-09-30 17:00:42 -0600561 p += l;
Jens Axboeadb02ba2009-06-03 10:47:44 +0200562 if (l >= 0 && l < linelen_last)
Jens Axboe37db14f2011-09-30 17:00:42 -0600563 p += sprintf(p, "%*s", linelen_last - l, "");
Jens Axboeadb02ba2009-06-03 10:47:44 +0200564 linelen_last = l;
Jens Axboed1bd7212009-06-03 10:53:45 +0200565
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200566 for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) {
567 free(rate_str[ddir]);
568 free(iops_str[ddir]);
569 }
Jens Axboe263e5292006-10-18 15:37:01 +0200570 }
Jens Axboe37db14f2011-09-30 17:00:42 -0600571 p += sprintf(p, "\r");
572
Jens Axboe3e47bd22012-02-29 13:45:02 +0100573 printf("%s", output);
Jens Axboee382e662013-02-22 20:48:56 +0100574
575 if (!eta_new_line_init) {
576 fio_gettime(&disp_eta_new_line, NULL);
577 eta_new_line_init = 1;
578 } else if (eta_new_line &&
579 mtime_since_now(&disp_eta_new_line) > eta_new_line * 1000) {
580 fio_gettime(&disp_eta_new_line, NULL);
581 eta_new_line_pending = 1;
582 }
583
Jens Axboe3e47bd22012-02-29 13:45:02 +0100584 fflush(stdout);
Jens Axboe263e5292006-10-18 15:37:01 +0200585}
586
Jens Axboecf451d12011-10-03 16:48:30 +0200587void print_thread_status(void)
588{
Jens Axboe1d1f45a2011-10-03 19:44:41 +0200589 struct jobs_eta *je;
Jens Axboeb814fb22011-10-12 09:20:34 +0200590 size_t size;
Jens Axboecf451d12011-10-03 16:48:30 +0200591
Jens Axboeb814fb22011-10-12 09:20:34 +0200592 if (!thread_number)
593 return;
Jens Axboecf451d12011-10-03 16:48:30 +0200594
Jens Axboeb814fb22011-10-12 09:20:34 +0200595 size = sizeof(*je) + thread_number * sizeof(char) + 1;
596 je = malloc(size);
597 memset(je, 0, size);
Jens Axboecf451d12011-10-03 16:48:30 +0200598
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200599 if (calc_thread_status(je, 0))
Jens Axboe1d1f45a2011-10-03 19:44:41 +0200600 display_thread_status(je);
601
602 free(je);
Jens Axboecf451d12011-10-03 16:48:30 +0200603}
Jens Axboeb75a3942011-10-03 16:03:43 +0200604
Jens Axboe2b13e712011-01-19 14:04:16 -0700605void print_status_init(int thr_number)
Jens Axboe263e5292006-10-18 15:37:01 +0200606{
Jens Axboef9ce7c02014-06-16 14:42:05 -0600607 __run_str[thr_number] = 'P';
608 update_condensed_str(__run_str, run_str);
Jens Axboe263e5292006-10-18 15:37:01 +0200609}