Commit | Line | Data |
---|---|---|
3c39a379 JA |
1 | #include <stdio.h> |
2 | #include <string.h> | |
3 | #include <sys/time.h> | |
4 | #include <sys/types.h> | |
5c4e1dbc | 5 | #include <sys/stat.h> |
3c39a379 JA |
6 | #include <dirent.h> |
7 | #include <libgen.h> | |
8 | #include <math.h> | |
9 | ||
10 | #include "fio.h" | |
3c39a379 JA |
11 | |
12 | static struct itimerval itimer; | |
5c4e1dbc | 13 | static struct list_head disk_list = LIST_HEAD_INIT(disk_list); |
3c39a379 JA |
14 | |
15 | static int get_io_ticks(struct disk_util *du, struct disk_util_stat *dus) | |
16 | { | |
17 | unsigned in_flight; | |
18 | char line[256]; | |
19 | FILE *f; | |
20 | char *p; | |
21 | ||
22 | f = fopen(du->path, "r"); | |
23 | if (!f) | |
24 | return 1; | |
25 | ||
26 | p = fgets(line, sizeof(line), f); | |
27 | if (!p) { | |
28 | fclose(f); | |
29 | return 1; | |
30 | } | |
31 | ||
32 | if (sscanf(p, "%u %u %llu %u %u %u %llu %u %u %u %u\n", &dus->ios[0], &dus->merges[0], &dus->sectors[0], &dus->ticks[0], &dus->ios[1], &dus->merges[1], &dus->sectors[1], &dus->ticks[1], &in_flight, &dus->io_ticks, &dus->time_in_queue) != 11) { | |
33 | fclose(f); | |
34 | return 1; | |
35 | } | |
36 | ||
37 | fclose(f); | |
38 | return 0; | |
39 | } | |
40 | ||
41 | static void update_io_tick_disk(struct disk_util *du) | |
42 | { | |
43 | struct disk_util_stat __dus, *dus, *ldus; | |
44 | struct timeval t; | |
45 | ||
46 | if (get_io_ticks(du, &__dus)) | |
47 | return; | |
48 | ||
49 | dus = &du->dus; | |
50 | ldus = &du->last_dus; | |
51 | ||
52 | dus->sectors[0] += (__dus.sectors[0] - ldus->sectors[0]); | |
53 | dus->sectors[1] += (__dus.sectors[1] - ldus->sectors[1]); | |
54 | dus->ios[0] += (__dus.ios[0] - ldus->ios[0]); | |
55 | dus->ios[1] += (__dus.ios[1] - ldus->ios[1]); | |
56 | dus->merges[0] += (__dus.merges[0] - ldus->merges[0]); | |
57 | dus->merges[1] += (__dus.merges[1] - ldus->merges[1]); | |
58 | dus->ticks[0] += (__dus.ticks[0] - ldus->ticks[0]); | |
59 | dus->ticks[1] += (__dus.ticks[1] - ldus->ticks[1]); | |
60 | dus->io_ticks += (__dus.io_ticks - ldus->io_ticks); | |
61 | dus->time_in_queue += (__dus.time_in_queue - ldus->time_in_queue); | |
62 | ||
63 | gettimeofday(&t, NULL); | |
64 | du->msec += mtime_since(&du->time, &t); | |
65 | memcpy(&du->time, &t, sizeof(t)); | |
66 | memcpy(ldus, &__dus, sizeof(__dus)); | |
67 | } | |
68 | ||
69 | void update_io_ticks(void) | |
70 | { | |
71 | struct list_head *entry; | |
72 | struct disk_util *du; | |
73 | ||
74 | list_for_each(entry, &disk_list) { | |
75 | du = list_entry(entry, struct disk_util, list); | |
76 | update_io_tick_disk(du); | |
77 | } | |
78 | } | |
79 | ||
80 | static int disk_util_exists(dev_t dev) | |
81 | { | |
82 | struct list_head *entry; | |
83 | struct disk_util *du; | |
84 | ||
85 | list_for_each(entry, &disk_list) { | |
86 | du = list_entry(entry, struct disk_util, list); | |
87 | ||
88 | if (du->dev == dev) | |
89 | return 1; | |
90 | } | |
91 | ||
92 | return 0; | |
93 | } | |
94 | ||
95 | static void disk_util_add(dev_t dev, char *path) | |
96 | { | |
97 | struct disk_util *du = malloc(sizeof(*du)); | |
98 | ||
99 | memset(du, 0, sizeof(*du)); | |
100 | INIT_LIST_HEAD(&du->list); | |
101 | sprintf(du->path, "%s/stat", path); | |
102 | du->name = strdup(basename(path)); | |
103 | du->dev = dev; | |
104 | ||
105 | gettimeofday(&du->time, NULL); | |
106 | get_io_ticks(du, &du->last_dus); | |
107 | ||
108 | list_add_tail(&du->list, &disk_list); | |
109 | } | |
110 | ||
111 | static int check_dev_match(dev_t dev, char *path) | |
112 | { | |
113 | unsigned int major, minor; | |
114 | char line[256], *p; | |
115 | FILE *f; | |
116 | ||
117 | f = fopen(path, "r"); | |
118 | if (!f) { | |
119 | perror("open path"); | |
120 | return 1; | |
121 | } | |
122 | ||
123 | p = fgets(line, sizeof(line), f); | |
124 | if (!p) { | |
125 | fclose(f); | |
126 | return 1; | |
127 | } | |
128 | ||
129 | if (sscanf(p, "%u:%u", &major, &minor) != 2) { | |
130 | fclose(f); | |
131 | return 1; | |
132 | } | |
133 | ||
134 | if (((major << 8) | minor) == dev) { | |
135 | fclose(f); | |
136 | return 0; | |
137 | } | |
138 | ||
139 | fclose(f); | |
140 | return 1; | |
141 | } | |
142 | ||
143 | static int find_block_dir(dev_t dev, char *path) | |
144 | { | |
145 | struct dirent *dir; | |
146 | struct stat st; | |
147 | int found = 0; | |
148 | DIR *D; | |
149 | ||
150 | D = opendir(path); | |
151 | if (!D) | |
152 | return 0; | |
153 | ||
154 | while ((dir = readdir(D)) != NULL) { | |
155 | char full_path[256]; | |
156 | ||
157 | if (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, "..")) | |
158 | continue; | |
159 | if (!strcmp(dir->d_name, "device")) | |
160 | continue; | |
161 | ||
162 | sprintf(full_path, "%s/%s", path, dir->d_name); | |
163 | ||
164 | if (!strcmp(dir->d_name, "dev")) { | |
165 | if (!check_dev_match(dev, full_path)) { | |
166 | found = 1; | |
167 | break; | |
168 | } | |
169 | } | |
170 | ||
171 | if (stat(full_path, &st) == -1) { | |
172 | perror("stat"); | |
173 | break; | |
174 | } | |
175 | ||
176 | if (!S_ISDIR(st.st_mode) || S_ISLNK(st.st_mode)) | |
177 | continue; | |
178 | ||
179 | found = find_block_dir(dev, full_path); | |
180 | if (found) { | |
181 | strcpy(path, full_path); | |
182 | break; | |
183 | } | |
184 | } | |
185 | ||
186 | closedir(D); | |
187 | return found; | |
188 | } | |
189 | ||
190 | void init_disk_util(struct thread_data *td) | |
191 | { | |
192 | struct stat st; | |
193 | char foo[256], tmp[256]; | |
194 | dev_t dev; | |
195 | char *p; | |
196 | ||
197 | if (!td->do_disk_util) | |
198 | return; | |
199 | ||
200 | if (!stat(td->file_name, &st)) { | |
201 | if (S_ISBLK(st.st_mode)) | |
202 | dev = st.st_rdev; | |
203 | else | |
204 | dev = st.st_dev; | |
205 | } else { | |
206 | /* | |
207 | * must be a file, open "." in that path | |
208 | */ | |
209 | strcpy(foo, td->file_name); | |
210 | p = dirname(foo); | |
211 | if (stat(p, &st)) { | |
212 | perror("disk util stat"); | |
213 | return; | |
214 | } | |
215 | ||
216 | dev = st.st_dev; | |
217 | } | |
218 | ||
219 | if (disk_util_exists(dev)) | |
220 | return; | |
221 | ||
222 | sprintf(foo, "/sys/block"); | |
223 | if (!find_block_dir(dev, foo)) | |
224 | return; | |
225 | ||
226 | /* | |
227 | * If there's a ../queue/ directory there, we are inside a partition. | |
228 | * Check if that is the case and jump back. For loop/md/dm etc we | |
229 | * are already in the right spot. | |
230 | */ | |
231 | sprintf(tmp, "%s/../queue", foo); | |
232 | if (!stat(tmp, &st)) { | |
233 | p = dirname(foo); | |
234 | sprintf(tmp, "%s/queue", p); | |
235 | if (stat(tmp, &st)) { | |
3b70d7e5 | 236 | log_err("unknown sysfs layout\n"); |
3c39a379 JA |
237 | return; |
238 | } | |
239 | sprintf(foo, "%s", p); | |
240 | } | |
241 | ||
242 | td->sysfs_root = strdup(foo); | |
243 | disk_util_add(dev, foo); | |
244 | } | |
245 | ||
246 | void disk_util_timer_arm(void) | |
247 | { | |
248 | itimer.it_value.tv_sec = 0; | |
249 | itimer.it_value.tv_usec = DISK_UTIL_MSEC * 1000; | |
250 | setitimer(ITIMER_REAL, &itimer, NULL); | |
251 | } | |
252 | ||
253 | void update_rusage_stat(struct thread_data *td) | |
254 | { | |
255 | if (!(td->runtime[0] + td->runtime[1])) | |
256 | return; | |
257 | ||
258 | getrusage(RUSAGE_SELF, &td->ru_end); | |
259 | ||
260 | td->usr_time += mtime_since(&td->ru_start.ru_utime, &td->ru_end.ru_utime); | |
261 | td->sys_time += mtime_since(&td->ru_start.ru_stime, &td->ru_end.ru_stime); | |
262 | td->ctx += td->ru_end.ru_nvcsw + td->ru_end.ru_nivcsw - (td->ru_start.ru_nvcsw + td->ru_start.ru_nivcsw); | |
263 | ||
264 | ||
265 | memcpy(&td->ru_start, &td->ru_end, sizeof(td->ru_end)); | |
266 | } | |
267 | ||
268 | static int calc_lat(struct io_stat *is, unsigned long *min, unsigned long *max, | |
269 | double *mean, double *dev) | |
270 | { | |
271 | double n; | |
272 | ||
273 | if (is->samples == 0) | |
274 | return 0; | |
275 | ||
276 | *min = is->min_val; | |
277 | *max = is->max_val; | |
278 | ||
279 | n = (double) is->samples; | |
280 | *mean = (double) is->val / n; | |
281 | *dev = sqrt(((double) is->val_sq - (*mean * *mean) / n) / (n - 1)); | |
3c39a379 JA |
282 | |
283 | return 1; | |
284 | } | |
285 | ||
286 | static void show_group_stats(struct group_run_stats *rs, int id) | |
287 | { | |
eb8bbf48 | 288 | fprintf(f_out, "\nRun status group %d (all jobs):\n", id); |
3c39a379 JA |
289 | |
290 | if (rs->max_run[DDIR_READ]) | |
eb8bbf48 | 291 | fprintf(f_out, " READ: io=%lluMiB, aggrb=%llu, minb=%llu, maxb=%llu, mint=%llumsec, maxt=%llumsec\n", rs->io_kb[0] >> 10, rs->agg[0], rs->min_bw[0], rs->max_bw[0], rs->min_run[0], rs->max_run[0]); |
3c39a379 | 292 | if (rs->max_run[DDIR_WRITE]) |
eb8bbf48 | 293 | fprintf(f_out, " WRITE: io=%lluMiB, aggrb=%llu, minb=%llu, maxb=%llu, mint=%llumsec, maxt=%llumsec\n", rs->io_kb[1] >> 10, rs->agg[1], rs->min_bw[1], rs->max_bw[1], rs->min_run[1], rs->max_run[1]); |
3c39a379 JA |
294 | } |
295 | ||
296 | static void show_disk_util(void) | |
297 | { | |
298 | struct disk_util_stat *dus; | |
299 | struct list_head *entry; | |
300 | struct disk_util *du; | |
301 | double util; | |
302 | ||
eb8bbf48 | 303 | fprintf(f_out, "\nDisk stats (read/write):\n"); |
3c39a379 JA |
304 | |
305 | list_for_each(entry, &disk_list) { | |
306 | du = list_entry(entry, struct disk_util, list); | |
307 | dus = &du->dus; | |
308 | ||
309 | util = (double) 100 * du->dus.io_ticks / (double) du->msec; | |
310 | if (util > 100.0) | |
311 | util = 100.0; | |
312 | ||
eb8bbf48 | 313 | fprintf(f_out, " %s: ios=%u/%u, merge=%u/%u, ticks=%u/%u, in_queue=%u, util=%3.2f%%\n", du->name, dus->ios[0], dus->ios[1], dus->merges[0], dus->merges[1], dus->ticks[0], dus->ticks[1], dus->time_in_queue, util); |
3c39a379 JA |
314 | } |
315 | } | |
316 | ||
317 | static void show_ddir_status(struct thread_data *td, struct group_run_stats *rs, | |
318 | int ddir) | |
319 | { | |
320 | char *ddir_str[] = { "read ", "write" }; | |
321 | unsigned long min, max; | |
322 | unsigned long long bw; | |
323 | double mean, dev; | |
324 | ||
325 | if (!td->runtime[ddir]) | |
326 | return; | |
327 | ||
328 | bw = td->io_bytes[ddir] / td->runtime[ddir]; | |
eb8bbf48 | 329 | fprintf(f_out, " %s: io=%6lluMiB, bw=%6lluKiB/s, runt=%6lumsec\n", ddir_str[ddir], td->io_bytes[ddir] >> 20, bw, td->runtime[ddir]); |
3c39a379 JA |
330 | |
331 | if (calc_lat(&td->slat_stat[ddir], &min, &max, &mean, &dev)) | |
eb8bbf48 | 332 | fprintf(f_out, " slat (msec): min=%5lu, max=%5lu, avg=%5.02f, dev=%5.02f\n", min, max, mean, dev); |
3c39a379 JA |
333 | |
334 | if (calc_lat(&td->clat_stat[ddir], &min, &max, &mean, &dev)) | |
eb8bbf48 | 335 | fprintf(f_out, " clat (msec): min=%5lu, max=%5lu, avg=%5.02f, dev=%5.02f\n", min, max, mean, dev); |
3c39a379 JA |
336 | |
337 | if (calc_lat(&td->bw_stat[ddir], &min, &max, &mean, &dev)) { | |
338 | double p_of_agg; | |
339 | ||
340 | p_of_agg = mean * 100 / (double) rs->agg[ddir]; | |
eb8bbf48 | 341 | fprintf(f_out, " bw (KiB/s) : min=%5lu, max=%5lu, per=%3.2f%%, avg=%5.02f, dev=%5.02f\n", min, max, p_of_agg, mean, dev); |
3c39a379 JA |
342 | } |
343 | } | |
344 | ||
345 | static void show_thread_status(struct thread_data *td, | |
346 | struct group_run_stats *rs) | |
347 | { | |
348 | double usr_cpu, sys_cpu; | |
349 | ||
350 | if (!(td->io_bytes[0] + td->io_bytes[1]) && !td->error) | |
351 | return; | |
352 | ||
eb8bbf48 | 353 | fprintf(f_out, "%s: (groupid=%d): err=%2d:\n",td->name, td->groupid, td->error); |
3c39a379 JA |
354 | |
355 | show_ddir_status(td, rs, td->ddir); | |
356 | if (td->io_bytes[td->ddir ^ 1]) | |
357 | show_ddir_status(td, rs, td->ddir ^ 1); | |
358 | ||
359 | if (td->runtime[0] + td->runtime[1]) { | |
360 | double runt = td->runtime[0] + td->runtime[1]; | |
361 | ||
362 | usr_cpu = (double) td->usr_time * 100 / runt; | |
363 | sys_cpu = (double) td->sys_time * 100 / runt; | |
364 | } else { | |
365 | usr_cpu = 0; | |
366 | sys_cpu = 0; | |
367 | } | |
368 | ||
eb8bbf48 | 369 | fprintf(f_out, " cpu : usr=%3.2f%%, sys=%3.2f%%, ctx=%lu\n", usr_cpu, sys_cpu, td->ctx); |
3c39a379 JA |
370 | } |
371 | ||
c6ae0a5b JA |
372 | static void show_ddir_status_terse(struct thread_data *td, |
373 | struct group_run_stats *rs, int ddir) | |
374 | { | |
375 | unsigned long min, max; | |
376 | unsigned long long bw; | |
377 | double mean, dev; | |
378 | ||
379 | bw = 0; | |
380 | if (td->runtime[ddir]) | |
381 | bw = td->io_bytes[ddir] / td->runtime[ddir]; | |
382 | ||
383 | fprintf(f_out, ",%llu,%llu,%lu", td->io_bytes[ddir] >> 10, bw, td->runtime[ddir]); | |
384 | ||
385 | if (calc_lat(&td->slat_stat[ddir], &min, &max, &mean, &dev)) | |
386 | fprintf(f_out, ",%lu,%lu,%f,%f", min, max, mean, dev); | |
387 | else | |
388 | fprintf(f_out, ",%lu,%lu,%f,%f", 0UL, 0UL, 0.0, 0.0); | |
389 | ||
390 | if (calc_lat(&td->clat_stat[ddir], &min, &max, &mean, &dev)) | |
391 | fprintf(f_out, ",%lu,%lu,%f,%f", min, max, mean, dev); | |
392 | else | |
393 | fprintf(f_out, ",%lu,%lu,%f,%f", 0UL, 0UL, 0.0, 0.0); | |
394 | ||
395 | if (calc_lat(&td->bw_stat[ddir], &min, &max, &mean, &dev)) { | |
396 | double p_of_agg; | |
397 | ||
398 | p_of_agg = mean * 100 / (double) rs->agg[ddir]; | |
399 | fprintf(f_out, ",%lu,%lu,%f%%,%f,%f", min, max, p_of_agg, mean, dev); | |
400 | } else | |
401 | fprintf(f_out, ",%lu,%lu,%f%%,%f,%f", 0UL, 0UL, 0.0, 0.0, 0.0); | |
402 | ||
403 | } | |
404 | ||
405 | ||
406 | static void show_thread_status_terse(struct thread_data *td, | |
407 | struct group_run_stats *rs) | |
408 | { | |
409 | double usr_cpu, sys_cpu; | |
410 | ||
411 | fprintf(f_out, "%s,%d,%d",td->name, td->groupid, td->error); | |
412 | ||
413 | show_ddir_status_terse(td, rs, 0); | |
414 | show_ddir_status_terse(td, rs, 1); | |
415 | ||
416 | if (td->runtime[0] + td->runtime[1]) { | |
417 | double runt = td->runtime[0] + td->runtime[1]; | |
418 | ||
419 | usr_cpu = (double) td->usr_time * 100 / runt; | |
420 | sys_cpu = (double) td->sys_time * 100 / runt; | |
421 | } else { | |
422 | usr_cpu = 0; | |
423 | sys_cpu = 0; | |
424 | } | |
425 | ||
426 | fprintf(f_out, ",%f%%,%f%%,%lu\n", usr_cpu, sys_cpu, td->ctx); | |
427 | } | |
428 | ||
3c39a379 JA |
429 | void show_run_stats(void) |
430 | { | |
431 | struct group_run_stats *runstats, *rs; | |
432 | struct thread_data *td; | |
433 | int i; | |
434 | ||
435 | runstats = malloc(sizeof(struct group_run_stats) * (groupid + 1)); | |
436 | ||
437 | for (i = 0; i < groupid + 1; i++) { | |
438 | rs = &runstats[i]; | |
439 | ||
440 | memset(rs, 0, sizeof(*rs)); | |
441 | rs->min_bw[0] = rs->min_run[0] = ~0UL; | |
442 | rs->min_bw[1] = rs->min_run[1] = ~0UL; | |
443 | } | |
444 | ||
445 | for (i = 0; i < thread_number; i++) { | |
446 | unsigned long long rbw, wbw; | |
447 | ||
448 | td = &threads[i]; | |
449 | ||
450 | if (td->error) { | |
eb8bbf48 | 451 | fprintf(f_out, "%s: %s\n", td->name, td->verror); |
3c39a379 JA |
452 | continue; |
453 | } | |
454 | ||
455 | rs = &runstats[td->groupid]; | |
456 | ||
457 | if (td->runtime[0] < rs->min_run[0] || !rs->min_run[0]) | |
458 | rs->min_run[0] = td->runtime[0]; | |
459 | if (td->runtime[0] > rs->max_run[0]) | |
460 | rs->max_run[0] = td->runtime[0]; | |
461 | if (td->runtime[1] < rs->min_run[1] || !rs->min_run[1]) | |
462 | rs->min_run[1] = td->runtime[1]; | |
463 | if (td->runtime[1] > rs->max_run[1]) | |
464 | rs->max_run[1] = td->runtime[1]; | |
465 | ||
466 | rbw = wbw = 0; | |
467 | if (td->runtime[0]) | |
468 | rbw = td->io_bytes[0] / (unsigned long long) td->runtime[0]; | |
469 | if (td->runtime[1]) | |
470 | wbw = td->io_bytes[1] / (unsigned long long) td->runtime[1]; | |
471 | ||
472 | if (rbw < rs->min_bw[0]) | |
473 | rs->min_bw[0] = rbw; | |
474 | if (wbw < rs->min_bw[1]) | |
475 | rs->min_bw[1] = wbw; | |
476 | if (rbw > rs->max_bw[0]) | |
477 | rs->max_bw[0] = rbw; | |
478 | if (wbw > rs->max_bw[1]) | |
479 | rs->max_bw[1] = wbw; | |
480 | ||
481 | rs->io_kb[0] += td->io_bytes[0] >> 10; | |
482 | rs->io_kb[1] += td->io_bytes[1] >> 10; | |
483 | } | |
484 | ||
485 | for (i = 0; i < groupid + 1; i++) { | |
486 | rs = &runstats[i]; | |
487 | ||
488 | if (rs->max_run[0]) | |
489 | rs->agg[0] = (rs->io_kb[0]*1024) / rs->max_run[0]; | |
490 | if (rs->max_run[1]) | |
491 | rs->agg[1] = (rs->io_kb[1]*1024) / rs->max_run[1]; | |
492 | } | |
493 | ||
494 | /* | |
495 | * don't overwrite last signal output | |
496 | */ | |
c6ae0a5b JA |
497 | if (!terse_output) |
498 | printf("\n"); | |
3c39a379 JA |
499 | |
500 | for (i = 0; i < thread_number; i++) { | |
501 | td = &threads[i]; | |
502 | rs = &runstats[td->groupid]; | |
503 | ||
c6ae0a5b JA |
504 | if (terse_output) |
505 | show_thread_status_terse(td, rs); | |
506 | else | |
507 | show_thread_status(td, rs); | |
3c39a379 JA |
508 | } |
509 | ||
c6ae0a5b JA |
510 | if (!terse_output) { |
511 | for (i = 0; i < groupid + 1; i++) | |
512 | show_group_stats(&runstats[i], i); | |
3c39a379 | 513 | |
c6ae0a5b JA |
514 | show_disk_util(); |
515 | } | |
3c39a379 JA |
516 | } |
517 | ||
518 | static inline void add_stat_sample(struct io_stat *is, unsigned long val) | |
519 | { | |
520 | if (val > is->max_val) | |
521 | is->max_val = val; | |
522 | if (val < is->min_val) | |
523 | is->min_val = val; | |
524 | ||
525 | is->val += val; | |
526 | is->val_sq += val * val; | |
527 | is->samples++; | |
528 | } | |
529 | ||
530 | static void add_log_sample(struct thread_data *td, struct io_log *iolog, | |
531 | unsigned long val, int ddir) | |
532 | { | |
533 | if (iolog->nr_samples == iolog->max_samples) { | |
534 | int new_size = sizeof(struct io_sample) * iolog->max_samples*2; | |
535 | ||
536 | iolog->log = realloc(iolog->log, new_size); | |
537 | iolog->max_samples <<= 1; | |
538 | } | |
539 | ||
540 | iolog->log[iolog->nr_samples].val = val; | |
541 | iolog->log[iolog->nr_samples].time = mtime_since_now(&td->epoch); | |
542 | iolog->log[iolog->nr_samples].ddir = ddir; | |
543 | iolog->nr_samples++; | |
544 | } | |
545 | ||
546 | void add_clat_sample(struct thread_data *td, int ddir, unsigned long msec) | |
547 | { | |
548 | add_stat_sample(&td->clat_stat[ddir], msec); | |
549 | ||
550 | if (td->clat_log) | |
551 | add_log_sample(td, td->clat_log, msec, ddir); | |
552 | } | |
553 | ||
554 | void add_slat_sample(struct thread_data *td, int ddir, unsigned long msec) | |
555 | { | |
556 | add_stat_sample(&td->slat_stat[ddir], msec); | |
557 | ||
558 | if (td->slat_log) | |
559 | add_log_sample(td, td->slat_log, msec, ddir); | |
560 | } | |
561 | ||
562 | void add_bw_sample(struct thread_data *td, int ddir) | |
563 | { | |
564 | unsigned long spent = mtime_since_now(&td->stat_sample_time[ddir]); | |
565 | unsigned long rate; | |
566 | ||
567 | if (spent < td->bw_avg_time) | |
568 | return; | |
569 | ||
570 | rate = (td->this_io_bytes[ddir] - td->stat_io_bytes[ddir]) / spent; | |
571 | add_stat_sample(&td->bw_stat[ddir], rate); | |
572 | ||
573 | if (td->bw_log) | |
574 | add_log_sample(td, td->bw_log, rate, ddir); | |
575 | ||
576 | gettimeofday(&td->stat_sample_time[ddir], NULL); | |
577 | td->stat_io_bytes[ddir] = td->this_io_bytes[ddir]; | |
578 | } | |
579 | ||
580 |