From 38726a78811ea476be2a33b52f9f176dc198ad19 Mon Sep 17 00:00:00 2001 From: pmf Date: Tue, 27 Nov 2007 16:43:21 +0000 Subject: [PATCH] resourceview: add trap resource git-svn-id: http://ltt.polymtl.ca/svn@2769 04897980-b3bd-0310-b5e0-8ef037075253 --- ltt/branches/poly/lttv/lttv/state.c | 51 ++++- ltt/branches/poly/lttv/lttv/state.h | 6 + .../lttv/modules/gui/resourceview/drawing.c | 10 + .../lttv/modules/gui/resourceview/drawing.h | 8 + .../modules/gui/resourceview/eventhooks.c | 177 ++++++++++++++++++ .../modules/gui/resourceview/processlist.c | 18 ++ .../modules/gui/resourceview/processlist.h | 5 +- 7 files changed, 270 insertions(+), 5 deletions(-) diff --git a/ltt/branches/poly/lttv/lttv/state.c b/ltt/branches/poly/lttv/lttv/state.c index 0bd17551..17c5906e 100644 --- a/ltt/branches/poly/lttv/lttv/state.c +++ b/ltt/branches/poly/lttv/lttv/state.c @@ -172,6 +172,7 @@ static GQuark LTTV_STATE_RESOURCE_CPUS_COUNT, LTTV_STATE_RESOURCE_IRQS, LTTV_STATE_RESOURCE_SOFT_IRQS, + LTTV_STATE_RESOURCE_TRAPS, LTTV_STATE_RESOURCE_BLKDEVS; static void create_max_time(LttvTraceState *tcs); @@ -263,7 +264,7 @@ gboolean rettrue(gpointer key, gpointer value, gpointer user_data) static void restore_init_state(LttvTraceState *self) { - guint i, nb_cpus, nb_irqs, nb_soft_irqs; + guint i, nb_cpus, nb_irqs, nb_soft_irqs, nb_traps; //LttvTracefileState *tfcs; @@ -290,6 +291,7 @@ restore_init_state(LttvTraceState *self) nb_cpus = ltt_trace_get_num_cpu(self->parent.t); nb_irqs = self->nb_irqs; nb_soft_irqs = self->nb_soft_irqs; + nb_traps = self->nb_traps; /* Put the per cpu running_process to beginning state : process 0. */ for(i=0; i< nb_cpus; i++) { @@ -325,6 +327,11 @@ restore_init_state(LttvTraceState *self) self->soft_irq_states[i].running = 0; } + /* reset trap states */ + for(i=0; itrap_states[i].running = 0; + } + /* reset bdev states */ g_hash_table_foreach(self->bdev_states, bdevstate_free_cb, NULL); //g_hash_table_steal_all(self->bdev_states); @@ -498,6 +505,9 @@ init(LttvTracesetState *self, LttvTraceset *ts) /* the kernel has a statically fixed max of 32 softirqs */ tcs->soft_irq_states = g_new(LttvSoftIRQState, tcs->nb_soft_irqs); + /* init trap stuff */ + tcs->trap_states = g_new(LttvTrapState, tcs->nb_traps); + /* init bdev resource stuff */ tcs->bdev_states = g_hash_table_new(g_int_hash, g_int_equal); @@ -1225,6 +1235,25 @@ static void lttv_state_free_soft_irq_states(LttvSoftIRQState *states, guint n) g_free(states); } +static LttvTrapState *lttv_state_copy_trap_states(LttvTrapState *states, guint n) +{ + guint i; + LttvTrapState *retval; + + retval = g_malloc(n*sizeof(LttvTrapState)); + + for(i=0; isoft_irq_states, nb_soft_irqs); } + /* save the trap state */ + nb_traps = self->nb_traps; + { + value = lttv_attribute_add(container, LTTV_STATE_RESOURCE_TRAPS, + LTTV_POINTER); + *(value.v_pointer) = lttv_state_copy_trap_states(self->trap_states, nb_traps); + } + /* save the blkdev states */ value = lttv_attribute_add(container, LTTV_STATE_RESOURCE_BLKDEVS, LTTV_POINTER); @@ -1421,7 +1458,7 @@ static void state_save(LttvTraceState *self, LttvAttribute *container) static void state_restore(LttvTraceState *self, LttvAttribute *container) { - guint i, nb_tracefile, pid, nb_cpus, nb_irqs, nb_soft_irqs; + guint i, nb_tracefile, pid, nb_cpus, nb_irqs, nb_soft_irqs, nb_traps; LttvTracefileState *tfcs; @@ -1487,6 +1524,13 @@ static void state_restore(LttvTraceState *self, LttvAttribute *container) lttv_state_free_soft_irq_states(self->soft_irq_states, nb_soft_irqs); self->soft_irq_states = lttv_state_copy_soft_irq_states(*(value.v_pointer), nb_soft_irqs); + /* restore trap resource states */ + nb_traps = self->nb_traps; + type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_TRAPS, &value); + g_assert(type == LTTV_POINTER); + lttv_state_free_trap_states(self->trap_states, nb_traps); + self->trap_states = lttv_state_copy_trap_states(*(value.v_pointer), nb_traps); + /* restore the blkdev states */ type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_BLKDEVS, &value); g_assert(type == LTTV_POINTER); @@ -3929,6 +3973,7 @@ static void module_init() LTTV_STATE_RESOURCE_CPUS = g_quark_from_string("cpu count"); LTTV_STATE_RESOURCE_IRQS = g_quark_from_string("irq resource states"); LTTV_STATE_RESOURCE_SOFT_IRQS = g_quark_from_string("soft irq resource states"); + LTTV_STATE_RESOURCE_TRAPS = g_quark_from_string("trap resource states"); LTTV_STATE_RESOURCE_BLKDEVS = g_quark_from_string("blkdevs resource states"); diff --git a/ltt/branches/poly/lttv/lttv/state.h b/ltt/branches/poly/lttv/lttv/state.h index 07867b10..aad7ef4b 100644 --- a/ltt/branches/poly/lttv/lttv/state.h +++ b/ltt/branches/poly/lttv/lttv/state.h @@ -311,6 +311,7 @@ typedef struct _LttvCPUState { GArray *mode_stack; guint last_irq; guint last_soft_irq; + guint last_trap; } LttvCPUState; typedef struct _LttvIRQState { @@ -321,6 +322,10 @@ typedef struct _LttvSoftIRQState { guint running; /* number of times it is currently running (on different processors) */ } LttvSoftIRQState; +typedef struct _LttvTrapState { + guint running; /* number of times it is currently running (on different processors) */ +} LttvTrapState; + typedef struct _LttvBdevState { GArray *mode_stack; } LttvBdevState; @@ -351,6 +356,7 @@ struct _LttvTraceState { LttvCPUState *cpu_states; /* state of each cpu */ LttvIRQState *irq_states; /* state of each irq handler */ LttvSoftIRQState *soft_irq_states; /* state of each softirq */ + LttvTrapState *trap_states; /* state of each trap */ GHashTable *bdev_states; /* state of the block devices */ }; diff --git a/ltt/branches/poly/lttv/modules/gui/resourceview/drawing.c b/ltt/branches/poly/lttv/modules/gui/resourceview/drawing.c index 2407bf6f..a78fd2e5 100644 --- a/ltt/branches/poly/lttv/modules/gui/resourceview/drawing.c +++ b/ltt/branches/poly/lttv/modules/gui/resourceview/drawing.c @@ -107,6 +107,13 @@ GdkColor drawing_colors_soft_irq[NUM_COLORS_SOFT_IRQ] = { 0, 0xFFFF, 0x9400, 0x9600 }, /* COL_SOFT_IRQ_BUSY */ }; +GdkColor drawing_colors_trap[NUM_COLORS_TRAP] = +{ /* Pixel, R, G, B */ + { 0, 0x0000, 0x0000, 0x0000 }, /* COL_TRAP_UNKNOWN */ + { 0, 0xBBBB, 0xBBBB, 0xBBBB }, /* COL_TRAP_IDLE */ + { 0, 0xFF00, 0xFF00, 0x0100 }, /* COL_TRAP_BUSY */ +}; + GdkColor drawing_colors_bdev[NUM_COLORS_BDEV] = { /* Pixel, R, G, B */ { 0, 0x0000, 0x0000, 0x0000 }, /* COL_BDEV_UNKNOWN */ @@ -1017,6 +1024,8 @@ Drawing_t *drawing_construct(ControlFlowData *control_flow_data) TRUE, success); gdk_colormap_alloc_colors(colormap, drawing_colors_soft_irq, NUM_COLORS_SOFT_IRQ, FALSE, TRUE, success); + gdk_colormap_alloc_colors(colormap, drawing_colors_trap, NUM_COLORS_TRAP, FALSE, + TRUE, success); gdk_colormap_alloc_colors(colormap, drawing_colors_bdev, NUM_COLORS_BDEV, FALSE, TRUE, success); @@ -1078,6 +1087,7 @@ void drawing_destroy(Drawing_t *drawing) gdk_colormap_free_colors(colormap, drawing_colors_cpu, NUM_COLORS_CPU); gdk_colormap_free_colors(colormap, drawing_colors_irq, NUM_COLORS_IRQ); gdk_colormap_free_colors(colormap, drawing_colors_soft_irq, NUM_COLORS_IRQ); + gdk_colormap_free_colors(colormap, drawing_colors_trap, NUM_COLORS_TRAP); gdk_colormap_free_colors(colormap, drawing_colors_bdev, NUM_COLORS_BDEV); // Do not unref here, Drawing_t destroyed by it's widget. diff --git a/ltt/branches/poly/lttv/modules/gui/resourceview/drawing.h b/ltt/branches/poly/lttv/modules/gui/resourceview/drawing.h index 0cecd6e6..16278fd4 100644 --- a/ltt/branches/poly/lttv/modules/gui/resourceview/drawing.h +++ b/ltt/branches/poly/lttv/modules/gui/resourceview/drawing.h @@ -74,6 +74,13 @@ typedef enum _draw_color_soft_irq { NUM_COLORS_SOFT_IRQ } draw_color_soft_irq; +typedef enum _draw_color_trap { + COL_TRAP_UNKNOWN, + COL_TRAP_IDLE, + COL_TRAP_BUSY, + NUM_COLORS_TRAP +} draw_color_trap; + typedef enum _draw_color_bdev { COL_BDEV_UNKNOWN, COL_BDEV_IDLE, @@ -86,6 +93,7 @@ extern GdkColor drawing_colors[NUM_COLORS]; extern GdkColor drawing_colors_cpu[NUM_COLORS_CPU]; extern GdkColor drawing_colors_irq[NUM_COLORS_IRQ]; extern GdkColor drawing_colors_soft_irq[NUM_COLORS_SOFT_IRQ]; +extern GdkColor drawing_colors_trap[NUM_COLORS_TRAP]; extern GdkColor drawing_colors_bdev[NUM_COLORS_BDEV]; /* This part of the viewer does : diff --git a/ltt/branches/poly/lttv/modules/gui/resourceview/eventhooks.c b/ltt/branches/poly/lttv/modules/gui/resourceview/eventhooks.c index 41fd3841..6e42ed32 100644 --- a/ltt/branches/poly/lttv/modules/gui/resourceview/eventhooks.c +++ b/ltt/branches/poly/lttv/modules/gui/resourceview/eventhooks.c @@ -319,6 +319,15 @@ static void soft_irq_set_line_color(PropertiesLine *prop_line, LttvSoftIRQState prop_line->color = drawing_colors_soft_irq[COL_SOFT_IRQ_BUSY]; } +static void trap_set_line_color(PropertiesLine *prop_line, LttvTrapState *s) +{ + GQuark present_state; + if(s->running == 0) + prop_line->color = drawing_colors_trap[COL_TRAP_IDLE]; + else + prop_line->color = drawing_colors_trap[COL_TRAP_BUSY]; +} + static void bdev_set_line_color(PropertiesLine *prop_line, LttvBdevState *s) { GQuark present_state; @@ -645,6 +654,7 @@ int before_execmode_hook(void *hook_data, void *call_data) before_execmode_hook_irq(hook_data, call_data); before_execmode_hook_soft_irq(hook_data, call_data); + before_execmode_hook_trap(hook_data, call_data); /* we are in a execmode, before the state update. We must draw the * items corresponding to the state before it changes : now is the right @@ -1130,6 +1140,171 @@ int before_execmode_hook_soft_irq(void *hook_data, void *call_data) return 0; } +int before_execmode_hook_trap(void *hook_data, void *call_data) +{ + LttvTraceHook *th = (LttvTraceHook*)hook_data; + EventsRequest *events_request = (EventsRequest*)th->hook_data; + ControlFlowData *resourceview_data = events_request->viewer_data; + + LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; + + LttvTracefileState *tfs = (LttvTracefileState *)call_data; + LttvTraceState *ts = (LttvTraceState *)tfc->t_context; + + LttEvent *e; + e = ltt_tracefile_get_event(tfc->tf); + + LttTime evtime = ltt_event_time(e); + + LttTrace *trace = tfc->t_context->t; + + /* we are in a execmode, before the state update. We must draw the + * items corresponding to the state before it changes : now is the right + * time to do it. + */ + /* For the pid */ + + guint64 trap; + guint cpu = tfs->cpu; + + guint16 ev_id_entry = marker_get_id_from_info(trace, marker_get_info_from_name(trace, lttv_merge_facility_event_name(LTT_FACILITY_KERNEL, LTT_EVENT_SOFT_IRQ_ENTRY))); + guint16 ev_id_exit = marker_get_id_from_info(trace, marker_get_info_from_name(trace, lttv_merge_facility_event_name(LTT_FACILITY_KERNEL, LTT_EVENT_SOFT_IRQ_EXIT))); + if(ev_id_entry == e->event_id) { + trap = ltt_event_get_long_unsigned(e, lttv_trace_get_hook_field(th, 0)); + } + else if(ev_id_exit == e->event_id) { + trap = ts->cpu_states[cpu].last_trap; + } + else { + return 0; + } + + guint trace_num = ts->parent.index; + + /* Well, the process_out existed : we must get it in the process hash + * or add it, and draw its items. + */ + /* Add process to process list (if not present) */ + guint pl_height = 0; + HashedResourceData *hashed_process_data = NULL; + ProcessList *process_list = resourceview_data->process_list; + + hashed_process_data = resourcelist_obtain_trap(resourceview_data, trace_num, trap); + + /* Now, the process is in the state hash and our own process hash. + * We definitely can draw the items related to the ending state. + */ + + if(likely(ltt_time_compare(hashed_process_data->next_good_time, + evtime) > 0)) + { + if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { + TimeWindow time_window = + lttvwindow_get_time_window(resourceview_data->tab); + +#ifdef EXTRA_CHECK + if(ltt_time_compare(evtime, time_window.start_time) == -1 + || ltt_time_compare(evtime, time_window.end_time) == 1) + return; +#endif //EXTRA_CHECK + Drawing_t *drawing = resourceview_data->drawing; + guint width = drawing->width; + guint x; + convert_time_to_pixels( + time_window, + evtime, + width, + &x); + + /* Draw collision indicator */ + gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); + gdk_draw_point(hashed_process_data->pixmap, + drawing->gc, + x, + COLLISION_POSITION(hashed_process_data->height)); + hashed_process_data->x.middle_marked = TRUE; + } + } + else { + TimeWindow time_window = + lttvwindow_get_time_window(resourceview_data->tab); + +#ifdef EXTRA_CHECK + if(ltt_time_compare(evtime, time_window.start_time) == -1 + || ltt_time_compare(evtime, time_window.end_time) == 1) + return; +#endif //EXTRA_CHECK + Drawing_t *drawing = resourceview_data->drawing; + guint width = drawing->width; + guint x; + + convert_time_to_pixels( + time_window, + evtime, + width, + &x); + + + /* Jump over draw if we are at the same x position */ + if(unlikely(x == hashed_process_data->x.middle && + hashed_process_data->x.middle_used)) + { + if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { + /* Draw collision indicator */ + gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); + gdk_draw_point(hashed_process_data->pixmap, + drawing->gc, + x, + COLLISION_POSITION(hashed_process_data->height)); + hashed_process_data->x.middle_marked = TRUE; + } + /* jump */ + } + else { + + DrawContext draw_context; + /* Now create the drawing context that will be used to draw + * items related to the last state. */ + draw_context.drawable = hashed_process_data->pixmap; + draw_context.gc = drawing->gc; + draw_context.pango_layout = drawing->pango_layout; + draw_context.drawinfo.start.x = hashed_process_data->x.middle; + draw_context.drawinfo.end.x = x; + + draw_context.drawinfo.y.over = 1; + draw_context.drawinfo.y.middle = (hashed_process_data->height/2); + draw_context.drawinfo.y.under = hashed_process_data->height; + + draw_context.drawinfo.start.offset.over = 0; + draw_context.drawinfo.start.offset.middle = 0; + draw_context.drawinfo.start.offset.under = 0; + draw_context.drawinfo.end.offset.over = 0; + draw_context.drawinfo.end.offset.middle = 0; + draw_context.drawinfo.end.offset.under = 0; + + { + /* Draw the line */ + PropertiesLine prop_line; + prop_line.line_width = STATE_LINE_WIDTH; + prop_line.style = GDK_LINE_SOLID; + prop_line.y = MIDDLE; + trap_set_line_color(&prop_line, &ts->trap_states[trap]); + draw_line((void*)&prop_line, (void*)&draw_context); + } + /* become the last x position */ + hashed_process_data->x.middle = x; + hashed_process_data->x.middle_used = TRUE; + hashed_process_data->x.middle_marked = FALSE; + + /* Calculate the next good time */ + convert_pixels_to_time(width, x+1, time_window, + &hashed_process_data->next_good_time); + } + } + + return 0; +} + int before_bdev_event_hook(void *hook_data, void *call_data) { @@ -1799,6 +1974,8 @@ void draw_closure(gpointer key, gpointer value, gpointer user_data) irq_set_line_color(&prop_line, &ts->irq_states[process_info->id]); else if(hashed_process_data->type == RV_RESOURCE_SOFT_IRQ) soft_irq_set_line_color(&prop_line, &ts->soft_irq_states[process_info->id]); + else if(hashed_process_data->type == RV_RESOURCE_TRAP) + trap_set_line_color(&prop_line, &ts->trap_states[process_info->id]); else if(hashed_process_data->type == RV_RESOURCE_BDEV) { gint devcode_gint = process_info->id; LttvBdevState *bdev = g_hash_table_lookup(ts->bdev_states, &devcode_gint); diff --git a/ltt/branches/poly/lttv/modules/gui/resourceview/processlist.c b/ltt/branches/poly/lttv/modules/gui/resourceview/processlist.c index cb4c7a7a..1af16a7e 100644 --- a/ltt/branches/poly/lttv/modules/gui/resourceview/processlist.c +++ b/ltt/branches/poly/lttv/modules/gui/resourceview/processlist.c @@ -373,6 +373,7 @@ ProcessList *processlist_construct(void) process_list->restypes[RV_RESOURCE_CPU].hash_table = g_hash_table_new(ru_numeric_hash_fct, ru_numeric_equ_fct); process_list->restypes[RV_RESOURCE_IRQ].hash_table = g_hash_table_new(ru_numeric_hash_fct, ru_numeric_equ_fct); process_list->restypes[RV_RESOURCE_SOFT_IRQ].hash_table = g_hash_table_new(ru_numeric_hash_fct, ru_numeric_equ_fct); + process_list->restypes[RV_RESOURCE_TRAP].hash_table = g_hash_table_new(ru_numeric_hash_fct, ru_numeric_equ_fct); process_list->restypes[RV_RESOURCE_BDEV].hash_table = g_hash_table_new(ru_numeric_hash_fct, ru_numeric_equ_fct); return process_list; @@ -482,6 +483,18 @@ GQuark make_soft_irq_name(ControlFlowData *resourceview_data, guint trace_num, g return name; } +GQuark make_trap_name(ControlFlowData *resourceview_data, guint trace_num, guint id) +{ + GQuark name; + gchar *str; + + str = g_strdup_printf("Trap %u", id); + name = g_quark_from_string(str); + g_free(str); + + return name; +} + GQuark make_bdev_name(ControlFlowData *resourceview_data, guint trace_num, guint id) { GQuark name; @@ -664,6 +677,11 @@ HashedResourceData *resourcelist_obtain_soft_irq(ControlFlowData *resourceview_d return resourcelist_obtain_generic(resourceview_data, RV_RESOURCE_SOFT_IRQ, trace_num, id, make_soft_irq_name); } +HashedResourceData *resourcelist_obtain_trap(ControlFlowData *resourceview_data, guint trace_num, guint id) +{ + return resourcelist_obtain_generic(resourceview_data, RV_RESOURCE_TRAP, trace_num, id, make_trap_name); +} + HashedResourceData *resourcelist_obtain_bdev(ControlFlowData *resourceview_data, guint trace_num, guint id) { return resourcelist_obtain_generic(resourceview_data, RV_RESOURCE_BDEV, trace_num, id, make_bdev_name); diff --git a/ltt/branches/poly/lttv/modules/gui/resourceview/processlist.h b/ltt/branches/poly/lttv/modules/gui/resourceview/processlist.h index 24e27941..9a14171c 100644 --- a/ltt/branches/poly/lttv/modules/gui/resourceview/processlist.h +++ b/ltt/branches/poly/lttv/modules/gui/resourceview/processlist.h @@ -45,8 +45,9 @@ #define RV_RESOURCE_CPU 1 #define RV_RESOURCE_IRQ 2 #define RV_RESOURCE_SOFT_IRQ 3 -#define RV_RESOURCE_BDEV 4 -#define RV_RESOURCE_COUNT 5 +#define RV_RESOURCE_TRAP 4 +#define RV_RESOURCE_BDEV 5 +#define RV_RESOURCE_COUNT 6 /* Enumeration of the columns */ enum -- 2.34.1