10 static char run_str[REAL_MAX_JOBS + 1];
13 * Sets the status of the 'td' in the printed status map.
15 static void check_str_update(struct thread_data *td)
17 char c = run_str[td->thread_number - 1];
19 switch (td->runstate) {
32 if (td->o.rwmix[DDIR_READ] == 100)
34 else if (td->o.rwmix[DDIR_WRITE] == 100)
39 if (td->o.rwmix[DDIR_READ] == 100)
41 else if (td->o.rwmix[DDIR_WRITE] == 100)
46 } else if (td_read(td)) {
77 log_err("state %d\n", td->runstate);
80 run_str[td->thread_number - 1] = c;
84 * Convert seconds to a printable string.
86 static void eta_to_str(char *str, unsigned long eta_sec)
88 unsigned int d, h, m, s;
101 str += sprintf(str, "%02ud:", d);
105 str += sprintf(str, "%02uh:", h);
107 str += sprintf(str, "%02um:", m);
108 str += sprintf(str, "%02us", s);
112 * Best effort calculation of the estimated pending runtime of a job.
114 static int thread_eta(struct thread_data *td)
116 unsigned long long bytes_total, bytes_done;
117 unsigned long eta_sec = 0;
118 unsigned long elapsed;
120 elapsed = (mtime_since_now(&td->epoch) + 999) / 1000;
122 bytes_total = td->total_io_size;
124 if (td->o.fill_device && td->o.size == -1ULL) {
125 if (!td->fill_device_size || td->fill_device_size == -1ULL)
128 bytes_total = td->fill_device_size;
132 * if writing, bytes_total will be twice the size. If mixing,
133 * assume a 50/50 split and thus bytes_total will be 50% larger.
135 if (td->o.do_verify && td->o.verify && td_write(td)) {
137 bytes_total = bytes_total * 3 / 2;
142 if (td->o.zone_size && td->o.zone_skip)
143 bytes_total /= (td->o.zone_skip / td->o.zone_size);
145 if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING) {
148 bytes_done = td->io_bytes[DDIR_READ] + td->io_bytes[DDIR_WRITE];
149 perc = (double) bytes_done / (double) bytes_total;
153 if (td->o.time_based) {
154 perc_t = (double) elapsed / (double) td->o.timeout;
159 eta_sec = (unsigned long) (elapsed * (1.0 / perc)) - elapsed;
162 eta_sec > (td->o.timeout + done_secs - elapsed))
163 eta_sec = td->o.timeout + done_secs - elapsed;
164 } else if (td->runstate == TD_NOT_CREATED || td->runstate == TD_CREATED
165 || td->runstate == TD_INITIALIZED
166 || td->runstate == TD_RAMP
167 || td->runstate == TD_PRE_READING) {
168 int t_eta = 0, r_eta = 0;
171 * We can only guess - assume it'll run the full timeout
172 * if given, otherwise assume it'll run at the specified rate.
175 t_eta = td->o.timeout + td->o.start_delay +
178 if (in_ramp_time(td)) {
179 unsigned long ramp_left;
181 ramp_left = mtime_since_now(&td->epoch);
182 ramp_left = (ramp_left + 999) / 1000;
183 if (ramp_left <= t_eta)
187 if (td->o.rate[0] || td->o.rate[1]) {
188 r_eta = (bytes_total / 1024) /
189 (td->o.rate[0] + td->o.rate[1]);
190 r_eta += td->o.start_delay;
194 eta_sec = min(r_eta, t_eta);
203 * thread is already done or waiting for fsync
211 static void calc_rate(unsigned long mtime, unsigned long long *io_bytes,
212 unsigned long long *prev_io_bytes, unsigned int *rate)
214 rate[0] = (io_bytes[0] - prev_io_bytes[0]) / mtime;
215 rate[1] = (io_bytes[1] - prev_io_bytes[1]) / mtime;
216 prev_io_bytes[0] = io_bytes[0];
217 prev_io_bytes[1] = io_bytes[1];
220 static void calc_iops(unsigned long mtime, unsigned long long *io_iops,
221 unsigned long long *prev_io_iops, unsigned int *iops)
223 iops[0] = ((io_iops[0] - prev_io_iops[0]) * 1000) / mtime;
224 iops[1] = ((io_iops[1] - prev_io_iops[1]) * 1000) / mtime;
225 prev_io_iops[0] = io_iops[0];
226 prev_io_iops[1] = io_iops[1];
230 * Print status of the jobs we know about. This includes rate estimates,
231 * ETA, thread state, etc.
233 void print_thread_status(void)
235 unsigned long elapsed = (mtime_since_genesis() + 999) / 1000;
236 int i, nr_ramp, nr_running, nr_pending, t_rate, m_rate;
237 int t_iops, m_iops, files_open;
238 struct thread_data *td;
241 unsigned long long io_bytes[2], io_iops[2];
242 unsigned long rate_time, disp_time, bw_avg_time, *eta_secs, eta_sec;
245 static unsigned long long rate_io_bytes[2];
246 static unsigned long long disp_io_bytes[2];
247 static unsigned long long disp_io_iops[2];
248 static struct timeval rate_prev_time, disp_prev_time;
249 static unsigned int rate[2], iops[2];
250 static int linelen_last;
252 char output[512], *p = output;
255 if (temp_stall_ts || terse_output || eta_print == FIO_ETA_NEVER)
258 if (!isatty(STDOUT_FILENO) && (eta_print != FIO_ETA_ALWAYS))
261 if (!rate_io_bytes[0] && !rate_io_bytes[1])
262 fill_start_time(&rate_prev_time);
263 if (!disp_io_bytes[0] && !disp_io_bytes[1])
264 fill_start_time(&disp_prev_time);
266 eta_secs = malloc(thread_number * sizeof(unsigned long));
267 memset(eta_secs, 0, thread_number * sizeof(unsigned long));
269 io_bytes[0] = io_bytes[1] = 0;
270 io_iops[0] = io_iops[1] = 0;
271 nr_pending = nr_running = t_rate = m_rate = t_iops = m_iops = 0;
273 bw_avg_time = ULONG_MAX;
276 if (td->o.bw_avg_time < bw_avg_time)
277 bw_avg_time = td->o.bw_avg_time;
278 if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING
279 || td->runstate == TD_FSYNCING
280 || td->runstate == TD_PRE_READING) {
282 t_rate += td->o.rate[0] + td->o.rate[1];
283 m_rate += td->o.ratemin[0] + td->o.ratemin[1];
284 t_iops += td->o.rate_iops[0] + td->o.rate_iops[1];
285 m_iops += td->o.rate_iops_min[0] +
286 td->o.rate_iops_min[1];
287 files_open += td->nr_open_files;
288 } else if (td->runstate == TD_RAMP) {
291 } else if (td->runstate < TD_RUNNING)
295 eta_secs[i] = thread_eta(td);
297 eta_secs[i] = INT_MAX;
299 check_str_update(td);
301 if (td->runstate > TD_RAMP) {
302 io_bytes[0] += td->io_bytes[0];
303 io_bytes[1] += td->io_bytes[1];
304 io_iops[0] += td->io_blocks[0];
305 io_iops[1] += td->io_blocks[1];
309 if (exitall_on_terminate)
315 if (!i2p && is_power_of_2(td->o.kb_base))
317 if (exitall_on_terminate) {
318 if (eta_secs[i] < eta_sec)
319 eta_sec = eta_secs[i];
321 if (eta_secs[i] > eta_sec)
322 eta_sec = eta_secs[i];
328 if (eta_sec != INT_MAX && elapsed) {
329 perc = (double) elapsed / (double) (elapsed + eta_sec);
330 eta_to_str(eta_str, eta_sec);
333 fio_gettime(&now, NULL);
334 rate_time = mtime_since(&rate_prev_time, &now);
336 if (write_bw_log && rate_time > bw_avg_time && !in_ramp_time(td)) {
337 calc_rate(rate_time, io_bytes, rate_io_bytes, rate);
338 memcpy(&rate_prev_time, &now, sizeof(now));
339 add_agg_sample(rate[DDIR_READ], DDIR_READ, 0);
340 add_agg_sample(rate[DDIR_WRITE], DDIR_WRITE, 0);
343 disp_time = mtime_since(&disp_prev_time, &now);
346 * Allow a little slack, the target is to print it every 1000 msecs
351 calc_rate(disp_time, io_bytes, disp_io_bytes, rate);
352 calc_iops(disp_time, io_iops, disp_io_iops, iops);
354 memcpy(&disp_prev_time, &now, sizeof(now));
356 if (!nr_running && !nr_pending)
359 p += sprintf(p, "Jobs: %d (f=%d)", nr_running, files_open);
360 if (m_rate || t_rate) {
363 mr = num2str(m_rate, 4, 0, i2p);
364 tr = num2str(t_rate, 4, 0, i2p);
365 p += sprintf(p, ", CR=%s/%s KB/s", tr, mr);
368 } else if (m_iops || t_iops)
369 p += sprintf(p, ", CR=%d/%d IOPS", t_iops, m_iops);
370 if (eta_sec != INT_MAX && nr_running) {
376 if ((!eta_sec && !eta_good) || nr_ramp == nr_running)
377 strcpy(perc_str, "-.-% done");
381 sprintf(perc_str, "%3.1f%% done", perc);
384 rate_str[0] = num2str(rate[0], 5, 10, i2p);
385 rate_str[1] = num2str(rate[1], 5, 10, i2p);
387 iops_str[0] = num2str(iops[0], 4, 1, 0);
388 iops_str[1] = num2str(iops[1], 4, 1, 0);
390 l = sprintf(p, ": [%s] [%s] [%s/%s /s] [%s/%s iops] [eta %s]",
391 run_str, perc_str, rate_str[0], rate_str[1],
392 iops_str[0], iops_str[1], eta_str);
394 if (l >= 0 && l < linelen_last)
395 p += sprintf(p, "%*s", linelen_last - l, "");
403 p += sprintf(p, "\r");
406 printf("%s", output);
409 fio_server_text_output(output, p - output);
412 void print_status_init(int thr_number)
414 run_str[thr_number] = 'P';