blob: 2c9b2b29cc7c5e6527ac3a251aa99a9394df59dd [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 Axboe1b427252012-03-14 15:03:03 +010057 unsigned int log_type;
Jens Axboeea51b952012-03-14 11:39:13 +010058
Jens Axboeb8bc8cb2011-12-01 09:04:31 +010059 /*
Jens Axboe3c568232013-09-30 12:17:34 -060060 * If we fail extending the log, stop collecting more entries.
61 */
62 unsigned int disabled;
63
64 /*
Jens Axboeccefd5f2014-06-30 20:59:03 -060065 * Log offsets
66 */
67 unsigned int log_offset;
68
69 /*
Jens Axboeb8bc8cb2011-12-01 09:04:31 +010070 * Windowed average, for logging single entries average over some
71 * period of time.
72 */
Shaohua Li6eaf09d2012-09-14 08:49:43 +020073 struct io_stat avg_window[DDIR_RWDIR_CNT];
Jens Axboeb8bc8cb2011-12-01 09:04:31 +010074 unsigned long avg_msec;
75 unsigned long avg_last;
Jens Axboe5995a6a2009-06-03 08:53:28 +020076};
77
Jens Axboeccefd5f2014-06-30 20:59:03 -060078static inline size_t __log_entry_sz(int log_offset)
79{
80 if (log_offset)
81 return sizeof(struct io_sample_offset);
82 else
83 return sizeof(struct io_sample);
84}
85
86static inline size_t log_entry_sz(struct io_log *log)
87{
88 return __log_entry_sz(log->log_offset);
89}
90
91static inline struct io_sample *__get_sample(void *samples, int log_offset,
92 uint64_t sample)
93{
94 return samples + sample * __log_entry_sz(log_offset);
95}
96
97static inline struct io_sample *get_sample(struct io_log *iolog,
98 uint64_t sample)
99{
100 return __get_sample(iolog->log, iolog->log_offset, sample);
101}
102
Jens Axboe0d29de82010-09-01 13:54:15 +0200103enum {
104 IP_F_ONRB = 1,
105 IP_F_ONLIST = 2,
106 IP_F_TRIMMED = 4,
Jens Axboef9401282014-02-06 12:17:37 -0700107 IP_F_IN_FLIGHT = 8,
Jens Axboe0d29de82010-09-01 13:54:15 +0200108};
109
Jens Axboe5995a6a2009-06-03 08:53:28 +0200110/*
111 * When logging io actions, this matches a single sent io_u
112 */
113struct io_piece {
114 union {
115 struct rb_node rb_node;
116 struct flist_head list;
117 };
Jens Axboe0d29de82010-09-01 13:54:15 +0200118 struct flist_head trim_list;
Jens Axboe5995a6a2009-06-03 08:53:28 +0200119 union {
120 int fileno;
121 struct fio_file *file;
122 };
123 unsigned long long offset;
Juan Casseda0a7bd2013-09-17 14:06:12 -0700124 unsigned short numberio;
Jens Axboe5995a6a2009-06-03 08:53:28 +0200125 unsigned long len;
Jens Axboea917a8b2010-09-02 13:23:20 +0200126 unsigned int flags;
Jens Axboe5995a6a2009-06-03 08:53:28 +0200127 enum fio_ddir ddir;
128 union {
129 unsigned long delay;
130 unsigned int file_action;
131 };
132};
133
134/*
135 * Log exports
136 */
137enum file_log_act {
138 FIO_LOG_ADD_FILE,
139 FIO_LOG_OPEN_FILE,
140 FIO_LOG_CLOSE_FILE,
141 FIO_LOG_UNLINK_FILE,
142};
143
Jens Axboe8062f522013-04-10 15:01:42 +0200144struct io_u;
Jens Axboe5995a6a2009-06-03 08:53:28 +0200145extern int __must_check read_iolog_get(struct thread_data *, struct io_u *);
146extern void log_io_u(struct thread_data *, struct io_u *);
147extern void log_file(struct thread_data *, struct fio_file *, enum file_log_act);
148extern int __must_check init_iolog(struct thread_data *td);
149extern void log_io_piece(struct thread_data *, struct io_u *);
Jens Axboe890b6652014-05-06 19:06:51 -0600150extern void unlog_io_piece(struct thread_data *, struct io_u *);
151extern void trim_io_piece(struct thread_data *, struct io_u *);
Jens Axboe5995a6a2009-06-03 08:53:28 +0200152extern void queue_io_piece(struct thread_data *, struct io_piece *);
153extern void prune_io_piece_log(struct thread_data *);
154extern void write_iolog_close(struct thread_data *);
155
156/*
157 * Logging
158 */
Peter Oberparleiter99007062014-02-20 14:20:05 +0100159extern void finalize_logs(struct thread_data *td);
Jens Axboe02af0982010-06-24 09:59:34 +0200160extern void add_lat_sample(struct thread_data *, enum fio_ddir, unsigned long,
Jens Axboeccefd5f2014-06-30 20:59:03 -0600161 unsigned int, uint64_t);
Jens Axboe5995a6a2009-06-03 08:53:28 +0200162extern void add_clat_sample(struct thread_data *, enum fio_ddir, unsigned long,
Jens Axboeccefd5f2014-06-30 20:59:03 -0600163 unsigned int, uint64_t);
Jens Axboe5995a6a2009-06-03 08:53:28 +0200164extern void add_slat_sample(struct thread_data *, enum fio_ddir, unsigned long,
Jens Axboeccefd5f2014-06-30 20:59:03 -0600165 unsigned int, uint64_t);
Jens Axboe5995a6a2009-06-03 08:53:28 +0200166extern void add_bw_sample(struct thread_data *, enum fio_ddir, unsigned int,
167 struct timeval *);
Erwan Velu9b7e6002013-08-02 16:39:40 +0200168extern void add_iops_sample(struct thread_data *, enum fio_ddir, unsigned int,
169 struct timeval *);
Jens Axboe5995a6a2009-06-03 08:53:28 +0200170extern void init_disk_util(struct thread_data *);
171extern void update_rusage_stat(struct thread_data *);
Jens Axboe987c4f42014-07-01 16:29:12 -0600172extern void setup_log(struct io_log **, unsigned long, int, int, const char *);
173extern void __finish_log(struct io_log *);
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200174extern struct io_log *agg_io_log[DDIR_RWDIR_CNT];
Jens Axboe5995a6a2009-06-03 08:53:28 +0200175extern int write_bw_log;
176extern void add_agg_sample(unsigned long, enum fio_ddir, unsigned int);
Jens Axboe905e3d42014-04-02 20:01:27 -0600177extern void fio_writeout_logs(struct thread_data *);
Jens Axboe5995a6a2009-06-03 08:53:28 +0200178
Jens Axboe0d29de82010-09-01 13:54:15 +0200179static inline void init_ipo(struct io_piece *ipo)
180{
181 memset(ipo, 0, sizeof(*ipo));
182 INIT_FLIST_HEAD(&ipo->trim_list);
183}
184
Jens Axboe5995a6a2009-06-03 08:53:28 +0200185#endif