+ RawTraceData * data;
+ if(size > 0){
+ int pid, tmpPid, i,j,len;
+ GList * list, *tmpList;
+ GArray * pid_array, * tmp_pid_array;
+
+ pid_array = g_array_sized_new(FALSE, TRUE, sizeof(int), 10);
+ tmp_pid_array = g_array_sized_new(FALSE, TRUE, sizeof(int), 10);
+
+ //if the queue is full, remove some data, keep the size of the queue constant
+ while(event_viewer_data->raw_trace_data_queue->length + size > RESERVE_BIG_SIZE){
+ remove_item_from_queue(event_viewer_data->raw_trace_data_queue,
+ event_viewer_data->append);
+ }
+
+ //update pid if it is not known
+ if(event_viewer_data->raw_trace_data_queue->length > 0){
+ list = event_viewer_data->raw_trace_data_queue->head;
+ tmpList = event_viewer_data->raw_trace_data_queue_tmp->head;
+ if(event_viewer_data->append){
+ for(i= event_viewer_data->raw_trace_data_queue->length-1;i>=0;i--){
+ data = (RawTraceData*)g_list_nth_data(list,i);
+ len = data->pid==0 ? -2 : data->pid;
+ if(data->cpu_id+1 > pid_array->len){
+ pid_array = g_array_set_size(pid_array,data->cpu_id+1);
+ pid_array = g_array_insert_val(pid_array,data->cpu_id,len);
+ pid_array = g_array_remove_index(pid_array,data->cpu_id+1);
+ }else if(data->cpu_id+1 < pid_array->len){
+ pid = g_array_index(pid_array,int,data->cpu_id);
+ if(pid == 0){
+ pid_array = g_array_insert_val(pid_array,data->cpu_id,len);
+ pid_array = g_array_remove_index(pid_array,data->cpu_id+1);
+ }
+ }
+ }
+
+ for(i=0;i<event_viewer_data->raw_trace_data_queue_tmp->length-1;i++){
+ data = (RawTraceData*)g_list_nth_data(tmpList,i);
+ len = data->pid==0 ? -2 : data->pid;
+ if(data->cpu_id+1 > tmp_pid_array->len){
+ tmp_pid_array = g_array_set_size(tmp_pid_array,data->cpu_id+1);
+ tmp_pid_array = g_array_insert_val(tmp_pid_array,data->cpu_id,len);
+ tmp_pid_array = g_array_remove_index(tmp_pid_array,data->cpu_id+1);
+ }else if(data->cpu_id+1 < tmp_pid_array->len){
+ pid = g_array_index(tmp_pid_array,int,data->cpu_id);
+ if(pid == 0){
+ tmp_pid_array = g_array_insert_val(tmp_pid_array,data->cpu_id,len);
+ tmp_pid_array = g_array_remove_index(tmp_pid_array,data->cpu_id+1);
+ }
+ }
+ }
+ }else{
+ for(i=0;i<event_viewer_data->raw_trace_data_queue->length-1;i++){
+ data = (RawTraceData*)g_list_nth_data(list,i);
+ len = data->pid==0 ? -2 : data->pid;
+ if(data->cpu_id+1 > pid_array->len){
+ pid_array = g_array_set_size(pid_array,data->cpu_id+1);
+ pid_array = g_array_insert_val(pid_array,data->cpu_id,len);
+ pid_array = g_array_remove_index(pid_array,data->cpu_id+1);
+ }else if(data->cpu_id+1 < pid_array->len){
+ pid = g_array_index(pid_array,int,data->cpu_id);
+ if(pid == 0){
+ pid_array = g_array_insert_val(pid_array,data->cpu_id,len);
+ pid_array = g_array_remove_index(pid_array,data->cpu_id+1);
+ }
+ }
+ }
+
+ for(i=event_viewer_data->raw_trace_data_queue_tmp->length-1;i>=0;i--){
+ data = (RawTraceData*)g_list_nth_data(tmpList,i);
+ len = data->pid==0 ? -2 : data->pid;
+ if(data->cpu_id+1 > tmp_pid_array->len){
+ tmp_pid_array = g_array_set_size(tmp_pid_array,data->cpu_id+1);
+ tmp_pid_array = g_array_insert_val(tmp_pid_array,data->cpu_id,len);
+ tmp_pid_array = g_array_remove_index(tmp_pid_array,data->cpu_id+1);
+ }else if(data->cpu_id+1 < tmp_pid_array->len){
+ pid = g_array_index(tmp_pid_array,int,data->cpu_id);
+ if(pid == 0){
+ tmp_pid_array = g_array_insert_val(tmp_pid_array,data->cpu_id,len);
+ tmp_pid_array = g_array_remove_index(tmp_pid_array,data->cpu_id+1);
+ }
+ }
+ }
+ }
+
+ len = pid_array->len > tmp_pid_array->len ? tmp_pid_array->len : pid_array->len;
+ for(j=0;j<len;j++){
+ pid = g_array_index(pid_array,int, j);
+ tmpPid = g_array_index(tmp_pid_array,int,j);
+ if(pid == -2)pid = 0;
+ if(tmpPid == -2) tmpPid = 0;
+
+ if(pid == -1 && tmpPid != -1){
+ for(i=0;i<event_viewer_data->raw_trace_data_queue->length;i++){
+ data = (RawTraceData*)g_list_nth_data(list,i);
+ if(data->pid == -1 && data->cpu_id == j) data->pid = tmpPid;
+ }
+ }else if(pid != -1 && tmpPid == -1){
+ for(i=0;i<event_viewer_data->raw_trace_data_queue_tmp->length;i++){
+ data = (RawTraceData*)g_list_nth_data(tmpList,i);
+ if(data->pid == -1 && data->cpu_id == j) data->pid = pid;
+ }
+ }
+ }
+ }
+
+ g_array_free(pid_array,TRUE);
+ g_array_free(tmp_pid_array, TRUE);
+
+ //add data from tmp queue into the queue
+ event_viewer_data->number_of_events = event_viewer_data->raw_trace_data_queue->length
+ + event_viewer_data->raw_trace_data_queue_tmp->length;
+ if(event_viewer_data->append){
+ if(event_viewer_data->raw_trace_data_queue->length > 0)
+ event_viewer_data->current_event_index = event_viewer_data->raw_trace_data_queue->length - 1;
+ else event_viewer_data->current_event_index = 0;
+ while((data = g_queue_pop_head(event_viewer_data->raw_trace_data_queue_tmp)) != NULL){
+ g_queue_push_tail(event_viewer_data->raw_trace_data_queue, data);
+ }
+ }else{
+ event_viewer_data->current_event_index += event_viewer_data->raw_trace_data_queue_tmp->length;
+ while((data = g_queue_pop_tail(event_viewer_data->raw_trace_data_queue_tmp)) != NULL){
+ g_queue_push_head(event_viewer_data->raw_trace_data_queue, data);
+ }
+ }
+ }
+}
+
+void get_events(EventViewerData* event_viewer_data, LttTime start,
+ LttTime end,unsigned max_num_events, unsigned * real_num_events)
+{
+ int size;
+ LttvTracesetContext * tsc = get_traceset_context(event_viewer_data->mw);
+
+ // context_add_hooks_api(event_viewer_data->mw, NULL, NULL, NULL, NULL, NULL, NULL,
+ // NULL, NULL, NULL,event_viewer_data->before_event_hooks,NULL);
+ add_context_hooks(event_viewer_data,tsc);
+
+ process_traceset_api(event_viewer_data->mw, start, end, max_num_events);
+
+ remove_context_hooks(event_viewer_data,tsc);
+ // context_remove_hooks_api(event_viewer_data->mw, NULL, NULL, NULL, NULL, NULL, NULL,
+ // NULL, NULL, NULL,event_viewer_data->before_event_hooks,NULL);
+
+ size = event_viewer_data->raw_trace_data_queue_tmp->length;
+ *real_num_events = size;