void categories_initialize(struct hash_table *categories, struct rmsummary *top, const char *summaries_file) { struct list *summaries = rmsummary_parse_file_multiple(summaries_file); if(!summaries) { fatal("Could not read '%s' file: %s\n", strerror(errno)); } char *name; struct category *c; hash_table_firstkey(categories); while(hash_table_nextkey(categories, &name, (void **) &c)) { category_clear_histograms(c); if(c->first_allocation) { rmsummary_delete(c->first_allocation); c->first_allocation = rmsummary_create(-1); } } struct rmsummary *s; list_first_item(summaries); while((s = list_pop_head(summaries))) { if(s->category) { c = category_lookup_or_create(categories, s->category); category_accumulate_summary(c, s, NULL); } rmsummary_delete(s); } hash_table_firstkey(categories); while(hash_table_nextkey(categories, &name, (void **) &c)) { category_update_first_allocation(c, NULL); category_clear_histograms(c); } }
struct rmDsummary *parse_summary(FILE *stream, char *filename, struct hash_table *categories) { static FILE *last_stream = NULL; static int summ_id = 1; if(last_stream != stream) { last_stream = stream; summ_id = 1; } else { summ_id++; } struct rmsummary *so = rmsummary_parse_next(stream); if(!so) return NULL; if(categories) { struct category *c = category_lookup_or_create(categories, ALL_SUMMARIES_CATEGORY); category_accumulate_summary(c, so, NULL); if(so->category) { c = category_lookup_or_create(categories, so->category); category_accumulate_summary(c, so, NULL); } } struct rmDsummary *s = rmsummary_to_rmDsummary(so); s->file = xxstrdup(filename); if(!s->task_id) { s->task_id = get_rule_number(filename); } rmsummary_delete(so); return s; }