03d7fdf3 |
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 | |
20 | |
21 | #ifndef _THREAD_LIST_H |
22 | #define _THREAD_LIST_H |
23 | |
24 | #include <gtk/gtk.h> |
25 | #include <gdk/gdk.h> |
26 | #include <lttv/state.h> |
27 | #include <ltt/ltt.h> |
28 | |
29 | #include "xenoltt_drawitem.h" |
30 | |
31 | /* The process list |
32 | * |
33 | * Tasks : |
34 | * Create a process list |
35 | * contains the data for the process list |
36 | * tells the height of the process list widget |
37 | * provides methods to add/remove process from the list |
38 | * note : the sync with drawing is left to the caller. |
39 | * provides helper function to convert a process unique identifier to |
40 | * pixels (in height). |
41 | * |
42 | */ |
43 | |
44 | |
45 | /* Enumeration of the columns */ |
46 | enum |
47 | { |
48 | THREAD_COLUMN, |
49 | PRIO_COLUMN, |
50 | PERIOD_COLUMN, |
51 | CPU_COLUMN, |
52 | BIRTH_S_COLUMN, |
53 | BIRTH_NS_COLUMN, |
54 | TRACE_COLUMN, |
55 | N_COLUMNS |
56 | }; |
57 | |
58 | |
59 | typedef struct _XenoThreadInfo { |
60 | |
61 | gulong address; |
62 | guint prio; |
63 | guint cpu; |
64 | guint period; |
65 | LttTime thread_birth; |
66 | guint trace_num; |
67 | |
68 | } XenoThreadInfo; |
69 | |
70 | typedef struct _HashedThreadData { |
71 | |
72 | GdkPixmap *pixmap; // Pixmap slice containing drawing buffer for the PID |
73 | gint height; // height of the pixmap |
74 | GtkTreeIter y_iter; // Access quickly to y pos. |
75 | // DrawContext *draw_context; |
76 | /* Information on current drawing */ |
77 | struct { |
78 | guint over; |
79 | gboolean over_used; /* inform the user that information is incomplete */ |
80 | gboolean over_marked; /* inform the user that information is incomplete */ |
81 | guint middle; |
82 | gboolean middle_used; /* inform the user that information is incomplete */ |
83 | gboolean middle_marked;/* inform the user that information is incomplete */ |
84 | guint under; |
85 | gboolean under_used; /* inform the user that information is incomplete */ |
86 | gboolean under_marked; /* inform the user that information is incomplete */ |
87 | } x; /* last x position saved by after state update */ |
88 | |
89 | LttTime next_good_time; /* precalculate the next time where the next |
90 | pixel is.*/ |
91 | |
92 | gulong timer_address; |
93 | |
94 | } HashedThreadData; |
95 | |
96 | struct _ThreadList { |
97 | |
98 | GtkWidget *thread_list_widget; |
99 | GtkListStore *list_store; |
100 | GtkWidget *button; /* one button of the tree view */ |
101 | GtkCellRenderer *renderer; |
102 | |
103 | /* A hash table by PID to speed up process position find in the list */ |
104 | GHashTable *thread_hash; |
105 | |
106 | guint number_of_thread; |
107 | gint cell_height; |
108 | |
109 | /* Current process pointer, one per cpu, one per trace */ |
110 | HashedThreadData ***current_hash_data; |
111 | |
112 | /* Array containing index -> pixmap correspondance. Must be updated |
113 | * every time the process list is reordered, process added or removed */ |
114 | GPtrArray * index_to_pixmap; |
115 | |
116 | }; |
117 | |
118 | |
119 | typedef struct _ThreadList ThreadList; |
120 | |
121 | |
122 | #ifndef TYPE_XENOLTT_DRAWING_T_DEFINED |
123 | #define TYPE_XENOLTT_DRAWING_T_DEFINED |
124 | typedef struct _XenoLtt_Drawing_t XenoLtt_Drawing_t; |
125 | #endif //TYPE_XENOLTT_DRAWING_T_DEFINED |
126 | |
127 | ThreadList *threadlist_construct(void); |
128 | void threadlist_destroy(ThreadList *thread_list); |
129 | GtkWidget *threadlist_get_widget(ThreadList *thread_list); |
130 | |
131 | void threadlist_clear(ThreadList *thread_list); |
132 | |
133 | // out : success (0) and height |
134 | /* CPU num is only used for PID 0 */ |
135 | int threadlist_add(ThreadList *thread_list, XenoLtt_Drawing_t * drawing, |
136 | guint address24, guint prio, guint cpu, guint period, |
137 | /*LttTime *process_birth,*/ LttTime *thread_birth, guint trace_num, GQuark name, guint *height, |
138 | XenoThreadInfo **thread_info, |
139 | HashedThreadData **hashed_thread_data); |
140 | // out : success (0) and height |
141 | int threadlist_remove(ThreadList *thread_list, guint pid, guint cpu, |
142 | LttTime *birth, guint trace_num); |
143 | |
144 | /* Set the name of a xenomai thread */ |
145 | void threadlist_set_name(ThreadList *thread_list, |
146 | GQuark name, |
147 | HashedThreadData *hashed_thread_data); |
148 | |
149 | /* Set the period of a thread */ |
150 | void threadlist_set_period(ThreadList *thread_list, |
151 | guint period, |
152 | HashedThreadData *hashed_thread_data); |
153 | |
154 | /* Set the priority of a thread */ |
155 | void threadlist_set_prio(ThreadList *thread_list, |
156 | guint prio, |
157 | HashedThreadData *hashed_thread_data); |
158 | |
159 | |
160 | /* Synchronize the list at the left and the drawing */ |
161 | void update_index_to_pixmap(ThreadList *thread_list); |
162 | |
163 | /* Update the width of each pixmap buffer for each process */ |
164 | void update_pixmap_size(ThreadList *thread_list, guint width); |
165 | |
166 | |
167 | /* Put src and/or dest to NULL to copy from/to the each PID specific pixmap */ |
168 | void copy_pixmap_region(ThreadList *thread_list, GdkDrawable *dest, |
169 | GdkGC *gc, GdkDrawable *src, |
170 | gint xsrc, gint ysrc, |
171 | gint xdest, gint ydest, gint width, gint height); |
172 | |
173 | /* If height is -1, the height of each pixmap is used */ |
174 | void rectangle_pixmap(ThreadList *thread_list, GdkGC *gc, |
175 | gboolean filled, gint x, gint y, gint width, gint height); |
176 | |
177 | /* Renders each pixmaps into on big drawable */ |
178 | void copy_pixmap_to_screen(ThreadList *thread_list, |
179 | GdkDrawable *dest, |
180 | GdkGC *gc, |
181 | gint x, gint y, |
182 | gint width, gint height); |
183 | |
184 | |
185 | static inline gint get_cell_height(GtkTreeView *TreeView) |
186 | { |
187 | gint height; |
188 | GtkTreeViewColumn *column = gtk_tree_view_get_column(TreeView, 0); |
189 | |
190 | gtk_tree_view_column_cell_get_size(column, NULL, NULL, NULL, NULL, &height); |
191 | |
192 | gint vertical_separator; |
193 | gtk_widget_style_get (GTK_WIDGET (TreeView), |
194 | "vertical-separator", &vertical_separator, |
195 | NULL); |
196 | height += vertical_separator; |
197 | |
198 | return height; |
199 | } |
200 | |
201 | static inline guint threadlist_get_height(ThreadList *thread_list) |
202 | { |
203 | return thread_list->cell_height * thread_list->number_of_thread ; |
204 | } |
205 | |
206 | |
207 | static inline HashedThreadData *threadlist_get_thread_data( |
208 | ThreadList *thread_list, |
209 | gulong address, guint cpu, LttTime *thread_birth, guint trace_num) |
210 | { |
211 | XenoThreadInfo thread_info; |
212 | |
213 | thread_info.address = address; |
214 | if(address == 0) |
215 | thread_info.cpu = cpu; |
216 | else |
217 | thread_info.cpu = ANY_CPU; |
218 | thread_info.thread_birth = *thread_birth; |
219 | thread_info.trace_num = trace_num; |
220 | |
221 | return (HashedThreadData*)g_hash_table_lookup(thread_list->thread_hash,&thread_info); |
222 | } |
223 | |
224 | |
225 | static gboolean find_timer(gpointer key, gpointer value, gpointer user_data){ |
226 | const HashedThreadData *pa = (const HashedThreadData*)value; |
227 | const gulong pb = (const gulong)user_data; |
228 | |
229 | return likely(pa->timer_address == pb); |
230 | } |
231 | |
232 | static inline XenoThreadInfo *threadlist_get_thread_from_timer( |
233 | ThreadList *thread_list,gulong timer_address) |
234 | { |
235 | return (HashedThreadData*)g_hash_table_find(thread_list->thread_hash,find_timer,timer_address); |
236 | } |
237 | |
238 | static inline gint threadlist_get_pixels_from_data( ThreadList *thread_list, |
239 | HashedThreadData *hashed_thread_data, |
240 | guint *y, |
241 | guint *height) |
242 | { |
243 | gint *path_indices; |
244 | GtkTreePath *tree_path; |
245 | |
246 | tree_path = gtk_tree_model_get_path((GtkTreeModel*)thread_list->list_store, |
247 | &hashed_thread_data->y_iter); |
248 | path_indices = gtk_tree_path_get_indices (tree_path); |
249 | |
250 | *height = get_cell_height((GtkTreeView*)thread_list->thread_list_widget); |
251 | *y = *height * path_indices[0]; |
252 | gtk_tree_path_free(tree_path); |
253 | |
254 | return 0; |
255 | |
256 | } |
257 | |
258 | static inline guint threadlist_get_index_from_data(ThreadList *thread_list, |
259 | HashedThreadData *hashed_thread_data) |
260 | { |
261 | gint *path_indices; |
262 | GtkTreePath *tree_path; |
263 | guint ret; |
264 | |
265 | tree_path = gtk_tree_model_get_path((GtkTreeModel*)thread_list->list_store, |
266 | &hashed_thread_data->y_iter); |
267 | path_indices = gtk_tree_path_get_indices (tree_path); |
268 | |
269 | ret = path_indices[0]; |
270 | |
271 | gtk_tree_path_free(tree_path); |
272 | |
273 | return ret; |
274 | } |
275 | |
276 | |
277 | |
278 | #endif // _THREAD_LIST_H |