continue implementation of resourceview
[lttv.git] / ltt / branches / poly / lttv / modules / gui / resourceview / processlist.h
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
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 {
46 NAME_COLUMN,
47 N_COLUMNS
48 };
49
50
51 typedef struct _ResourceInfo {
52 GQuark name;
53 guint trace_num;
54 guint type;
55 guint id;
56 } ResourceInfo;
57
58 typedef struct _HashedResourceData {
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
80 } HashedResourceData;
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 */
96 HashedResourceData ***current_hash_data;
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 */
121 int processlist_add(ProcessList *process_list, Drawing_t * drawing,
122 guint pid, guint tgid, guint cpu, guint ppid,
123 LttTime *birth, guint trace_num, GQuark name, GQuark brand, guint *height,
124 ResourceInfo **process_info,
125 HashedResourceData **hashed_process_data);
126 // out : success (0) and height
127 int processlist_remove(ProcessList *process_list, guint pid, guint cpu,
128 LttTime *birth, guint trace_num);
129
130 /* Set the name of a process */
131 void processlist_set_name(ProcessList *process_list,
132 GQuark name,
133 HashedResourceData *hashed_process_data);
134
135 void processlist_set_brand(ProcessList *process_list,
136 GQuark brand,
137 HashedResourceData *hashed_process_data);
138
139 /* Set the ppid of a process */
140 void processlist_set_tgid(ProcessList *process_list,
141 guint tgid,
142 HashedResourceData *hashed_process_data);
143 void processlist_set_ppid(ProcessList *process_list,
144 guint ppid,
145 HashedResourceData *hashed_process_data);
146
147
148 /* Synchronize the list at the left and the drawing */
149 void update_index_to_pixmap(ProcessList *process_list);
150
151 /* Update the width of each pixmap buffer for each process */
152 void update_pixmap_size(ProcessList *process_list, guint width);
153
154
155 /* Put src and/or dest to NULL to copy from/to the each PID specific pixmap */
156 void copy_pixmap_region(ProcessList *process_list, GdkDrawable *dest,
157 GdkGC *gc, GdkDrawable *src,
158 gint xsrc, gint ysrc,
159 gint xdest, gint ydest, gint width, gint height);
160
161 /* If height is -1, the height of each pixmap is used */
162 void rectangle_pixmap(ProcessList *process_list, GdkGC *gc,
163 gboolean filled, gint x, gint y, gint width, gint height);
164
165 /* Renders each pixmaps into on big drawable */
166 void copy_pixmap_to_screen(ProcessList *process_list,
167 GdkDrawable *dest,
168 GdkGC *gc,
169 gint x, gint y,
170 gint width, gint height);
171
172
173 static inline gint get_cell_height(GtkTreeView *TreeView)
174 {
175 gint height;
176 GtkTreeViewColumn *column = gtk_tree_view_get_column(TreeView, 0);
177
178 gtk_tree_view_column_cell_get_size(column, NULL, NULL, NULL, NULL, &height);
179
180 gint vertical_separator;
181 gtk_widget_style_get (GTK_WIDGET (TreeView),
182 "vertical-separator", &vertical_separator,
183 NULL);
184 height += vertical_separator;
185
186 return height;
187 }
188
189 static inline guint processlist_get_height(ProcessList *process_list)
190 {
191 return process_list->cell_height * process_list->number_of_process ;
192 }
193
194
195 static inline HashedResourceData *processlist_get_process_data(
196 ProcessList *process_list, GQuark resource_name, guint trace_num)
197 {
198 ResourceInfo resource_info;
199
200 // process_info.pid = pid;
201 // if(pid == 0)
202 // process_info.cpu = cpu;
203 // else
204 // process_info.cpu = ANY_CPU;
205 // process_info.birth = *birth;
206 // process_info.trace_num = trace_num;
207 resource_info.name = resource_name;
208 resource_info.trace_num = trace_num;
209
210 return (HashedResourceData*)g_hash_table_lookup(
211 process_list->process_hash,
212 &resource_info);
213 }
214
215
216 static inline gint processlist_get_pixels_from_data( ProcessList *process_list,
217 HashedResourceData *hashed_process_data,
218 guint *y,
219 guint *height)
220 {
221 gint *path_indices;
222 GtkTreePath *tree_path;
223
224 tree_path = gtk_tree_model_get_path((GtkTreeModel*)process_list->list_store,
225 &hashed_process_data->y_iter);
226 path_indices = gtk_tree_path_get_indices (tree_path);
227
228 *height = get_cell_height((GtkTreeView*)process_list->process_list_widget);
229 *y = *height * path_indices[0];
230 gtk_tree_path_free(tree_path);
231
232 return 0;
233
234 }
235
236 static inline guint processlist_get_index_from_data(ProcessList *process_list,
237 HashedResourceData *hashed_process_data)
238 {
239 gint *path_indices;
240 GtkTreePath *tree_path;
241 guint ret;
242
243 tree_path = gtk_tree_model_get_path((GtkTreeModel*)process_list->list_store,
244 &hashed_process_data->y_iter);
245 path_indices = gtk_tree_path_get_indices (tree_path);
246
247 ret = path_indices[0];
248
249 gtk_tree_path_free(tree_path);
250
251 return ret;
252 }
253
254
255
256 #endif // _PROCESS_LIST_H
This page took 0.036328 seconds and 4 git commands to generate.