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" |
28 | |
29 | /* The process list |
30 | * |
31 | * Tasks : |
32 | * Create a process list |
33 | * contains the data for the process list |
34 | * tells the height of the process list widget |
35 | * provides methods to add/remove process from the list |
36 | * note : the sync with drawing is left to the caller. |
37 | * provides helper function to convert a process unique identifier to |
38 | * pixels (in height). |
39 | * |
40 | */ |
41 | |
42 | |
43 | /* Enumeration of the columns */ |
44 | enum |
45 | { |
c4e6f4dc |
46 | NAME_COLUMN, |
9e01e6d4 |
47 | N_COLUMNS |
48 | }; |
49 | |
50 | |
c4e6f4dc |
51 | typedef struct _ResourceInfo { |
58a9b31b |
52 | GQuark name; |
53 | guint trace_num; |
c4e6f4dc |
54 | } ResourceInfo; |
9e01e6d4 |
55 | |
c4e6f4dc |
56 | typedef struct _HashedResourceData { |
9e01e6d4 |
57 | |
58 | GdkPixmap *pixmap; // Pixmap slice containing drawing buffer for the PID |
59 | gint height; // height of the pixmap |
60 | GtkTreeIter y_iter; // Access quickly to y pos. |
61 | // DrawContext *draw_context; |
62 | /* Information on current drawing */ |
63 | struct { |
64 | guint over; |
65 | gboolean over_used; /* inform the user that information is incomplete */ |
66 | gboolean over_marked; /* inform the user that information is incomplete */ |
67 | guint middle; |
68 | gboolean middle_used; /* inform the user that information is incomplete */ |
69 | gboolean middle_marked;/* inform the user that information is incomplete */ |
70 | guint under; |
71 | gboolean under_used; /* inform the user that information is incomplete */ |
72 | gboolean under_marked; /* inform the user that information is incomplete */ |
73 | } x; /* last x position saved by after state update */ |
74 | |
75 | LttTime next_good_time; /* precalculate the next time where the next |
76 | pixel is.*/ |
77 | |
c4e6f4dc |
78 | } HashedResourceData; |
9e01e6d4 |
79 | |
80 | struct _ProcessList { |
81 | |
82 | GtkWidget *process_list_widget; |
83 | GtkListStore *list_store; |
84 | GtkWidget *button; /* one button of the tree view */ |
85 | GtkCellRenderer *renderer; |
86 | |
87 | /* A hash table by PID to speed up process position find in the list */ |
88 | GHashTable *process_hash; |
89 | |
90 | guint number_of_process; |
91 | gint cell_height; |
92 | |
93 | /* Current process pointer, one per cpu, one per trace */ |
58a9b31b |
94 | HashedResourceData ***current_hash_data; |
9e01e6d4 |
95 | |
96 | /* Array containing index -> pixmap correspondance. Must be updated |
97 | * every time the process list is reordered, process added or removed */ |
98 | GPtrArray * index_to_pixmap; |
99 | |
100 | }; |
101 | |
102 | |
103 | typedef struct _ProcessList ProcessList; |
104 | |
105 | |
106 | #ifndef TYPE_DRAWING_T_DEFINED |
107 | #define TYPE_DRAWING_T_DEFINED |
108 | typedef struct _Drawing_t Drawing_t; |
109 | #endif //TYPE_DRAWING_T_DEFINED |
110 | |
111 | ProcessList *processlist_construct(void); |
112 | void processlist_destroy(ProcessList *process_list); |
113 | GtkWidget *processlist_get_widget(ProcessList *process_list); |
114 | |
115 | void processlist_clear(ProcessList *process_list); |
116 | |
117 | // out : success (0) and height |
118 | /* CPU num is only used for PID 0 */ |
119 | int processlist_add(ProcessList *process_list, Drawing_t * drawing, |
120 | guint pid, guint tgid, guint cpu, guint ppid, |
121 | LttTime *birth, guint trace_num, GQuark name, GQuark brand, guint *height, |
58a9b31b |
122 | ResourceInfo **process_info, |
123 | HashedResourceData **hashed_process_data); |
9e01e6d4 |
124 | // out : success (0) and height |
125 | int processlist_remove(ProcessList *process_list, guint pid, guint cpu, |
126 | LttTime *birth, guint trace_num); |
127 | |
128 | /* Set the name of a process */ |
129 | void processlist_set_name(ProcessList *process_list, |
130 | GQuark name, |
58a9b31b |
131 | HashedResourceData *hashed_process_data); |
9e01e6d4 |
132 | |
133 | void processlist_set_brand(ProcessList *process_list, |
134 | GQuark brand, |
58a9b31b |
135 | HashedResourceData *hashed_process_data); |
9e01e6d4 |
136 | |
137 | /* Set the ppid of a process */ |
138 | void processlist_set_tgid(ProcessList *process_list, |
139 | guint tgid, |
58a9b31b |
140 | HashedResourceData *hashed_process_data); |
9e01e6d4 |
141 | void processlist_set_ppid(ProcessList *process_list, |
142 | guint ppid, |
58a9b31b |
143 | HashedResourceData *hashed_process_data); |
9e01e6d4 |
144 | |
145 | |
146 | /* Synchronize the list at the left and the drawing */ |
147 | void update_index_to_pixmap(ProcessList *process_list); |
148 | |
149 | /* Update the width of each pixmap buffer for each process */ |
150 | void update_pixmap_size(ProcessList *process_list, guint width); |
151 | |
152 | |
153 | /* Put src and/or dest to NULL to copy from/to the each PID specific pixmap */ |
154 | void copy_pixmap_region(ProcessList *process_list, GdkDrawable *dest, |
155 | GdkGC *gc, GdkDrawable *src, |
156 | gint xsrc, gint ysrc, |
157 | gint xdest, gint ydest, gint width, gint height); |
158 | |
159 | /* If height is -1, the height of each pixmap is used */ |
160 | void rectangle_pixmap(ProcessList *process_list, GdkGC *gc, |
161 | gboolean filled, gint x, gint y, gint width, gint height); |
162 | |
163 | /* Renders each pixmaps into on big drawable */ |
164 | void copy_pixmap_to_screen(ProcessList *process_list, |
165 | GdkDrawable *dest, |
166 | GdkGC *gc, |
167 | gint x, gint y, |
168 | gint width, gint height); |
169 | |
170 | |
171 | static inline gint get_cell_height(GtkTreeView *TreeView) |
172 | { |
173 | gint height; |
174 | GtkTreeViewColumn *column = gtk_tree_view_get_column(TreeView, 0); |
175 | |
176 | gtk_tree_view_column_cell_get_size(column, NULL, NULL, NULL, NULL, &height); |
177 | |
178 | gint vertical_separator; |
179 | gtk_widget_style_get (GTK_WIDGET (TreeView), |
180 | "vertical-separator", &vertical_separator, |
181 | NULL); |
182 | height += vertical_separator; |
183 | |
184 | return height; |
185 | } |
186 | |
187 | static inline guint processlist_get_height(ProcessList *process_list) |
188 | { |
189 | return process_list->cell_height * process_list->number_of_process ; |
190 | } |
191 | |
192 | |
58a9b31b |
193 | static inline HashedResourceData *processlist_get_process_data( |
194 | ProcessList *process_list, GQuark resource_name, guint trace_num) |
9e01e6d4 |
195 | { |
58a9b31b |
196 | ResourceInfo resource_info; |
197 | |
198 | // process_info.pid = pid; |
199 | // if(pid == 0) |
200 | // process_info.cpu = cpu; |
201 | // else |
202 | // process_info.cpu = ANY_CPU; |
203 | // process_info.birth = *birth; |
204 | // process_info.trace_num = trace_num; |
205 | resource_info.name = resource_name; |
206 | resource_info.trace_num = trace_num; |
207 | |
208 | return (HashedResourceData*)g_hash_table_lookup( |
9e01e6d4 |
209 | process_list->process_hash, |
58a9b31b |
210 | &resource_info); |
9e01e6d4 |
211 | } |
212 | |
213 | |
214 | static inline gint processlist_get_pixels_from_data( ProcessList *process_list, |
58a9b31b |
215 | HashedResourceData *hashed_process_data, |
9e01e6d4 |
216 | guint *y, |
217 | guint *height) |
218 | { |
219 | gint *path_indices; |
220 | GtkTreePath *tree_path; |
221 | |
222 | tree_path = gtk_tree_model_get_path((GtkTreeModel*)process_list->list_store, |
223 | &hashed_process_data->y_iter); |
224 | path_indices = gtk_tree_path_get_indices (tree_path); |
225 | |
226 | *height = get_cell_height((GtkTreeView*)process_list->process_list_widget); |
227 | *y = *height * path_indices[0]; |
228 | gtk_tree_path_free(tree_path); |
229 | |
230 | return 0; |
231 | |
232 | } |
233 | |
234 | static inline guint processlist_get_index_from_data(ProcessList *process_list, |
58a9b31b |
235 | HashedResourceData *hashed_process_data) |
9e01e6d4 |
236 | { |
237 | gint *path_indices; |
238 | GtkTreePath *tree_path; |
239 | guint ret; |
240 | |
241 | tree_path = gtk_tree_model_get_path((GtkTreeModel*)process_list->list_store, |
242 | &hashed_process_data->y_iter); |
243 | path_indices = gtk_tree_path_get_indices (tree_path); |
244 | |
245 | ret = path_indices[0]; |
246 | |
247 | gtk_tree_path_free(tree_path); |
248 | |
249 | return ret; |
250 | } |
251 | |
252 | |
253 | |
254 | #endif // _PROCESS_LIST_H |