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) {
32 } else if (td_read(td)) {
60 log_err("state %d\n", td->runstate);
63 run_str[td->thread_number - 1] = c;
67 * Convert seconds to a printable string.
69 static void eta_to_str(char *str, unsigned long eta_sec)
71 unsigned int d, h, m, s;
84 str += sprintf(str, "%02ud:", d);
88 str += sprintf(str, "%02uh:", h);
90 str += sprintf(str, "%02um:", m);
91 str += sprintf(str, "%02us", s);
95 * Best effort calculation of the estimated pending runtime of a job.
97 static int thread_eta(struct thread_data *td, unsigned long elapsed)
99 unsigned long long bytes_total, bytes_done;
100 unsigned long eta_sec = 0;
102 bytes_total = td->total_io_size;
105 * if writing, bytes_total will be twice the size. If mixing,
106 * assume a 50/50 split and thus bytes_total will be 50% larger.
108 if (td->o.do_verify && td->o.verify && td_write(td)) {
110 bytes_total = bytes_total * 3 / 2;
115 if (td->o.zone_size && td->o.zone_skip)
116 bytes_total /= (td->o.zone_skip / td->o.zone_size);
118 if (td->o.fill_device && td->o.size == -1ULL)
121 if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING) {
124 bytes_done = td->io_bytes[DDIR_READ] + td->io_bytes[DDIR_WRITE];
125 perc = (double) bytes_done / (double) bytes_total;
129 if (td->o.time_based) {
130 perc_t = (double) elapsed / (double) td->o.timeout;
135 eta_sec = (unsigned long) (elapsed * (1.0 / perc)) - elapsed;
138 eta_sec > (td->o.timeout + done_secs - elapsed))
139 eta_sec = td->o.timeout + done_secs - elapsed;
140 } else if (td->runstate == TD_NOT_CREATED || td->runstate == TD_CREATED
141 || td->runstate == TD_INITIALIZED) {
142 int t_eta = 0, r_eta = 0;
145 * We can only guess - assume it'll run the full timeout
146 * if given, otherwise assume it'll run at the specified rate.
149 t_eta = td->o.timeout + td->o.start_delay;
151 r_eta = (bytes_total / 1024) / td->o.rate;
152 r_eta += td->o.start_delay;
156 eta_sec = min(r_eta, t_eta);
165 * thread is already done or waiting for fsync
173 static void calc_rate(unsigned long mtime, unsigned long long *io_bytes,
174 unsigned long long *prev_io_bytes, unsigned int *rate)
176 rate[0] = (io_bytes[0] - prev_io_bytes[0]) / mtime;
177 rate[1] = (io_bytes[1] - prev_io_bytes[1]) / mtime;
178 prev_io_bytes[0] = io_bytes[0];
179 prev_io_bytes[1] = io_bytes[1];
183 * Print status of the jobs we know about. This includes rate estimates,
184 * ETA, thread state, etc.
186 void print_thread_status(void)
188 unsigned long elapsed = mtime_since_genesis() / 1000;
189 int i, nr_running, nr_pending, t_rate, m_rate;
190 int t_iops, m_iops, files_open;
191 struct thread_data *td;
194 unsigned long long io_bytes[2];
195 unsigned long rate_time, disp_time, bw_avg_time, *eta_secs, eta_sec;
198 static unsigned long long rate_io_bytes[2];
199 static unsigned long long disp_io_bytes[2];
200 static struct timeval rate_prev_time, disp_prev_time;
201 static unsigned int rate[2];
202 static int linelen_last;
205 if (temp_stall_ts || terse_output || eta_print == FIO_ETA_NEVER)
208 if (!isatty(STDOUT_FILENO) && (eta_print != FIO_ETA_ALWAYS))
211 if (!rate_io_bytes[0] && !rate_io_bytes[1])
212 fill_start_time(&rate_prev_time);
213 if (!disp_io_bytes[0] && !disp_io_bytes[1])
214 fill_start_time(&disp_prev_time);
216 eta_secs = malloc(thread_number * sizeof(unsigned long));
217 memset(eta_secs, 0, thread_number * sizeof(unsigned long));
219 io_bytes[0] = io_bytes[1] = 0;
220 nr_pending = nr_running = t_rate = m_rate = t_iops = m_iops = 0;
221 bw_avg_time = ULONG_MAX;
224 if (td->o.bw_avg_time < bw_avg_time)
225 bw_avg_time = td->o.bw_avg_time;
226 if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING
227 || td->runstate == TD_FSYNCING) {
229 t_rate += td->o.rate;
230 m_rate += td->o.ratemin;
231 t_iops += td->o.rate_iops;
232 m_iops += td->o.rate_iops_min;
233 files_open += td->nr_open_files;
234 } else if (td->runstate < TD_RUNNING)
238 eta_secs[i] = thread_eta(td, elapsed);
240 eta_secs[i] = INT_MAX;
242 check_str_update(td);
243 io_bytes[0] += td->io_bytes[0];
244 io_bytes[1] += td->io_bytes[1];
247 if (exitall_on_terminate)
253 if (exitall_on_terminate) {
254 if (eta_secs[i] < eta_sec)
255 eta_sec = eta_secs[i];
257 if (eta_secs[i] > eta_sec)
258 eta_sec = eta_secs[i];
264 if (eta_sec != INT_MAX && elapsed) {
265 perc = (double) elapsed / (double) (elapsed + eta_sec);
266 eta_to_str(eta_str, eta_sec);
269 fio_gettime(&now, NULL);
270 rate_time = mtime_since(&rate_prev_time, &now);
272 if (write_bw_log && rate_time > bw_avg_time) {
273 calc_rate(rate_time, io_bytes, rate_io_bytes, rate);
274 memcpy(&rate_prev_time, &now, sizeof(now));
275 add_agg_sample(rate[DDIR_READ], DDIR_READ);
276 add_agg_sample(rate[DDIR_WRITE], DDIR_WRITE);
279 disp_time = mtime_since(&disp_prev_time, &now);
280 if (disp_time < 1000)
283 calc_rate(disp_time, io_bytes, disp_io_bytes, rate);
284 memcpy(&disp_prev_time, &now, sizeof(now));
286 if (!nr_running && !nr_pending)
289 printf("Jobs: %d (f=%d)", nr_running, files_open);
290 if (m_rate || t_rate)
291 printf(", CR=%d/%d KiB/s", t_rate, m_rate);
292 else if (m_iops || t_iops)
293 printf(", CR=%d/%d IOPS", t_iops, m_iops);
294 if (eta_sec != INT_MAX && nr_running) {
298 if (!eta_sec && !eta_good)
299 strcpy(perc_str, "-.-% done");
303 sprintf(perc_str, "%3.1f%% done", perc);
306 ll = printf(": [%s] [%s] [%6u/%6u kb/s] [eta %s]",
307 run_str, perc_str, rate[0], rate[1], eta_str);
308 if (ll >= 0 && ll < linelen_last)
309 printf("%*s", linelen_last - ll, "");
316 void print_status_init(int thread_number)
318 run_str[thread_number] = 'P';