xref: /aosp_15_r20/external/blktrace/iowatcher/blkparse.h (revision 1a3d31e37cc95e9919fd86900a2b6a555f55952c)
1*1a3d31e3SAndroid Build Coastguard Worker /*
2*1a3d31e3SAndroid Build Coastguard Worker  * Copyright (C) 2012 Fusion-io
3*1a3d31e3SAndroid Build Coastguard Worker  *
4*1a3d31e3SAndroid Build Coastguard Worker  *  This program is free software; you can redistribute it and/or
5*1a3d31e3SAndroid Build Coastguard Worker  *  modify it under the terms of the GNU General Public
6*1a3d31e3SAndroid Build Coastguard Worker  *  License v2 as published by the Free Software Foundation.
7*1a3d31e3SAndroid Build Coastguard Worker  *
8*1a3d31e3SAndroid Build Coastguard Worker  *  This program is distributed in the hope that it will be useful,
9*1a3d31e3SAndroid Build Coastguard Worker  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10*1a3d31e3SAndroid Build Coastguard Worker  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11*1a3d31e3SAndroid Build Coastguard Worker  *  GNU General Public License for more details.
12*1a3d31e3SAndroid Build Coastguard Worker  *
13*1a3d31e3SAndroid Build Coastguard Worker  *  You should have received a copy of the GNU General Public License
14*1a3d31e3SAndroid Build Coastguard Worker  *  along with this program; if not, write to the Free Software
15*1a3d31e3SAndroid Build Coastguard Worker  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16*1a3d31e3SAndroid Build Coastguard Worker  *
17*1a3d31e3SAndroid Build Coastguard Worker  *  Parts of this file were imported from Jens Axboe's blktrace sources (also GPL)
18*1a3d31e3SAndroid Build Coastguard Worker  */
19*1a3d31e3SAndroid Build Coastguard Worker #ifndef __IOWATCH_BLKPARSE__
20*1a3d31e3SAndroid Build Coastguard Worker #define __IOWATCH_BLKPARSE__
21*1a3d31e3SAndroid Build Coastguard Worker #define MINORBITS 20
22*1a3d31e3SAndroid Build Coastguard Worker #define MINORMASK ((1 << MINORBITS) - 1)
23*1a3d31e3SAndroid Build Coastguard Worker #define SECONDS(x)              ((unsigned long long)(x) / 1000000000)
24*1a3d31e3SAndroid Build Coastguard Worker #define NANO_SECONDS(x)         ((unsigned long long)(x) % 1000000000)
25*1a3d31e3SAndroid Build Coastguard Worker #define DOUBLE_TO_NANO_ULL(d)   ((unsigned long long)((d) * 1000000000))
26*1a3d31e3SAndroid Build Coastguard Worker #define CHECK_MAGIC(t)          (((t)->magic & 0xffffff00) == BLK_IO_TRACE_MAGIC)
27*1a3d31e3SAndroid Build Coastguard Worker 
28*1a3d31e3SAndroid Build Coastguard Worker struct dev_info {
29*1a3d31e3SAndroid Build Coastguard Worker 	u32 device;
30*1a3d31e3SAndroid Build Coastguard Worker 	u64 min;
31*1a3d31e3SAndroid Build Coastguard Worker 	u64 max;
32*1a3d31e3SAndroid Build Coastguard Worker 	u64 map;
33*1a3d31e3SAndroid Build Coastguard Worker };
34*1a3d31e3SAndroid Build Coastguard Worker 
35*1a3d31e3SAndroid Build Coastguard Worker #define MAX_DEVICES_PER_TRACE 64
36*1a3d31e3SAndroid Build Coastguard Worker 
37*1a3d31e3SAndroid Build Coastguard Worker struct trace {
38*1a3d31e3SAndroid Build Coastguard Worker 	int fd;
39*1a3d31e3SAndroid Build Coastguard Worker 	u64 len;
40*1a3d31e3SAndroid Build Coastguard Worker 	char *start;
41*1a3d31e3SAndroid Build Coastguard Worker 	char *cur;
42*1a3d31e3SAndroid Build Coastguard Worker 	struct blk_io_trace *io;
43*1a3d31e3SAndroid Build Coastguard Worker 	u64 start_timestamp;
44*1a3d31e3SAndroid Build Coastguard Worker 	struct timespec abs_start_time;
45*1a3d31e3SAndroid Build Coastguard Worker 
46*1a3d31e3SAndroid Build Coastguard Worker 	/*
47*1a3d31e3SAndroid Build Coastguard Worker 	 * flags for the things we find in the stream
48*1a3d31e3SAndroid Build Coastguard Worker 	 * we prefer different events for different things
49*1a3d31e3SAndroid Build Coastguard Worker 	 */
50*1a3d31e3SAndroid Build Coastguard Worker 	int found_issue;
51*1a3d31e3SAndroid Build Coastguard Worker 	int found_completion;
52*1a3d31e3SAndroid Build Coastguard Worker 	int found_queue;
53*1a3d31e3SAndroid Build Coastguard Worker 
54*1a3d31e3SAndroid Build Coastguard Worker 	char *mpstat_start;
55*1a3d31e3SAndroid Build Coastguard Worker 	char *mpstat_cur;
56*1a3d31e3SAndroid Build Coastguard Worker 	u64 mpstat_len;
57*1a3d31e3SAndroid Build Coastguard Worker 	int mpstat_fd;
58*1a3d31e3SAndroid Build Coastguard Worker 	int mpstat_seconds;
59*1a3d31e3SAndroid Build Coastguard Worker 	int mpstat_num_cpus;
60*1a3d31e3SAndroid Build Coastguard Worker 
61*1a3d31e3SAndroid Build Coastguard Worker 	char *fio_start;
62*1a3d31e3SAndroid Build Coastguard Worker 	char *fio_cur;
63*1a3d31e3SAndroid Build Coastguard Worker 	u64 fio_len;
64*1a3d31e3SAndroid Build Coastguard Worker 	int fio_fd;
65*1a3d31e3SAndroid Build Coastguard Worker 	int fio_seconds;
66*1a3d31e3SAndroid Build Coastguard Worker 	int num_devices;
67*1a3d31e3SAndroid Build Coastguard Worker 	struct dev_info devices[MAX_DEVICES_PER_TRACE];
68*1a3d31e3SAndroid Build Coastguard Worker };
69*1a3d31e3SAndroid Build Coastguard Worker 
70*1a3d31e3SAndroid Build Coastguard Worker struct trace_file {
71*1a3d31e3SAndroid Build Coastguard Worker 	struct list_head list;
72*1a3d31e3SAndroid Build Coastguard Worker 	char *filename;
73*1a3d31e3SAndroid Build Coastguard Worker 	char *label;
74*1a3d31e3SAndroid Build Coastguard Worker 	struct trace *trace;
75*1a3d31e3SAndroid Build Coastguard Worker 	unsigned int stop_seconds;	/* Time when trace stops */
76*1a3d31e3SAndroid Build Coastguard Worker 	unsigned int min_seconds;	/* Beginning of the interval we should plot */
77*1a3d31e3SAndroid Build Coastguard Worker 	unsigned int max_seconds;	/* End of the interval we should plot */
78*1a3d31e3SAndroid Build Coastguard Worker 	u64 min_offset;
79*1a3d31e3SAndroid Build Coastguard Worker 	u64 max_offset;
80*1a3d31e3SAndroid Build Coastguard Worker 
81*1a3d31e3SAndroid Build Coastguard Worker 	char *reads_color;
82*1a3d31e3SAndroid Build Coastguard Worker 	char *writes_color;
83*1a3d31e3SAndroid Build Coastguard Worker 	char *line_color;
84*1a3d31e3SAndroid Build Coastguard Worker 
85*1a3d31e3SAndroid Build Coastguard Worker 	struct graph_line_data *tput_writes_gld;
86*1a3d31e3SAndroid Build Coastguard Worker 	struct graph_line_data *tput_reads_gld;
87*1a3d31e3SAndroid Build Coastguard Worker 	struct graph_line_data *iop_gld;
88*1a3d31e3SAndroid Build Coastguard Worker 	struct graph_line_data *latency_gld;
89*1a3d31e3SAndroid Build Coastguard Worker 	struct graph_line_data *queue_depth_gld;
90*1a3d31e3SAndroid Build Coastguard Worker 
91*1a3d31e3SAndroid Build Coastguard Worker 	int fio_trace;
92*1a3d31e3SAndroid Build Coastguard Worker 	struct graph_line_data *fio_gld;
93*1a3d31e3SAndroid Build Coastguard Worker 
94*1a3d31e3SAndroid Build Coastguard Worker 	/* Number of entries in gdd_writes / gdd_reads */
95*1a3d31e3SAndroid Build Coastguard Worker 	int io_plots;
96*1a3d31e3SAndroid Build Coastguard Worker 
97*1a3d31e3SAndroid Build Coastguard Worker 	/* Allocated array size for gdd_writes / gdd_reads */
98*1a3d31e3SAndroid Build Coastguard Worker 	int io_plots_allocated;
99*1a3d31e3SAndroid Build Coastguard Worker 	struct graph_dot_data **gdd_writes;
100*1a3d31e3SAndroid Build Coastguard Worker 	struct graph_dot_data **gdd_reads;
101*1a3d31e3SAndroid Build Coastguard Worker 
102*1a3d31e3SAndroid Build Coastguard Worker 	unsigned int mpstat_min_seconds;
103*1a3d31e3SAndroid Build Coastguard Worker 	unsigned int mpstat_max_seconds;
104*1a3d31e3SAndroid Build Coastguard Worker 	unsigned int mpstat_stop_seconds;
105*1a3d31e3SAndroid Build Coastguard Worker 	struct graph_line_data **mpstat_gld;
106*1a3d31e3SAndroid Build Coastguard Worker };
107*1a3d31e3SAndroid Build Coastguard Worker 
MAJOR(unsigned int dev)108*1a3d31e3SAndroid Build Coastguard Worker static inline unsigned int MAJOR(unsigned int dev)
109*1a3d31e3SAndroid Build Coastguard Worker {
110*1a3d31e3SAndroid Build Coastguard Worker 	return dev >> MINORBITS;
111*1a3d31e3SAndroid Build Coastguard Worker }
112*1a3d31e3SAndroid Build Coastguard Worker 
MINOR(unsigned int dev)113*1a3d31e3SAndroid Build Coastguard Worker static inline unsigned int MINOR(unsigned int dev)
114*1a3d31e3SAndroid Build Coastguard Worker {
115*1a3d31e3SAndroid Build Coastguard Worker 	return dev & MINORMASK;
116*1a3d31e3SAndroid Build Coastguard Worker }
117*1a3d31e3SAndroid Build Coastguard Worker 
118*1a3d31e3SAndroid Build Coastguard Worker void init_io_hash_table(void);
119*1a3d31e3SAndroid Build Coastguard Worker void init_process_hash_table(void);
120*1a3d31e3SAndroid Build Coastguard Worker struct trace *open_trace(char *filename);
121*1a3d31e3SAndroid Build Coastguard Worker u64 find_last_time(struct trace *trace);
122*1a3d31e3SAndroid Build Coastguard Worker void find_extreme_offsets(struct trace *trace, u64 *min_ret, u64 *max_ret,
123*1a3d31e3SAndroid Build Coastguard Worker 			  u64 *max_bank_ret, u64 *max_offset_ret);
124*1a3d31e3SAndroid Build Coastguard Worker int filter_outliers(struct trace *trace, u64 min_offset, u64 max_offset,
125*1a3d31e3SAndroid Build Coastguard Worker 		    u64 *yzoom_min, u64 *yzoom_max);
126*1a3d31e3SAndroid Build Coastguard Worker int action_char_to_num(char action);
127*1a3d31e3SAndroid Build Coastguard Worker void add_iop(struct trace *trace, struct graph_line_data *gld);
128*1a3d31e3SAndroid Build Coastguard Worker void check_record(struct trace *trace);
129*1a3d31e3SAndroid Build Coastguard Worker void add_completed_io(struct trace *trace,
130*1a3d31e3SAndroid Build Coastguard Worker 		      struct graph_line_data *latency_gld);
131*1a3d31e3SAndroid Build Coastguard Worker void add_io(struct trace *trace, struct trace_file *tf);
132*1a3d31e3SAndroid Build Coastguard Worker void add_tput(struct trace *trace, struct graph_line_data *writes_gld,
133*1a3d31e3SAndroid Build Coastguard Worker 	      struct graph_line_data *reads_gld);
134*1a3d31e3SAndroid Build Coastguard Worker void add_pending_io(struct trace *trace, struct graph_line_data *gld);
135*1a3d31e3SAndroid Build Coastguard Worker int next_record(struct trace *trace);
136*1a3d31e3SAndroid Build Coastguard Worker u64 get_record_time(struct trace *trace);
137*1a3d31e3SAndroid Build Coastguard Worker void first_record(struct trace *trace);
138*1a3d31e3SAndroid Build Coastguard Worker #endif
139