blob: 6503acffd10659b2ff4e5d5f187b9d5c516de28b [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,
70};
71
Jens Axboe5995a6a2009-06-03 08:53:28 +020072/*
73 * When logging io actions, this matches a single sent io_u
74 */
75struct io_piece {
76 union {
77 struct rb_node rb_node;
78 struct flist_head list;
79 };
Jens Axboe0d29de82010-09-01 13:54:15 +020080 struct flist_head trim_list;
Jens Axboe5995a6a2009-06-03 08:53:28 +020081 union {
82 int fileno;
83 struct fio_file *file;
84 };
85 unsigned long long offset;
86 unsigned long len;
Jens Axboea917a8b2010-09-02 13:23:20 +020087 unsigned int flags;
Jens Axboe5995a6a2009-06-03 08:53:28 +020088 enum fio_ddir ddir;
89 union {
90 unsigned long delay;
91 unsigned int file_action;
92 };
93};
94
95/*
96 * Log exports
97 */
98enum file_log_act {
99 FIO_LOG_ADD_FILE,
100 FIO_LOG_OPEN_FILE,
101 FIO_LOG_CLOSE_FILE,
102 FIO_LOG_UNLINK_FILE,
103};
104
Jens Axboe8062f522013-04-10 15:01:42 +0200105struct io_u;
Jens Axboe5995a6a2009-06-03 08:53:28 +0200106extern int __must_check read_iolog_get(struct thread_data *, struct io_u *);
107extern void log_io_u(struct thread_data *, struct io_u *);
108extern void log_file(struct thread_data *, struct fio_file *, enum file_log_act);
109extern int __must_check init_iolog(struct thread_data *td);
110extern void log_io_piece(struct thread_data *, struct io_u *);
111extern void queue_io_piece(struct thread_data *, struct io_piece *);
112extern void prune_io_piece_log(struct thread_data *);
113extern void write_iolog_close(struct thread_data *);
114
115/*
116 * Logging
117 */
Jens Axboe02af0982010-06-24 09:59:34 +0200118extern void add_lat_sample(struct thread_data *, enum fio_ddir, unsigned long,
119 unsigned int);
Jens Axboe5995a6a2009-06-03 08:53:28 +0200120extern void add_clat_sample(struct thread_data *, enum fio_ddir, unsigned long,
121 unsigned int);
122extern void add_slat_sample(struct thread_data *, enum fio_ddir, unsigned long,
123 unsigned int);
124extern void add_bw_sample(struct thread_data *, enum fio_ddir, unsigned int,
125 struct timeval *);
Erwan Velu9b7e6002013-08-02 16:39:40 +0200126extern void add_iops_sample(struct thread_data *, enum fio_ddir, unsigned int,
127 struct timeval *);
Jens Axboe5995a6a2009-06-03 08:53:28 +0200128extern void init_disk_util(struct thread_data *);
129extern void update_rusage_stat(struct thread_data *);
Jens Axboeea51b952012-03-14 11:39:13 +0100130extern void setup_log(struct io_log **, unsigned long, int);
Jens Axboe5995a6a2009-06-03 08:53:28 +0200131extern void finish_log(struct thread_data *, struct io_log *, const char *);
132extern void finish_log_named(struct thread_data *, struct io_log *, const char *, const char *);
133extern void __finish_log(struct io_log *, const char *);
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200134extern struct io_log *agg_io_log[DDIR_RWDIR_CNT];
Jens Axboe5995a6a2009-06-03 08:53:28 +0200135extern int write_bw_log;
136extern void add_agg_sample(unsigned long, enum fio_ddir, unsigned int);
137
Jens Axboe0d29de82010-09-01 13:54:15 +0200138static inline void init_ipo(struct io_piece *ipo)
139{
140 memset(ipo, 0, sizeof(*ipo));
141 INIT_FLIST_HEAD(&ipo->trim_list);
142}
143
Jens Axboe5995a6a2009-06-03 08:53:28 +0200144#endif