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 {
22 unsigned int stat_type;
26 FIO_FILESTAT_STAT = 1,
27 FIO_FILESTAT_LSTAT = 2,
28 /*FIO_FILESTAT_STATX = 3,*/
31 static struct fio_option options[] = {
36 .off1 = offsetof(struct filestat_options, stat_type),
37 .help = "Specify stat system call type to measure lookup/getattr performance",
41 .oval = FIO_FILESTAT_STAT,
42 .help = "Use stat(2)",
45 .oval = FIO_FILESTAT_LSTAT,
46 .help = "Use lstat(2)",
50 .oval = FIO_FILESTAT_STATX,
51 .help = "Use statx(2)",
55 .category = FIO_OPT_C_ENGINE,
56 .group = FIO_OPT_G_FILESTAT,
63 static int stat_file(struct thread_data *td, struct fio_file *f)
65 struct filestat_options *o = td->eo;
66 struct timespec start;
67 int do_lat = !td->o.disable_lat;
71 dprint(FD_FILE, "fd stat %s\n", f->file_name);
73 if (f->filetype != FIO_TYPE_FILE) {
74 log_err("fio: only files are supported\n");
77 if (!strcmp(f->file_name, "-")) {
78 log_err("fio: can't read/write to stdin/out\n");
83 fio_gettime(&start, NULL);
85 switch (o->stat_type){
86 case FIO_FILESTAT_STAT:
87 ret = stat(f->file_name, &statbuf);
89 case FIO_FILESTAT_LSTAT:
90 ret = lstat(f->file_name, &statbuf);
98 char buf[FIO_VERROR_SIZE];
101 snprintf(buf, sizeof(buf), "stat(%s) type=%u", f->file_name,
103 td_verror(td, e, buf);
108 struct fc_data *data = td->io_ops_data;
111 nsec = ntime_since_now(&start);
112 add_clat_sample(td, data->stat_ddir, nsec, 0, 0, 0);
118 static enum fio_q_status queue_io(struct thread_data *td, struct io_u fio_unused *io_u)
120 return FIO_Q_COMPLETED;
123 static int init(struct thread_data *td)
125 struct fc_data *data;
127 data = calloc(1, sizeof(*data));
130 data->stat_ddir = DDIR_READ;
131 else if (td_write(td))
132 data->stat_ddir = DDIR_WRITE;
134 td->io_ops_data = data;
138 static void cleanup(struct thread_data *td)
140 struct fc_data *data = td->io_ops_data;
145 static int stat_invalidate(struct thread_data *td, struct fio_file *f)
147 /* do nothing because file not opened */
151 static struct ioengine_ops ioengine = {
153 .version = FIO_IOOPS_VERSION,
157 .invalidate = stat_invalidate,
158 .get_file_size = generic_get_file_size,
159 .open_file = stat_file,
160 .flags = FIO_SYNCIO | FIO_FAKEIO |
161 FIO_NOSTATS | FIO_NOFILEHASH,
163 .option_struct_size = sizeof(struct filestat_options),
166 static void fio_init fio_filestat_register(void)
168 register_ioengine(&ioengine);
171 static void fio_exit fio_filestat_unregister(void)
173 unregister_ioengine(&ioengine);