4 #include "lib/rbtree.h"
5 #include "lib/ieee754.h"
10 * Use for maintaining statistics
22 * A single data sample
31 struct io_sample_offset {
44 #define DEF_LOG_ENTRIES 1024
45 #define MAX_LOG_ENTRIES (1024 * DEF_LOG_ENTRIES)
47 #define LOG_QUIESCE_SZ (64 * 1024 * 1024)
50 struct flist_head list;
57 * Dynamically growing data sample log
61 * Entries already logged
63 struct flist_head io_logs;
67 * When the current log runs out of space, store events here until
68 * we have a chance to regrow
70 struct io_logs *pending;
72 unsigned int log_ddir_mask;
76 struct thread_data *td;
78 unsigned int log_type;
81 * If we fail extending the log, stop collecting more entries.
88 unsigned int log_offset;
91 * Max size of log entries before a chunk is compressed
96 * Don't deflate for storing, just store the compressed bits
98 unsigned int log_gz_store;
101 * Windowed average, for logging single entries average over some
104 struct io_stat avg_window[DDIR_RWDIR_CNT];
105 unsigned long avg_msec;
106 unsigned long avg_last;
108 pthread_mutex_t chunk_lock;
109 unsigned int chunk_seq;
110 struct flist_head chunk_list;
114 * If the upper bit is set, then we have the offset as well
116 #define LOG_OFFSET_SAMPLE_BIT 0x80000000U
117 #define io_sample_ddir(io) ((io)->__ddir & ~LOG_OFFSET_SAMPLE_BIT)
119 static inline void io_sample_set_ddir(struct io_log *log,
120 struct io_sample *io,
123 io->__ddir = ddir | log->log_ddir_mask;
126 static inline size_t __log_entry_sz(int log_offset)
129 return sizeof(struct io_sample_offset);
131 return sizeof(struct io_sample);
134 static inline size_t log_entry_sz(struct io_log *log)
136 return __log_entry_sz(log->log_offset);
139 static inline struct io_sample *__get_sample(void *samples, int log_offset,
142 uint64_t sample_offset = sample * __log_entry_sz(log_offset);
143 return (struct io_sample *) ((char *) samples + sample_offset);
146 struct io_logs *iolog_cur_log(struct io_log *);
147 uint64_t iolog_nr_samples(struct io_log *);
148 void regrow_logs(struct thread_data *);
150 static inline struct io_sample *get_sample(struct io_log *iolog,
151 struct io_logs *cur_log,
154 return __get_sample(cur_log->log, iolog->log_offset, sample);
165 * When logging io actions, this matches a single sent io_u
169 struct rb_node rb_node;
170 struct flist_head list;
172 struct flist_head trim_list;
175 struct fio_file *file;
177 unsigned long long offset;
178 unsigned short numberio;
184 unsigned int file_action;
199 extern int __must_check read_iolog_get(struct thread_data *, struct io_u *);
200 extern void log_io_u(const struct thread_data *, const struct io_u *);
201 extern void log_file(struct thread_data *, struct fio_file *, enum file_log_act);
202 extern int __must_check init_iolog(struct thread_data *td);
203 extern void log_io_piece(struct thread_data *, struct io_u *);
204 extern void unlog_io_piece(struct thread_data *, struct io_u *);
205 extern void trim_io_piece(struct thread_data *, const struct io_u *);
206 extern void queue_io_piece(struct thread_data *, struct io_piece *);
207 extern void prune_io_piece_log(struct thread_data *);
208 extern void write_iolog_close(struct thread_data *);
209 extern int iolog_compress_init(struct thread_data *, struct sk_out *);
210 extern void iolog_compress_exit(struct thread_data *);
211 extern size_t log_chunk_sizes(struct io_log *);
214 extern int iolog_file_inflate(const char *);
221 struct thread_data *td;
222 unsigned long avg_msec;
230 static inline bool per_unit_log(struct io_log *log)
232 return log && !log->avg_msec;
235 extern void finalize_logs(struct thread_data *td, bool);
236 extern void setup_log(struct io_log **, struct log_params *, const char *);
237 extern void flush_log(struct io_log *, int);
238 extern void flush_samples(FILE *, void *, uint64_t);
239 extern void free_log(struct io_log *);
240 extern void fio_writeout_logs(bool);
241 extern void td_writeout_logs(struct thread_data *, bool);
242 extern int iolog_cur_flush(struct io_log *, struct io_logs *);
244 static inline void init_ipo(struct io_piece *ipo)
246 memset(ipo, 0, sizeof(*ipo));
247 INIT_FLIST_HEAD(&ipo->trim_list);
250 struct iolog_compress {
251 struct flist_head list;