blob: f491feaacb56bfc3791530781ee36211b819c994 [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 Axboefca70352011-07-06 20:12:54 +020010static char run_str[REAL_MAX_JOBS + 1];
Jens Axboe263e5292006-10-18 15:37:01 +020011
12/*
13 * Sets the status of the 'td' in the printed status map.
14 */
15static void check_str_update(struct thread_data *td)
16{
17 char c = run_str[td->thread_number - 1];
18
19 switch (td->runstate) {
Jens Axboe5ec10ea2008-03-06 15:42:00 +010020 case TD_REAPED:
Jens Axboe4f7e57a2012-03-30 21:21:20 +020021 if (td->error)
22 c = 'X';
Jens Axboea5e371a2012-04-02 09:47:09 -070023 else if (td->sig)
24 c = 'K';
Jens Axboe4f7e57a2012-03-30 21:21:20 +020025 else
26 c = '_';
Jens Axboe5ec10ea2008-03-06 15:42:00 +010027 break;
28 case TD_EXITED:
29 c = 'E';
30 break;
Jens Axboeb29ee5b2008-09-11 10:17:26 +020031 case TD_RAMP:
32 c = '/';
33 break;
Jens Axboe5ec10ea2008-03-06 15:42:00 +010034 case TD_RUNNING:
35 if (td_rw(td)) {
Jens Axboee3b3f812011-09-01 09:58:11 -060036 if (td_random(td)) {
37 if (td->o.rwmix[DDIR_READ] == 100)
38 c = 'r';
39 else if (td->o.rwmix[DDIR_WRITE] == 100)
40 c = 'w';
41 else
42 c = 'm';
43 } else {
44 if (td->o.rwmix[DDIR_READ] == 100)
45 c = 'R';
46 else if (td->o.rwmix[DDIR_WRITE] == 100)
47 c = 'W';
48 else
49 c = 'M';
50 }
Jens Axboe5ec10ea2008-03-06 15:42:00 +010051 } else if (td_read(td)) {
52 if (td_random(td))
53 c = 'r';
54 else
55 c = 'R';
56 } else {
57 if (td_random(td))
58 c = 'w';
59 else
60 c = 'W';
61 }
62 break;
Jens Axboeb0f65862009-05-20 11:52:15 +020063 case TD_PRE_READING:
64 c = 'p';
65 break;
Jens Axboe5ec10ea2008-03-06 15:42:00 +010066 case TD_VERIFYING:
67 c = 'V';
68 break;
69 case TD_FSYNCING:
70 c = 'F';
71 break;
72 case TD_CREATED:
73 c = 'C';
74 break;
75 case TD_INITIALIZED:
76 c = 'I';
77 break;
78 case TD_NOT_CREATED:
79 c = 'P';
80 break;
81 default:
82 log_err("state %d\n", td->runstate);
Jens Axboe263e5292006-10-18 15:37:01 +020083 }
84
85 run_str[td->thread_number - 1] = c;
86}
87
88/*
89 * Convert seconds to a printable string.
90 */
Jens Axboe3e47bd22012-02-29 13:45:02 +010091void eta_to_str(char *str, unsigned long eta_sec)
Jens Axboe263e5292006-10-18 15:37:01 +020092{
93 unsigned int d, h, m, s;
Jens Axboe165faf12007-02-07 11:30:37 +010094 int disp_hour = 0;
Jens Axboe263e5292006-10-18 15:37:01 +020095
Jens Axboe263e5292006-10-18 15:37:01 +020096 s = eta_sec % 60;
97 eta_sec /= 60;
98 m = eta_sec % 60;
99 eta_sec /= 60;
100 h = eta_sec % 24;
101 eta_sec /= 24;
102 d = eta_sec;
103
Jens Axboe165faf12007-02-07 11:30:37 +0100104 if (d) {
105 disp_hour = 1;
Jens Axboe1e97cce2006-12-05 11:44:16 +0100106 str += sprintf(str, "%02ud:", d);
Jens Axboe263e5292006-10-18 15:37:01 +0200107 }
Jens Axboe165faf12007-02-07 11:30:37 +0100108
109 if (h || disp_hour)
Jens Axboe1e97cce2006-12-05 11:44:16 +0100110 str += sprintf(str, "%02uh:", h);
Jens Axboe263e5292006-10-18 15:37:01 +0200111
Jens Axboe1e97cce2006-12-05 11:44:16 +0100112 str += sprintf(str, "%02um:", m);
113 str += sprintf(str, "%02us", s);
Jens Axboe263e5292006-10-18 15:37:01 +0200114}
115
116/*
117 * Best effort calculation of the estimated pending runtime of a job.
118 */
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200119static int thread_eta(struct thread_data *td)
Jens Axboe263e5292006-10-18 15:37:01 +0200120{
121 unsigned long long bytes_total, bytes_done;
Jens Axboe1e97cce2006-12-05 11:44:16 +0100122 unsigned long eta_sec = 0;
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200123 unsigned long elapsed;
124
125 elapsed = (mtime_since_now(&td->epoch) + 999) / 1000;
Jens Axboe263e5292006-10-18 15:37:01 +0200126
127 bytes_total = td->total_io_size;
128
Jens Axboe2e3bd4c2010-05-17 12:29:57 +0200129 if (td->o.fill_device && td->o.size == -1ULL) {
130 if (!td->fill_device_size || td->fill_device_size == -1ULL)
131 return 0;
132
133 bytes_total = td->fill_device_size;
134 }
135
Jens Axboe74939e32006-10-19 20:37:12 +0200136 /*
137 * if writing, bytes_total will be twice the size. If mixing,
138 * assume a 50/50 split and thus bytes_total will be 50% larger.
139 */
Jens Axboe0dd83772007-09-04 12:38:28 +0200140 if (td->o.do_verify && td->o.verify && td_write(td)) {
Jens Axboe74939e32006-10-19 20:37:12 +0200141 if (td_rw(td))
142 bytes_total = bytes_total * 3 / 2;
143 else
144 bytes_total <<= 1;
145 }
146
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100147 if (td->o.zone_size && td->o.zone_skip)
148 bytes_total /= (td->o.zone_skip / td->o.zone_size);
Jens Axboe263e5292006-10-18 15:37:01 +0200149
150 if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING) {
Jens Axboecf4464c2007-04-17 20:14:42 +0200151 double perc, perc_t;
Jens Axboe263e5292006-10-18 15:37:01 +0200152
153 bytes_done = td->io_bytes[DDIR_READ] + td->io_bytes[DDIR_WRITE];
154 perc = (double) bytes_done / (double) bytes_total;
155 if (perc > 1.0)
156 perc = 1.0;
157
Jens Axboecf4464c2007-04-17 20:14:42 +0200158 if (td->o.time_based) {
159 perc_t = (double) elapsed / (double) td->o.timeout;
160 if (perc_t < perc)
161 perc = perc_t;
162 }
163
Jens Axboe1e97cce2006-12-05 11:44:16 +0100164 eta_sec = (unsigned long) (elapsed * (1.0 / perc)) - elapsed;
Jens Axboe263e5292006-10-18 15:37:01 +0200165
Jens Axboed3eeeab2008-04-06 12:19:05 +0200166 if (td->o.timeout &&
167 eta_sec > (td->o.timeout + done_secs - elapsed))
168 eta_sec = td->o.timeout + done_secs - elapsed;
Jens Axboe263e5292006-10-18 15:37:01 +0200169 } else if (td->runstate == TD_NOT_CREATED || td->runstate == TD_CREATED
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200170 || td->runstate == TD_INITIALIZED
Jens Axboeb0f65862009-05-20 11:52:15 +0200171 || td->runstate == TD_RAMP
172 || td->runstate == TD_PRE_READING) {
Jens Axboe263e5292006-10-18 15:37:01 +0200173 int t_eta = 0, r_eta = 0;
174
175 /*
176 * We can only guess - assume it'll run the full timeout
177 * if given, otherwise assume it'll run at the specified rate.
178 */
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200179 if (td->o.timeout) {
Signed-off-by Steven Prattcda99fa2010-12-14 08:31:36 +0100180 t_eta = td->o.timeout + td->o.start_delay +
181 td->o.ramp_time;
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200182
183 if (in_ramp_time(td)) {
184 unsigned long ramp_left;
185
Signed-off-by Steven Prattcda99fa2010-12-14 08:31:36 +0100186 ramp_left = mtime_since_now(&td->epoch);
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200187 ramp_left = (ramp_left + 999) / 1000;
188 if (ramp_left <= t_eta)
189 t_eta -= ramp_left;
190 }
191 }
Jens Axboe581e7142009-06-09 12:47:16 +0200192 if (td->o.rate[0] || td->o.rate[1]) {
Jens Axboe0b9d69e2009-09-11 22:29:54 +0200193 r_eta = (bytes_total / 1024) /
194 (td->o.rate[0] + td->o.rate[1]);
Jens Axboed3eeeab2008-04-06 12:19:05 +0200195 r_eta += td->o.start_delay;
Jens Axboe263e5292006-10-18 15:37:01 +0200196 }
197
198 if (r_eta && t_eta)
199 eta_sec = min(r_eta, t_eta);
200 else if (r_eta)
201 eta_sec = r_eta;
202 else if (t_eta)
203 eta_sec = t_eta;
204 else
205 eta_sec = 0;
206 } else {
207 /*
208 * thread is already done or waiting for fsync
209 */
210 eta_sec = 0;
211 }
212
213 return eta_sec;
214}
215
Jens Axboe46fda8d2007-02-11 00:49:30 +0100216static void calc_rate(unsigned long mtime, unsigned long long *io_bytes,
217 unsigned long long *prev_io_bytes, unsigned int *rate)
218{
Jens Axboeb7f05eb2012-05-11 20:33:02 +0200219 int i;
220
221 for (i = 0; i <= DDIR_WRITE; i++) {
222 unsigned long long diff;
223
224 diff = io_bytes[i] - prev_io_bytes[i];
225 rate[i] = ((1000 * diff) / mtime) / 1024;
226 }
Jens Axboe46fda8d2007-02-11 00:49:30 +0100227 prev_io_bytes[0] = io_bytes[0];
228 prev_io_bytes[1] = io_bytes[1];
229}
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100230
Jens Axboeadb02ba2009-06-03 10:47:44 +0200231static void calc_iops(unsigned long mtime, unsigned long long *io_iops,
232 unsigned long long *prev_io_iops, unsigned int *iops)
233{
234 iops[0] = ((io_iops[0] - prev_io_iops[0]) * 1000) / mtime;
235 iops[1] = ((io_iops[1] - prev_io_iops[1]) * 1000) / mtime;
236 prev_io_iops[0] = io_iops[0];
237 prev_io_iops[1] = io_iops[1];
238}
239
Jens Axboe263e5292006-10-18 15:37:01 +0200240/*
241 * Print status of the jobs we know about. This includes rate estimates,
242 * ETA, thread state, etc.
243 */
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200244int calc_thread_status(struct jobs_eta *je, int force)
Jens Axboe263e5292006-10-18 15:37:01 +0200245{
Jens Axboe34572e22006-10-20 09:33:18 +0200246 struct thread_data *td;
Jens Axboeb75a3942011-10-03 16:03:43 +0200247 int i;
248 unsigned long rate_time, disp_time, bw_avg_time, *eta_secs;
249 unsigned long long io_bytes[2];
250 unsigned long long io_iops[2];
Jens Axboe46fda8d2007-02-11 00:49:30 +0100251 struct timeval now;
252
253 static unsigned long long rate_io_bytes[2];
254 static unsigned long long disp_io_bytes[2];
Jens Axboeadb02ba2009-06-03 10:47:44 +0200255 static unsigned long long disp_io_iops[2];
Jens Axboe46fda8d2007-02-11 00:49:30 +0100256 static struct timeval rate_prev_time, disp_prev_time;
Jens Axboe6043c572006-11-03 11:37:47 +0100257
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200258 if (!force) {
259 if (temp_stall_ts || terse_output || eta_print == FIO_ETA_NEVER)
260 return 0;
Aaron Carrolle592a062007-09-14 09:49:41 +0200261
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200262 if (!isatty(STDOUT_FILENO) && (eta_print != FIO_ETA_ALWAYS))
263 return 0;
264 }
Jens Axboe263e5292006-10-18 15:37:01 +0200265
Jens Axboe46fda8d2007-02-11 00:49:30 +0100266 if (!rate_io_bytes[0] && !rate_io_bytes[1])
267 fill_start_time(&rate_prev_time);
268 if (!disp_io_bytes[0] && !disp_io_bytes[1])
269 fill_start_time(&disp_prev_time);
Jens Axboe6043c572006-11-03 11:37:47 +0100270
Jens Axboed3eeeab2008-04-06 12:19:05 +0200271 eta_secs = malloc(thread_number * sizeof(unsigned long));
272 memset(eta_secs, 0, thread_number * sizeof(unsigned long));
Jens Axboe263e5292006-10-18 15:37:01 +0200273
Jens Axboeb75a3942011-10-03 16:03:43 +0200274 je->elapsed_sec = (mtime_since_genesis() + 999) / 1000;
275
Jens Axboe6043c572006-11-03 11:37:47 +0100276 io_bytes[0] = io_bytes[1] = 0;
Jens Axboeadb02ba2009-06-03 10:47:44 +0200277 io_iops[0] = io_iops[1] = 0;
Jens Axboebb3884d2007-01-17 17:23:11 +1100278 bw_avg_time = ULONG_MAX;
Jens Axboe34572e22006-10-20 09:33:18 +0200279 for_each_td(td, i) {
Jens Axboeb7f05eb2012-05-11 20:33:02 +0200280 if (is_power_of_2(td->o.kb_base))
281 je->is_pow2 = 1;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100282 if (td->o.bw_avg_time < bw_avg_time)
283 bw_avg_time = td->o.bw_avg_time;
Jens Axboe46fda8d2007-02-11 00:49:30 +0100284 if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING
Jens Axboeb0f65862009-05-20 11:52:15 +0200285 || td->runstate == TD_FSYNCING
286 || td->runstate == TD_PRE_READING) {
Jens Axboeb75a3942011-10-03 16:03:43 +0200287 je->nr_running++;
Jens Axboe242c38d2012-08-20 14:44:22 +0200288 if (td_read(td)) {
Jens Axboec2e9cc42012-08-21 15:34:13 +0200289 je->t_rate[0] += td->o.rate[DDIR_READ];
290 je->t_iops[0] += td->o.rate_iops[DDIR_READ];
291 je->m_rate[0] += td->o.ratemin[DDIR_READ];
292 je->m_iops[0] += td->o.rate_iops_min[DDIR_READ];
Jens Axboe242c38d2012-08-20 14:44:22 +0200293 }
294 if (td_write(td)) {
Jens Axboec2e9cc42012-08-21 15:34:13 +0200295 je->t_rate[1] += td->o.rate[DDIR_WRITE];
296 je->t_iops[1] += td->o.rate_iops[DDIR_WRITE];
297 je->m_rate[1] += td->o.ratemin[DDIR_WRITE];
298 je->m_iops[1] += td->o.rate_iops_min[DDIR_WRITE];
Jens Axboe242c38d2012-08-20 14:44:22 +0200299 }
Jens Axboeb75a3942011-10-03 16:03:43 +0200300 je->files_open += td->nr_open_files;
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200301 } else if (td->runstate == TD_RAMP) {
Jens Axboeb75a3942011-10-03 16:03:43 +0200302 je->nr_running++;
303 je->nr_ramp++;
Jens Axboe263e5292006-10-18 15:37:01 +0200304 } else if (td->runstate < TD_RUNNING)
Jens Axboeb75a3942011-10-03 16:03:43 +0200305 je->nr_pending++;
Jens Axboe263e5292006-10-18 15:37:01 +0200306
Jens Axboeb75a3942011-10-03 16:03:43 +0200307 if (je->elapsed_sec >= 3)
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200308 eta_secs[i] = thread_eta(td);
Jens Axboe263e5292006-10-18 15:37:01 +0200309 else
310 eta_secs[i] = INT_MAX;
311
312 check_str_update(td);
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200313
314 if (td->runstate > TD_RAMP) {
315 io_bytes[0] += td->io_bytes[0];
316 io_bytes[1] += td->io_bytes[1];
Jens Axboeadb02ba2009-06-03 10:47:44 +0200317 io_iops[0] += td->io_blocks[0];
318 io_iops[1] += td->io_blocks[1];
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200319 }
Jens Axboe263e5292006-10-18 15:37:01 +0200320 }
321
322 if (exitall_on_terminate)
Jens Axboeb75a3942011-10-03 16:03:43 +0200323 je->eta_sec = INT_MAX;
Jens Axboe263e5292006-10-18 15:37:01 +0200324 else
Jens Axboeb75a3942011-10-03 16:03:43 +0200325 je->eta_sec = 0;
Jens Axboe263e5292006-10-18 15:37:01 +0200326
Jens Axboe34572e22006-10-20 09:33:18 +0200327 for_each_td(td, i) {
Shaozhi Shawn Ye9c5a3852008-09-10 09:09:37 +0200328 if (exitall_on_terminate) {
Jens Axboeb75a3942011-10-03 16:03:43 +0200329 if (eta_secs[i] < je->eta_sec)
330 je->eta_sec = eta_secs[i];
Shaozhi Shawn Ye9c5a3852008-09-10 09:09:37 +0200331 } else {
Jens Axboeb75a3942011-10-03 16:03:43 +0200332 if (eta_secs[i] > je->eta_sec)
333 je->eta_sec = eta_secs[i];
Shaozhi Shawn Ye9c5a3852008-09-10 09:09:37 +0200334 }
Jens Axboe263e5292006-10-18 15:37:01 +0200335 }
336
Jens Axboeeecf2722006-10-20 14:00:36 +0200337 free(eta_secs);
338
Jens Axboe46fda8d2007-02-11 00:49:30 +0100339 fio_gettime(&now, NULL);
340 rate_time = mtime_since(&rate_prev_time, &now);
341
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200342 if (write_bw_log && rate_time > bw_avg_time && !in_ramp_time(td)) {
Jens Axboeb75a3942011-10-03 16:03:43 +0200343 calc_rate(rate_time, io_bytes, rate_io_bytes, je->rate);
Jens Axboe46fda8d2007-02-11 00:49:30 +0100344 memcpy(&rate_prev_time, &now, sizeof(now));
Jens Axboeb75a3942011-10-03 16:03:43 +0200345 add_agg_sample(je->rate[DDIR_READ], DDIR_READ, 0);
346 add_agg_sample(je->rate[DDIR_WRITE], DDIR_WRITE, 0);
Jens Axboe6043c572006-11-03 11:37:47 +0100347 }
348
Jens Axboe46fda8d2007-02-11 00:49:30 +0100349 disp_time = mtime_since(&disp_prev_time, &now);
Jens Axboea5b01f12010-11-11 09:19:49 +0100350
351 /*
352 * Allow a little slack, the target is to print it every 1000 msecs
353 */
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200354 if (!force && disp_time < 900)
Jens Axboeb75a3942011-10-03 16:03:43 +0200355 return 0;
Jens Axboe46fda8d2007-02-11 00:49:30 +0100356
Jens Axboeb75a3942011-10-03 16:03:43 +0200357 calc_rate(disp_time, io_bytes, disp_io_bytes, je->rate);
358 calc_iops(disp_time, io_iops, disp_io_iops, je->iops);
Jens Axboeadb02ba2009-06-03 10:47:44 +0200359
Jens Axboe46fda8d2007-02-11 00:49:30 +0100360 memcpy(&disp_prev_time, &now, sizeof(now));
361
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200362 if (!force && !je->nr_running && !je->nr_pending)
Jens Axboeb75a3942011-10-03 16:03:43 +0200363 return 0;
364
Jens Axboe1d1f45a2011-10-03 19:44:41 +0200365 je->nr_threads = thread_number;
366 memcpy(je->run_str, run_str, thread_number * sizeof(char));
367
Jens Axboeb75a3942011-10-03 16:03:43 +0200368 return 1;
369}
370
Jens Axboecf451d12011-10-03 16:48:30 +0200371void display_thread_status(struct jobs_eta *je)
Jens Axboeb75a3942011-10-03 16:03:43 +0200372{
Jens Axboeb75a3942011-10-03 16:03:43 +0200373 static int linelen_last;
374 static int eta_good;
Jens Axboe79074e72012-04-18 20:39:48 +0200375 char output[REAL_MAX_JOBS + 512], *p = output;
Jens Axboeb75a3942011-10-03 16:03:43 +0200376 char eta_str[128];
377 double perc = 0.0;
Jens Axboeb75a3942011-10-03 16:03:43 +0200378
Jens Axboecf451d12011-10-03 16:48:30 +0200379 if (je->eta_sec != INT_MAX && je->elapsed_sec) {
380 perc = (double) je->elapsed_sec / (double) (je->elapsed_sec + je->eta_sec);
381 eta_to_str(eta_str, je->eta_sec);
Jens Axboeb75a3942011-10-03 16:03:43 +0200382 }
383
Jens Axboecf451d12011-10-03 16:48:30 +0200384 p += sprintf(p, "Jobs: %d (f=%d)", je->nr_running, je->files_open);
Jens Axboe3e47bd22012-02-29 13:45:02 +0100385 if (je->m_rate[0] || je->m_rate[1] || je->t_rate[0] || je->t_rate[1]) {
Jens Axboe581e7142009-06-09 12:47:16 +0200386 char *tr, *mr;
387
Jens Axboec41a9d02012-05-11 20:38:59 +0200388 mr = num2str(je->m_rate[0] + je->m_rate[1], 4, 0, je->is_pow2);
389 tr = num2str(je->t_rate[0] + je->t_rate[1], 4, 0, je->is_pow2);
Jens Axboe37db14f2011-09-30 17:00:42 -0600390 p += sprintf(p, ", CR=%s/%s KB/s", tr, mr);
Jens Axboe581e7142009-06-09 12:47:16 +0200391 free(tr);
392 free(mr);
Jens Axboe3e47bd22012-02-29 13:45:02 +0100393 } else if (je->m_iops[0] || je->m_iops[1] || je->t_iops[0] || je->t_iops[1]) {
394 p += sprintf(p, ", CR=%d/%d IOPS",
395 je->t_iops[0] + je->t_iops[1],
Jens Axboe88e4bea2012-08-21 15:34:36 +0200396 je->m_iops[0] + je->m_iops[1]);
Jens Axboe3e47bd22012-02-29 13:45:02 +0100397 }
Jens Axboecf451d12011-10-03 16:48:30 +0200398 if (je->eta_sec != INT_MAX && je->nr_running) {
Jens Axboe0721d112008-06-05 09:03:05 +0200399 char perc_str[32];
Jens Axboeadb02ba2009-06-03 10:47:44 +0200400 char *iops_str[2];
Jens Axboed1bd7212009-06-03 10:53:45 +0200401 char *rate_str[2];
Jens Axboe79074e72012-04-18 20:39:48 +0200402 size_t left;
Jens Axboeadb02ba2009-06-03 10:47:44 +0200403 int l;
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100404
Jens Axboecf451d12011-10-03 16:48:30 +0200405 if ((!je->eta_sec && !eta_good) || je->nr_ramp == je->nr_running)
Jens Axboecac58fd2008-06-06 01:17:03 +0200406 strcpy(perc_str, "-.-% done");
407 else {
408 eta_good = 1;
409 perc *= 100.0;
Jens Axboe0721d112008-06-05 09:03:05 +0200410 sprintf(perc_str, "%3.1f%% done", perc);
Jens Axboecac58fd2008-06-06 01:17:03 +0200411 }
Jens Axboe0721d112008-06-05 09:03:05 +0200412
Jens Axboeb7f05eb2012-05-11 20:33:02 +0200413 rate_str[0] = num2str(je->rate[0], 5, 1024, je->is_pow2);
414 rate_str[1] = num2str(je->rate[1], 5, 1024, je->is_pow2);
Jens Axboed1bd7212009-06-03 10:53:45 +0200415
Jens Axboecf451d12011-10-03 16:48:30 +0200416 iops_str[0] = num2str(je->iops[0], 4, 1, 0);
417 iops_str[1] = num2str(je->iops[1], 4, 1, 0);
Jens Axboeadb02ba2009-06-03 10:47:44 +0200418
Jens Axboe79074e72012-04-18 20:39:48 +0200419 left = sizeof(output) - (p - output) - 1;
420
421 l = snprintf(p, left, ": [%s] [%s] [%s/%s /s] [%s/%s iops] [eta %s]",
Jens Axboe1d1f45a2011-10-03 19:44:41 +0200422 je->run_str, perc_str, rate_str[0],
423 rate_str[1], iops_str[0], iops_str[1], eta_str);
Jens Axboe37db14f2011-09-30 17:00:42 -0600424 p += l;
Jens Axboeadb02ba2009-06-03 10:47:44 +0200425 if (l >= 0 && l < linelen_last)
Jens Axboe37db14f2011-09-30 17:00:42 -0600426 p += sprintf(p, "%*s", linelen_last - l, "");
Jens Axboeadb02ba2009-06-03 10:47:44 +0200427 linelen_last = l;
Jens Axboed1bd7212009-06-03 10:53:45 +0200428
429 free(rate_str[0]);
430 free(rate_str[1]);
Jens Axboeadb02ba2009-06-03 10:47:44 +0200431 free(iops_str[0]);
432 free(iops_str[1]);
Jens Axboe263e5292006-10-18 15:37:01 +0200433 }
Jens Axboe37db14f2011-09-30 17:00:42 -0600434 p += sprintf(p, "\r");
435
Jens Axboe3e47bd22012-02-29 13:45:02 +0100436 printf("%s", output);
437 fflush(stdout);
Jens Axboe263e5292006-10-18 15:37:01 +0200438}
439
Jens Axboecf451d12011-10-03 16:48:30 +0200440void print_thread_status(void)
441{
Jens Axboe1d1f45a2011-10-03 19:44:41 +0200442 struct jobs_eta *je;
Jens Axboeb814fb22011-10-12 09:20:34 +0200443 size_t size;
Jens Axboecf451d12011-10-03 16:48:30 +0200444
Jens Axboeb814fb22011-10-12 09:20:34 +0200445 if (!thread_number)
446 return;
Jens Axboecf451d12011-10-03 16:48:30 +0200447
Jens Axboeb814fb22011-10-12 09:20:34 +0200448 size = sizeof(*je) + thread_number * sizeof(char) + 1;
449 je = malloc(size);
450 memset(je, 0, size);
Jens Axboecf451d12011-10-03 16:48:30 +0200451
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200452 if (calc_thread_status(je, 0))
Jens Axboe1d1f45a2011-10-03 19:44:41 +0200453 display_thread_status(je);
454
455 free(je);
Jens Axboecf451d12011-10-03 16:48:30 +0200456}
Jens Axboeb75a3942011-10-03 16:03:43 +0200457
Jens Axboe2b13e712011-01-19 14:04:16 -0700458void print_status_init(int thr_number)
Jens Axboe263e5292006-10-18 15:37:01 +0200459{
Jens Axboe2b13e712011-01-19 14:04:16 -0700460 run_str[thr_number] = 'P';
Jens Axboe263e5292006-10-18 15:37:01 +0200461}