X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Flttv%2Fstats.c;h=4265853d83bab764b3ff032d674f7ff65db7156c;hb=8988dccf4c097d6f96e72ececda8646e974b0a58;hp=d0bb4cdf6ea2a855144d530942d3faf194972968;hpb=b445142a71748192520cfd645b4963e23070a486;p=lttv.git diff --git a/ltt/branches/poly/lttv/stats.c b/ltt/branches/poly/lttv/stats.c index d0bb4cdf..4265853d 100644 --- a/ltt/branches/poly/lttv/stats.c +++ b/ltt/branches/poly/lttv/stats.c @@ -1,9 +1,12 @@ +#include #include #include #include #include +#define BUF_SIZE 256 + GQuark LTTV_STATS_PROCESS_UNKNOWN, LTTV_STATS_PROCESSES, @@ -327,9 +330,9 @@ static void mode_change(LttvTracefileStats *tfcs) lttv_attribute_find(tfcs->current_events_tree, LTTV_STATS_CPU_TIME, LTTV_TIME, &cpu_time); - TimeSub(delta, tfcs->parent.parent.timestamp, + delta = ltt_time_sub(tfcs->parent.parent.timestamp, tfcs->parent.process->state->change); - TimeAdd(*(cpu_time.v_time), *(cpu_time.v_time), delta); + *(cpu_time.v_time) = ltt_time_add(*(cpu_time.v_time), delta); } @@ -341,15 +344,15 @@ static void mode_end(LttvTracefileStats *tfcs) lttv_attribute_find(tfcs->current_events_tree, LTTV_STATS_ELAPSED_TIME, LTTV_TIME, &elapsed_time); - TimeSub(delta, tfcs->parent.parent.timestamp, + delta = ltt_time_sub(tfcs->parent.parent.timestamp, tfcs->parent.process->state->entry); - TimeAdd(*(elapsed_time.v_time), *(elapsed_time.v_time), delta); + *(elapsed_time.v_time) = ltt_time_add(*(elapsed_time.v_time), delta); lttv_attribute_find(tfcs->current_events_tree, LTTV_STATS_CPU_TIME, LTTV_TIME, &cpu_time); - TimeSub(delta, tfcs->parent.parent.timestamp, + delta = ltt_time_sub(tfcs->parent.parent.timestamp, tfcs->parent.process->state->change); - TimeAdd(*(cpu_time.v_time), *(cpu_time.v_time), delta); + *(cpu_time.v_time) = ltt_time_add(*(cpu_time.v_time), delta); } @@ -794,6 +797,7 @@ lttv_stats_remove_event_hooks(LttvTracesetStats *self) hook.id), hook.h, &g_array_index(after_hooks, LttvTraceHook, k)); } } + g_critical("lttv_stats_remove_event_hooks()"); g_array_free(before_hooks, TRUE); g_array_free(after_hooks, TRUE); } @@ -822,3 +826,355 @@ void lttv_stats_destroy() { } +void lttv_stats_save_attribute(LttvAttribute *attr, char *indent, FILE * fp) +{ + LttvAttributeType type; + LttvAttributeValue value; + LttvAttributeName name; + char type_value[BUF_SIZE]; + int i, nb_attr, flag; + + nb_attr = lttv_attribute_get_number(attr); + for(i=0;itv_sec, + value.v_time->tv_nsec); + break; + case LTTV_POINTER: + sprintf(type_value, "POINTER\0"); + break; + case LTTV_STRING: + sprintf(type_value, "%s\0", *value.v_string); + break; + default: + flag = 0; + break; + } + if(flag == 0) continue; + fprintf(fp,"%s",indent,type,g_quark_to_string(name)); + fprintf(fp,"%s",type_value); + fprintf(fp," \n"); + } + +} + +void lttv_stats_save_statistics(LttvTracesetStats *self) +{ + LttvTracesetStats *tscs = self; + LttvTraceStats *tcs; + LttvTraceset *traceset = tscs->parent.parent.ts; + LttvAttributeType type; + LttvAttributeValue value; + LttvAttributeName name; + + char filename[BUF_SIZE]; + FILE * fp; + char indent[10][24]= {" ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " " + }; + + + int i, j, k, l, m, n, nb_trace, nb_process, nb_cpu, nb_mode_type, nb_submode; + + LttvAttribute *main_tree, *processes_tree, *process_tree, *cpus_tree, + *cpu_tree, *mode_tree, *mode_types_tree, *submodes_tree, + *submode_tree, *event_types_tree; + + nb_trace = lttv_traceset_number(traceset); + + for(i = 0 ; i < nb_trace ; i++) { + tcs = (LttvTraceStats *)(tscs->parent.parent.traces[i]); + + filename[0] = '\0'; + strcat(filename,ltt_trace_name(tcs->parent.parent.t)); + strcat(filename,"/statistics.xml"); + fp = fopen(filename,"w"); + if(!fp){ + g_warning("can not open the file %s for saving statistics\n", filename); + exit(1); + } + + main_tree = tcs->stats; + processes_tree = lttv_attribute_find_subdir(main_tree, LTTV_STATS_PROCESSES); + nb_process = lttv_attribute_get_number(processes_tree); + + fprintf(fp, " \n",g_quark_to_string(LTTV_STATS_PROCESSES)); //root NODE + + for(j = 0 ; j < nb_process ; j++) { + type = lttv_attribute_get(processes_tree, j, &name, &value); + process_tree = LTTV_ATTRIBUTE(*(value.v_gobject)); + + fprintf(fp,"%s \n",indent[0],g_quark_to_string(name)); //process NODE + lttv_stats_save_attribute(process_tree,indent[1], fp); + fprintf(fp,"%s \n", indent[1],g_quark_to_string(LTTV_STATS_CPU)); //cpus NODE + + cpus_tree = lttv_attribute_find_subdir(process_tree, LTTV_STATS_CPU); + nb_cpu = lttv_attribute_get_number(cpus_tree); + + for(k = 0 ; k < nb_cpu ; k++) { + type = lttv_attribute_get(cpus_tree, k, &name, &value); + cpu_tree = LTTV_ATTRIBUTE(*(value.v_gobject)); + + fprintf(fp,"%s \n",indent[2],g_quark_to_string(name)); //cpu NODE + lttv_stats_save_attribute(cpu_tree,indent[3], fp); + fprintf(fp,"%s \n",indent[3],g_quark_to_string(LTTV_STATS_MODE_TYPES)); //mode_types NODE + + mode_types_tree = lttv_attribute_find_subdir(cpu_tree,LTTV_STATS_MODE_TYPES); + nb_mode_type = lttv_attribute_get_number(mode_types_tree); + + for(l = 0 ; l < nb_mode_type ; l++) { + type = lttv_attribute_get(mode_types_tree, l, &name, &value); + mode_tree = LTTV_ATTRIBUTE(*(value.v_gobject)); + + fprintf(fp,"%s \n",indent[4],g_quark_to_string(name)); //mode NODE + lttv_stats_save_attribute(mode_tree,indent[5], fp); + fprintf(fp,"%s \n",indent[5],g_quark_to_string(LTTV_STATS_SUBMODES)); //sub_modes NODE + + submodes_tree = lttv_attribute_find_subdir(mode_tree,LTTV_STATS_SUBMODES); + nb_submode = lttv_attribute_get_number(submodes_tree); + + for(m = 0 ; m < nb_submode ; m++) { + type = lttv_attribute_get(submodes_tree, m, &name, &value); + submode_tree = LTTV_ATTRIBUTE(*(value.v_gobject)); + fprintf(fp,"%s \n",indent[6],g_quark_to_string(name)); //sub_mode NODE + lttv_stats_save_attribute(submode_tree,indent[7], fp); + fprintf(fp,"%s \n",indent[7],g_quark_to_string(LTTV_STATS_EVENT_TYPES)); //event_types NODE + + event_types_tree = lttv_attribute_find_subdir(submode_tree, LTTV_STATS_EVENT_TYPES); + lttv_stats_save_attribute(event_types_tree,indent[8], fp); + + fprintf(fp,"%s \n",indent[7]); //event_types NODE + fprintf(fp,"%s \n",indent[6]); //sub_mode NODE + } + fprintf(fp,"%s \n",indent[5]); //sub_modes NODE + fprintf(fp,"%s \n",indent[4]); //mode NODE + } + fprintf(fp,"%s \n",indent[3]); //mode_type NODE + fprintf(fp,"%s \n",indent[2]); //cpu NODE + } + fprintf(fp,"%s \n",indent[1]); //cpus NODE + fprintf(fp,"%s \n", indent[0]); //process NODE + } + fprintf(fp, "\n"); //root NODE + fclose(fp); + } +} + + +/* Functions to parse statistic.xml file (using glib xml parser) */ + +typedef struct _ParserStruct{ + GPtrArray * attribute; + LttvAttributeType type; + LttvAttributeName name; +} ParserStruct; + +static void stats_parser_start_element (GMarkupParseContext *context, + const gchar *element_name, + const gchar **attribute_names, + const gchar **attribute_values, + gpointer user_data, + GError **error) +{ + ParserStruct * parser = (ParserStruct *)user_data; + int len; + LttvAttributeType type; + LttvAttributeName name; + LttvAttribute * parent_att, *new_att; + + len = parser->attribute->len; + parent_att = (LttvAttribute *)g_ptr_array_index (parser->attribute, len-1); + + if(strcmp("NODE", element_name) == 0){ + type = LTTV_GOBJECT; + name = g_quark_from_string(attribute_values[0]); + new_att = lttv_attribute_find_subdir(parent_att,name); + g_ptr_array_add(parser->attribute, (gpointer)new_att); + }else if(strcmp("VALUE", element_name) == 0){ + parser->type = (LttvAttributeType) atoi(attribute_values[0]); + parser->name = g_quark_from_string(attribute_values[1]); + }else{ + g_warning("This is not statistics.xml file\n"); + exit(1); + } +} + +static void stats_parser_end_element (GMarkupParseContext *context, + const gchar *element_name, + gpointer user_data, + GError **error) +{ + ParserStruct * parser = (ParserStruct *)user_data; + int len; + LttvAttribute * parent_att; + + len = parser->attribute->len; + parent_att = (LttvAttribute *)g_ptr_array_index (parser->attribute, len-1); + + if(strcmp("NODE", element_name) == 0){ + g_ptr_array_remove_index(parser->attribute, len-1); + }else if(strcmp("VALUE", element_name) == 0){ + }else{ + g_warning("This is not statistics.xml file\n"); + exit(1); + } + +} + +static void stats_parser_characters (GMarkupParseContext *context, + const gchar *text, + gsize text_len, + gpointer user_data, + GError **error) +{ + ParserStruct * parser = (ParserStruct *)user_data; + LttvAttributeValue value; + int len; + LttvAttribute * parent_att; + char *pos; + + pos = (char*)text; + for(len=0;lenattribute->len; + parent_att = (LttvAttribute *)g_ptr_array_index (parser->attribute, len-1); + if(!lttv_attribute_find(parent_att,parser->name, parser->type, &value)){ + g_warning("can not find value\n"); + exit(1); + } + + switch(parser->type) { + case LTTV_INT: + *value.v_int = atoi(text); + break; + case LTTV_UINT: + *value.v_uint = (unsigned)atoi(text); + break; + case LTTV_LONG: + *value.v_long = atol(text); + break; + case LTTV_ULONG: + *value.v_ulong = (unsigned long)atol(text); + break; + case LTTV_FLOAT: + *value.v_float = atof(text); + break; + case LTTV_DOUBLE: + *value.v_float = atof(text); + break; + case LTTV_TIME: + pos = strrchr(text,'.'); + if(pos){ + *pos = '\0'; + pos++; + value.v_time->tv_sec = atol(text); + value.v_time->tv_nsec = atol(pos); + }else{ + g_warning("The time value format is wrong\n"); + exit(1); + } + break; + case LTTV_POINTER: + break; + case LTTV_STRING: + *value.v_string = g_strdup(text); + break; + default: + break; + } + +} + +gboolean lttv_stats_load_statistics(LttvTracesetStats *self) +{ + FILE * fp; + char buf[BUF_SIZE]; + LttvTracesetStats *tscs = self; + LttvTraceStats *tcs; + LttvTraceset *traceset = tscs->parent.parent.ts; + char filename[BUF_SIZE]; + + GMarkupParseContext * context; + GError * error; + GMarkupParser markup_parser = + { + stats_parser_start_element, + stats_parser_end_element, + stats_parser_characters, + NULL, /* passthrough */ + NULL /* error */ + }; + + int i, nb_trace; + LttvAttribute *main_tree; + ParserStruct a_parser_struct; + a_parser_struct.attribute = g_ptr_array_new(); + + nb_trace = lttv_traceset_number(traceset); + + for(i = 0 ; i < nb_trace ; i++) { + tcs = (LttvTraceStats *)(tscs->parent.parent.traces[i]); + + filename[0] = '\0'; + strcat(filename,ltt_trace_name(tcs->parent.parent.t)); + strcat(filename,"/statistics.xml"); + fp = fopen(filename,"r"); + if(!fp){ + g_warning("can not open the file %s for reading statistics\n", filename); + return FALSE; + } + + main_tree = tcs->stats; + g_ptr_array_add(a_parser_struct.attribute,(gpointer)main_tree); + + context = g_markup_parse_context_new(&markup_parser, 0, (gpointer)&a_parser_struct, NULL); + + while(fgets(buf,BUF_SIZE, fp) != NULL){ + if(!g_markup_parse_context_parse(context, buf, BUF_SIZE, &error)){ + g_warning("Can not parse xml file: \n%s\n", error->message); + exit(1); + } + } + fclose(fp); + } + + sum_stats(NULL, (void *)self); + + return TRUE; +}