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