10 static char run_str[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) {
35 } else if (td_read(td)) {
66 log_err("state %d\n", td->runstate);
69 run_str[td->thread_number - 1] = c;
73 * Convert seconds to a printable string.
75 static void eta_to_str(char *str, unsigned long eta_sec)
77 unsigned int d, h, m, s;
90 str += sprintf(str, "%02ud:", d);
94 str += sprintf(str, "%02uh:", h);
96 str += sprintf(str, "%02um:", m);
97 str += sprintf(str, "%02us", s);
101 * Best effort calculation of the estimated pending runtime of a job.
103 static int thread_eta(struct thread_data *td)
105 unsigned long long bytes_total, bytes_done;
106 unsigned long eta_sec = 0;
107 unsigned long elapsed;
109 elapsed = (mtime_since_now(&td->epoch) + 999) / 1000;
111 bytes_total = td->total_io_size;
114 * if writing, bytes_total will be twice the size. If mixing,
115 * assume a 50/50 split and thus bytes_total will be 50% larger.
117 if (td->o.do_verify && td->o.verify && td_write(td)) {
119 bytes_total = bytes_total * 3 / 2;
124 if (td->o.zone_size && td->o.zone_skip)
125 bytes_total /= (td->o.zone_skip / td->o.zone_size);
127 if (td->o.fill_device && td->o.size == -1ULL)
130 if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING) {
133 bytes_done = td->io_bytes[DDIR_READ] + td->io_bytes[DDIR_WRITE];
134 perc = (double) bytes_done / (double) bytes_total;
138 if (td->o.time_based) {
139 perc_t = (double) elapsed / (double) td->o.timeout;
144 eta_sec = (unsigned long) (elapsed * (1.0 / perc)) - elapsed;
147 eta_sec > (td->o.timeout + done_secs - elapsed))
148 eta_sec = td->o.timeout + done_secs - elapsed;
149 } else if (td->runstate == TD_NOT_CREATED || td->runstate == TD_CREATED
150 || td->runstate == TD_INITIALIZED
151 || td->runstate == TD_RAMP
152 || td->runstate == TD_PRE_READING) {
153 int t_eta = 0, r_eta = 0;
156 * We can only guess - assume it'll run the full timeout
157 * if given, otherwise assume it'll run at the specified rate.
160 t_eta = td->o.timeout + td->o.start_delay;
162 if (in_ramp_time(td)) {
163 unsigned long ramp_left;
165 ramp_left = mtime_since_now(&td->start);
166 ramp_left = (ramp_left + 999) / 1000;
167 if (ramp_left <= t_eta)
171 if (td->o.rate[0] || td->o.rate[1]) {
172 r_eta = (bytes_total / 1024) /
173 (td->o.rate[0] + td->o.rate[1]);
174 r_eta += td->o.start_delay;
178 eta_sec = min(r_eta, t_eta);
187 * thread is already done or waiting for fsync
195 static void calc_rate(unsigned long mtime, unsigned long long *io_bytes,
196 unsigned long long *prev_io_bytes, unsigned int *rate)
198 rate[0] = (io_bytes[0] - prev_io_bytes[0]) / mtime;
199 rate[1] = (io_bytes[1] - prev_io_bytes[1]) / mtime;
200 prev_io_bytes[0] = io_bytes[0];
201 prev_io_bytes[1] = io_bytes[1];
204 static void calc_iops(unsigned long mtime, unsigned long long *io_iops,
205 unsigned long long *prev_io_iops, unsigned int *iops)
207 iops[0] = ((io_iops[0] - prev_io_iops[0]) * 1000) / mtime;
208 iops[1] = ((io_iops[1] - prev_io_iops[1]) * 1000) / mtime;
209 prev_io_iops[0] = io_iops[0];
210 prev_io_iops[1] = io_iops[1];
214 * Print status of the jobs we know about. This includes rate estimates,
215 * ETA, thread state, etc.
217 void print_thread_status(void)
219 unsigned long elapsed = (mtime_since_genesis() + 999) / 1000;
220 int i, nr_ramp, nr_running, nr_pending, t_rate, m_rate;
221 int t_iops, m_iops, files_open;
222 struct thread_data *td;
225 unsigned long long io_bytes[2], io_iops[2];
226 unsigned long rate_time, disp_time, bw_avg_time, *eta_secs, eta_sec;
229 static unsigned long long rate_io_bytes[2];
230 static unsigned long long disp_io_bytes[2];
231 static unsigned long long disp_io_iops[2];
232 static struct timeval rate_prev_time, disp_prev_time;
233 static unsigned int rate[2], iops[2];
234 static int linelen_last;
238 if (temp_stall_ts || terse_output || eta_print == FIO_ETA_NEVER)
241 if (!isatty(STDOUT_FILENO) && (eta_print != FIO_ETA_ALWAYS))
244 if (!rate_io_bytes[0] && !rate_io_bytes[1])
245 fill_start_time(&rate_prev_time);
246 if (!disp_io_bytes[0] && !disp_io_bytes[1])
247 fill_start_time(&disp_prev_time);
249 eta_secs = malloc(thread_number * sizeof(unsigned long));
250 memset(eta_secs, 0, thread_number * sizeof(unsigned long));
252 io_bytes[0] = io_bytes[1] = 0;
253 io_iops[0] = io_iops[1] = 0;
254 nr_pending = nr_running = t_rate = m_rate = t_iops = m_iops = 0;
256 bw_avg_time = ULONG_MAX;
259 if (td->o.bw_avg_time < bw_avg_time)
260 bw_avg_time = td->o.bw_avg_time;
261 if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING
262 || td->runstate == TD_FSYNCING
263 || td->runstate == TD_PRE_READING) {
265 t_rate += td->o.rate[0] + td->o.rate[1];
266 m_rate += td->o.ratemin[0] + td->o.ratemin[1];
267 t_iops += td->o.rate_iops[0] + td->o.rate_iops[1];
268 m_iops += td->o.rate_iops_min[0] +
269 td->o.rate_iops_min[1];
270 files_open += td->nr_open_files;
271 } else if (td->runstate == TD_RAMP) {
274 } else if (td->runstate < TD_RUNNING)
278 eta_secs[i] = thread_eta(td);
280 eta_secs[i] = INT_MAX;
282 check_str_update(td);
284 if (td->runstate > TD_RAMP) {
285 io_bytes[0] += td->io_bytes[0];
286 io_bytes[1] += td->io_bytes[1];
287 io_iops[0] += td->io_blocks[0];
288 io_iops[1] += td->io_blocks[1];
292 if (exitall_on_terminate)
298 if (!i2p && is_power_of_2(td->o.kb_base))
300 if (exitall_on_terminate) {
301 if (eta_secs[i] < eta_sec)
302 eta_sec = eta_secs[i];
304 if (eta_secs[i] > eta_sec)
305 eta_sec = eta_secs[i];
311 if (eta_sec != INT_MAX && elapsed) {
312 perc = (double) elapsed / (double) (elapsed + eta_sec);
313 eta_to_str(eta_str, eta_sec);
316 fio_gettime(&now, NULL);
317 rate_time = mtime_since(&rate_prev_time, &now);
319 if (write_bw_log && rate_time > bw_avg_time && !in_ramp_time(td)) {
320 calc_rate(rate_time, io_bytes, rate_io_bytes, rate);
321 memcpy(&rate_prev_time, &now, sizeof(now));
322 add_agg_sample(rate[DDIR_READ], DDIR_READ, 0);
323 add_agg_sample(rate[DDIR_WRITE], DDIR_WRITE, 0);
326 disp_time = mtime_since(&disp_prev_time, &now);
327 if (disp_time < 1000)
330 calc_rate(disp_time, io_bytes, disp_io_bytes, rate);
331 calc_iops(disp_time, io_iops, disp_io_iops, iops);
333 memcpy(&disp_prev_time, &now, sizeof(now));
335 if (!nr_running && !nr_pending)
338 printf("Jobs: %d (f=%d)", nr_running, files_open);
339 if (m_rate || t_rate) {
342 mr = num2str(m_rate, 4, 0, i2p);
343 tr = num2str(t_rate, 4, 0, i2p);
344 printf(", CR=%s/%s KB/s", tr, mr);
347 } else if (m_iops || t_iops)
348 printf(", CR=%d/%d IOPS", t_iops, m_iops);
349 if (eta_sec != INT_MAX && nr_running) {
355 if ((!eta_sec && !eta_good) || nr_ramp == nr_running)
356 strcpy(perc_str, "-.-% done");
360 sprintf(perc_str, "%3.1f%% done", perc);
363 rate_str[0] = num2str(rate[0], 5, 10, i2p);
364 rate_str[1] = num2str(rate[1], 5, 10, i2p);
366 iops_str[0] = num2str(iops[0], 4, 1, 0);
367 iops_str[1] = num2str(iops[1], 4, 1, 0);
369 l = printf(": [%s] [%s] [%s/%s /s] [%s/%s iops] [eta %s]",
370 run_str, perc_str, rate_str[0], rate_str[1],
371 iops_str[0], iops_str[1], eta_str);
372 if (l >= 0 && l < linelen_last)
373 printf("%*s", linelen_last - l, "");
385 void print_status_init(int thread_number)
387 run_str[thread_number] = 'P';