+ GtkTreeIter iter;
+ int i;
+ GtkTreeModel *model = GTK_TREE_MODEL(Event_Viewer_Data->Store_M);
+ GtkTreePath *Tree_Path;
+ RawTraceData * raw_data;
+ ScrollDirection direction = SCROLL_NONE;
+ GList * first;
+ int Event_Number;
+ double value = Event_Viewer_Data->previous_value - time_value;
+ LttTime start, end, time;
+ LttEvent * ev;
+ unsigned backward_num, minNum, maxNum;
+ LttTracefile * tf;
+ unsigned block_num, event_num;
+ unsigned size = 1, count = 0;
+ gboolean needBackwardAgain, backward;
+
+ g_warning("DEBUG : get_test_data, time value %f\n", time_value);
+
+ // if(Event_Number > Event_Viewer_Data->Last_Event ||
+ // Event_Number + List_Height-1 < Event_Viewer_Data->First_Event ||
+ // Event_Viewer_Data->First_Event == -1)
+ {
+ /* no event can be reused, clear and start from nothing */
+ if(value == -1.0) direction = SCROLL_STEP_DOWN;
+ else if(value == 1.0 ) direction = SCROLL_STEP_UP;
+ else if(value == -2.0) direction = SCROLL_PAGE_DOWN;
+ else if(value == 2.0 ) direction = SCROLL_PAGE_UP;
+ else if(value == 0.0 ) direction = SCROLL_NONE;
+ else direction = SCROLL_JUMP;
+
+ switch(direction){
+ case SCROLL_STEP_UP:
+ case SCROLL_PAGE_UP:
+ if(direction == SCROLL_PAGE_UP){
+ backward = List_Height>Event_Viewer_Data->start_event_index ? TRUE : FALSE;
+ }else{
+ backward = Event_Viewer_Data->start_event_index == 0 ? TRUE : FALSE;
+ }
+ if(backward){
+ Event_Viewer_Data->append = FALSE;
+ do{
+ if(direction == SCROLL_PAGE_UP){
+ minNum = List_Height - Event_Viewer_Data->start_event_index ;
+ }else{
+ minNum = 1;
+ }
+
+ first = Event_Viewer_Data->raw_trace_data_queue->head;
+ raw_data = (RawTraceData*)g_list_nth_data(first,0);
+ end = raw_data->time;
+ end.tv_nsec--;
+ ltt_event_position_get(&raw_data->ep, &block_num, &event_num, &tf);
+ if(size !=0){
+ if(event_num > minNum){
+ backward_num = event_num > RESERVE_SMALL_SIZE
+ ? event_num - RESERVE_SMALL_SIZE : 1;
+ ltt_event_position_set(&raw_data->ep, block_num, backward_num);
+ ltt_tracefile_seek_position(tf, &raw_data->ep);
+ ev = ltt_tracefile_read(tf);
+ start = ltt_event_time(ev);
+ maxNum = G_MAXULONG;
+ }else{
+ if(block_num > 1){
+ ltt_event_position_set(&raw_data->ep, block_num-1, 1);
+ ltt_tracefile_seek_position(tf, &raw_data->ep);
+ ev = ltt_tracefile_read(tf);
+ start = ltt_event_time(ev);
+ }else{
+ start.tv_sec = 0;
+ start.tv_nsec = 0;
+ }
+ maxNum = G_MAXULONG;
+ }
+ }else{
+ if(block_num > count){
+ ltt_event_position_set(&raw_data->ep, block_num-count, 1);
+ ltt_tracefile_seek_position(tf, &raw_data->ep);
+ ev = ltt_tracefile_read(tf);
+ start = ltt_event_time(ev);
+ }else{
+ start.tv_sec = 0;
+ start.tv_nsec = 0;
+ }
+ maxNum = G_MAXULONG;
+ }
+
+ Event_Viewer_Data->current_event_index = Event_Viewer_Data->start_event_index;
+ get_events(Event_Viewer_Data, start, end, maxNum, &size);
+ Event_Viewer_Data->start_event_index = Event_Viewer_Data->current_event_index;
+
+ if(size < minNum && (start.tv_sec !=0 || start.tv_nsec !=0))
+ needBackwardAgain = TRUE;
+ else needBackwardAgain = FALSE;
+ if(size == 0){
+ count++;
+ }else{
+ count = 0;
+ }
+ }while(needBackwardAgain);
+ }
+ if(direction == SCROLL_STEP_UP)
+ Event_Number = Event_Viewer_Data->start_event_index - 1;
+ else
+ Event_Number = Event_Viewer_Data->start_event_index - List_Height;
+ break;
+ case SCROLL_STEP_DOWN:
+ if(Event_Viewer_Data->end_event_index == Event_Viewer_Data->Number_Of_Events - 1){
+ Event_Viewer_Data->append = TRUE;
+ first = Event_Viewer_Data->raw_trace_data_queue->head;
+ raw_data = (RawTraceData*)g_list_nth_data(first,Event_Viewer_Data->Number_Of_Events - 1);
+ start = raw_data->time;
+ start.tv_nsec++;
+ end.tv_sec = G_MAXULONG;
+ end.tv_nsec = G_MAXULONG;
+ get_events(Event_Viewer_Data, start, end, RESERVE_SMALL_SIZE, &size);
+ }else size = 1;
+ if(size > 0) Event_Number = Event_Viewer_Data->start_event_index + 1;
+ else Event_Number = Event_Viewer_Data->start_event_index;
+ break;
+ case SCROLL_PAGE_DOWN:
+ if(Event_Viewer_Data->end_event_index >= Event_Viewer_Data->Number_Of_Events - 1 - List_Height){
+ Event_Viewer_Data->append = TRUE;
+ first = Event_Viewer_Data->raw_trace_data_queue->head;
+ raw_data = (RawTraceData*)g_list_nth_data(first,Event_Viewer_Data->Number_Of_Events - 1);
+ start = raw_data->time;
+ start.tv_nsec++;
+ end.tv_sec = G_MAXULONG;
+ end.tv_nsec = G_MAXULONG;
+ get_events(Event_Viewer_Data, start, end, RESERVE_SMALL_SIZE,&size);
+ }
+ if(List_Height <= Event_Viewer_Data->Number_Of_Events - 1 - Event_Viewer_Data->end_event_index)
+ Event_Number = Event_Viewer_Data->start_event_index + List_Height - 1;
+ else
+ Event_Number = Event_Viewer_Data->Number_Of_Events - 1 - List_Height;
+ break;
+ case SCROLL_JUMP:
+ Event_Viewer_Data->append = TRUE;
+ remove_all_items_from_queue(Event_Viewer_Data->raw_trace_data_queue);
+ end.tv_sec = G_MAXULONG;
+ end.tv_nsec = G_MAXULONG;
+ start = Event_Viewer_Data->time_span.startTime;
+ value = (int)(time_value / NANSECOND_CONST);
+ start.tv_sec += value;
+ value = time_value / NANSECOND_CONST - value;
+ value *= NANSECOND_CONST;
+ start.tv_nsec += value;
+ if(start.tv_nsec > NANSECOND_CONST){
+ start.tv_sec++;
+ start.tv_nsec -= NANSECOND_CONST;
+ }
+ Event_Viewer_Data->previous_value = time_value;
+ get_events(Event_Viewer_Data, start, end, RESERVE_SMALL_SIZE,&size);
+ if(size < List_Height){
+ Event_Viewer_Data->append = FALSE;
+ first = Event_Viewer_Data->raw_trace_data_queue->head;
+ raw_data = (RawTraceData*)g_list_nth_data(first,0);
+ end = raw_data->time;
+ end.tv_nsec--;
+ ltt_event_position_get(&raw_data->ep, &block_num, &event_num, &tf);
+
+ if(event_num > List_Height - size){
+ backward_num = event_num > RESERVE_SMALL_SIZE
+ ? event_num - RESERVE_SMALL_SIZE : 1;
+ ltt_event_position_set(&raw_data->ep, block_num, backward_num);
+ ltt_tracefile_seek_position(tf, &raw_data->ep);
+ ev = ltt_tracefile_read(tf);
+ start = ltt_event_time(ev);
+ maxNum = G_MAXULONG;
+ Event_Viewer_Data->current_event_index = 0;
+ get_events(Event_Viewer_Data, start, end, maxNum, &size);
+ Event_Viewer_Data->start_event_index = Event_Viewer_Data->current_event_index;
+ }
+ Event_Number = Event_Viewer_Data->raw_trace_data_queue->length - List_Height;
+ }else{
+ Event_Number = 0;
+ }
+ break;
+ case SCROLL_NONE:
+ Event_Number = Event_Viewer_Data->current_event_index;
+ break;
+ default:
+ break;
+ }
+
+ //update the value of the scroll bar
+ if(direction != SCROLL_NONE && direction != SCROLL_JUMP){
+ first = Event_Viewer_Data->raw_trace_data_queue->head;
+ raw_data = (RawTraceData*)g_list_nth_data(first,Event_Number);
+ value = raw_data->time.tv_sec;
+ value -= Event_Viewer_Data->time_span.startTime.tv_sec;
+ value *= NANSECOND_CONST;
+ value -= Event_Viewer_Data->time_span.startTime.tv_nsec;
+ value += raw_data->time.tv_nsec;
+ Event_Viewer_Data->VAdjust_C->value = value;
+ g_signal_stop_emission_by_name(G_OBJECT(Event_Viewer_Data->VAdjust_C), "value-changed");
+ Event_Viewer_Data->previous_value = value;
+ }
+
+
+ Event_Viewer_Data->start_event_index = Event_Number;
+ Event_Viewer_Data->end_event_index = Event_Number + List_Height - 1;
+
+ first = Event_Viewer_Data->raw_trace_data_queue->head;
+ gtk_list_store_clear(Event_Viewer_Data->Store_M);
+ for(i=Event_Number; i<Event_Number+List_Height; i++)
+ {
+ guint64 real_data;
+
+ if(i>=Event_Viewer_Data->Number_Of_Events) break;
+
+ raw_data = (RawTraceData*)g_list_nth_data(first, i);
+
+ // Add a new row to the model
+ real_data = raw_data->time.tv_sec;
+ real_data *= NANSECOND_CONST;
+ real_data += raw_data->time.tv_nsec;
+ gtk_list_store_append (Event_Viewer_Data->Store_M, &iter);
+ gtk_list_store_set (Event_Viewer_Data->Store_M, &iter,
+ CPUID_COLUMN, raw_data->cpu_id,
+ EVENT_COLUMN, raw_data->event_name,
+ TIME_COLUMN, real_data,
+ PID_COLUMN, raw_data->pid,
+ ENTRY_LEN_COLUMN, raw_data->entry_length,
+ EVENT_DESCR_COLUMN, raw_data->event_description,
+ -1);
+/*
+ gtk_list_store_append (Event_Viewer_Data->Store_M, &iter);
+ gtk_list_store_set (Event_Viewer_Data->Store_M, &iter,
+ CPUID_COLUMN, 0,
+ EVENT_COLUMN, "event irq",
+ TIME_COLUMN, i,
+ PID_COLUMN, 100,
+ ENTRY_LEN_COLUMN, 17,
+ EVENT_DESCR_COLUMN, "Detailed information",
+ -1);
+*/
+ }
+ }
+#ifdef DEBUG //do not use this, it's slower and broken
+ // } else {
+ /* Some events will be reused */
+ if(Event_Number < Event_Viewer_Data->First_Event)
+ {
+ /* scrolling up, prepend events */
+ Tree_Path = gtk_tree_path_new_from_indices
+ (Event_Number+List_Height-1 -
+ Event_Viewer_Data->First_Event + 1,
+ -1);
+ for(i=0; i<Event_Viewer_Data->Last_Event-(Event_Number+List_Height-1);
+ i++)
+ {
+ /* Remove the last events from the list */
+ if(gtk_tree_model_get_iter(model, &iter, Tree_Path))
+ gtk_list_store_remove(Event_Viewer_Data->Store_M, &iter);
+ }
+
+ for(i=Event_Viewer_Data->First_Event-1; i>=Event_Number; i--)
+ {
+ if(i>=Event_Viewer_Data->Number_Of_Events) break;
+ /* Prepend new events */
+ gtk_list_store_prepend (Event_Viewer_Data->Store_M, &iter);
+ gtk_list_store_set (Event_Viewer_Data->Store_M, &iter,
+ CPUID_COLUMN, 0,
+ EVENT_COLUMN, "event irq",
+ TIME_COLUMN, i,
+ PID_COLUMN, 100,
+ ENTRY_LEN_COLUMN, 17,
+ EVENT_DESCR_COLUMN, "Detailed information",
+ -1);
+ }
+ } else {
+ /* Scrolling down, append events */
+ for(i=Event_Viewer_Data->First_Event; i<Event_Number; i++)