iowatcher: Add support for limitting IO graph offset from below
[blktrace.git] / iowatcher / plot.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  */
18 #ifndef __IOWATCH_PLOT__
19 #define __IOWATCH_PLOT__
20 #define MAX_TICKS 10
21
22 #include "list.h"
23
24 typedef __u64 u64;
25 typedef __u32 u32;
26 typedef __u16 u16;
27
28
29 /* values for the plot direction field */
30 #define PLOT_DOWN 0
31 #define PLOT_ACROSS 1
32
33 struct plot {
34         int fd;
35
36         /* svg style y = 0 is the top of the graph */
37         int start_y_offset;
38
39         /* abs coords of the start of X start of the plot */
40         int start_x_offset;
41
42         int add_xlabel;
43         int no_legend;
44
45         /*
46          * these two are for anyone that wants
47          * to add a plot after this one, it tells
48          * them how much space we took up
49          */
50         int total_height;
51         int total_width;
52         char **legend_lines;
53         int legend_index;
54         int num_legend_lines;
55         int direction;
56
57         /*
58          * timeline is a vertical line through line graphs that
59          * is used by the movie mode to show where in the graph
60          * our current frame lives
61          */
62         int timeline;
63 };
64
65 struct graph_line_pair {
66         u64 count;
67         u64 sum;
68 };
69
70 struct graph_line_data {
71         /* total number of seconds in this graph */
72         int seconds;
73
74         int stop_seconds;
75
76         /* Y max */
77         u64 max;
78
79         /* label for this graph */
80         char *label;
81         struct graph_line_pair data[];
82 };
83
84 struct graph_dot_data {
85         u64 min_offset;
86         u64 max_offset;
87         u64 max_bank;
88         u64 max_bank_offset;
89         u64 total_ios;
90         u64 total_bank_ios;
91
92         int add_bank_ios;
93
94         /* in pixels, number of rows in our bitmap */
95         int rows;
96         /* in pixels, number of cols in our bitmap */
97         int cols;
98
99         /* total number of seconds in this graph */
100         int seconds;
101         int stop_seconds;
102
103         /* label for the legend */
104         char *label;
105
106         /* bitmap, one bit for each cell to light up */
107         unsigned char data[];
108 };
109
110 struct plot_history {
111         struct list_head list;
112         double history_max;
113         int history_len;
114         int num_used;
115         int col;
116         char *color;
117         double *history;
118 };
119
120 int svg_io_graph(struct plot *plot, struct graph_dot_data *gdd, char *color);
121 int svg_line_graph(struct plot *plot, struct graph_line_data *gld, char *color, int thresh1, int thresh2);
122 struct graph_line_data *alloc_line_data(int seconds, int stop_seconds);
123 void free_line_data(struct graph_line_data *gld);
124 struct graph_dot_data *alloc_dot_data(int seconds, u64 min_offset, u64 max_offset, int stop_seconds);
125 void free_dot_data(struct graph_dot_data *gdd);
126 void set_gdd_bit(struct graph_dot_data *gdd, u64 offset, double bytes, double time);
127 void print_gdd(struct graph_dot_data *gdd);
128 void write_svg_header(int fd);
129 struct plot *alloc_plot(void);
130 int close_plot(struct plot *plot);
131 int close_plot_no_height(struct plot *plot);
132 void setup_axis(struct plot *plot);
133 void set_xticks(struct plot *plot, int num_ticks, int first, int last);
134 void set_yticks(struct plot *plot, int num_ticks, int first, int last, char *units);
135 void set_plot_title(struct plot *plot, char *title);
136 void set_plot_label(struct plot *plot, char *label);
137 void set_xlabel(struct plot *plot, char *label);
138 void set_ylabel(struct plot *plot, char *label);
139 void scale_line_graph_bytes(u64 *max, char **units, u64 factor);
140 void scale_line_graph_time(u64 *max, char **units);
141 void write_drop_shadow(struct plot *plot);
142 void write_drop_shadow_line(struct plot *plot);
143 void svg_write_legend(struct plot *plot);
144 void svg_add_legend(struct plot *plot, char *text, char *extra, char *color);
145 void svg_alloc_legend(struct plot *plot, int num_lines);
146 void set_legend_width(int longest_str);
147 void set_rolling_avg(int rolling);
148 void svg_free_legend(struct plot *plot);
149 void set_io_graph_scale(int scale);
150 void set_plot_output(struct plot *plot, char *filename);
151 void set_graph_size(int width, int height);
152 void get_graph_size(int *width, int *height);
153 int svg_io_graph_movie(struct graph_dot_data *gdd, struct plot_history *ph, int col);
154 int svg_io_graph_movie_array(struct plot *plot, struct plot_history *ph);
155 void svg_write_time_line(struct plot *plot, int col);
156 void set_graph_height(int h);
157 void set_graph_width(int w);
158 int close_plot_file(struct plot *plot);
159 int svg_io_graph_movie_array_spindle(struct plot *plot, struct plot_history *ph);
160 void rewind_spindle_steps(int num);
161 void setup_axis_spindle(struct plot *plot);
162 int close_plot_col(struct plot *plot);
163 #endif