Several fixes to the stats_tree
- Avoid creating a copy of every branch at reinitialization this used to cause some GTK warnings and a leakage of tree nodes - propperly check the optarg to avoid getting junk in the filter text this caused a crash svn path=/trunk/; revision=13534
This commit is contained in:
parent
f2375c3127
commit
93c46dde91
|
@ -153,6 +153,7 @@ static void free_stat_node( stat_node* node ) {
|
|||
if(node->st->free_node_pr) node->st->free_node_pr(node);
|
||||
|
||||
if (node->hash) g_hash_table_destroy(node->hash);
|
||||
|
||||
if (node->rng) g_free(node->rng);
|
||||
|
||||
if (node->name) g_free(node->name);
|
||||
|
@ -213,6 +214,9 @@ extern void reinit_stats_tree(void* p) {
|
|||
free_stat_node(child);
|
||||
}
|
||||
|
||||
st->root.children = NULL;
|
||||
st->root.counter = 0;
|
||||
|
||||
if (st->init) {
|
||||
st->init(st);
|
||||
}
|
||||
|
@ -364,7 +368,8 @@ static stat_node* new_stat_node(stats_tree* st,
|
|||
node->st = (stats_tree*) st;
|
||||
node->hash = with_hash ? g_hash_table_new(g_str_hash,g_str_equal) : NULL;
|
||||
node->parent = NULL;
|
||||
|
||||
node->rng = NULL;
|
||||
|
||||
if (as_parent_node) {
|
||||
g_hash_table_insert(st->names,
|
||||
node->name,
|
||||
|
|
|
@ -97,6 +97,9 @@ extern int tick_range(stats_tree* st,
|
|||
int parent_id,
|
||||
int value_in_range);
|
||||
|
||||
#define tick_range_with_parent_name(st,name,parent_name,value_in_range) \
|
||||
tick_range((st),(name),get_parent_id_by_name((st),(parent_name),(value_in_range))
|
||||
|
||||
/* */
|
||||
extern int create_pivot_node(stats_tree* st,
|
||||
const gchar* name,
|
||||
|
|
|
@ -77,7 +77,6 @@ struct _stats_tree {
|
|||
guint8* name;
|
||||
guint8* tapname;
|
||||
|
||||
/* is this realy needed? */
|
||||
char* filter;
|
||||
|
||||
/* times */
|
||||
|
|
|
@ -24,12 +24,10 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
TODO
|
||||
TODO:
|
||||
|
||||
- at reinitialization I have one of these for every node in the tree
|
||||
Gtk-CRITICAL **: file gtktreestore.c: line 1044 (gtk_tree_store_set): assertion `VALID_ITER (iter, tree_store)' failed
|
||||
|
||||
- GTK1
|
||||
- GTK1 something better than just a textbox
|
||||
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
@ -93,17 +91,19 @@ static void setup_gtk_node_pr(stat_node* node) {
|
|||
GtkTreeIter* parent = NULL;
|
||||
#endif
|
||||
|
||||
|
||||
node->pr = g_malloc(sizeof(st_node_pres));
|
||||
|
||||
#if GTK_MAJOR_VERSION >= 2
|
||||
if ( node->parent && node->parent->pr )
|
||||
|
||||
if ( node->parent && node->parent->pr ) {
|
||||
parent = node->parent->pr->iter;
|
||||
|
||||
node->pr->iter = g_malloc(sizeof(GtkTreeIter));
|
||||
|
||||
}
|
||||
|
||||
if (node->st->pr->store) {
|
||||
node->pr->iter = g_malloc0(sizeof(GtkTreeIter));
|
||||
|
||||
gtk_tree_store_append (node->st->pr->store, node->pr->iter, parent);
|
||||
/* g_message("setup_gtk_node_pr: %s",node->name); */
|
||||
gtk_tree_store_set(node->st->pr->store, node->pr->iter, TITLE_COLUMN, node->name, RATE_COLUMN, "", COUNT_COLUMN, "", -1);
|
||||
}
|
||||
#else
|
||||
|
@ -123,7 +123,6 @@ static void draw_gtk_node(stat_node* node) {
|
|||
get_strings_from_node(node, value, rate, percent);
|
||||
|
||||
if (node->st->pr->store) {
|
||||
/* g_message("draw_gtk_node: %s",node->name); */
|
||||
gtk_tree_store_set(node->st->pr->store, node->pr->iter,
|
||||
RATE_COLUMN, rate,
|
||||
COUNT_COLUMN, value,
|
||||
|
@ -145,10 +144,10 @@ static void draw_gtk_tree( void *psp ) {
|
|||
stat_node* child;
|
||||
|
||||
#if GTK_MAJOR_VERSION >= 2
|
||||
for (child = st->root.children; child; child = child->next )
|
||||
|
||||
for (child = st->root.children; child; child = child->next ) {
|
||||
draw_gtk_node(child);
|
||||
|
||||
gtk_tree_view_set_model(GTK_TREE_VIEW(st->pr->tree),GTK_TREE_MODEL(st->pr->store));
|
||||
}
|
||||
#else
|
||||
GString* text = g_string_new("");
|
||||
gchar* fmt;
|
||||
|
@ -163,12 +162,12 @@ static void draw_gtk_tree( void *psp ) {
|
|||
stat_branch_to_str(child,text,0);
|
||||
}
|
||||
|
||||
gtk_text_freeze(st->pr->textbox);
|
||||
gtk_text_set_point(st->pr->textbox,0);
|
||||
gtk_text_forward_delete(st->pr->textbox,gtk_text_get_length(st->pr->textbox));
|
||||
gtk_text_insert(st->pr->textbox,NULL,
|
||||
gtk_text_freeze(GTK_TEXT(st->pr->textbox));
|
||||
gtk_text_set_point(GTK_TEXT(st->pr->textbox),0);
|
||||
gtk_text_forward_delete(GTK_TEXT(st->pr->textbox),gtk_text_get_length(st->pr->textbox));
|
||||
gtk_text_insert(GTK_TEXT(st->pr->textbox),NULL,
|
||||
NULL,NULL,text->str,-1);
|
||||
gtk_text_thaw(st->pr->textbox);
|
||||
gtk_text_thaw(GTK_TEXT(st->pr->textbox));
|
||||
|
||||
g_string_free(text,TRUE);
|
||||
#endif
|
||||
|
@ -199,6 +198,7 @@ static void init_gtk_tree(char* optarg) {
|
|||
guint8* window_name = NULL;
|
||||
GString* error_string;
|
||||
GtkWidget *scr_win;
|
||||
guint init_strlen;
|
||||
#if GTK_MAJOR_VERSION >= 2
|
||||
GtkTreeViewColumn* column;
|
||||
GtkCellRenderer* renderer;
|
||||
|
@ -208,8 +208,15 @@ static void init_gtk_tree(char* optarg) {
|
|||
st = get_stats_tree_by_abbr(abbr);
|
||||
|
||||
if (st != NULL) {
|
||||
if (strncmp (optarg, st->pr->stat_dlg->init_string, strlen(st->pr->stat_dlg->init_string)) == 0){
|
||||
st->filter=((guint8*)optarg)+strlen(st->pr->stat_dlg->init_string);
|
||||
init_strlen = strlen(st->pr->stat_dlg->init_string);
|
||||
|
||||
if (strncmp (optarg, st->pr->stat_dlg->init_string, init_strlen) == 0){
|
||||
if (init_strlen == strlen(optarg)) {
|
||||
st->filter= "";
|
||||
} else {
|
||||
st->filter=((guint8*)optarg)+init_strlen+1;
|
||||
}
|
||||
|
||||
} else {
|
||||
st->filter=NULL;
|
||||
}
|
||||
|
@ -222,7 +229,7 @@ static void init_gtk_tree(char* optarg) {
|
|||
g_error("could not obtain stats_tree abbr from optarg");
|
||||
}
|
||||
|
||||
window_name = g_strdup_printf("%s Stats Tree", st->abbr);
|
||||
window_name = g_strdup_printf("%s Stats Tree", st->name);
|
||||
|
||||
st->pr->win = window_new_with_geom(GTK_WINDOW_TOPLEVEL,window_name,window_name);
|
||||
g_free(window_name);
|
||||
|
@ -283,16 +290,16 @@ static void init_gtk_tree(char* optarg) {
|
|||
gtk_tree_view_column_set_sizing(column,GTK_TREE_VIEW_COLUMN_AUTOSIZE);
|
||||
gtk_tree_view_append_column (GTK_TREE_VIEW (st->pr->tree), column);
|
||||
#else
|
||||
st->pr->textbox = gtk_text_new(NULL,NULL);
|
||||
gtk_text_set_editable(st->pr->textbox,TRUE);
|
||||
gtk_container_add( GTK_CONTAINER(scr_win), st->pr->textbox);
|
||||
st->pr->textbox = GTK_TEXT(gtk_text_new(NULL,NULL));
|
||||
gtk_text_set_editable(GTK_TEXT(st->pr->textbox),TRUE);
|
||||
gtk_container_add( GTK_CONTAINER(scr_win), GTK_WIDGET(st->pr->textbox));
|
||||
gtk_container_add( GTK_CONTAINER(st->pr->win), scr_win);
|
||||
#endif
|
||||
|
||||
error_string = register_tap_listener( st->tapname,
|
||||
st,
|
||||
st->filter,
|
||||
/* reinit_stats_tree*/ NULL,
|
||||
NULL,
|
||||
stats_tree_packet,
|
||||
draw_gtk_tree);
|
||||
|
||||
|
@ -310,7 +317,13 @@ static void init_gtk_tree(char* optarg) {
|
|||
gtk_widget_show_all(st->pr->win);
|
||||
window_present(st->pr->win);
|
||||
|
||||
if (st->init) st->init(st);
|
||||
gtk_tree_view_set_model(GTK_TREE_VIEW(st->pr->tree),GTK_TREE_MODEL(st->pr->store));
|
||||
|
||||
if (st->filter) {
|
||||
reinit_stats_tree(st);
|
||||
} else {
|
||||
st->init(st);
|
||||
}
|
||||
|
||||
cf_retap_packets(&cfile);
|
||||
|
||||
|
@ -353,6 +366,6 @@ register_tap_listener_stats_tree_stat(void)
|
|||
{
|
||||
stats_tree_presentation(register_gtk_stats_tree_tap,
|
||||
setup_gtk_node_pr, NULL,
|
||||
draw_gtk_node,
|
||||
NULL,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
}
|
||||
|
|
|
@ -45,15 +45,17 @@ struct _tree_pres {
|
|||
static void draw_stats_tree(void *psp) {
|
||||
stats_tree *st = psp;
|
||||
GString* s;
|
||||
gchar* fmt;
|
||||
stat_node* child;
|
||||
|
||||
s = g_string_new("\n===================================================================\n");
|
||||
|
||||
g_string_sprintfa(s,"Statistics for %s\n===================================================================\n",
|
||||
st->name);
|
||||
fmt = g_strdup_printf(" %%s%%-%us%%12s\t%%12s\t%%12s\n",stats_branch_max_name_len(&st->root,0));
|
||||
g_string_sprintfa(s,fmt,"",st->name,"value","rate","percent");
|
||||
g_free(fmt);
|
||||
g_string_sprintfa(s,"-------------------------------------------------------------------\n");
|
||||
|
||||
for (child = st->root.children; child; child = child->next ) {
|
||||
stat_branch_to_str(child,s,1);
|
||||
stat_branch_to_str(child,s,0);
|
||||
}
|
||||
|
||||
s = g_string_append(s,"\n===================================================================\n");
|
||||
|
|
Loading…
Reference in New Issue