aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarren Hart <dvhltc@us.ibm.com>2009-12-30 14:09:53 -0500
committerDarren Hart <dvhltc@us.ibm.com>2009-12-30 23:25:34 -0500
commit882d2abd9571ba87c81c41b16275224de678dfa9 (patch)
treee6a61d887655f11d96342aa50a8ff00f625a57a8
parent53336fb4d2d41f865557bb5ff0bc686db5e31793 (diff)
trace-view: Self-adjusting fixed width trace-view
By using fixed width columns and fixed height rows, the view can now render over 400k events without any noticable lag. This makes it so large traces can now be viewed in one "page" of the trace-view-model. The new trace-view-data-func() is called when the view wants to render cell (which it only has to do when it's visible now that we use fixed sizings). Here we check the string width in pixels and resize the column if necessary. By tracking the max character width of each column, we can avoid doing the expensive Pango pixel width test as often. By adding a little extra padding, we anticipate one more character, further reducing the overhead. The first full scroll down and up shows no noticable lag due to these calculations once the optimizations were implemented. V2: fix an unused var warning and use a long when casting to a pointer. Signed-off-by: Darren Hart <dvhltc@us.ibm.com>
-rw-r--r--trace-view-store.h2
-rw-r--r--trace-view.c149
2 files changed, 94 insertions, 57 deletions
diff --git a/trace-view-store.h b/trace-view-store.h
index db755d5..35f1193 100644
--- a/trace-view-store.h
+++ b/trace-view-store.h
@@ -128,7 +128,7 @@ GType trace_view_store_get_type (void);
128 128
129TraceViewStore *trace_view_store_new (struct tracecmd_input *handle); 129TraceViewStore *trace_view_store_new (struct tracecmd_input *handle);
130 130
131#define TRACE_VIEW_DEFAULT_MAX_ROWS 1000 131#define TRACE_VIEW_DEFAULT_MAX_ROWS 1000000
132 132
133#if 0 133#if 0
134void trace_view_store_append_record (TraceViewStore *trace_view_store, 134void trace_view_store_append_record (TraceViewStore *trace_view_store,
diff --git a/trace-view.c b/trace-view.c
index dadf35c..d4a5bbd 100644
--- a/trace-view.c
+++ b/trace-view.c
@@ -22,6 +22,7 @@
22#include <string.h> 22#include <string.h>
23#include <stdarg.h> 23#include <stdarg.h>
24#include <gtk/gtk.h> 24#include <gtk/gtk.h>
25#include <glib-object.h>
25 26
26#include "trace-cmd.h" 27#include "trace-cmd.h"
27#include "trace-local.h" 28#include "trace-local.h"
@@ -39,6 +40,29 @@ enum {
39 NUM_COLS 40 NUM_COLS
40}; 41};
41 42
43static char* col_labels[] = {
44 "#",
45 "CPU",
46 "Time Stamp",
47 "Task",
48 "PID",
49 "Latency",
50 "Event",
51 "Info",
52 NULL
53};
54static int col_chars[] = {
55 0, /* INDEX */
56 0, /* CPU */
57 0, /* TS */
58 0, /* COMM */
59 0, /* PID */
60 0, /* LAT */
61 0, /* EVENT */
62 0, /* INFO */
63 0
64};
65
42static GtkTreeModel * 66static GtkTreeModel *
43create_trace_view_model(struct tracecmd_input *handle) 67create_trace_view_model(struct tracecmd_input *handle)
44{ 68{
@@ -75,6 +99,58 @@ spin_changed(gpointer data, GtkWidget *spin)
75 g_object_unref(model); 99 g_object_unref(model);
76} 100}
77 101
102void trace_view_data_func(GtkTreeViewColumn *column, GtkCellRenderer *renderer,
103 GtkTreeModel *model, GtkTreeIter *iter,
104 gpointer data)
105{
106 long col_num = (long)data;
107 int str_len, label_len;
108 gchar *text, *str;
109 int new_w, x_pad;
110 GValue val = {0};
111 GtkWidget *view;
112
113 PangoFontDescription *pfd;
114 PangoLayout *playout;
115
116 /* Put the text in the renderer. */
117 gtk_tree_model_get_value(model, iter, col_num, &val);
118 g_object_set_property(G_OBJECT(renderer), "text", &val);
119
120 g_object_get(G_OBJECT(renderer),
121 "text", &text,
122 "font-desc", &pfd, /* apparently don't have to free this */
123 NULL);
124
125 /* Make sure there is enough room to render the column label. */
126 str = text;
127 str_len = strlen(str);
128 label_len = strlen(col_labels[col_num]);
129 if (label_len > str_len) {
130 str = col_labels[col_num];
131 str_len = label_len;
132 }
133
134 /* Don't bother with pango unless we have more chars than the max. */
135 if (str_len > col_chars[col_num]) {
136 col_chars[col_num] = str_len;
137
138 view = GTK_WIDGET(gtk_tree_view_column_get_tree_view(column));
139 playout = gtk_widget_create_pango_layout(GTK_WIDGET(view), str);
140 pango_layout_set_font_description(playout, pfd);
141 pango_layout_get_pixel_size(playout, &new_w, NULL);
142 gtk_cell_renderer_get_padding(renderer, &x_pad, NULL);
143 /* +10 to avoid another adjustment for one char */
144 new_w += 2*x_pad + 10;
145
146 if (new_w > gtk_tree_view_column_get_width(column))
147 gtk_tree_view_column_set_fixed_width(column, new_w);
148 }
149
150 g_value_unset(&val);
151 g_free(text);
152}
153
78void 154void
79trace_view_load(GtkWidget *view, struct tracecmd_input *handle, 155trace_view_load(GtkWidget *view, struct tracecmd_input *handle,
80 GtkWidget *spin) 156 GtkWidget *spin)
@@ -94,62 +170,23 @@ trace_view_load(GtkWidget *view, struct tracecmd_input *handle,
94 "family-set", TRUE, 170 "family-set", TRUE,
95 NULL); 171 NULL);
96 172
97 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), 173 /*
98 -1, 174 * Set fixed height mode now which will cause all the columns below to
99 "#", 175 * be created with their sizing property to be set to
100 renderer, 176 * GTK_TREE_VIEW_COLUMN_FIXED.
101 "text", COL_INDEX, 177 */
102 NULL); 178 gtk_tree_view_set_fixed_height_mode(GTK_TREE_VIEW(view), TRUE);
103 179
104 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), 180 for (long c = 0; c < NUM_COLS; c++)
105 -1, 181 {
106 "CPU", 182 gtk_tree_view_insert_column_with_data_func(GTK_TREE_VIEW(view),
107 renderer, 183 -1,
108 "text", COL_CPU, 184 col_labels[c],
109 NULL); 185 (c == COL_LAT || c == COL_INFO) ? fix_renderer : renderer,
110 186 trace_view_data_func,
111 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), 187 (gpointer)c,
112 -1, 188 NULL);
113 "Time Stamp", 189 }
114 renderer,
115 "text", COL_TS,
116 NULL);
117
118 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
119 -1,
120 "Task",
121 renderer,
122 "text", COL_COMM,
123 NULL);
124
125 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
126 -1,
127 "PID",
128 renderer,
129 "text", COL_PID,
130 NULL);
131
132 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
133 -1,
134 "Latency",
135 fix_renderer,
136 "text", COL_LAT,
137 NULL);
138
139 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
140 -1,
141 "Event",
142 renderer,
143 "text", COL_EVENT,
144 NULL);
145
146
147 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
148 -1,
149 "Info",
150 fix_renderer,
151 "text", COL_INFO,
152 NULL);
153 190
154 model = create_trace_view_model(handle); 191 model = create_trace_view_model(handle);
155 192