| 1 | /* This file is part of the Linux Trace Toolkit viewer |
| 2 | * Copyright (C) 2006 Parisa heidari (inspired from CFV by Mathieu Desnoyers) |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License Version 2 as |
| 6 | * 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, |
| 16 | * MA 02111-1307, USA. |
| 17 | */ |
| 18 | |
| 19 | |
| 20 | #ifndef _HISTODRAWING_H |
| 21 | #define _HISTODRAWING_H |
| 22 | |
| 23 | #include <glib.h> |
| 24 | #include <gdk/gdk.h> |
| 25 | #include <gtk/gtk.h> |
| 26 | #include <ltt/ltt.h> |
| 27 | #include <lttv/tracecontext.h> |
| 28 | #include <lttv/state.h> |
| 29 | #include <lttvwindow/lttvwindow.h> |
| 30 | #include "histocfv.h" |
| 31 | #include "histodrawitem.h" |
| 32 | |
| 33 | |
| 34 | #define SAFETY 50 // safety pixels at right and bottom of pixmap buffer |
| 35 | |
| 36 | typedef enum _draw_color { |
| 37 | COL_BLACK, |
| 38 | COL_WHITE, |
| 39 | COL_RUN_USER_MODE,/* green */ |
| 40 | COL_RUN_SYSCALL, /* pale blue */ |
| 41 | COL_RUN_TRAP, /* yellow */ |
| 42 | COL_RUN_IRQ, /* red */ |
| 43 | COL_WAIT, /* dark red */ |
| 44 | COL_WAIT_CPU, /* dark yellow */ |
| 45 | COL_ZOMBIE, /* dark purple */ |
| 46 | COL_WAIT_FORK, /* dark green */ |
| 47 | COL_EXIT, /* "less dark" magenta */ |
| 48 | COL_MODE_UNKNOWN, /* white */ |
| 49 | COL_UNNAMED, /* white */ |
| 50 | NUM_COLORS } draw_color; |
| 51 | |
| 52 | extern GdkColor histo_drawing_colors[NUM_COLORS]; |
| 53 | |
| 54 | /* This part of the viewer does : |
| 55 | * Draw horizontal lines, getting graphic context as arg. |
| 56 | * Copy region of the screen into another. |
| 57 | * Modify the boundaries to reflect a scale change. (resize) |
| 58 | * Refresh the physical screen with the pixmap |
| 59 | * A helper function is provided here to convert from time to process |
| 60 | * identifier to pixels and the contrary (will be useful for mouse selection). |
| 61 | * Insert an empty square in the drawing, moving the bottom part. |
| 62 | * |
| 63 | * Note: The last point is exactly why it would not be so easy to add the |
| 64 | * vertical line functionnality as in the original version of LTT. In order |
| 65 | * to do so, we should keep all processes in the list for the duration of |
| 66 | * all the trace instead of dynamically adding and removing them when we |
| 67 | * scroll. Another possibility is to redraw all the visible area when a new |
| 68 | * process is added to the list. The second solution seems more appropriate |
| 69 | * to me. |
| 70 | * |
| 71 | * |
| 72 | * The pixmap used has the width of the physical window, but the height |
| 73 | * of the shown processes. |
| 74 | */ |
| 75 | |
| 76 | #ifndef TYPE_histoDrawing_t_DEFINED |
| 77 | #define TYPE_histoDrawing_t_DEFINED |
| 78 | typedef struct _histoDrawing_t histoDrawing_t; |
| 79 | #endif //TYPE_DRAWING_T_DEFINED |
| 80 | |
| 81 | #ifndef TYPE_HistoControlFlowData_DEFINED |
| 82 | #define TYPE_HistoControlFlowData_DEFINED |
| 83 | typedef struct _HistoControlFlowData HistoControlFlowData; |
| 84 | #endif //TYPE_HistoControlFlowData_DEFINED |
| 85 | |
| 86 | struct _histoDrawing_t { |
| 87 | GtkWidget *vbox; |
| 88 | GtkWidget *drawing_area; |
| 89 | /* |
| 90 | GtkWidget *hbox; |
| 91 | GtkWidget *viewport; |
| 92 | GtkWidget *scrollbar;*///at this time,not necessary for histogram |
| 93 | |
| 94 | GtkWidget *ruler_hbox; |
| 95 | GtkWidget *ruler; |
| 96 | GtkWidget *padding; |
| 97 | //vertical ruler |
| 98 | GtkWidget *vruler_drawing_hbox; |
| 99 | GtkWidget *vertical_ruler; |
| 100 | |
| 101 | GdkPixmap *pixmap; |
| 102 | HistoControlFlowData *histo_control_flow_data; |
| 103 | |
| 104 | PangoLayout *pango_layout; |
| 105 | |
| 106 | gint height, width, depth; |
| 107 | /* height and width of allocated buffer pixmap */ |
| 108 | gint alloc_height, alloc_width; |
| 109 | |
| 110 | /* X coordinate of damaged region */ |
| 111 | gint damage_begin, damage_end; /* damaged region to be exposed, |
| 112 | updated per chunk */ |
| 113 | LttTime last_start; |
| 114 | GdkGC *dotted_gc; |
| 115 | GdkGC *gc; |
| 116 | GdkGC *ruler_gc_butt; |
| 117 | GdkGC *ruler_gc_round; |
| 118 | |
| 119 | /* Position of the horizontal selector, -1 for none */ |
| 120 | gint horizontal_sel; |
| 121 | }; |
| 122 | |
| 123 | histoDrawing_t *histo_drawing_construct(HistoControlFlowData *histo_control_flow_data); |
| 124 | void histo_drawing_destroy(histoDrawing_t *drawing); |
| 125 | |
| 126 | |
| 127 | void histo_drawing_data_request(histoDrawing_t *drawing, |
| 128 | gint x, gint y, |
| 129 | gint width, |
| 130 | gint height); |
| 131 | |
| 132 | GtkWidget *histo_drawing_get_widget(histoDrawing_t *drawing); |
| 133 | GtkWidget *histo_drawing_get_drawing_area(histoDrawing_t *drawing); |
| 134 | |
| 135 | void histo_drawing_draw_line(histoDrawing_t *drawing, |
| 136 | GdkPixmap *pixmap, |
| 137 | guint x1, guint y1, |
| 138 | guint x2, guint y2, |
| 139 | GdkGC *GC); |
| 140 | |
| 141 | //void drawing_copy(histoDrawing_t *drawing, |
| 142 | // guint xsrc, guint ysrc, |
| 143 | // guint xdest, guint ydest, |
| 144 | // guint width, guint height); |
| 145 | |
| 146 | /* Clear the drawing : make it 1xwidth. */ |
| 147 | void histo_drawing_clear(histoDrawing_t *drawing,guint clear_from,guint clear_to); |
| 148 | |
| 149 | /* Insert a square corresponding to a new process in the list */ |
| 150 | static void drawing_insert_square(histoDrawing_t *drawing, |
| 151 | guint y, |
| 152 | guint height); |
| 153 | |
| 154 | /* Remove a square corresponding to a removed process in the list */ |
| 155 | static void drawing_remove_square(histoDrawing_t *drawing, |
| 156 | guint y, |
| 157 | guint height); |
| 158 | |
| 159 | void histo_drawing_update_ruler(histoDrawing_t *drawing, TimeWindow *time_window); |
| 160 | |
| 161 | void histo_drawing_update_vertical_ruler(histoDrawing_t *drawing);//, TimeWindow *time_window); |
| 162 | |
| 163 | void histo_drawing_request_expose(EventsRequest *events_request, |
| 164 | LttvTracesetState *tss, |
| 165 | LttTime end_time); |
| 166 | |
| 167 | void histo_drawing_data_request_begin(EventsRequest *events_request, |
| 168 | LttvTracesetState *tss); |
| 169 | void histo_drawing_chunk_begin(EventsRequest *events_request, LttvTracesetState *tss); |
| 170 | |
| 171 | |
| 172 | |
| 173 | static void |
| 174 | tree_row_activated(GtkTreeModel *treemodel, |
| 175 | GtkTreePath *arg1, |
| 176 | GtkTreeViewColumn *arg2, |
| 177 | gpointer user_data); |
| 178 | |
| 179 | |
| 180 | /* histo_convert_pixels_to_time |
| 181 | * |
| 182 | * Convert from window pixel and time interval to an absolute time. |
| 183 | */ |
| 184 | static inline void histo_convert_pixels_to_time( |
| 185 | gint width, |
| 186 | guint x, |
| 187 | TimeWindow time_window, |
| 188 | LttTime *time) |
| 189 | { |
| 190 | double time_d; |
| 191 | |
| 192 | time_d = time_window.time_width_double; |
| 193 | time_d = time_d / (double)width * (double)x; |
| 194 | *time = ltt_time_from_double(time_d); |
| 195 | *time = ltt_time_add(time_window.start_time, *time); |
| 196 | } |
| 197 | |
| 198 | |
| 199 | static inline void histo_convert_time_to_pixels( |
| 200 | TimeWindow time_window, |
| 201 | LttTime time, |
| 202 | int width, |
| 203 | guint *x) |
| 204 | { |
| 205 | double time_d; |
| 206 | #ifdef EXTRA_CHECK |
| 207 | g_assert(ltt_time_compare(window_time_begin, time) <= 0 && |
| 208 | ltt_time_compare(window_time_end, time) >= 0); |
| 209 | #endif //EXTRA_CHECK |
| 210 | |
| 211 | time = ltt_time_sub(time, time_window.start_time); |
| 212 | |
| 213 | time_d = ltt_time_to_double(time); |
| 214 | |
| 215 | if(time_window.time_width_double == 0.0) { |
| 216 | g_assert(time_d == 0.0); |
| 217 | *x = 0; |
| 218 | } else { |
| 219 | *x = (guint)(time_d / time_window.time_width_double * (double)width); |
| 220 | } |
| 221 | |
| 222 | } |
| 223 | |
| 224 | #endif // _DRAWING_H |