1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Mathieu Desnoyers
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;
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.
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,
21 #ifndef _THREAD_LIST_H
22 #define _THREAD_LIST_H
26 #include <lttv/state.h>
29 #include "xenoltt_drawitem.h"
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
45 /* Enumeration of the columns */
59 typedef struct _XenoThreadInfo
{
70 typedef struct _HashedThreadData
{
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 */
79 gboolean over_used
; /* inform the user that information is incomplete */
80 gboolean over_marked
; /* inform the user that information is incomplete */
82 gboolean middle_used
; /* inform the user that information is incomplete */
83 gboolean middle_marked
;/* inform the user that information is incomplete */
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 */
89 LttTime next_good_time
; /* precalculate the next time where the next
98 GtkWidget
*thread_list_widget
;
99 GtkListStore
*list_store
;
100 GtkWidget
*button
; /* one button of the tree view */
101 GtkCellRenderer
*renderer
;
103 /* A hash table by PID to speed up process position find in the list */
104 GHashTable
*thread_hash
;
106 guint number_of_thread
;
109 /* Current process pointer, one per cpu, one per trace */
110 HashedThreadData
***current_hash_data
;
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
;
119 typedef struct _ThreadList ThreadList
;
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
127 ThreadList
*threadlist_construct(void);
128 void threadlist_destroy(ThreadList
*thread_list
);
129 GtkWidget
*threadlist_get_widget(ThreadList
*thread_list
);
131 void threadlist_clear(ThreadList
*thread_list
);
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
);
144 /* Set the name of a xenomai thread */
145 void threadlist_set_name(ThreadList
*thread_list
,
147 HashedThreadData
*hashed_thread_data
);
149 /* Set the period of a thread */
150 void threadlist_set_period(ThreadList
*thread_list
,
152 HashedThreadData
*hashed_thread_data
);
154 /* Set the priority of a thread */
155 void threadlist_set_prio(ThreadList
*thread_list
,
157 HashedThreadData
*hashed_thread_data
);
160 /* Synchronize the list at the left and the drawing */
161 void update_index_to_pixmap(ThreadList
*thread_list
);
163 /* Update the width of each pixmap buffer for each process */
164 void update_pixmap_size(ThreadList
*thread_list
, guint width
);
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
);
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
);
177 /* Renders each pixmaps into on big drawable */
178 void copy_pixmap_to_screen(ThreadList
*thread_list
,
182 gint width
, gint height
);
185 static inline gint
get_cell_height(GtkTreeView
*TreeView
)
188 GtkTreeViewColumn
*column
= gtk_tree_view_get_column(TreeView
, 0);
190 gtk_tree_view_column_cell_get_size(column
, NULL
, NULL
, NULL
, NULL
, &height
);
192 gint vertical_separator
;
193 gtk_widget_style_get (GTK_WIDGET (TreeView
),
194 "vertical-separator", &vertical_separator
,
196 height
+= vertical_separator
;
201 static inline guint
threadlist_get_height(ThreadList
*thread_list
)
203 return thread_list
->cell_height
* thread_list
->number_of_thread
;
207 static inline HashedThreadData
*threadlist_get_thread_data(
208 ThreadList
*thread_list
,
209 gulong address
, guint cpu
, LttTime
*thread_birth
, guint trace_num
)
211 XenoThreadInfo thread_info
;
213 thread_info
.address
= address
;
215 thread_info
.cpu
= cpu
;
217 thread_info
.cpu
= ANY_CPU
;
218 thread_info
.thread_birth
= *thread_birth
;
219 thread_info
.trace_num
= trace_num
;
221 return (HashedThreadData
*)g_hash_table_lookup(thread_list
->thread_hash
,&thread_info
);
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
;
229 return likely(pa
->timer_address
== pb
);
232 static inline XenoThreadInfo
*threadlist_get_thread_from_timer(
233 ThreadList
*thread_list
,gulong timer_address
)
235 return (HashedThreadData
*)g_hash_table_find(thread_list
->thread_hash
,find_timer
,timer_address
);
238 static inline gint
threadlist_get_pixels_from_data( ThreadList
*thread_list
,
239 HashedThreadData
*hashed_thread_data
,
244 GtkTreePath
*tree_path
;
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
);
250 *height
= get_cell_height((GtkTreeView
*)thread_list
->thread_list_widget
);
251 *y
= *height
* path_indices
[0];
252 gtk_tree_path_free(tree_path
);
258 static inline guint
threadlist_get_index_from_data(ThreadList
*thread_list
,
259 HashedThreadData
*hashed_thread_data
)
262 GtkTreePath
*tree_path
;
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
);
269 ret
= path_indices
[0];
271 gtk_tree_path_free(tree_path
);
278 #endif // _THREAD_LIST_H