fio.1 - escape the escape character so it shows up
[fio.git] / iolog.h
... / ...
CommitLineData
1#ifndef FIO_IOLOG_H
2#define FIO_IOLOG_H
3
4#include "lib/rbtree.h"
5#include "lib/ieee754.h"
6#include "flist.h"
7#include "ioengine.h"
8
9/*
10 * Use for maintaining statistics
11 */
12struct io_stat {
13 uint64_t max_val;
14 uint64_t min_val;
15 uint64_t samples;
16
17 fio_fp64_t mean;
18 fio_fp64_t S;
19};
20
21/*
22 * A single data sample
23 */
24struct io_sample {
25 uint64_t time;
26 uint64_t val;
27 uint32_t ddir;
28 uint32_t bs;
29};
30
31struct io_sample_offset {
32 struct io_sample s;
33 uint64_t offset;
34};
35
36enum {
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
44/*
45 * Dynamically growing data sample log
46 */
47struct io_log {
48 /*
49 * Entries already logged
50 */
51 uint64_t nr_samples;
52 uint64_t max_samples;
53 void *log;
54
55 char *filename;
56
57 struct thread_data *td;
58
59 unsigned int log_type;
60
61 /*
62 * If we fail extending the log, stop collecting more entries.
63 */
64 unsigned int disabled;
65
66 /*
67 * Log offsets
68 */
69 unsigned int log_offset;
70
71 /*
72 * Max size of log entries before a chunk is compressed
73 */
74 unsigned int log_gz;
75
76 /*
77 * Windowed average, for logging single entries average over some
78 * period of time.
79 */
80 struct io_stat avg_window[DDIR_RWDIR_CNT];
81 unsigned long avg_msec;
82 unsigned long avg_last;
83
84 pthread_mutex_t chunk_lock;
85 unsigned int chunk_seq;
86 struct flist_head chunk_list;
87};
88
89static 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
114enum {
115 IP_F_ONRB = 1,
116 IP_F_ONLIST = 2,
117 IP_F_TRIMMED = 4,
118 IP_F_IN_FLIGHT = 8,
119};
120
121/*
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 };
129 struct flist_head trim_list;
130 union {
131 int fileno;
132 struct fio_file *file;
133 };
134 unsigned long long offset;
135 unsigned short numberio;
136 unsigned long len;
137 unsigned int flags;
138 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
155struct io_u;
156extern 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 *);
161extern void unlog_io_piece(struct thread_data *, struct io_u *);
162extern void trim_io_piece(struct thread_data *, struct io_u *);
163extern 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 */
170struct 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
179extern void finalize_logs(struct thread_data *td);
180extern void add_lat_sample(struct thread_data *, enum fio_ddir, unsigned long,
181 unsigned int, uint64_t);
182extern void add_clat_sample(struct thread_data *, enum fio_ddir, unsigned long,
183 unsigned int, uint64_t);
184extern void add_slat_sample(struct thread_data *, enum fio_ddir, unsigned long,
185 unsigned int, uint64_t);
186extern void add_bw_sample(struct thread_data *, enum fio_ddir, unsigned int,
187 struct timeval *);
188extern void add_iops_sample(struct thread_data *, enum fio_ddir, unsigned int,
189 struct timeval *);
190extern void init_disk_util(struct thread_data *);
191extern void update_rusage_stat(struct thread_data *);
192extern void setup_log(struct io_log **, struct log_params *, const char *);
193extern void flush_log(struct io_log *);
194extern void free_log(struct io_log *);
195extern struct io_log *agg_io_log[DDIR_RWDIR_CNT];
196extern int write_bw_log;
197extern void add_agg_sample(unsigned long, enum fio_ddir, unsigned int);
198extern void fio_writeout_logs(struct thread_data *);
199extern int iolog_flush(struct io_log *, int);
200
201static inline void init_ipo(struct io_piece *ipo)
202{
203 memset(ipo, 0, sizeof(*ipo));
204 INIT_FLIST_HEAD(&ipo->trim_list);
205}
206
207#endif