iowatcher: Initial revision
[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 typedef __u64 u64;
23 typedef __u32 u32;
24 typedef __u16 u16;
25
26 struct plot {
27         int fd;
28
29         /* svg style y = 0 is the top of the graph */
30         int start_y_offset;
31
32         /* abs coords of the start of X start of the plot */
33         int start_x_offset;
34
35         int add_xlabel;
36
37         /*
38          * these two are for anyone that wants
39          * to add a plot after this one, it tells
40          * them how much space we took up
41          */
42         int total_height;
43         int total_width;
44         char **legend_lines;
45         int legend_index;
46         int num_legend_lines;
47 };
48
49 struct graph_line_pair {
50         u64 count;
51         u64 sum;
52 };
53
54 struct graph_line_data {
55         /* total number of seconds in this graph */
56         int seconds;
57
58         int stop_seconds;
59
60         /* Y max */
61         u64 max;
62
63         /* label for this graph */
64         char *label;
65         struct graph_line_pair data[];
66 };
67
68 struct graph_dot_data {
69         u64 max_offset;
70         u64 total_ios;
71
72         /* in pixels, number of rows in our bitmap */
73         int rows;
74         /* in pixels, number of cols in our bitmap */
75         int cols;
76
77         /* total number of seconds in this graph */
78         int seconds;
79         int stop_seconds;
80
81         /* label for the legend */
82         char *label;
83
84         /* bitmap, one bit for each cell to light up */
85         unsigned char data[];
86 };
87
88 int svg_io_graph(struct plot *plot, struct graph_dot_data *gdd, char *color);
89 int svg_line_graph(struct plot *plot, struct graph_line_data *gld, char *color);
90 struct graph_line_data *alloc_line_data(int seconds, int stop_seconds);
91 void free_line_data(struct graph_line_data *gld);
92 struct graph_dot_data *alloc_dot_data(int seconds, u64 max_offset, int stop_seconds);
93 void free_dot_data(struct graph_dot_data *gdd);
94 void set_gdd_bit(struct graph_dot_data *gdd, u64 offset, int bytes, double time);
95 void print_gdd(struct graph_dot_data *gdd);
96 void write_svg_header(int fd);
97 struct plot *alloc_plot(int fd);
98 int close_plot(struct plot *plot);
99 void setup_axis(struct plot *plot);
100 void set_xticks(struct plot *plot, int num_ticks, int first, int last);
101 void set_yticks(struct plot *plot, int num_ticks, int first, int last, char *units);
102 void set_plot_title(struct plot *plot, char *title);
103 void set_plot_label(struct plot *plot, char *label);
104 void set_xlabel(struct plot *plot, char *label);
105 void set_ylabel(struct plot *plot, char *label);
106 void scale_line_graph_bytes(u64 *max, char **units, u64 factor);
107 void scale_line_graph_time(u64 *max, char **units);
108 void write_drop_shadow(struct plot *plot);
109 void write_drop_shadow_line(struct plot *plot);
110 void svg_write_legend(struct plot *plot);
111 void svg_add_legend(struct plot *plot, char *text, char *extra, char *color);
112 void svg_alloc_legend(struct plot *plot, int num_lines);
113 void set_legend_width(int longest_str);
114 void set_rolling_avg(int rolling);
115 #endif