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