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