11 static char run_str[MAX_JOBS + 1];
14 * Sets the status of the 'td' in the printed status map.
16 static void check_str_update(struct thread_data *td)
18 char c = run_str[td->thread_number - 1];
20 switch (td->runstate) {
33 } else if (td_read(td)) {
61 log_err("state %d\n", td->runstate);
64 run_str[td->thread_number - 1] = c;
68 * Convert seconds to a printable string.
70 static void eta_to_str(char *str, int eta_sec)
72 unsigned int d, h, m, s;
87 str += sprintf(str, "%02ud:", d);
91 str += sprintf(str, "%02uh:", h);
93 str += sprintf(str, "%02um:", m);
94 str += sprintf(str, "%02us", s);
98 * Best effort calculation of the estimated pending runtime of a job.
100 static int thread_eta(struct thread_data *td, unsigned long elapsed)
102 unsigned long long bytes_total, bytes_done;
103 unsigned long eta_sec = 0;
105 bytes_total = td->total_io_size;
108 * if writing, bytes_total will be twice the size. If mixing,
109 * assume a 50/50 split and thus bytes_total will be 50% larger.
113 bytes_total = bytes_total * 3 / 2;
118 if (td->o.zone_size && td->o.zone_skip)
119 bytes_total /= (td->o.zone_skip / td->o.zone_size);
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 eta_sec = (unsigned long) (elapsed * (1.0 / perc)) - elapsed;
131 if (td->o.timeout && eta_sec > (td->o.timeout - elapsed))
132 eta_sec = td->o.timeout - elapsed;
133 } else if (td->runstate == TD_NOT_CREATED || td->runstate == TD_CREATED
134 || td->runstate == TD_INITIALIZED) {
135 int t_eta = 0, r_eta = 0;
138 * We can only guess - assume it'll run the full timeout
139 * if given, otherwise assume it'll run at the specified rate.
142 t_eta = td->o.timeout + td->o.start_delay - elapsed;
144 r_eta = (bytes_total / 1024) / td->o.rate;
145 r_eta += td->o.start_delay - elapsed;
149 eta_sec = min(r_eta, t_eta);
158 * thread is already done or waiting for fsync
166 static void calc_rate(unsigned long mtime, unsigned long long *io_bytes,
167 unsigned long long *prev_io_bytes, unsigned int *rate)
169 rate[0] = (io_bytes[0] - prev_io_bytes[0]) / mtime;
170 rate[1] = (io_bytes[1] - prev_io_bytes[1]) / mtime;
171 prev_io_bytes[0] = io_bytes[0];
172 prev_io_bytes[1] = io_bytes[1];
176 * Print status of the jobs we know about. This includes rate estimates,
177 * ETA, thread state, etc.
179 void print_thread_status(void)
181 unsigned long elapsed = mtime_since_genesis() / 1000;
182 int i, nr_running, nr_pending, t_rate, m_rate, *eta_secs, eta_sec;
183 int t_iops, m_iops, files_open;
184 struct thread_data *td;
187 unsigned long long io_bytes[2];
188 unsigned long rate_time, disp_time, bw_avg_time;
191 static unsigned long long rate_io_bytes[2];
192 static unsigned long long disp_io_bytes[2];
193 static struct timeval rate_prev_time, disp_prev_time;
194 static unsigned int rate[2];
196 if (temp_stall_ts || terse_output)
199 if (!rate_io_bytes[0] && !rate_io_bytes[1])
200 fill_start_time(&rate_prev_time);
201 if (!disp_io_bytes[0] && !disp_io_bytes[1])
202 fill_start_time(&disp_prev_time);
204 eta_secs = malloc(thread_number * sizeof(int));
205 memset(eta_secs, 0, thread_number * sizeof(int));
207 io_bytes[0] = io_bytes[1] = 0;
208 nr_pending = nr_running = t_rate = m_rate = t_iops = m_iops = 0;
209 bw_avg_time = ULONG_MAX;
212 if (td->o.bw_avg_time < bw_avg_time)
213 bw_avg_time = td->o.bw_avg_time;
214 if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING
215 || td->runstate == TD_FSYNCING) {
217 t_rate += td->o.rate;
218 m_rate += td->o.ratemin;
219 t_iops += td->o.rate_iops;
220 m_iops += td->o.rate_iops_min;
221 files_open += td->nr_open_files;
222 } else if (td->runstate < TD_RUNNING)
226 eta_secs[i] = thread_eta(td, elapsed);
228 eta_secs[i] = INT_MAX;
230 check_str_update(td);
231 io_bytes[0] += td->io_bytes[0];
232 io_bytes[1] += td->io_bytes[1];
235 if (exitall_on_terminate)
241 if (exitall_on_terminate) {
242 if (eta_secs[i] < eta_sec)
243 eta_sec = eta_secs[i];
245 if (eta_secs[i] > eta_sec)
246 eta_sec = eta_secs[i];
252 if (eta_sec != INT_MAX && elapsed) {
253 perc = (double) elapsed / (double) (elapsed + eta_sec);
254 eta_to_str(eta_str, eta_sec);
257 fio_gettime(&now, NULL);
258 rate_time = mtime_since(&rate_prev_time, &now);
260 if (write_bw_log && rate_time> bw_avg_time) {
261 calc_rate(rate_time, io_bytes, rate_io_bytes, rate);
262 memcpy(&rate_prev_time, &now, sizeof(now));
263 add_agg_sample(rate[DDIR_READ], DDIR_READ);
264 add_agg_sample(rate[DDIR_WRITE], DDIR_WRITE);
267 disp_time = mtime_since(&disp_prev_time, &now);
268 if (disp_time < 1000)
271 calc_rate(disp_time, io_bytes, disp_io_bytes, rate);
272 memcpy(&disp_prev_time, &now, sizeof(now));
274 if (!nr_running && !nr_pending)
277 printf("Jobs: %d (f=%d)", nr_running, files_open);
278 if (m_rate || t_rate)
279 printf(", CR=%d/%d KiB/s", t_rate, m_rate);
280 else if (m_iops || t_iops)
281 printf(", CR=%d/%d IOPS", t_iops, m_iops);
282 if (eta_sec != INT_MAX && nr_running) {
284 printf(": [%s] [%3.1f%% done] [%6u/%6u kb/s] [eta %s]", run_str, perc, rate[0], rate[1], eta_str);
290 void print_status_init(int thread_number)
292 run_str[thread_number] = 'P';