9e01e6d4 |
1 | /* This file is part of the Linux Trace Toolkit viewer |
2 | * Copyright (C) 2003-2004 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 | |
9e01e6d4 |
19 | #ifndef _PROCESS_LIST_H |
20 | #define _PROCESS_LIST_H |
21 | |
22 | #include <gtk/gtk.h> |
23 | #include <gdk/gdk.h> |
24 | #include <lttv/state.h> |
25 | #include <ltt/ltt.h> |
26 | |
27 | #include "drawitem.h" |
67f72973 |
28 | #include "cfv.h" |
9e01e6d4 |
29 | |
30 | /* The process list |
31 | * |
32 | * Tasks : |
33 | * Create a process list |
34 | * contains the data for the process list |
35 | * tells the height of the process list widget |
36 | * provides methods to add/remove process from the list |
37 | * note : the sync with drawing is left to the caller. |
38 | * provides helper function to convert a process unique identifier to |
39 | * pixels (in height). |
40 | * |
41 | */ |
42 | |
67f72973 |
43 | /* Unique identifiers for resource types */ |
44 | #define RV_RESOURCE_MACHINE 0 |
45 | #define RV_RESOURCE_CPU 1 |
46 | #define RV_RESOURCE_IRQ 2 |
0305fe77 |
47 | #define RV_RESOURCE_SOFT_IRQ 3 |
38726a78 |
48 | #define RV_RESOURCE_TRAP 4 |
49 | #define RV_RESOURCE_BDEV 5 |
50 | #define RV_RESOURCE_COUNT 6 |
9e01e6d4 |
51 | |
52 | /* Enumeration of the columns */ |
53 | enum |
54 | { |
c4e6f4dc |
55 | NAME_COLUMN, |
67f72973 |
56 | DATA_COLUMN, |
9e01e6d4 |
57 | N_COLUMNS |
58 | }; |
59 | |
67f72973 |
60 | /* |
c4e6f4dc |
61 | typedef struct _ResourceInfo { |
58a9b31b |
62 | GQuark name; |
63 | guint trace_num; |
44ffb95f |
64 | guint type; |
8743690d |
65 | guint64 id; |
c4e6f4dc |
66 | } ResourceInfo; |
67f72973 |
67 | */ |
68 | |
69 | typedef struct _ResourceUniqueNumeric { |
70 | guint trace_num; |
71 | guint id; |
72 | } ResourceUniqueNumeric; |
9e01e6d4 |
73 | |
c4e6f4dc |
74 | typedef struct _HashedResourceData { |
67f72973 |
75 | guint type; |
9e01e6d4 |
76 | |
77 | GdkPixmap *pixmap; // Pixmap slice containing drawing buffer for the PID |
78 | gint height; // height of the pixmap |
79 | GtkTreeIter y_iter; // Access quickly to y pos. |
80 | // DrawContext *draw_context; |
81 | /* Information on current drawing */ |
82 | struct { |
83 | guint over; |
84 | gboolean over_used; /* inform the user that information is incomplete */ |
85 | gboolean over_marked; /* inform the user that information is incomplete */ |
86 | guint middle; |
87 | gboolean middle_used; /* inform the user that information is incomplete */ |
88 | gboolean middle_marked;/* inform the user that information is incomplete */ |
89 | guint under; |
90 | gboolean under_used; /* inform the user that information is incomplete */ |
91 | gboolean under_marked; /* inform the user that information is incomplete */ |
92 | } x; /* last x position saved by after state update */ |
93 | |
94 | LttTime next_good_time; /* precalculate the next time where the next |
95 | pixel is.*/ |
96 | |
c4e6f4dc |
97 | } HashedResourceData; |
9e01e6d4 |
98 | |
67f72973 |
99 | struct _ResourceType { |
100 | /* functions for the hash table below */ |
101 | guint (*hashfunc)(gconstpointer); |
102 | gboolean (*hashequalfunc)(gconstpointer,gconstpointer); |
103 | /* a hashtable containing the data of each resource of this type */ |
104 | GHashTable *hash_table; |
105 | }; |
106 | typedef struct _ResourceType ResourceType; |
107 | |
9e01e6d4 |
108 | struct _ProcessList { |
109 | |
110 | GtkWidget *process_list_widget; |
67f72973 |
111 | GtkTreeStore *list_store; |
9e01e6d4 |
112 | GtkWidget *button; /* one button of the tree view */ |
113 | GtkCellRenderer *renderer; |
114 | |
115 | /* A hash table by PID to speed up process position find in the list */ |
67f72973 |
116 | // GHashTable *process_hash; |
9e01e6d4 |
117 | |
118 | guint number_of_process; |
119 | gint cell_height; |
120 | |
121 | /* Current process pointer, one per cpu, one per trace */ |
58a9b31b |
122 | HashedResourceData ***current_hash_data; |
9e01e6d4 |
123 | |
124 | /* Array containing index -> pixmap correspondance. Must be updated |
125 | * every time the process list is reordered, process added or removed */ |
126 | GPtrArray * index_to_pixmap; |
127 | |
67f72973 |
128 | ResourceType restypes[RV_RESOURCE_COUNT]; |
9e01e6d4 |
129 | }; |
130 | |
67f72973 |
131 | typedef struct _UpdateIndexPixmapArg { |
132 | ProcessList *process_list; |
133 | guint count; |
134 | } UpdateIndexPixmapArg; |
9e01e6d4 |
135 | |
67f72973 |
136 | #ifndef TYPE_PROCESSLIST_DEFINED |
137 | #define TYPE_PROCESSLIST_DEFINED |
9e01e6d4 |
138 | typedef struct _ProcessList ProcessList; |
67f72973 |
139 | #endif //TYPE_PROCESSLIST_DEFINED |
9e01e6d4 |
140 | |
141 | |
142 | #ifndef TYPE_DRAWING_T_DEFINED |
143 | #define TYPE_DRAWING_T_DEFINED |
144 | typedef struct _Drawing_t Drawing_t; |
145 | #endif //TYPE_DRAWING_T_DEFINED |
146 | |
147 | ProcessList *processlist_construct(void); |
148 | void processlist_destroy(ProcessList *process_list); |
149 | GtkWidget *processlist_get_widget(ProcessList *process_list); |
150 | |
151 | void processlist_clear(ProcessList *process_list); |
152 | |
153 | // out : success (0) and height |
154 | /* CPU num is only used for PID 0 */ |
67f72973 |
155 | //int resourcelist_add( ProcessList *process_list, Drawing_t *drawing, guint trace_num, |
156 | // GQuark name, guint type, guint id, guint *height, ResourceInfo **pm_resource_info, |
157 | // HashedResourceData **pm_hashed_resource_data, GQuark parent); |
8743690d |
158 | |
9e01e6d4 |
159 | // out : success (0) and height |
160 | int processlist_remove(ProcessList *process_list, guint pid, guint cpu, |
161 | LttTime *birth, guint trace_num); |
162 | |
163 | /* Set the name of a process */ |
164 | void processlist_set_name(ProcessList *process_list, |
165 | GQuark name, |
58a9b31b |
166 | HashedResourceData *hashed_process_data); |
9e01e6d4 |
167 | |
168 | void processlist_set_brand(ProcessList *process_list, |
169 | GQuark brand, |
58a9b31b |
170 | HashedResourceData *hashed_process_data); |
9e01e6d4 |
171 | |
172 | /* Set the ppid of a process */ |
173 | void processlist_set_tgid(ProcessList *process_list, |
174 | guint tgid, |
58a9b31b |
175 | HashedResourceData *hashed_process_data); |
9e01e6d4 |
176 | void processlist_set_ppid(ProcessList *process_list, |
177 | guint ppid, |
58a9b31b |
178 | HashedResourceData *hashed_process_data); |
9e01e6d4 |
179 | |
180 | |
181 | /* Synchronize the list at the left and the drawing */ |
182 | void update_index_to_pixmap(ProcessList *process_list); |
183 | |
184 | /* Update the width of each pixmap buffer for each process */ |
185 | void update_pixmap_size(ProcessList *process_list, guint width); |
186 | |
187 | |
188 | /* Put src and/or dest to NULL to copy from/to the each PID specific pixmap */ |
189 | void copy_pixmap_region(ProcessList *process_list, GdkDrawable *dest, |
190 | GdkGC *gc, GdkDrawable *src, |
191 | gint xsrc, gint ysrc, |
192 | gint xdest, gint ydest, gint width, gint height); |
193 | |
194 | /* If height is -1, the height of each pixmap is used */ |
195 | void rectangle_pixmap(ProcessList *process_list, GdkGC *gc, |
196 | gboolean filled, gint x, gint y, gint width, gint height); |
197 | |
198 | /* Renders each pixmaps into on big drawable */ |
199 | void copy_pixmap_to_screen(ProcessList *process_list, |
200 | GdkDrawable *dest, |
201 | GdkGC *gc, |
202 | gint x, gint y, |
203 | gint width, gint height); |
204 | |
9e01e6d4 |
205 | static inline gint get_cell_height(GtkTreeView *TreeView) |
206 | { |
207 | gint height; |
208 | GtkTreeViewColumn *column = gtk_tree_view_get_column(TreeView, 0); |
209 | |
210 | gtk_tree_view_column_cell_get_size(column, NULL, NULL, NULL, NULL, &height); |
211 | |
212 | gint vertical_separator; |
213 | gtk_widget_style_get (GTK_WIDGET (TreeView), |
214 | "vertical-separator", &vertical_separator, |
215 | NULL); |
216 | height += vertical_separator; |
217 | |
218 | return height; |
219 | } |
220 | |
221 | static inline guint processlist_get_height(ProcessList *process_list) |
222 | { |
223 | return process_list->cell_height * process_list->number_of_process ; |
224 | } |
225 | |
226 | |
67f72973 |
227 | //static inline HashedResourceData *processlist_get_process_data( |
228 | // ProcessList *process_list, GQuark resource_name, guint trace_num) |
229 | //{ |
230 | // ResourceInfo resource_info; |
231 | // |
232 | //// process_info.pid = pid; |
233 | //// if(pid == 0) |
234 | //// process_info.cpu = cpu; |
235 | //// else |
236 | //// process_info.cpu = ANY_CPU; |
237 | //// process_info.birth = *birth; |
238 | //// process_info.trace_num = trace_num; |
239 | // resource_info.name = resource_name; |
240 | // resource_info.trace_num = trace_num; |
241 | // |
242 | // return (HashedResourceData*)g_hash_table_lookup( |
243 | // process_list->process_hash, |
244 | // &resource_info); |
245 | //} |
246 | // |
9e01e6d4 |
247 | |
248 | static inline gint processlist_get_pixels_from_data( ProcessList *process_list, |
58a9b31b |
249 | HashedResourceData *hashed_process_data, |
9e01e6d4 |
250 | guint *y, |
251 | guint *height) |
252 | { |
253 | gint *path_indices; |
254 | GtkTreePath *tree_path; |
255 | |
256 | tree_path = gtk_tree_model_get_path((GtkTreeModel*)process_list->list_store, |
257 | &hashed_process_data->y_iter); |
258 | path_indices = gtk_tree_path_get_indices (tree_path); |
259 | |
260 | *height = get_cell_height((GtkTreeView*)process_list->process_list_widget); |
261 | *y = *height * path_indices[0]; |
262 | gtk_tree_path_free(tree_path); |
263 | |
264 | return 0; |
265 | |
266 | } |
267 | |
268 | static inline guint processlist_get_index_from_data(ProcessList *process_list, |
58a9b31b |
269 | HashedResourceData *hashed_process_data) |
9e01e6d4 |
270 | { |
271 | gint *path_indices; |
272 | GtkTreePath *tree_path; |
273 | guint ret; |
67f72973 |
274 | gint depth; |
9e01e6d4 |
275 | |
276 | tree_path = gtk_tree_model_get_path((GtkTreeModel*)process_list->list_store, |
277 | &hashed_process_data->y_iter); |
278 | path_indices = gtk_tree_path_get_indices (tree_path); |
67f72973 |
279 | depth = gtk_tree_path_get_depth(tree_path); |
9e01e6d4 |
280 | |
67f72973 |
281 | // ret = path_indices[1]+path_indices[0]+1; |
9e01e6d4 |
282 | ret = path_indices[0]; |
67f72973 |
283 | if(depth>1) |
284 | ret+= 1+path_indices[1]; |
9e01e6d4 |
285 | |
286 | gtk_tree_path_free(tree_path); |
287 | |
288 | return ret; |
289 | } |
290 | |
67f72973 |
291 | /* Return the hash table used to store the data of each resource of a given resource type */ |
292 | |
293 | static inline GHashTable *resourcelist_get_resource_hash_table(ControlFlowData *resourceview_data, guint type) |
294 | { |
295 | return resourceview_data->process_list->restypes[type].hash_table; |
296 | } |
297 | |
9e01e6d4 |
298 | |
299 | |
300 | #endif // _PROCESS_LIST_H |