| 1 | /****************************************************************************** |
| 2 | * Draw_Item.c |
| 3 | * |
| 4 | * This file contains methods responsible for drawing a generic type of data |
| 5 | * in a drawable. Doing this generically will permit user defined drawing |
| 6 | * behavior in a later time. |
| 7 | * |
| 8 | * This file provides an API which is meant to be reusable for all viewers that |
| 9 | * need to show information in line, icon, text, background or point form in |
| 10 | * a drawable area having time for x axis. The y axis, in the control flow |
| 11 | * viewer case, is corresponding to the different processes, but it can be |
| 12 | * reused integrally for cpu, and eventually locks, buffers, network |
| 13 | * interfaces... What will differ between the viewers is the precise |
| 14 | * information which interests us. We may think that the most useful |
| 15 | * information for control flow are some specific events, like schedule |
| 16 | * change, and processes'states. It may differ for a cpu viewer : the |
| 17 | * interesting information could be more the execution mode of each cpu. |
| 18 | * This API in meant to make viewer's writers life easier : it will become |
| 19 | * a simple choice of icons and line types for the precise information |
| 20 | * the viewer has to provide (agremented with keeping supplementary records |
| 21 | * and modifying slightly the DrawContext to suit the needs.) |
| 22 | * |
| 23 | * We keep each data type in attributes, keys to specific information |
| 24 | * being formed from the GQuark corresponding to the information received. |
| 25 | * (facilities / facility_name / events / eventname.) |
| 26 | * (cpus/cpu_name, process_states/ps_name, |
| 27 | * execution_modes/em_name, execution_submodes/es_name). |
| 28 | * The goal is then to provide a generic way to print information on the |
| 29 | * screen for all this different information. |
| 30 | * |
| 31 | * Information can be printed as |
| 32 | * |
| 33 | * - text (text + color + size + position (over or under line) |
| 34 | * - icon (icon filename, corresponding to a loaded icon, accessible through |
| 35 | * a GQuark. Icons are loaded statically at the guiControlFlow level during |
| 36 | * module initialization and can be added on the fly if not present in the |
| 37 | * GQuark.) The habitual place for xpm icons is in |
| 38 | * ${prefix}/share/LinuxTraceToolkit.) + position (over or under line) |
| 39 | * - line (color, width, style) |
| 40 | * - Arc (can be seen as points) (color, size) |
| 41 | * - background color (color) |
| 42 | * |
| 43 | * Each item has an array of hooks (hook list). Each hook represents an |
| 44 | * operation to perform. We seek the array each time we want to |
| 45 | * draw an item. We execute each operation in order. An operation type |
| 46 | * is associated with each hook to permit user listing and modification |
| 47 | * of these operations. The operation type is also used to find the |
| 48 | * corresponding priority for the sorting. Operation type and priorities |
| 49 | * are enum and a static int table. |
| 50 | * |
| 51 | * The array has to be sorted by priority each time we add a task in it. |
| 52 | * A priority is associated with each operation type. It permits |
| 53 | * to perform background color selection before line or text drawing. We also |
| 54 | * draw lines before text, so the text appears over the lines. |
| 55 | * |
| 56 | * Executing all the arrays of operations for a specific event (which |
| 57 | * implies information for state, event, cpu, execution mode and submode) |
| 58 | * has to be done in a same DrawContext. The goal there is to keep the offset |
| 59 | * of the text and icons over and under the middle line, so a specific |
| 60 | * event could be printed as ( R Si 0 for running, scheduled in, cpu 0 ), |
| 61 | * text being easy to replace with icons. The DrawContext is passed as |
| 62 | * call_data for the operation hooks. |
| 63 | * |
| 64 | * We use the lttv global attributes to keep track of the loaded icons. |
| 65 | * If we need an icon, we look for it in the icons / icon name pathname. |
| 66 | * If found, we use the pointer to it. If not, we load the pixmap in |
| 67 | * memory and set the pointer to the GdkPixmap in the attributes. |
| 68 | * |
| 69 | * Author : Mathieu Desnoyers, October 2003 |
| 70 | */ |
| 71 | |
| 72 | #include <glib.h> |
| 73 | #include <lttv/hook.h> |
| 74 | #include <lttv/attribute.h> |
| 75 | #include <lttv/iattribute.h> |
| 76 | |
| 77 | #include <lttv/processTrace.h> |
| 78 | #include <lttv/state.h> |
| 79 | |
| 80 | /* The DrawContext keeps information about the current drawing position and |
| 81 | * the previous one, so we can use both to draw lines. |
| 82 | * |
| 83 | * over : position for drawing over the middle line. |
| 84 | * middle : middle line position. |
| 85 | * under : position for drawing under the middle line. |
| 86 | */ |
| 87 | struct _DrawContext { |
| 88 | GdkDrawable *drawable; |
| 89 | GdkGC *gc; |
| 90 | |
| 91 | DrawInfo *Current; |
| 92 | DrawInfo *Previous; |
| 93 | }; |
| 94 | |
| 95 | struct _DrawInfo { |
| 96 | ItemInfo *over; |
| 97 | ItemInfo *middle; |
| 98 | ItemInfo *under; |
| 99 | }; |
| 100 | |
| 101 | /* LttvExecutionState is accessible through the LttvTracefileState. Is has |
| 102 | * a pointer to the LttvProcessState which points to the top of stack |
| 103 | * execution state : LttvExecutionState *state. |
| 104 | * |
| 105 | * LttvExecutionState contains (useful here): |
| 106 | * LttvExecutionMode t, |
| 107 | * LttvExecutionSubmode n, |
| 108 | * LttvProcessStatus s |
| 109 | * |
| 110 | * |
| 111 | * LttvTraceState will be used in the case we need the string of the |
| 112 | * different processes, eventtype_names, syscall_names, trap_names, irq_names. |
| 113 | * |
| 114 | * LttvTracefileState also gives the cpu_name and, as it herits from |
| 115 | * LttvTracefileContext, it gives the LttEvent structure, which is needed |
| 116 | * to get facility name and event name. |
| 117 | */ |
| 118 | struct _ItemInfo { |
| 119 | gint x, y; |
| 120 | LttvTraceState *ts; |
| 121 | LttvTracefileState *tfs; |
| 122 | }; |
| 123 | |
| 124 | |
| 125 | /* |
| 126 | * The Item element is only used so the DrawOperation is modifiable by users. |
| 127 | * During drawing, only the Hook is needed. |
| 128 | */ |
| 129 | struct _DrawOperation { |
| 130 | DrawableItems Item; |
| 131 | LttvHooks *Hook; |
| 132 | }; |
| 133 | |
| 134 | /* |
| 135 | * We define here each items that can be drawn, together with their |
| 136 | * associated priority. Many item types can have the same priority, |
| 137 | * it's only used for quicksorting the operations when we add a new one |
| 138 | * to the array of operations to perform. Lower priorities are executed |
| 139 | * first. So, for example, we may want to give background color a value |
| 140 | * of 10 while a line would have 20, so the background color, which |
| 141 | * is in fact a rectangle, does not hide the line. |
| 142 | */ |
| 143 | |
| 144 | typedef enum _DrawableItems { |
| 145 | ITEM_TEXT, ITEM_ICON, ITEM_LINE, ITEM_POINT, ITEM_BACKGROUND |
| 146 | } DrawableItems; |
| 147 | |
| 148 | static gchar * Items_Priorities = { |
| 149 | 50, /* ITEM_TEXT */ |
| 150 | 40, /* ITEM_ICON */ |
| 151 | 20, /* ITEM_LINE */ |
| 152 | 30, /* ITEM_POINT */ |
| 153 | 10 /* ITEM_BACKGROUND */ |
| 154 | }; |
| 155 | |
| 156 | typedef enum _RelPos { |
| 157 | OVER, MIDDLE, UNDER |
| 158 | } RelPos; |
| 159 | |
| 160 | /* |
| 161 | * Here are the different structures describing each item type that can be |
| 162 | * drawn. They contain the information necessary to draw the item : not the |
| 163 | * position (this is provided by the DrawContext), but the text, icon name, |
| 164 | * line width, color; all the properties of the specific items. |
| 165 | */ |
| 166 | |
| 167 | struct _PropertiesText { |
| 168 | GdkColor *foreground; |
| 169 | GdkColor *background; |
| 170 | gint size; |
| 171 | gchar *Text; |
| 172 | RelPos position; |
| 173 | }; |
| 174 | |
| 175 | |
| 176 | struct _PropertiesIcon { |
| 177 | gchar *icon_name; |
| 178 | gint width; |
| 179 | gint height; |
| 180 | RelPos position; |
| 181 | }; |
| 182 | |
| 183 | struct _PropertiesLine { |
| 184 | GdkColor *color; |
| 185 | gint line_width; |
| 186 | GdkLineStyle style; |
| 187 | RelPos position; |
| 188 | }; |
| 189 | |
| 190 | struct _PropertiesArc { |
| 191 | GdkColor *color; |
| 192 | gint size; /* We force circle by width = height */ |
| 193 | gboolean filled; |
| 194 | RelPos position; |
| 195 | }; |
| 196 | |
| 197 | struct _PropertiesBG { |
| 198 | GdkColor *color; |
| 199 | }; |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | /* Drawing hook functions */ |
| 206 | gboolean DrawText( void *hook_data, void *call_data) |
| 207 | { |
| 208 | PropertiesText *Properties = (PropertiesText*)hook_data; |
| 209 | DrawContext *Draw_Context = (DrawContext*)call_data; |
| 210 | } |
| 211 | |
| 212 | gboolean DrawIcon( void *hook_data, void *call_data) |
| 213 | { |
| 214 | PropertiesIcon *Properties = (PropertiesIcon*)hook_data; |
| 215 | DrawContext *Draw_Context = (DrawContext*)call_data; |
| 216 | |
| 217 | } |
| 218 | |
| 219 | gboolean DrawLine( void *hook_data, void *call_data) |
| 220 | { |
| 221 | PropertiesLine *Properties = (PropertiesLine*)hook_data; |
| 222 | DrawContext *Draw_Context = (DrawContext*)call_data; |
| 223 | |
| 224 | } |
| 225 | |
| 226 | gboolean DrawArc( void *hook_data, void *call_data) |
| 227 | { |
| 228 | PropertiesArc *Properties = (PropertiesArc*)hook_data; |
| 229 | DrawContext *Draw_Context = (DrawContext*)call_data; |
| 230 | |
| 231 | } |
| 232 | |
| 233 | gboolean DrawBG( void *hook_data, void *call_data) |
| 234 | { |
| 235 | PropertiesBG *Properties = (PropertiesBG*)hook_data; |
| 236 | DrawContext *Draw_Context = (DrawContext*)call_data; |
| 237 | |
| 238 | } |
| 239 | |
| 240 | |