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