blob: 66c596e92ff8bc77edde7c072f451156a46a5228 [file] [log] [blame]
Jens Axboe5995a6a2009-06-03 08:53:28 +02001#ifndef FIO_IOLOG_H
2#define FIO_IOLOG_H
3
Jens Axboe05775432012-03-21 14:07:11 +01004#include "lib/rbtree.h"
Jens Axboec7c6cb42011-10-13 14:12:40 +02005#include "lib/ieee754.h"
Jens Axboe836fcc02013-01-24 09:08:45 -07006#include "flist.h"
Jens Axboeec412652012-03-08 12:37:31 +01007#include "ioengine.h"
Jens Axboe802ad4a2011-10-05 09:51:58 +02008
Jens Axboe5995a6a2009-06-03 08:53:28 +02009/*
10 * Use for maintaining statistics
11 */
12struct io_stat {
Jens Axboe7b9f7332011-10-03 10:06:44 +020013 uint64_t max_val;
14 uint64_t min_val;
15 uint64_t samples;
Jens Axboe5995a6a2009-06-03 08:53:28 +020016
Jens Axboe802ad4a2011-10-05 09:51:58 +020017 fio_fp64_t mean;
18 fio_fp64_t S;
Jens Axboe5995a6a2009-06-03 08:53:28 +020019};
20
21/*
22 * A single data sample
23 */
24struct io_sample {
Jens Axboe1b427252012-03-14 15:03:03 +010025 uint64_t time;
26 uint64_t val;
27 uint32_t ddir;
28 uint32_t bs;
Jens Axboe5995a6a2009-06-03 08:53:28 +020029};
30
Jens Axboeccefd5f2014-06-30 20:59:03 -060031struct io_sample_offset {
32 struct io_sample s;
33 uint64_t offset;
34};
35
Jens Axboeea51b952012-03-14 11:39:13 +010036enum {
37 IO_LOG_TYPE_LAT = 1,
38 IO_LOG_TYPE_CLAT,
39 IO_LOG_TYPE_SLAT,
40 IO_LOG_TYPE_BW,
41 IO_LOG_TYPE_IOPS,
42};
43
Jens Axboe5995a6a2009-06-03 08:53:28 +020044/*
45 * Dynamically growing data sample log
46 */
47struct io_log {
Jens Axboeb8bc8cb2011-12-01 09:04:31 +010048 /*
49 * Entries already logged
50 */
Jens Axboef2b9a672014-07-01 08:47:11 -060051 uint64_t nr_samples;
52 uint64_t max_samples;
Jens Axboeccefd5f2014-06-30 20:59:03 -060053 void *log;
Jens Axboeb8bc8cb2011-12-01 09:04:31 +010054
Jens Axboe987c4f42014-07-01 16:29:12 -060055 char *filename;
56
Jens Axboe38a812d2014-07-03 09:10:39 -060057 struct thread_data *td;
58
Jens Axboe1b427252012-03-14 15:03:03 +010059 unsigned int log_type;
Jens Axboeea51b952012-03-14 11:39:13 +010060
Jens Axboeb8bc8cb2011-12-01 09:04:31 +010061 /*
Jens Axboe3c568232013-09-30 12:17:34 -060062 * If we fail extending the log, stop collecting more entries.
63 */
64 unsigned int disabled;
65
66 /*
Jens Axboeccefd5f2014-06-30 20:59:03 -060067 * Log offsets
68 */
69 unsigned int log_offset;
70
71 /*
Jens Axboe38a812d2014-07-03 09:10:39 -060072 * Max size of log entries before a chunk is compressed
73 */
74 unsigned int log_gz;
75
76 /*
Jens Axboeb8bc8cb2011-12-01 09:04:31 +010077 * Windowed average, for logging single entries average over some
78 * period of time.
79 */
Shaohua Li6eaf09d2012-09-14 08:49:43 +020080 struct io_stat avg_window[DDIR_RWDIR_CNT];
Jens Axboeb8bc8cb2011-12-01 09:04:31 +010081 unsigned long avg_msec;
82 unsigned long avg_last;
Jens Axboe38a812d2014-07-03 09:10:39 -060083
84 pthread_mutex_t chunk_lock;
85 unsigned int chunk_seq;
86 struct flist_head chunk_list;
Jens Axboe5995a6a2009-06-03 08:53:28 +020087};
88
Jens Axboeccefd5f2014-06-30 20:59:03 -060089static inline size_t __log_entry_sz(int log_offset)
90{
91 if (log_offset)
92 return sizeof(struct io_sample_offset);
93 else
94 return sizeof(struct io_sample);
95}
96
97static inline size_t log_entry_sz(struct io_log *log)
98{
99 return __log_entry_sz(log->log_offset);
100}
101
102static inline struct io_sample *__get_sample(void *samples, int log_offset,
103 uint64_t sample)
104{
105 return samples + sample * __log_entry_sz(log_offset);
106}
107
108static inline struct io_sample *get_sample(struct io_log *iolog,
109 uint64_t sample)
110{
111 return __get_sample(iolog->log, iolog->log_offset, sample);
112}
113
Jens Axboe0d29de82010-09-01 13:54:15 +0200114enum {
115 IP_F_ONRB = 1,
116 IP_F_ONLIST = 2,
117 IP_F_TRIMMED = 4,
Jens Axboef9401282014-02-06 12:17:37 -0700118 IP_F_IN_FLIGHT = 8,
Jens Axboe0d29de82010-09-01 13:54:15 +0200119};
120
Jens Axboe5995a6a2009-06-03 08:53:28 +0200121/*
122 * When logging io actions, this matches a single sent io_u
123 */
124struct io_piece {
125 union {
126 struct rb_node rb_node;
127 struct flist_head list;
128 };
Jens Axboe0d29de82010-09-01 13:54:15 +0200129 struct flist_head trim_list;
Jens Axboe5995a6a2009-06-03 08:53:28 +0200130 union {
131 int fileno;
132 struct fio_file *file;
133 };
134 unsigned long long offset;
Juan Casseda0a7bd2013-09-17 14:06:12 -0700135 unsigned short numberio;
Jens Axboe5995a6a2009-06-03 08:53:28 +0200136 unsigned long len;
Jens Axboea917a8b2010-09-02 13:23:20 +0200137 unsigned int flags;
Jens Axboe5995a6a2009-06-03 08:53:28 +0200138 enum fio_ddir ddir;
139 union {
140 unsigned long delay;
141 unsigned int file_action;
142 };
143};
144
145/*
146 * Log exports
147 */
148enum file_log_act {
149 FIO_LOG_ADD_FILE,
150 FIO_LOG_OPEN_FILE,
151 FIO_LOG_CLOSE_FILE,
152 FIO_LOG_UNLINK_FILE,
153};
154
Jens Axboe8062f522013-04-10 15:01:42 +0200155struct io_u;
Jens Axboe5995a6a2009-06-03 08:53:28 +0200156extern int __must_check read_iolog_get(struct thread_data *, struct io_u *);
157extern void log_io_u(struct thread_data *, struct io_u *);
158extern void log_file(struct thread_data *, struct fio_file *, enum file_log_act);
159extern int __must_check init_iolog(struct thread_data *td);
160extern void log_io_piece(struct thread_data *, struct io_u *);
Jens Axboe890b6652014-05-06 19:06:51 -0600161extern void unlog_io_piece(struct thread_data *, struct io_u *);
162extern void trim_io_piece(struct thread_data *, struct io_u *);
Jens Axboe5995a6a2009-06-03 08:53:28 +0200163extern void queue_io_piece(struct thread_data *, struct io_piece *);
164extern void prune_io_piece_log(struct thread_data *);
165extern void write_iolog_close(struct thread_data *);
166
167/*
168 * Logging
169 */
Jens Axboe38a812d2014-07-03 09:10:39 -0600170struct log_params {
171 struct thread_data *td;
172 unsigned long avg_msec;
173 int log_type;
174 int log_offset;
175 int log_gz;
176 int log_compress;
177};
178
Peter Oberparleiter99007062014-02-20 14:20:05 +0100179extern void finalize_logs(struct thread_data *td);
Jens Axboe02af0982010-06-24 09:59:34 +0200180extern void add_lat_sample(struct thread_data *, enum fio_ddir, unsigned long,
Jens Axboeccefd5f2014-06-30 20:59:03 -0600181 unsigned int, uint64_t);
Jens Axboe5995a6a2009-06-03 08:53:28 +0200182extern void add_clat_sample(struct thread_data *, enum fio_ddir, unsigned long,
Jens Axboeccefd5f2014-06-30 20:59:03 -0600183 unsigned int, uint64_t);
Jens Axboe5995a6a2009-06-03 08:53:28 +0200184extern void add_slat_sample(struct thread_data *, enum fio_ddir, unsigned long,
Jens Axboeccefd5f2014-06-30 20:59:03 -0600185 unsigned int, uint64_t);
Jens Axboe5995a6a2009-06-03 08:53:28 +0200186extern void add_bw_sample(struct thread_data *, enum fio_ddir, unsigned int,
187 struct timeval *);
Erwan Velu9b7e6002013-08-02 16:39:40 +0200188extern void add_iops_sample(struct thread_data *, enum fio_ddir, unsigned int,
189 struct timeval *);
Jens Axboe5995a6a2009-06-03 08:53:28 +0200190extern void init_disk_util(struct thread_data *);
191extern void update_rusage_stat(struct thread_data *);
Jens Axboe38a812d2014-07-03 09:10:39 -0600192extern void setup_log(struct io_log **, struct log_params *, const char *);
193extern void flush_log(struct io_log *);
Jens Axboe633d8252014-07-02 13:36:34 -0600194extern void free_log(struct io_log *);
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200195extern struct io_log *agg_io_log[DDIR_RWDIR_CNT];
Jens Axboe5995a6a2009-06-03 08:53:28 +0200196extern int write_bw_log;
197extern void add_agg_sample(unsigned long, enum fio_ddir, unsigned int);
Jens Axboe905e3d42014-04-02 20:01:27 -0600198extern void fio_writeout_logs(struct thread_data *);
Jens Axboe38a812d2014-07-03 09:10:39 -0600199extern int iolog_flush(struct io_log *, int);
Jens Axboe5995a6a2009-06-03 08:53:28 +0200200
Jens Axboe0d29de82010-09-01 13:54:15 +0200201static inline void init_ipo(struct io_piece *ipo)
202{
203 memset(ipo, 0, sizeof(*ipo));
204 INIT_FLIST_HEAD(&ipo->trim_list);
205}
206
Jens Axboe5995a6a2009-06-03 08:53:28 +0200207#endif