blob: 3af56682c64eaeecbd35e19c753cb315ecabec80 [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 /*
Jens Axboe3c568232013-09-30 12:17:34 -060053 * If we fail extending the log, stop collecting more entries.
54 */
55 unsigned int disabled;
56
57 /*
Jens Axboeb8bc8cb2011-12-01 09:04:31 +010058 * Windowed average, for logging single entries average over some
59 * period of time.
60 */
Shaohua Li6eaf09d2012-09-14 08:49:43 +020061 struct io_stat avg_window[DDIR_RWDIR_CNT];
Jens Axboeb8bc8cb2011-12-01 09:04:31 +010062 unsigned long avg_msec;
63 unsigned long avg_last;
Jens Axboe5995a6a2009-06-03 08:53:28 +020064};
65
Jens Axboe0d29de82010-09-01 13:54:15 +020066enum {
67 IP_F_ONRB = 1,
68 IP_F_ONLIST = 2,
69 IP_F_TRIMMED = 4,
Jens Axboef9401282014-02-06 12:17:37 -070070 IP_F_IN_FLIGHT = 8,
Jens Axboe0d29de82010-09-01 13:54:15 +020071};
72
Jens Axboe5995a6a2009-06-03 08:53:28 +020073/*
74 * When logging io actions, this matches a single sent io_u
75 */
76struct io_piece {
77 union {
78 struct rb_node rb_node;
79 struct flist_head list;
80 };
Jens Axboe0d29de82010-09-01 13:54:15 +020081 struct flist_head trim_list;
Jens Axboe5995a6a2009-06-03 08:53:28 +020082 union {
83 int fileno;
84 struct fio_file *file;
85 };
86 unsigned long long offset;
Juan Casseda0a7bd2013-09-17 14:06:12 -070087 unsigned short numberio;
Jens Axboe5995a6a2009-06-03 08:53:28 +020088 unsigned long len;
Jens Axboea917a8b2010-09-02 13:23:20 +020089 unsigned int flags;
Jens Axboe5995a6a2009-06-03 08:53:28 +020090 enum fio_ddir ddir;
91 union {
92 unsigned long delay;
93 unsigned int file_action;
94 };
95};
96
97/*
98 * Log exports
99 */
100enum file_log_act {
101 FIO_LOG_ADD_FILE,
102 FIO_LOG_OPEN_FILE,
103 FIO_LOG_CLOSE_FILE,
104 FIO_LOG_UNLINK_FILE,
105};
106
Jens Axboe8062f522013-04-10 15:01:42 +0200107struct io_u;
Jens Axboe5995a6a2009-06-03 08:53:28 +0200108extern int __must_check read_iolog_get(struct thread_data *, struct io_u *);
109extern void log_io_u(struct thread_data *, struct io_u *);
110extern void log_file(struct thread_data *, struct fio_file *, enum file_log_act);
111extern int __must_check init_iolog(struct thread_data *td);
112extern void log_io_piece(struct thread_data *, struct io_u *);
Jens Axboe890b6652014-05-06 19:06:51 -0600113extern void unlog_io_piece(struct thread_data *, struct io_u *);
114extern void trim_io_piece(struct thread_data *, struct io_u *);
Jens Axboe5995a6a2009-06-03 08:53:28 +0200115extern void queue_io_piece(struct thread_data *, struct io_piece *);
116extern void prune_io_piece_log(struct thread_data *);
117extern void write_iolog_close(struct thread_data *);
118
119/*
120 * Logging
121 */
Peter Oberparleiter99007062014-02-20 14:20:05 +0100122extern void finalize_logs(struct thread_data *td);
Jens Axboe02af0982010-06-24 09:59:34 +0200123extern void add_lat_sample(struct thread_data *, enum fio_ddir, unsigned long,
124 unsigned int);
Jens Axboe5995a6a2009-06-03 08:53:28 +0200125extern void add_clat_sample(struct thread_data *, enum fio_ddir, unsigned long,
126 unsigned int);
127extern void add_slat_sample(struct thread_data *, enum fio_ddir, unsigned long,
128 unsigned int);
129extern void add_bw_sample(struct thread_data *, enum fio_ddir, unsigned int,
130 struct timeval *);
Erwan Velu9b7e6002013-08-02 16:39:40 +0200131extern void add_iops_sample(struct thread_data *, enum fio_ddir, unsigned int,
132 struct timeval *);
Jens Axboe5995a6a2009-06-03 08:53:28 +0200133extern void init_disk_util(struct thread_data *);
134extern void update_rusage_stat(struct thread_data *);
Jens Axboeea51b952012-03-14 11:39:13 +0100135extern void setup_log(struct io_log **, unsigned long, int);
Jens Axboe5995a6a2009-06-03 08:53:28 +0200136extern void __finish_log(struct io_log *, const char *);
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200137extern struct io_log *agg_io_log[DDIR_RWDIR_CNT];
Jens Axboe5995a6a2009-06-03 08:53:28 +0200138extern int write_bw_log;
139extern void add_agg_sample(unsigned long, enum fio_ddir, unsigned int);
Jens Axboe905e3d42014-04-02 20:01:27 -0600140extern void fio_writeout_logs(struct thread_data *);
Jens Axboe5995a6a2009-06-03 08:53:28 +0200141
Jens Axboe0d29de82010-09-01 13:54:15 +0200142static inline void init_ipo(struct io_piece *ipo)
143{
144 memset(ipo, 0, sizeof(*ipo));
145 INIT_FLIST_HEAD(&ipo->trim_list);
146}
147
Jens Axboe5995a6a2009-06-03 08:53:28 +0200148#endif