+void get_events(EventViewerData* Event_Viewer_Data, LttTime start,
+ LttTime end,unsigned maxNumEvents, unsigned * realNumEvent)
+{
+ int size;
+ RawTraceData * data;
+ contextAddHooks(Event_Viewer_Data->mw, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL,Event_Viewer_Data->before_event_hooks,NULL);
+ processTraceset(Event_Viewer_Data->mw, start, end, maxNumEvents);
+ contextRemoveHooks(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;
+ *realNumEvent = size;
+ if(size > 0){
+ int pid, tmpPid, i;
+ GList * list, *tmpList;
+
+ //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){
+ data = (RawTraceData*)g_list_nth_data(list, Event_Viewer_Data->raw_trace_data_queue->length-1);
+ pid = data->pid;
+ data = (RawTraceData*)g_list_nth_data(tmpList, 0);
+ tmpPid = data->pid;
+ }else{
+ data = (RawTraceData*)g_list_nth_data(list, 0);
+ pid = data->pid;
+ data = (RawTraceData*)g_list_nth_data(tmpList, Event_Viewer_Data->raw_trace_data_queue_tmp->length-1);
+ tmpPid = data->pid;
+ }
+
+ 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->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->pid = tmpPid;
+ }
+ }
+ }
+
+ //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);
+ }
+ }
+ }
+}
+
+static void get_event_detail(LttEvent *e, LttField *f, GString * s)
+{
+ LttType *type;
+ LttField *element;
+ char *name;
+ int nb, i;
+
+ type = ltt_field_type(f);
+ switch(ltt_type_class(type)) {
+ case LTT_INT:
+ g_string_append_printf(s, " %ld", ltt_event_get_long_int(e,f));
+ break;
+
+ case LTT_UINT:
+ g_string_append_printf(s, " %lu", ltt_event_get_long_unsigned(e,f));
+ break;
+
+ case LTT_FLOAT:
+ g_string_append_printf(s, " %g", ltt_event_get_double(e,f));
+ break;
+
+ case LTT_STRING:
+ g_string_append_printf(s, " \"%s\"", ltt_event_get_string(e,f));
+ break;
+
+ case LTT_ENUM:
+ g_string_append_printf(s, " %s", ltt_enum_string_get(type,
+ ltt_event_get_unsigned(e,f)-1));
+ break;
+
+ case LTT_ARRAY:
+ case LTT_SEQUENCE:
+ g_string_append_printf(s, " {");
+ nb = ltt_event_field_element_number(e,f);
+ element = ltt_field_element(f);
+ for(i = 0 ; i < nb ; i++) {
+ ltt_event_field_element_select(e,f,i);
+ get_event_detail(e, element, s);
+ }
+ g_string_append_printf(s, " }");
+ break;
+
+ case LTT_STRUCT:
+ g_string_append_printf(s, " {");
+ nb = ltt_type_member_number(type);
+ for(i = 0 ; i < nb ; i++) {
+ element = ltt_field_member(f,i);
+ ltt_type_member_type(type, i, &name);
+ g_string_append_printf(s, " %s = ", name);
+ get_event_detail(e, element, s);
+ }
+ g_string_append_printf(s, " }");
+ break;
+ }
+
+}
+
+static void get_pid(unsigned * in, unsigned * out, char * s)
+{
+ char * str;
+ str = strstr(s, "out =");
+ if (str){
+ str = str + 5;
+ sscanf(str,"%d", out);
+ }else{
+ g_warning("Can not find out pid\n");
+ }
+
+ str = strstr(s,"in =");
+ if (str){
+ str = str + 4;
+ sscanf(str,"%d", in);
+ }else{
+ g_warning("Can not find in pid\n");
+ }
+}
+
+gboolean parse_event(void *hook_data, void *call_data)
+{
+ EventViewerData *Event_Viewer_Data = (EventViewerData *)hook_data;
+ LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
+ LttvTracefileState *tfs = (LttvTracefileState *)call_data;
+
+ RawTraceData * tmpRawTraceData,*prevRawTraceData = NULL, *data=NULL;
+ LttEvent *e;
+ LttTime time;
+ LttField * field;
+ unsigned in=0, out=0;
+ int i;
+ GString * detailEvent = g_string_new("");
+ GList * list;
+
+ e = tfc->e;
+ field = ltt_event_field(e);
+ time = ltt_event_time(e);
+
+ if(Event_Viewer_Data->raw_trace_data_queue_tmp->length){
+ list = g_list_last(Event_Viewer_Data->raw_trace_data_queue_tmp->head);
+ prevRawTraceData = (RawTraceData *)(list->data);
+ }
+
+ tmpRawTraceData = g_new(RawTraceData,1);
+ tmpRawTraceData->cpu_id = ltt_event_cpu_id(e);
+ tmpRawTraceData->event_name = g_strdup(ltt_eventtype_name(ltt_event_eventtype(e)));
+ tmpRawTraceData->time = time;
+
+ if(prevRawTraceData) tmpRawTraceData->pid = prevRawTraceData->pid;
+ else tmpRawTraceData->pid = -1;
+
+ tmpRawTraceData->entry_length = field == NULL ? 0 : field->field_size;
+ if(field) get_event_detail(e, field, detailEvent);
+ tmpRawTraceData->event_description = g_strdup(detailEvent->str);
+
+ if(strcmp(tmpRawTraceData->event_name, "schedchange") == 0){
+ get_pid(&in, &out, detailEvent->str);
+ }
+
+
+ if(in != 0 || out != 0){
+ tmpRawTraceData->pid = in;
+ if(prevRawTraceData && prevRawTraceData->pid == -1){
+ list = Event_Viewer_Data->raw_trace_data_queue_tmp->head;
+ for(i=0;i<Event_Viewer_Data->raw_trace_data_queue_tmp->length;i++){
+ data = (RawTraceData *)g_list_nth_data(list,i);
+ data->pid = out;
+ }
+ }
+ }
+
+ ltt_event_position(e, &tmpRawTraceData->ep);
+
+ if(Event_Viewer_Data->raw_trace_data_queue_tmp->length >= RESERVE_SMALL_SIZE){
+ if(Event_Viewer_Data->append){
+ list = g_list_last(Event_Viewer_Data->raw_trace_data_queue_tmp->head);
+ data = (RawTraceData *)(list->data);
+ if(data->time.tv_sec == time.tv_sec &&
+ data->time.tv_nsec == time.tv_nsec){
+ g_queue_push_tail(Event_Viewer_Data->raw_trace_data_queue_tmp,tmpRawTraceData);
+ }else{
+ g_free(tmpRawTraceData);
+ }
+ }else{
+ remove_item_from_queue(Event_Viewer_Data->raw_trace_data_queue_tmp,TRUE);
+ g_queue_push_tail(Event_Viewer_Data->raw_trace_data_queue_tmp,tmpRawTraceData);
+ }
+ }else{
+ g_queue_push_tail (Event_Viewer_Data->raw_trace_data_queue_tmp,tmpRawTraceData);
+ }
+
+ g_string_free(detailEvent, TRUE);
+
+ return FALSE;
+}
+
+void remove_item_from_queue(GQueue * q, gboolean fromHead)
+{
+ RawTraceData *data1, *data2 = NULL;
+ GList * list;
+
+ if(fromHead){
+ data1 = (RawTraceData *)g_queue_pop_head(q);
+ list = g_list_first(q->head);
+ if(list)
+ data2 = (RawTraceData *)(list->data);
+ }else{
+ data1 = (RawTraceData *)g_queue_pop_tail(q);
+ list = g_list_last(q->head);
+ if(list)
+ data2 = (RawTraceData *)(list->data);
+ }
+
+ if(data2){
+ if(data1->time.tv_sec == data2->time.tv_sec &&
+ data1->time.tv_nsec == data2->time.tv_nsec){
+ remove_item_from_queue(q, fromHead);
+ }
+ }
+
+ g_free(data1);
+
+ return;
+}
+
+void remove_all_items_from_queue(GQueue *q)
+{
+ RawTraceData *data;
+ while((data = (RawTraceData *)g_queue_pop_head(q)) != NULL){
+ g_free(data);
+ }
+}
+
+void remove_instance(GtkCustomHBox * box){
+ int i;
+ EventViewerData *Event_Viewer_Data ;
+
+ for(i=0;i<g_slist_length(sEvent_Viewer_Data_List);i++){
+ Event_Viewer_Data = (EventViewerData *)g_slist_nth_data(sEvent_Viewer_Data_List, i);
+ if((void*)box == (void*)Event_Viewer_Data->instance_container){
+ sEvent_Viewer_Data_List = g_slist_remove(sEvent_Viewer_Data_List, Event_Viewer_Data);
+ GuiEvents_free(Event_Viewer_Data);
+ break;
+ }
+ }
+}