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