iowatcher: Initial revision
[blktrace.git] / iowatcher / blkparse.h
1 /*
2  * Copyright (C) 2012 Fusion-io
3  *
4  *  This program is free software; you can redistribute it and/or
5  *  modify it under the terms of the GNU General Public
6  *  License v2 as published by the Free Software Foundation.
7  *
8  *  This program is distributed in the hope that it will be useful,
9  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  *  GNU General Public License for more details.
12  *
13  *  You should have received a copy of the GNU General Public License
14  *  along with this program; if not, write to the Free Software
15  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16  *
17  *  Parts of this file were imported from Jens Axboe's blktrace sources (also GPL)
18  */
19 #ifndef __IOWATCH_BLKPARSE__
20 #define __IOWATCH_BLKPARSE__
21 #define MINORBITS 20
22 #define MINORMASK ((1 << MINORBITS) - 1)
23 #define SECONDS(x)              ((unsigned long long)(x) / 1000000000)
24 #define NANO_SECONDS(x)         ((unsigned long long)(x) % 1000000000)
25 #define DOUBLE_TO_NANO_ULL(d)   ((unsigned long long)((d) * 1000000000))
26 #define CHECK_MAGIC(t)          (((t)->magic & 0xffffff00) == BLK_IO_TRACE_MAGIC)
27
28 struct trace {
29         int fd;
30         u64 len;
31         char *start;
32         char *cur;
33         struct blk_io_trace *io;
34         u64 start_timestamp;
35         struct timespec abs_start_time;
36
37         /*
38          * flags for the things we find in the stream
39          * we prefer different events for different things
40          */
41         int found_issue;
42         int found_completion;
43         int found_queue;
44 };
45
46 static inline unsigned int MAJOR(unsigned int dev)
47 {
48         return dev >> MINORBITS;
49 }
50
51 static inline unsigned int MINOR(unsigned int dev)
52 {
53         return dev & MINORMASK;
54 }
55
56 void init_io_hash_table(void);
57 struct trace *open_trace(char *filename);
58 u64 find_last_time(struct trace *trace);
59 u64 find_highest_offset(struct trace *trace);
60 int filter_outliers(struct trace *trace, u64 max_offset,
61                     u64 *yzoom_min, u64 *yzoom_max);
62
63 void add_iop(struct trace *trace, struct graph_line_data *gld);
64 void check_record(struct trace *trace);
65 void add_completed_io(struct trace *trace,
66                       struct graph_line_data *latency_gld);
67 void add_io(struct trace *trace, struct graph_dot_data *gdd_writes,
68             struct graph_dot_data *gdd_reads);
69 void add_tput(struct trace *trace, struct graph_line_data *gld);
70 void add_pending_io(struct trace *trace, struct graph_line_data *gld);
71 int next_record(struct trace *trace);
72 void first_record(struct trace *trace);
73 #endif