/* destroys the whole tree instance */ extern void stats_tree_free(stats_tree *st) { stat_node *child; stat_node *next; g_free(st->filter); g_hash_table_destroy(st->names); g_ptr_array_free(st->parents,TRUE); g_free(st->display_name); for (child = st->root.children; child; child = next ) { /* child->next will be gone after free_stat_node, so cache it here */ next = child->next; free_stat_node(child); } if (st->cfg->free_tree_pr) st->cfg->free_tree_pr(st); if (st->cfg->cleanup) st->cfg->cleanup(st); g_free(st); }
/* frees the resources allocated by a stat_tree node */ static void free_stat_node(stat_node *node) { stat_node *child; stat_node *next; burst_bucket *bucket; if (node->children) { for (child = node->children; child; child = next ) { /* child->next will be gone after free_stat_node, so cache it here */ next = child->next; free_stat_node(child); } } if(node->st->cfg->free_node_pr) node->st->cfg->free_node_pr(node); if (node->hash) g_hash_table_destroy(node->hash); while (node->bh) { bucket = node->bh; node->bh = bucket->next; g_free(bucket); } g_free(node->rng); g_free(node->name); g_free(node); }
extern void stats_tree_reinit(void *p) { stats_tree *st = (stats_tree *)p; stat_node *child; stat_node *next; for (child = st->root.children; child; child = next) { /* child->next will be gone after free_stat_node, so cache it here */ next = child->next; free_stat_node(child); } st->root.children = NULL; st->root.counter = 0; if (st->cfg->init) { st->cfg->init(st); } }
extern void stats_tree_reinit(void *p) { stats_tree *st = (stats_tree *)p; stat_node *child; stat_node *next; for (child = st->root.children; child; child = next) { /* child->next will be gone after free_stat_node, so cache it here */ next = child->next; free_stat_node(child); } st->root.children = NULL; st->root.counter = 0; st->root.total = 0; st->root.minvalue = G_MAXINT; st->root.maxvalue = G_MININT; st->root.st_flags = 0; st->root.bh = (burst_bucket*)g_malloc0(sizeof(burst_bucket)); st->root.bt = st->root.bh; st->root.bcount = 0; st->root.max_burst = 0; st->root.burst_time = -1.0; /* No more stat_nodes left in tree - clean out hash, array */ g_hash_table_remove_all(st->names); if (st->parents->len>1) { g_ptr_array_remove_range(st->parents, 1, st->parents->len-1); } /* Do not update st_flags for the tree (sorting) - leave as was */ st->num_columns = N_COLUMNS; g_free(st->display_name); st->display_name= stats_tree_get_displayname(st->cfg->name); if (st->cfg->init) { st->cfg->init(st); } }