blob: 70990975f132578a5c2d949a15341d9be7de1be0 [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 Axboeea51b952012-03-14 11:39:13 +010031enum {
32 IO_LOG_TYPE_LAT = 1,
33 IO_LOG_TYPE_CLAT,
34 IO_LOG_TYPE_SLAT,
35 IO_LOG_TYPE_BW,
36 IO_LOG_TYPE_IOPS,
37};
38
Jens Axboe5995a6a2009-06-03 08:53:28 +020039/*
40 * Dynamically growing data sample log
41 */
42struct io_log {
Jens Axboeb8bc8cb2011-12-01 09:04:31 +010043 /*
44 * Entries already logged
45 */
Jens Axboe5995a6a2009-06-03 08:53:28 +020046 unsigned long nr_samples;
47 unsigned long max_samples;
48 struct io_sample *log;
Jens Axboeb8bc8cb2011-12-01 09:04:31 +010049
Jens Axboe1b427252012-03-14 15:03:03 +010050 unsigned int log_type;
Jens Axboeea51b952012-03-14 11:39:13 +010051
Jens Axboeb8bc8cb2011-12-01 09:04:31 +010052 /*
53 * Windowed average, for logging single entries average over some
54 * period of time.
55 */
Shaohua Li6eaf09d2012-09-14 08:49:43 +020056 struct io_stat avg_window[DDIR_RWDIR_CNT];
Jens Axboeb8bc8cb2011-12-01 09:04:31 +010057 unsigned long avg_msec;
58 unsigned long avg_last;
Jens Axboe5995a6a2009-06-03 08:53:28 +020059};
60
Jens Axboe0d29de82010-09-01 13:54:15 +020061enum {
62 IP_F_ONRB = 1,
63 IP_F_ONLIST = 2,
64 IP_F_TRIMMED = 4,
65};
66
Jens Axboe5995a6a2009-06-03 08:53:28 +020067/*
68 * When logging io actions, this matches a single sent io_u
69 */
70struct io_piece {
71 union {
72 struct rb_node rb_node;
73 struct flist_head list;
74 };
Jens Axboe0d29de82010-09-01 13:54:15 +020075 struct flist_head trim_list;
Jens Axboe5995a6a2009-06-03 08:53:28 +020076 union {
77 int fileno;
78 struct fio_file *file;
79 };
80 unsigned long long offset;
81 unsigned long len;
Jens Axboea917a8b2010-09-02 13:23:20 +020082 unsigned int flags;
Jens Axboe5995a6a2009-06-03 08:53:28 +020083 enum fio_ddir ddir;
84 union {
85 unsigned long delay;
86 unsigned int file_action;
87 };
88};
89
90/*
91 * Log exports
92 */
93enum file_log_act {
94 FIO_LOG_ADD_FILE,
95 FIO_LOG_OPEN_FILE,
96 FIO_LOG_CLOSE_FILE,
97 FIO_LOG_UNLINK_FILE,
98};
99
Jens Axboe8062f522013-04-10 15:01:42 +0200100struct io_u;
Jens Axboe5995a6a2009-06-03 08:53:28 +0200101extern int __must_check read_iolog_get(struct thread_data *, struct io_u *);
102extern void log_io_u(struct thread_data *, struct io_u *);
103extern void log_file(struct thread_data *, struct fio_file *, enum file_log_act);
104extern int __must_check init_iolog(struct thread_data *td);
105extern void log_io_piece(struct thread_data *, struct io_u *);
106extern void queue_io_piece(struct thread_data *, struct io_piece *);
107extern void prune_io_piece_log(struct thread_data *);
108extern void write_iolog_close(struct thread_data *);
109
110/*
111 * Logging
112 */
Jens Axboe02af0982010-06-24 09:59:34 +0200113extern void add_lat_sample(struct thread_data *, enum fio_ddir, unsigned long,
114 unsigned int);
Jens Axboe5995a6a2009-06-03 08:53:28 +0200115extern void add_clat_sample(struct thread_data *, enum fio_ddir, unsigned long,
116 unsigned int);
117extern void add_slat_sample(struct thread_data *, enum fio_ddir, unsigned long,
118 unsigned int);
119extern void add_bw_sample(struct thread_data *, enum fio_ddir, unsigned int,
120 struct timeval *);
Jens Axboec8eeb9d2011-10-05 14:02:22 +0200121extern void add_iops_sample(struct thread_data *, enum fio_ddir, struct timeval *);
Jens Axboe5995a6a2009-06-03 08:53:28 +0200122extern void init_disk_util(struct thread_data *);
123extern void update_rusage_stat(struct thread_data *);
Jens Axboeea51b952012-03-14 11:39:13 +0100124extern void setup_log(struct io_log **, unsigned long, int);
Jens Axboe5995a6a2009-06-03 08:53:28 +0200125extern void finish_log(struct thread_data *, struct io_log *, const char *);
126extern void finish_log_named(struct thread_data *, struct io_log *, const char *, const char *);
127extern void __finish_log(struct io_log *, const char *);
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200128extern struct io_log *agg_io_log[DDIR_RWDIR_CNT];
Jens Axboe5995a6a2009-06-03 08:53:28 +0200129extern int write_bw_log;
130extern void add_agg_sample(unsigned long, enum fio_ddir, unsigned int);
131
Jens Axboe0d29de82010-09-01 13:54:15 +0200132static inline void init_ipo(struct io_piece *ipo)
133{
134 memset(ipo, 0, sizeof(*ipo));
135 INIT_FLIST_HEAD(&ipo->trim_list);
136}
137
Jens Axboe5995a6a2009-06-03 08:53:28 +0200138#endif