4 * IO engine that doesn't do any IO, just stat files and tracks the latency
10 #include <sys/types.h>
14 #include "../optgroup.h"
17 enum fio_ddir stat_ddir;
20 struct filestat_options {
25 static struct fio_option options[] = {
30 .off1 = offsetof(struct filestat_options, lstat),
31 .help = "Use lstat(2) to measure lookup/getattr performance",
33 .category = FIO_OPT_C_ENGINE,
34 .group = FIO_OPT_G_FILESTAT,
41 static int stat_file(struct thread_data *td, struct fio_file *f)
43 struct filestat_options *o = td->eo;
44 struct timespec start;
45 int do_lat = !td->o.disable_lat;
49 dprint(FD_FILE, "fd stat %s\n", f->file_name);
51 if (f->filetype != FIO_TYPE_FILE) {
52 log_err("fio: only files are supported\n");
55 if (!strcmp(f->file_name, "-")) {
56 log_err("fio: can't read/write to stdin/out\n");
61 fio_gettime(&start, NULL);
64 ret = lstat(f->file_name, &statbuf);
66 ret = stat(f->file_name, &statbuf);
69 char buf[FIO_VERROR_SIZE];
72 snprintf(buf, sizeof(buf), "%sstat(%s)",
73 o->lstat ? "l" : "", f->file_name);
74 td_verror(td, e, buf);
79 struct fc_data *data = td->io_ops_data;
82 nsec = ntime_since_now(&start);
83 add_clat_sample(td, data->stat_ddir, nsec, 0, 0, 0);
89 static enum fio_q_status queue_io(struct thread_data *td, struct io_u fio_unused *io_u)
91 return FIO_Q_COMPLETED;
94 static int init(struct thread_data *td)
98 data = calloc(1, sizeof(*data));
101 data->stat_ddir = DDIR_READ;
102 else if (td_write(td))
103 data->stat_ddir = DDIR_WRITE;
105 td->io_ops_data = data;
109 static void cleanup(struct thread_data *td)
111 struct fc_data *data = td->io_ops_data;
116 static int stat_invalidate(struct thread_data *td, struct fio_file *f)
118 /* do nothing because file not opened */
122 static struct ioengine_ops ioengine = {
124 .version = FIO_IOOPS_VERSION,
128 .invalidate = stat_invalidate,
129 .get_file_size = generic_get_file_size,
130 .open_file = stat_file,
131 .flags = FIO_SYNCIO | FIO_FAKEIO |
132 FIO_NOSTATS | FIO_NOFILEHASH,
134 .option_struct_size = sizeof(struct filestat_options),
137 static void fio_init fio_filestat_register(void)
139 register_ioengine(&ioengine);
142 static void fio_exit fio_filestat_unregister(void)
144 unregister_ioengine(&ioengine);