Commit | Line | Data |
---|---|---|
5995a6a4 JA |
1 | #ifndef FIO_IOLOG_H |
2 | #define FIO_IOLOG_H | |
3 | ||
05775438 | 4 | #include "lib/rbtree.h" |
c7c6cb4c | 5 | #include "lib/ieee754.h" |
836fcc0f | 6 | #include "flist.h" |
ec41265e | 7 | #include "ioengine.h" |
802ad4a8 | 8 | |
5995a6a4 JA |
9 | /* |
10 | * Use for maintaining statistics | |
11 | */ | |
12 | struct io_stat { | |
7b9f733a JA |
13 | uint64_t max_val; |
14 | uint64_t min_val; | |
15 | uint64_t samples; | |
5995a6a4 | 16 | |
802ad4a8 JA |
17 | fio_fp64_t mean; |
18 | fio_fp64_t S; | |
5995a6a4 JA |
19 | }; |
20 | ||
21 | /* | |
22 | * A single data sample | |
23 | */ | |
24 | struct io_sample { | |
1b42725f JA |
25 | uint64_t time; |
26 | uint64_t val; | |
27 | uint32_t ddir; | |
28 | uint32_t bs; | |
5995a6a4 JA |
29 | }; |
30 | ||
ae588852 JA |
31 | struct io_sample_offset { |
32 | struct io_sample s; | |
33 | uint64_t offset; | |
34 | }; | |
35 | ||
ea51b956 JA |
36 | enum { |
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 | ||
5995a6a4 JA |
44 | /* |
45 | * Dynamically growing data sample log | |
46 | */ | |
47 | struct io_log { | |
b8bc8cba JA |
48 | /* |
49 | * Entries already logged | |
50 | */ | |
3c865f32 JA |
51 | uint64_t nr_samples; |
52 | uint64_t max_samples; | |
ae588852 | 53 | void *log; |
b8bc8cba | 54 | |
cb7e0ace JA |
55 | char *filename; |
56 | ||
aee2ab67 JA |
57 | struct thread_data *td; |
58 | ||
1b42725f | 59 | unsigned int log_type; |
ea51b956 | 60 | |
3c568239 JA |
61 | /* |
62 | * If we fail extending the log, stop collecting more entries. | |
63 | */ | |
64 | unsigned int disabled; | |
65 | ||
ae588852 JA |
66 | /* |
67 | * Log offsets | |
68 | */ | |
69 | unsigned int log_offset; | |
70 | ||
aee2ab67 JA |
71 | /* |
72 | * Max size of log entries before a chunk is compressed | |
73 | */ | |
74 | unsigned int log_gz; | |
75 | ||
b8bc8cba JA |
76 | /* |
77 | * Windowed average, for logging single entries average over some | |
78 | * period of time. | |
79 | */ | |
6eaf09d6 | 80 | struct io_stat avg_window[DDIR_RWDIR_CNT]; |
b8bc8cba JA |
81 | unsigned long avg_msec; |
82 | unsigned long avg_last; | |
aee2ab67 JA |
83 | |
84 | pthread_mutex_t chunk_lock; | |
85 | unsigned int chunk_seq; | |
86 | struct flist_head chunk_list; | |
5995a6a4 JA |
87 | }; |
88 | ||
ae588852 JA |
89 | static 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 | ||
97 | static inline size_t log_entry_sz(struct io_log *log) | |
98 | { | |
99 | return __log_entry_sz(log->log_offset); | |
100 | } | |
101 | ||
102 | static 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 | ||
108 | static 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 | ||
0d29de83 JA |
114 | enum { |
115 | IP_F_ONRB = 1, | |
116 | IP_F_ONLIST = 2, | |
117 | IP_F_TRIMMED = 4, | |
f9401285 | 118 | IP_F_IN_FLIGHT = 8, |
0d29de83 JA |
119 | }; |
120 | ||
5995a6a4 JA |
121 | /* |
122 | * When logging io actions, this matches a single sent io_u | |
123 | */ | |
124 | struct io_piece { | |
125 | union { | |
126 | struct rb_node rb_node; | |
127 | struct flist_head list; | |
128 | }; | |
0d29de83 | 129 | struct flist_head trim_list; |
5995a6a4 JA |
130 | union { |
131 | int fileno; | |
132 | struct fio_file *file; | |
133 | }; | |
134 | unsigned long long offset; | |
da0a7bd2 | 135 | unsigned short numberio; |
5995a6a4 | 136 | unsigned long len; |
a917a8b3 | 137 | unsigned int flags; |
5995a6a4 JA |
138 | enum fio_ddir ddir; |
139 | union { | |
140 | unsigned long delay; | |
141 | unsigned int file_action; | |
142 | }; | |
143 | }; | |
144 | ||
145 | /* | |
146 | * Log exports | |
147 | */ | |
148 | enum 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 | ||
8062f527 | 155 | struct io_u; |
5995a6a4 JA |
156 | extern int __must_check read_iolog_get(struct thread_data *, struct io_u *); |
157 | extern void log_io_u(struct thread_data *, struct io_u *); | |
158 | extern void log_file(struct thread_data *, struct fio_file *, enum file_log_act); | |
159 | extern int __must_check init_iolog(struct thread_data *td); | |
160 | extern void log_io_piece(struct thread_data *, struct io_u *); | |
890b6656 JA |
161 | extern void unlog_io_piece(struct thread_data *, struct io_u *); |
162 | extern void trim_io_piece(struct thread_data *, struct io_u *); | |
5995a6a4 JA |
163 | extern void queue_io_piece(struct thread_data *, struct io_piece *); |
164 | extern void prune_io_piece_log(struct thread_data *); | |
165 | extern void write_iolog_close(struct thread_data *); | |
166 | ||
167 | /* | |
168 | * Logging | |
169 | */ | |
aee2ab67 JA |
170 | struct 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 | ||
99007068 | 179 | extern void finalize_logs(struct thread_data *td); |
02af0988 | 180 | extern void add_lat_sample(struct thread_data *, enum fio_ddir, unsigned long, |
ae588852 | 181 | unsigned int, uint64_t); |
5995a6a4 | 182 | extern void add_clat_sample(struct thread_data *, enum fio_ddir, unsigned long, |
ae588852 | 183 | unsigned int, uint64_t); |
5995a6a4 | 184 | extern void add_slat_sample(struct thread_data *, enum fio_ddir, unsigned long, |
ae588852 | 185 | unsigned int, uint64_t); |
5995a6a4 JA |
186 | extern void add_bw_sample(struct thread_data *, enum fio_ddir, unsigned int, |
187 | struct timeval *); | |
9b7e600d EV |
188 | extern void add_iops_sample(struct thread_data *, enum fio_ddir, unsigned int, |
189 | struct timeval *); | |
5995a6a4 JA |
190 | extern void init_disk_util(struct thread_data *); |
191 | extern void update_rusage_stat(struct thread_data *); | |
aee2ab67 JA |
192 | extern void setup_log(struct io_log **, struct log_params *, const char *); |
193 | extern void flush_log(struct io_log *); | |
518dac09 | 194 | extern void free_log(struct io_log *); |
6eaf09d6 | 195 | extern struct io_log *agg_io_log[DDIR_RWDIR_CNT]; |
5995a6a4 JA |
196 | extern int write_bw_log; |
197 | extern void add_agg_sample(unsigned long, enum fio_ddir, unsigned int); | |
905e3d4f | 198 | extern void fio_writeout_logs(struct thread_data *); |
aee2ab67 | 199 | extern int iolog_flush(struct io_log *, int); |
5995a6a4 | 200 | |
0d29de83 JA |
201 | static inline void init_ipo(struct io_piece *ipo) |
202 | { | |
203 | memset(ipo, 0, sizeof(*ipo)); | |
204 | INIT_FLIST_HEAD(&ipo->trim_list); | |
205 | } | |
206 | ||
5995a6a4 | 207 | #endif |