Commit | Line | Data |
---|---|---|
263e529f JA |
1 | /* |
2 | * Status and ETA code | |
3 | */ | |
4 | #include <unistd.h> | |
5 | #include <fcntl.h> | |
6 | #include <string.h> | |
7 | ||
8 | #include "fio.h" | |
263e529f JA |
9 | |
10 | static char run_str[MAX_JOBS + 1]; | |
11 | ||
12 | /* | |
13 | * Sets the status of the 'td' in the printed status map. | |
14 | */ | |
15 | static void check_str_update(struct thread_data *td) | |
16 | { | |
17 | char c = run_str[td->thread_number - 1]; | |
18 | ||
19 | switch (td->runstate) { | |
5ec10eaa JA |
20 | case TD_REAPED: |
21 | c = '_'; | |
22 | break; | |
23 | case TD_EXITED: | |
24 | c = 'E'; | |
25 | break; | |
b29ee5b3 JA |
26 | case TD_RAMP: |
27 | c = '/'; | |
28 | break; | |
5ec10eaa JA |
29 | case TD_RUNNING: |
30 | if (td_rw(td)) { | |
31 | if (td_random(td)) | |
32 | c = 'm'; | |
33 | else | |
34 | c = 'M'; | |
35 | } else if (td_read(td)) { | |
36 | if (td_random(td)) | |
37 | c = 'r'; | |
38 | else | |
39 | c = 'R'; | |
40 | } else { | |
41 | if (td_random(td)) | |
42 | c = 'w'; | |
43 | else | |
44 | c = 'W'; | |
45 | } | |
46 | break; | |
b0f65863 JA |
47 | case TD_PRE_READING: |
48 | c = 'p'; | |
49 | break; | |
5ec10eaa JA |
50 | case TD_VERIFYING: |
51 | c = 'V'; | |
52 | break; | |
53 | case TD_FSYNCING: | |
54 | c = 'F'; | |
55 | break; | |
56 | case TD_CREATED: | |
57 | c = 'C'; | |
58 | break; | |
59 | case TD_INITIALIZED: | |
60 | c = 'I'; | |
61 | break; | |
62 | case TD_NOT_CREATED: | |
63 | c = 'P'; | |
64 | break; | |
65 | default: | |
66 | log_err("state %d\n", td->runstate); | |
263e529f JA |
67 | } |
68 | ||
69 | run_str[td->thread_number - 1] = c; | |
70 | } | |
71 | ||
72 | /* | |
73 | * Convert seconds to a printable string. | |
74 | */ | |
9c02f6ef | 75 | static void eta_to_str(char *str, unsigned long eta_sec) |
263e529f JA |
76 | { |
77 | unsigned int d, h, m, s; | |
165faf16 | 78 | int disp_hour = 0; |
263e529f | 79 | |
263e529f JA |
80 | s = eta_sec % 60; |
81 | eta_sec /= 60; | |
82 | m = eta_sec % 60; | |
83 | eta_sec /= 60; | |
84 | h = eta_sec % 24; | |
85 | eta_sec /= 24; | |
86 | d = eta_sec; | |
87 | ||
165faf16 JA |
88 | if (d) { |
89 | disp_hour = 1; | |
1e97cce9 | 90 | str += sprintf(str, "%02ud:", d); |
263e529f | 91 | } |
165faf16 JA |
92 | |
93 | if (h || disp_hour) | |
1e97cce9 | 94 | str += sprintf(str, "%02uh:", h); |
263e529f | 95 | |
1e97cce9 JA |
96 | str += sprintf(str, "%02um:", m); |
97 | str += sprintf(str, "%02us", s); | |
263e529f JA |
98 | } |
99 | ||
100 | /* | |
101 | * Best effort calculation of the estimated pending runtime of a job. | |
102 | */ | |
b29ee5b3 | 103 | static int thread_eta(struct thread_data *td) |
263e529f JA |
104 | { |
105 | unsigned long long bytes_total, bytes_done; | |
1e97cce9 | 106 | unsigned long eta_sec = 0; |
b29ee5b3 JA |
107 | unsigned long elapsed; |
108 | ||
109 | elapsed = (mtime_since_now(&td->epoch) + 999) / 1000; | |
263e529f JA |
110 | |
111 | bytes_total = td->total_io_size; | |
112 | ||
74939e38 JA |
113 | /* |
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. | |
116 | */ | |
0dd8377f | 117 | if (td->o.do_verify && td->o.verify && td_write(td)) { |
74939e38 JA |
118 | if (td_rw(td)) |
119 | bytes_total = bytes_total * 3 / 2; | |
120 | else | |
121 | bytes_total <<= 1; | |
122 | } | |
123 | ||
2dc1bbeb JA |
124 | if (td->o.zone_size && td->o.zone_skip) |
125 | bytes_total /= (td->o.zone_skip / td->o.zone_size); | |
263e529f | 126 | |
9c5a3854 SSY |
127 | if (td->o.fill_device && td->o.size == -1ULL) |
128 | return 0; | |
129 | ||
263e529f | 130 | if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING) { |
cf4464ca | 131 | double perc, perc_t; |
263e529f JA |
132 | |
133 | bytes_done = td->io_bytes[DDIR_READ] + td->io_bytes[DDIR_WRITE]; | |
134 | perc = (double) bytes_done / (double) bytes_total; | |
135 | if (perc > 1.0) | |
136 | perc = 1.0; | |
137 | ||
cf4464ca JA |
138 | if (td->o.time_based) { |
139 | perc_t = (double) elapsed / (double) td->o.timeout; | |
140 | if (perc_t < perc) | |
141 | perc = perc_t; | |
142 | } | |
143 | ||
1e97cce9 | 144 | eta_sec = (unsigned long) (elapsed * (1.0 / perc)) - elapsed; |
263e529f | 145 | |
d3eeeabc JA |
146 | if (td->o.timeout && |
147 | eta_sec > (td->o.timeout + done_secs - elapsed)) | |
148 | eta_sec = td->o.timeout + done_secs - elapsed; | |
263e529f | 149 | } else if (td->runstate == TD_NOT_CREATED || td->runstate == TD_CREATED |
b29ee5b3 | 150 | || td->runstate == TD_INITIALIZED |
b0f65863 JA |
151 | || td->runstate == TD_RAMP |
152 | || td->runstate == TD_PRE_READING) { | |
263e529f JA |
153 | int t_eta = 0, r_eta = 0; |
154 | ||
155 | /* | |
156 | * We can only guess - assume it'll run the full timeout | |
157 | * if given, otherwise assume it'll run at the specified rate. | |
158 | */ | |
b29ee5b3 | 159 | if (td->o.timeout) { |
d3eeeabc | 160 | t_eta = td->o.timeout + td->o.start_delay; |
b29ee5b3 JA |
161 | |
162 | if (in_ramp_time(td)) { | |
163 | unsigned long ramp_left; | |
164 | ||
165 | ramp_left = mtime_since_now(&td->start); | |
166 | ramp_left = (ramp_left + 999) / 1000; | |
167 | if (ramp_left <= t_eta) | |
168 | t_eta -= ramp_left; | |
169 | } | |
170 | } | |
581e7141 JA |
171 | if (td->o.rate[0] || td->o.rate[1]) { |
172 | r_eta = (bytes_total / 1024) / (td->o.rate[0] + td->o.rate[1]); | |
d3eeeabc | 173 | r_eta += td->o.start_delay; |
263e529f JA |
174 | } |
175 | ||
176 | if (r_eta && t_eta) | |
177 | eta_sec = min(r_eta, t_eta); | |
178 | else if (r_eta) | |
179 | eta_sec = r_eta; | |
180 | else if (t_eta) | |
181 | eta_sec = t_eta; | |
182 | else | |
183 | eta_sec = 0; | |
184 | } else { | |
185 | /* | |
186 | * thread is already done or waiting for fsync | |
187 | */ | |
188 | eta_sec = 0; | |
189 | } | |
190 | ||
191 | return eta_sec; | |
192 | } | |
193 | ||
46fda8d0 JA |
194 | static void calc_rate(unsigned long mtime, unsigned long long *io_bytes, |
195 | unsigned long long *prev_io_bytes, unsigned int *rate) | |
196 | { | |
197 | rate[0] = (io_bytes[0] - prev_io_bytes[0]) / mtime; | |
198 | rate[1] = (io_bytes[1] - prev_io_bytes[1]) / mtime; | |
199 | prev_io_bytes[0] = io_bytes[0]; | |
200 | prev_io_bytes[1] = io_bytes[1]; | |
201 | } | |
5ec10eaa | 202 | |
adb02ba8 JA |
203 | static void calc_iops(unsigned long mtime, unsigned long long *io_iops, |
204 | unsigned long long *prev_io_iops, unsigned int *iops) | |
205 | { | |
206 | iops[0] = ((io_iops[0] - prev_io_iops[0]) * 1000) / mtime; | |
207 | iops[1] = ((io_iops[1] - prev_io_iops[1]) * 1000) / mtime; | |
208 | prev_io_iops[0] = io_iops[0]; | |
209 | prev_io_iops[1] = io_iops[1]; | |
210 | } | |
211 | ||
263e529f JA |
212 | /* |
213 | * Print status of the jobs we know about. This includes rate estimates, | |
214 | * ETA, thread state, etc. | |
215 | */ | |
216 | void print_thread_status(void) | |
217 | { | |
b29ee5b3 JA |
218 | unsigned long elapsed = (mtime_since_genesis() + 999) / 1000; |
219 | int i, nr_ramp, nr_running, nr_pending, t_rate, m_rate; | |
e6e41602 | 220 | int t_iops, m_iops, files_open; |
34572e28 | 221 | struct thread_data *td; |
2eaa41ce | 222 | char eta_str[128]; |
263e529f | 223 | double perc = 0.0; |
adb02ba8 | 224 | unsigned long long io_bytes[2], io_iops[2]; |
d3eeeabc | 225 | unsigned long rate_time, disp_time, bw_avg_time, *eta_secs, eta_sec; |
46fda8d0 JA |
226 | struct timeval now; |
227 | ||
228 | static unsigned long long rate_io_bytes[2]; | |
229 | static unsigned long long disp_io_bytes[2]; | |
adb02ba8 | 230 | static unsigned long long disp_io_iops[2]; |
46fda8d0 | 231 | static struct timeval rate_prev_time, disp_prev_time; |
adb02ba8 | 232 | static unsigned int rate[2], iops[2]; |
43819609 | 233 | static int linelen_last; |
cac58fd5 | 234 | static int eta_good; |
6043c579 | 235 | |
e592a06b AC |
236 | if (temp_stall_ts || terse_output || eta_print == FIO_ETA_NEVER) |
237 | return; | |
238 | ||
239 | if (!isatty(STDOUT_FILENO) && (eta_print != FIO_ETA_ALWAYS)) | |
263e529f JA |
240 | return; |
241 | ||
46fda8d0 JA |
242 | if (!rate_io_bytes[0] && !rate_io_bytes[1]) |
243 | fill_start_time(&rate_prev_time); | |
244 | if (!disp_io_bytes[0] && !disp_io_bytes[1]) | |
245 | fill_start_time(&disp_prev_time); | |
6043c579 | 246 | |
d3eeeabc JA |
247 | eta_secs = malloc(thread_number * sizeof(unsigned long)); |
248 | memset(eta_secs, 0, thread_number * sizeof(unsigned long)); | |
263e529f | 249 | |
6043c579 | 250 | io_bytes[0] = io_bytes[1] = 0; |
adb02ba8 | 251 | io_iops[0] = io_iops[1] = 0; |
ac71feb1 | 252 | nr_pending = nr_running = t_rate = m_rate = t_iops = m_iops = 0; |
b29ee5b3 | 253 | nr_ramp = 0; |
bb3884d8 | 254 | bw_avg_time = ULONG_MAX; |
e6e41602 | 255 | files_open = 0; |
34572e28 | 256 | for_each_td(td, i) { |
2dc1bbeb JA |
257 | if (td->o.bw_avg_time < bw_avg_time) |
258 | bw_avg_time = td->o.bw_avg_time; | |
46fda8d0 | 259 | if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING |
b0f65863 JA |
260 | || td->runstate == TD_FSYNCING |
261 | || td->runstate == TD_PRE_READING) { | |
263e529f | 262 | nr_running++; |
581e7141 JA |
263 | t_rate += td->o.rate[0] + td->o.rate[1]; |
264 | m_rate += td->o.ratemin[0] + td->o.ratemin[1]; | |
265 | t_iops += td->o.rate_iops[0] + td->o.rate_iops[1]; | |
266 | m_iops += td->o.rate_iops_min[0] + td->o.rate_iops_min[1]; | |
e6e41602 | 267 | files_open += td->nr_open_files; |
b29ee5b3 JA |
268 | } else if (td->runstate == TD_RAMP) { |
269 | nr_running++; | |
270 | nr_ramp++; | |
263e529f JA |
271 | } else if (td->runstate < TD_RUNNING) |
272 | nr_pending++; | |
273 | ||
274 | if (elapsed >= 3) | |
b29ee5b3 | 275 | eta_secs[i] = thread_eta(td); |
263e529f JA |
276 | else |
277 | eta_secs[i] = INT_MAX; | |
278 | ||
279 | check_str_update(td); | |
b29ee5b3 JA |
280 | |
281 | if (td->runstate > TD_RAMP) { | |
282 | io_bytes[0] += td->io_bytes[0]; | |
283 | io_bytes[1] += td->io_bytes[1]; | |
adb02ba8 JA |
284 | io_iops[0] += td->io_blocks[0]; |
285 | io_iops[1] += td->io_blocks[1]; | |
b29ee5b3 | 286 | } |
263e529f JA |
287 | } |
288 | ||
289 | if (exitall_on_terminate) | |
290 | eta_sec = INT_MAX; | |
291 | else | |
292 | eta_sec = 0; | |
293 | ||
34572e28 | 294 | for_each_td(td, i) { |
9c5a3854 SSY |
295 | if (exitall_on_terminate) { |
296 | if (eta_secs[i] < eta_sec) | |
297 | eta_sec = eta_secs[i]; | |
298 | } else { | |
299 | if (eta_secs[i] > eta_sec) | |
300 | eta_sec = eta_secs[i]; | |
301 | } | |
263e529f JA |
302 | } |
303 | ||
eecf272f JA |
304 | free(eta_secs); |
305 | ||
263e529f JA |
306 | if (eta_sec != INT_MAX && elapsed) { |
307 | perc = (double) elapsed / (double) (elapsed + eta_sec); | |
308 | eta_to_str(eta_str, eta_sec); | |
309 | } | |
310 | ||
46fda8d0 JA |
311 | fio_gettime(&now, NULL); |
312 | rate_time = mtime_since(&rate_prev_time, &now); | |
313 | ||
b29ee5b3 | 314 | if (write_bw_log && rate_time > bw_avg_time && !in_ramp_time(td)) { |
46fda8d0 JA |
315 | calc_rate(rate_time, io_bytes, rate_io_bytes, rate); |
316 | memcpy(&rate_prev_time, &now, sizeof(now)); | |
306ddc97 JA |
317 | add_agg_sample(rate[DDIR_READ], DDIR_READ, 0); |
318 | add_agg_sample(rate[DDIR_WRITE], DDIR_WRITE, 0); | |
6043c579 JA |
319 | } |
320 | ||
46fda8d0 JA |
321 | disp_time = mtime_since(&disp_prev_time, &now); |
322 | if (disp_time < 1000) | |
323 | return; | |
324 | ||
325 | calc_rate(disp_time, io_bytes, disp_io_bytes, rate); | |
adb02ba8 JA |
326 | calc_iops(disp_time, io_iops, disp_io_iops, iops); |
327 | ||
46fda8d0 JA |
328 | memcpy(&disp_prev_time, &now, sizeof(now)); |
329 | ||
263e529f JA |
330 | if (!nr_running && !nr_pending) |
331 | return; | |
332 | ||
e6e41602 | 333 | printf("Jobs: %d (f=%d)", nr_running, files_open); |
581e7141 JA |
334 | if (m_rate || t_rate) { |
335 | char *tr, *mr; | |
336 | ||
337 | mr = num2str(m_rate, 4, 0, 1); | |
338 | tr = num2str(t_rate, 4, 0, 1); | |
339 | printf(", CR=%s/%s KiB/s", tr, mr); | |
340 | free(tr); | |
341 | free(mr); | |
342 | } else if (m_iops || t_iops) | |
ac71feb1 | 343 | printf(", CR=%d/%d IOPS", t_iops, m_iops); |
263e529f | 344 | if (eta_sec != INT_MAX && nr_running) { |
0721d11e | 345 | char perc_str[32]; |
adb02ba8 | 346 | char *iops_str[2]; |
d1bd7213 | 347 | char *rate_str[2]; |
adb02ba8 | 348 | int l; |
5ec10eaa | 349 | |
b29ee5b3 | 350 | if ((!eta_sec && !eta_good) || nr_ramp == nr_running) |
cac58fd5 JA |
351 | strcpy(perc_str, "-.-% done"); |
352 | else { | |
353 | eta_good = 1; | |
354 | perc *= 100.0; | |
0721d11e | 355 | sprintf(perc_str, "%3.1f%% done", perc); |
cac58fd5 | 356 | } |
0721d11e | 357 | |
d1bd7213 JA |
358 | rate_str[0] = num2str(rate[0], 5, 10, 1); |
359 | rate_str[1] = num2str(rate[1], 5, 10, 1); | |
360 | ||
adb02ba8 JA |
361 | iops_str[0] = num2str(iops[0], 4, 1, 0); |
362 | iops_str[1] = num2str(iops[1], 4, 1, 0); | |
363 | ||
d1bd7213 JA |
364 | l = printf(": [%s] [%s] [%s/%s /s] [%s/%s iops] [eta %s]", |
365 | run_str, perc_str, rate_str[0], rate_str[1], | |
adb02ba8 JA |
366 | iops_str[0], iops_str[1], eta_str); |
367 | if (l >= 0 && l < linelen_last) | |
368 | printf("%*s", linelen_last - l, ""); | |
369 | linelen_last = l; | |
d1bd7213 JA |
370 | |
371 | free(rate_str[0]); | |
372 | free(rate_str[1]); | |
adb02ba8 JA |
373 | free(iops_str[0]); |
374 | free(iops_str[1]); | |
263e529f JA |
375 | } |
376 | printf("\r"); | |
377 | fflush(stdout); | |
263e529f JA |
378 | } |
379 | ||
380 | void print_status_init(int thread_number) | |
381 | { | |
382 | run_str[thread_number] = 'P'; | |
383 | } |