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;
73 static int always_d, always_h;
87 str += sprintf(str, "%02dd:", d);
91 str += sprintf(str, "%02dh:", h);
94 str += sprintf(str, "%02dm:", m);
95 str += sprintf(str, "%02ds", s);
99 * Best effort calculation of the estimated pending runtime of a job.
101 static int thread_eta(struct thread_data *td, unsigned long elapsed)
103 unsigned long long bytes_total, bytes_done;
104 unsigned int eta_sec = 0;
106 bytes_total = td->total_io_size;
109 * if writing, bytes_total will be twice the size. If mixing,
110 * assume a 50/50 split and thus bytes_total will be 50% larger.
114 bytes_total = bytes_total * 3 / 2;
119 if (td->zone_size && td->zone_skip)
120 bytes_total /= (td->zone_skip / td->zone_size);
122 if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING) {
125 bytes_done = td->io_bytes[DDIR_READ] + td->io_bytes[DDIR_WRITE];
126 perc = (double) bytes_done / (double) bytes_total;
130 eta_sec = (elapsed * (1.0 / perc)) - elapsed;
132 if (td->timeout && eta_sec > (td->timeout - elapsed))
133 eta_sec = td->timeout - elapsed;
134 } else if (td->runstate == TD_NOT_CREATED || td->runstate == TD_CREATED
135 || td->runstate == TD_INITIALIZED) {
136 int t_eta = 0, r_eta = 0;
139 * We can only guess - assume it'll run the full timeout
140 * if given, otherwise assume it'll run at the specified rate.
143 t_eta = td->timeout + td->start_delay - elapsed;
145 r_eta = (bytes_total / 1024) / td->rate;
146 r_eta += td->start_delay - elapsed;
150 eta_sec = min(r_eta, t_eta);
159 * thread is already done or waiting for fsync
168 * Print status of the jobs we know about. This includes rate estimates,
169 * ETA, thread state, etc.
171 void print_thread_status(void)
173 unsigned long elapsed = mtime_since_genesis() / 1000;
174 int i, nr_running, nr_pending, t_rate, m_rate, *eta_secs, eta_sec;
178 if (temp_stall_ts || terse_output)
181 eta_secs = malloc(thread_number * sizeof(int));
182 memset(eta_secs, 0, thread_number * sizeof(int));
184 nr_pending = nr_running = t_rate = m_rate = 0;
185 for (i = 0; i < thread_number; i++) {
186 struct thread_data *td = &threads[i];
188 if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING||
189 td->runstate == TD_FSYNCING) {
192 m_rate += td->ratemin;
193 } else if (td->runstate < TD_RUNNING)
197 eta_secs[i] = thread_eta(td, elapsed);
199 eta_secs[i] = INT_MAX;
201 check_str_update(td);
204 if (exitall_on_terminate)
209 for (i = 0; i < thread_number; i++) {
210 if (exitall_on_terminate) {
211 if (eta_secs[i] < eta_sec)
212 eta_sec = eta_secs[i];
214 if (eta_secs[i] > eta_sec)
215 eta_sec = eta_secs[i];
219 if (eta_sec != INT_MAX && elapsed) {
220 perc = (double) elapsed / (double) (elapsed + eta_sec);
221 eta_to_str(eta_str, eta_sec);
224 if (!nr_running && !nr_pending)
227 printf("Threads running: %d", nr_running);
228 if (m_rate || t_rate)
229 printf(", commitrate %d/%dKiB/sec", t_rate, m_rate);
230 if (eta_sec != INT_MAX && nr_running) {
232 printf(": [%s] [%3.2f%% done] [eta %s]", run_str, perc,eta_str);
239 void print_status_init(int thread_number)
241 run_str[thread_number] = 'P';