HACK: 1. try to match RowsetProperties
[wireshark-wip.git] / ui / gtk / service_response_time_table.c
blob570028f758b8432bc1cc57c5edb2b46114f17cea
1 /* service_response_time_table.c
2 * service_response_time_table 2003 Ronnie Sahlberg
3 * Helper routines common to all service response time statistics
4 * tap.
6 * $Id$
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "config.h"
29 #include <gtk/gtk.h>
30 #include <stdio.h>
32 #include "epan/packet_info.h"
34 #include "ui/simple_dialog.h"
35 #include "ui/utf8_entities.h"
37 #include "ui/gtk/service_response_time_table.h"
38 #include "ui/gtk/filter_utils.h"
39 #include "ui/gtk/gui_utils.h"
41 #define NANOSECS_PER_SEC 1000000000
43 enum
45 INDEX_COLUMN,
46 PROCEDURE_COLUMN,
47 CALLS_COLUMN,
48 MIN_SRT_COLUMN,
49 MAX_SRT_COLUMN,
50 AVG_SRT_COLUMN,
51 N_COLUMNS
55 static void
56 srt_select_filter_cb(GtkWidget *widget _U_, gpointer callback_data, guint callback_action)
58 srt_stat_table *rst = (srt_stat_table *)callback_data;
59 char *str = NULL;
60 GtkTreeIter iter;
61 GtkTreeModel *model;
62 GtkTreeSelection *sel;
63 int selection;
65 if(rst->filter_string==NULL){
66 return;
69 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW(rst->table));
71 if (!gtk_tree_selection_get_selected(sel, &model, &iter))
72 return;
74 gtk_tree_model_get (model, &iter, INDEX_COLUMN, &selection, -1);
75 if(selection>=(int)rst->num_procs){
76 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "No procedure selected");
77 return;
80 str = g_strdup_printf("%s==%d", rst->filter_string, selection);
82 apply_selected_filter (callback_action, str);
84 g_free(str);
87 static gboolean
88 srt_show_popup_menu_cb(void *widg _U_, GdkEvent *event, srt_stat_table *rst)
90 GdkEventButton *bevent = (GdkEventButton *)event;
92 if(event->type==GDK_BUTTON_PRESS && bevent->button==3){
93 gtk_menu_popup(GTK_MENU(rst->menu), NULL, NULL, NULL, NULL,
94 bevent->button, bevent->time);
97 return FALSE;
101 /* Action callbacks */
102 static void
103 apply_as_selected_cb(GtkWidget *widget, gpointer user_data)
105 srt_select_filter_cb( widget , user_data, CALLBACK_MATCH(ACTYPE_SELECTED, 0));
107 static void
108 apply_as_not_selected_cb(GtkWidget *widget, gpointer user_data)
110 srt_select_filter_cb( widget , user_data, CALLBACK_MATCH(ACTYPE_NOT_SELECTED, 0));
112 static void
113 apply_as_and_selected_cb(GtkWidget *widget, gpointer user_data)
115 srt_select_filter_cb( widget , user_data, CALLBACK_MATCH(ACTYPE_AND_SELECTED, 0));
117 static void
118 apply_as_or_selected_cb(GtkWidget *widget, gpointer user_data)
120 srt_select_filter_cb( widget , user_data, CALLBACK_MATCH(ACTYPE_OR_SELECTED, 0));
122 static void
123 apply_as_and_not_selected_cb(GtkWidget *widget, gpointer user_data)
125 srt_select_filter_cb( widget , user_data, CALLBACK_MATCH(ACTYPE_AND_NOT_SELECTED, 0));
127 static void
128 apply_as_or_not_selected_cb(GtkWidget *widget, gpointer user_data)
130 srt_select_filter_cb( widget , user_data, CALLBACK_MATCH(ACTYPE_OR_NOT_SELECTED, 0));
133 static void
134 prep_as_selected_cb(GtkWidget *widget, gpointer user_data)
136 srt_select_filter_cb( widget , user_data, CALLBACK_PREPARE(ACTYPE_SELECTED, 0));
138 static void
139 prep_as_not_selected_cb(GtkWidget *widget, gpointer user_data)
141 srt_select_filter_cb( widget , user_data, CALLBACK_PREPARE(ACTYPE_NOT_SELECTED, 0));
143 static void
144 prep_as_and_selected_cb(GtkWidget *widget, gpointer user_data)
146 srt_select_filter_cb( widget , user_data, CALLBACK_PREPARE(ACTYPE_AND_SELECTED, 0));
148 static void
149 prep_as_or_selected_cb(GtkWidget *widget, gpointer user_data)
151 srt_select_filter_cb( widget , user_data, CALLBACK_PREPARE(ACTYPE_OR_SELECTED, 0));
153 static void
154 prep_as_and_not_selected_cb(GtkWidget *widget, gpointer user_data)
156 srt_select_filter_cb( widget , user_data, CALLBACK_PREPARE(ACTYPE_AND_NOT_SELECTED, 0));
158 static void
159 prep_as_or_not_selected_cb(GtkWidget *widget, gpointer user_data)
161 srt_select_filter_cb( widget , user_data, CALLBACK_PREPARE(ACTYPE_OR_NOT_SELECTED, 0));
164 static void
165 find_selected_cb(GtkWidget *widget, gpointer user_data)
167 srt_select_filter_cb( widget , user_data, CALLBACK_FIND_FRAME(ACTYPE_SELECTED, 0));
169 static void
170 find_not_selected_cb(GtkWidget *widget, gpointer user_data)
172 srt_select_filter_cb( widget , user_data, CALLBACK_FIND_FRAME(ACTYPE_NOT_SELECTED, 0));
174 static void
175 find_prev_selected_cb(GtkWidget *widget, gpointer user_data)
177 srt_select_filter_cb( widget , user_data, CALLBACK_FIND_PREVIOUS(ACTYPE_SELECTED, 0));
179 static void
180 find_prev_not_selected_cb(GtkWidget *widget, gpointer user_data)
182 srt_select_filter_cb( widget , user_data, CALLBACK_FIND_PREVIOUS(ACTYPE_NOT_SELECTED, 0));
184 static void
185 find_next_selected_cb(GtkWidget *widget, gpointer user_data)
187 srt_select_filter_cb( widget , user_data, CALLBACK_FIND_NEXT(ACTYPE_SELECTED, 0));
189 static void
190 find_next_not_selected_cb(GtkWidget *widget, gpointer user_data)
192 srt_select_filter_cb( widget , user_data, CALLBACK_FIND_NEXT(ACTYPE_NOT_SELECTED, 0));
194 static void
195 color_selected_cb(GtkWidget *widget, gpointer user_data)
197 srt_select_filter_cb( widget , user_data, CALLBACK_COLORIZE(ACTYPE_SELECTED, 0));
199 static void
200 color_not_selected_cb(GtkWidget *widget, gpointer user_data)
202 srt_select_filter_cb( widget , user_data, CALLBACK_COLORIZE(ACTYPE_SELECTED, 0));
205 static const char *ui_desc_service_resp_t_filter_popup =
206 "<ui>\n"
207 " <popup name='ServiceRespTFilterPopup'>\n"
208 " <menu action='/Apply as Filter'>\n"
209 " <menuitem action='/Apply as Filter/Selected'/>\n"
210 " <menuitem action='/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " not Selected'/>\n"
211 " <menuitem action='/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " and Selected'/>\n"
212 " <menuitem action='/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " or Selected'/>\n"
213 " <menuitem action='/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " and not Selected'/>\n"
214 " <menuitem action='/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " or not Selected'/>\n"
215 " </menu>\n"
216 " <menu action='/Prepare a Filter'>\n"
217 " <menuitem action='/Prepare a Filter/Selected'/>\n"
218 " <menuitem action='/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " not Selected'/>\n"
219 " <menuitem action='/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " and Selected'/>\n"
220 " <menuitem action='/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " or Selected'/>\n"
221 " <menuitem action='/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " and not Selected'/>\n"
222 " <menuitem action='/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " or not Selected'/>\n"
223 " </menu>\n"
224 " <menu action='/Find Frame'>\n"
225 " <menu action='/Find Frame/Find Frame'>\n"
226 " <menuitem action='/Find Frame/Selected'/>\n"
227 " <menuitem action='/Find Frame/Not Selected'/>\n"
228 " </menu>\n"
229 " <menu action='/Find Frame/Find Next'>\n"
230 " <menuitem action='/Find Next/Selected'/>\n"
231 " <menuitem action='/Find Next/Not Selected'/>\n"
232 " </menu>\n"
233 " <menu action='/Find Frame/Find Previous'>\n"
234 " <menuitem action='/Find Previous/Selected'/>\n"
235 " <menuitem action='/Find Previous/Not Selected'/>\n"
236 " </menu>\n"
237 " </menu>\n"
238 " <menu action='/Colorize Procedure'>\n"
239 " <menuitem action='/Colorize Procedure/Selected'/>\n"
240 " <menuitem action='/Colorize Procedure/Not Selected'/>\n"
241 " </menu>\n"
242 " </popup>\n"
243 "</ui>\n";
246 * GtkActionEntry
247 * typedef struct {
248 * const gchar *name;
249 * const gchar *stock_id;
250 * const gchar *label;
251 * const gchar *accelerator;
252 * const gchar *tooltip;
253 * GCallback callback;
254 * } GtkActionEntry;
255 * const gchar *name; The name of the action.
256 * const gchar *stock_id; The stock id for the action, or the name of an icon from the icon theme.
257 * const gchar *label; The label for the action. This field should typically be marked for translation,
258 * see gtk_action_group_set_translation_domain().
259 * If label is NULL, the label of the stock item with id stock_id is used.
260 * const gchar *accelerator; The accelerator for the action, in the format understood by gtk_accelerator_parse().
261 * const gchar *tooltip; The tooltip for the action. This field should typically be marked for translation,
262 * see gtk_action_group_set_translation_domain().
263 * GCallback callback; The function to call when the action is activated.
266 static const GtkActionEntry service_resp_t__popup_entries[] = {
267 { "/Apply as Filter", NULL, "Apply as Filter", NULL, NULL, NULL },
268 { "/Prepare a Filter", NULL, "Prepare a Filter", NULL, NULL, NULL },
269 { "/Find Frame", NULL, "Find Frame", NULL, NULL, NULL },
270 { "/Find Frame/Find Frame", NULL, "Find Frame", NULL, NULL, NULL },
271 { "/Find Frame/Find Next", NULL, "Find Next" , NULL, NULL, NULL },
272 { "/Find Frame/Find Previous", NULL, "Find Previous", NULL, NULL, NULL },
273 { "/Colorize Procedure", NULL, "Colorize Procedure", NULL, NULL, NULL },
274 { "/Apply as Filter/Selected", NULL, "Selected", NULL, "Selected", G_CALLBACK(apply_as_selected_cb) },
275 { "/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " not Selected", G_CALLBACK(apply_as_not_selected_cb) },
276 { "/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " and Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " and Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " and Selected", G_CALLBACK(apply_as_and_selected_cb) },
277 { "/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " or Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " or Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " or Selected", G_CALLBACK(apply_as_or_selected_cb) },
278 { "/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " and not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " and not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " and not Selected", G_CALLBACK(apply_as_and_not_selected_cb) },
279 { "/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " or not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " or not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " or not Selected", G_CALLBACK(apply_as_or_not_selected_cb) },
280 { "/Prepare a Filter/Selected", NULL, "Selected", NULL, "selcted", G_CALLBACK(prep_as_selected_cb) },
281 { "/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " not Selected", G_CALLBACK(prep_as_not_selected_cb) },
282 { "/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " and Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " and Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " and Selected", G_CALLBACK(prep_as_and_selected_cb) },
283 { "/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " or Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " or Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " or Selected", G_CALLBACK(prep_as_or_selected_cb) },
284 { "/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " and not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " and not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " and not Selected", G_CALLBACK(prep_as_and_not_selected_cb) },
285 { "/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " or not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " or not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " or not Selected", G_CALLBACK(prep_as_or_not_selected_cb) },
286 { "/Find Frame/Selected", NULL, "Selected", NULL, "Selected", G_CALLBACK(find_selected_cb) },
287 { "/Find Frame/Not Selected", NULL, "Not Selected", NULL, "Not Selected", G_CALLBACK(find_not_selected_cb) },
288 { "/Find Previous/Selected", NULL, "Selected", NULL, "Selected", G_CALLBACK(find_prev_selected_cb) },
289 { "/Find Previous/Not Selected", NULL, "Not Selected", NULL, "Not Selected", G_CALLBACK(find_prev_not_selected_cb) },
290 { "/Find Next/Selected", NULL, "Selected", NULL, "Selected", G_CALLBACK(find_next_selected_cb) },
291 { "/Find Next/Not Selected", NULL, "Not Selected", NULL, "Not Selected", G_CALLBACK(find_next_not_selected_cb) },
292 { "/Colorize Procedure/Selected", NULL, "Selected", NULL, "Selected", G_CALLBACK(color_selected_cb) },
293 { "/Colorize Procedure/Not Selected", NULL, "Not Selected", NULL, "Not Selected", G_CALLBACK(color_not_selected_cb) },
296 static void
297 srt_create_popup_menu(srt_stat_table *rst)
299 GtkUIManager *ui_manager;
300 GtkActionGroup *action_group;
301 GError *error = NULL;
303 action_group = gtk_action_group_new ("ServiceRespTFilterPopupActionGroup");
304 gtk_action_group_add_actions (action_group, /* the action group */
305 (GtkActionEntry *)service_resp_t__popup_entries, /* an array of action descriptions */
306 G_N_ELEMENTS(service_resp_t__popup_entries), /* the number of entries */
307 rst); /* data to pass to the action callbacks */
309 ui_manager = gtk_ui_manager_new ();
310 gtk_ui_manager_insert_action_group (ui_manager,
311 action_group,
312 0); /* the position at which the group will be inserted */
313 gtk_ui_manager_add_ui_from_string (ui_manager,ui_desc_service_resp_t_filter_popup, -1, &error);
314 if (error != NULL)
316 fprintf (stderr, "Warning: building service response time filter popup failed: %s\n",
317 error->message);
318 g_error_free (error);
319 error = NULL;
321 rst->menu = gtk_ui_manager_get_widget(ui_manager, "/ServiceRespTFilterPopup");
322 g_signal_connect(rst->table, "button_press_event", G_CALLBACK(srt_show_popup_menu_cb), rst);
326 /* ---------------- */
327 static void
328 srt_time_func (GtkTreeViewColumn *column _U_,
329 GtkCellRenderer *renderer,
330 GtkTreeModel *model,
331 GtkTreeIter *iter,
332 gpointer user_data)
334 gchar *str;
335 nstime_t *data;
337 /* The col to get data from is in userdata */
338 gint data_column = GPOINTER_TO_INT(user_data);
340 gtk_tree_model_get(model, iter, data_column, &data, -1);
341 if (!data) {
342 g_object_set(renderer, "text", "", NULL);
343 return;
345 str = g_strdup_printf("%3d.%06d", (int)data->secs, (data->nsecs+500)/1000);
346 g_object_set(renderer, "text", str, NULL);
347 g_free(str);
350 static void
351 srt_avg_func (GtkTreeViewColumn *column _U_,
352 GtkCellRenderer *renderer,
353 GtkTreeModel *model,
354 GtkTreeIter *iter,
355 gpointer user_data)
357 gchar *str;
358 guint64 td;
359 gint data_column = GPOINTER_TO_INT(user_data);
361 gtk_tree_model_get(model, iter, data_column, &td, -1);
362 str=g_strdup_printf("%3d.%06d",
363 (int)(td/1000000), (int)(td%1000000));
364 g_object_set(renderer, "text", str, NULL);
365 g_free(str);
368 static gint
369 srt_time_sort_func(GtkTreeModel *model,
370 GtkTreeIter *a,
371 GtkTreeIter *b,
372 gpointer user_data)
374 nstime_t *ns_a;
375 nstime_t *ns_b;
376 gint ret = 0;
377 gint data_column = GPOINTER_TO_INT(user_data);
379 gtk_tree_model_get(model, a, data_column, &ns_a, -1);
380 gtk_tree_model_get(model, b, data_column, &ns_b, -1);
382 if (ns_a == ns_b) {
383 ret = 0;
385 else if (ns_a == NULL || ns_b == NULL) {
386 ret = (ns_a == NULL) ? -1 : 1;
388 else {
389 ret = nstime_cmp(ns_a,ns_b);
391 return ret;
395 XXX Resizable columns are ugly when there's more than on table cf. SMB
397 void
398 init_srt_table(srt_stat_table *rst, int num_procs, GtkWidget *vbox, const char *filter_string)
400 int i;
401 GtkListStore *store;
402 GtkWidget *tree;
403 GtkTreeViewColumn *column;
404 GtkCellRenderer *renderer;
405 GtkTreeSortable *sortable;
406 GtkTreeSelection *sel;
408 static const char *default_titles[] = { "Index", "Procedure", "Calls", "Min SRT", "Max SRT", "Avg SRT" };
410 /* Create the store */
411 store = gtk_list_store_new (N_COLUMNS, /* Total number of columns */
412 G_TYPE_INT, /* Index */
413 G_TYPE_STRING, /* Procedure */
414 G_TYPE_UINT, /* Calls */
415 G_TYPE_POINTER, /* Min SRT */
416 G_TYPE_POINTER, /* Max SRT */
417 G_TYPE_UINT64); /* Avg SRT */
419 /* Create a view */
420 tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
421 rst->table = GTK_TREE_VIEW(tree);
422 sortable = GTK_TREE_SORTABLE(store);
424 /* The view now holds a reference. We can get rid of our own reference */
425 g_object_unref (G_OBJECT (store));
427 if(filter_string){
428 rst->filter_string=g_strdup(filter_string);
429 } else {
430 rst->filter_string=NULL;
432 for (i = 0; i < N_COLUMNS; i++) {
433 renderer = gtk_cell_renderer_text_new ();
434 if (i != PROCEDURE_COLUMN) {
435 /* right align numbers */
436 g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL);
438 g_object_set(renderer, "ypad", 0, NULL);
439 switch (i) {
440 case MIN_SRT_COLUMN:
441 case MAX_SRT_COLUMN:
442 column = gtk_tree_view_column_new_with_attributes (default_titles[i], renderer, NULL);
443 gtk_tree_view_column_set_cell_data_func(column, renderer, srt_time_func, GINT_TO_POINTER(i), NULL);
444 gtk_tree_sortable_set_sort_func(sortable, i, srt_time_sort_func, GINT_TO_POINTER(i), NULL);
445 break;
446 case AVG_SRT_COLUMN:
447 column = gtk_tree_view_column_new_with_attributes (default_titles[i], renderer, NULL);
448 gtk_tree_view_column_set_cell_data_func(column, renderer, srt_avg_func, GINT_TO_POINTER(i), NULL);
449 break;
450 default:
451 column = gtk_tree_view_column_new_with_attributes (default_titles[i], renderer, "text",
452 i, NULL);
453 break;
456 gtk_tree_view_column_set_sort_column_id(column, i);
457 gtk_tree_view_column_set_resizable(column, TRUE);
458 gtk_tree_view_append_column (rst->table, column);
459 if (i == CALLS_COLUMN) {
460 /* XXX revert order sort */
461 gtk_tree_view_column_clicked(column);
462 gtk_tree_view_column_clicked(column);
466 rst->scrolled_window=scrolled_window_new(NULL, NULL);
467 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(rst->scrolled_window),
468 GTK_SHADOW_IN);
469 gtk_container_add(GTK_CONTAINER(rst->scrolled_window), GTK_WIDGET (rst->table));
470 gtk_box_pack_start(GTK_BOX(vbox), rst->scrolled_window, TRUE, TRUE, 0);
472 gtk_tree_view_set_reorderable (rst->table, FALSE);
473 /* Now enable the sorting of each column */
474 gtk_tree_view_set_rules_hint(rst->table, TRUE);
475 gtk_tree_view_set_headers_clickable(rst->table, TRUE);
477 gtk_widget_show(rst->scrolled_window);
479 rst->num_procs=num_procs;
480 rst->procedures=(srt_procedure_t *)g_malloc(sizeof(srt_procedure_t)*num_procs);
481 for(i=0;i<num_procs;i++){
482 time_stat_init(&rst->procedures[i].stats);
483 rst->procedures[i].index = 0;
484 rst->procedures[i].procedure = NULL;
487 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(rst->table));
488 gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
489 /* create popup menu for this table */
490 if(rst->filter_string){
491 srt_create_popup_menu(rst);
495 void
496 init_srt_table_row(srt_stat_table *rst, int indx, const char *procedure)
498 /* we have discovered a new procedure. Extend the table accordingly */
499 if(indx>=rst->num_procs){
500 int old_num_procs=rst->num_procs;
501 int i;
503 rst->num_procs=indx+1;
504 rst->procedures=(srt_procedure_t *)g_realloc(rst->procedures, sizeof(srt_procedure_t)*(rst->num_procs));
505 for(i=old_num_procs;i<rst->num_procs;i++){
506 time_stat_init(&rst->procedures[i].stats);
507 rst->procedures[i].index = i;
508 rst->procedures[i].procedure=NULL;
511 rst->procedures[indx].index = indx;
512 rst->procedures[indx].procedure=g_strdup(procedure);
515 void
516 add_srt_table_data(srt_stat_table *rst, int indx, const nstime_t *req_time, packet_info *pinfo)
518 srt_procedure_t *rp;
519 nstime_t t, delta;
521 g_assert(indx >= 0 && indx < rst->num_procs);
522 rp=&rst->procedures[indx];
525 * If the count of calls for this procedure is currently zero, it's
526 * going to become non-zero, so add a row for it (we don't want
527 * rows for procedures that have no calls - especially if the
528 * procedure has no calls because the index doesn't correspond
529 * to a procedure, but is an unused/reserved value).
531 * (Yes, this means that the rows aren't in order by anything
532 * interesting. That's why we have the table sorted by a column.)
535 if (rp->stats.num==0){
536 GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model(rst->table));
537 gtk_list_store_append(store, &rp->iter);
538 gtk_list_store_set(store, &rp->iter,
539 INDEX_COLUMN, rp->index,
540 PROCEDURE_COLUMN, rp->procedure,
541 CALLS_COLUMN, rp->stats.num,
542 MIN_SRT_COLUMN, NULL,
543 MAX_SRT_COLUMN, NULL,
544 AVG_SRT_COLUMN, (guint64)0,
545 -1);
548 /* calculate time delta between request and reply */
549 t=pinfo->fd->abs_ts;
550 nstime_delta(&delta, &t, req_time);
552 time_stat_update(&rp->stats, &delta, pinfo);
555 void
556 draw_srt_table_data(srt_stat_table *rst)
558 int i;
559 guint64 td;
560 GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model(rst->table));
562 for(i=0;i<rst->num_procs;i++){
563 /* ignore procedures with no calls (they don't have rows) */
564 if(rst->procedures[i].stats.num==0){
565 continue;
567 /* Scale the average SRT in units of 1us and round to the nearest us.
568 tot.secs is a time_t which may be 32 or 64 bits (or even floating)
569 depending uon the platform. After casting tot.secs to 64 bits, it
570 would take a capture with a duration of over 136 *years* to
571 overflow the secs portion of td. */
572 td = ((guint64)(rst->procedures[i].stats.tot.secs))*NANOSECS_PER_SEC + rst->procedures[i].stats.tot.nsecs;
573 td = ((td / rst->procedures[i].stats.num) + 500) / 1000;
575 gtk_list_store_set(store, &rst->procedures[i].iter,
576 CALLS_COLUMN, rst->procedures[i].stats.num,
577 MIN_SRT_COLUMN, &rst->procedures[i].stats.min,
578 MAX_SRT_COLUMN, &rst->procedures[i].stats.max,
579 AVG_SRT_COLUMN, td,
580 -1);
585 void
586 reset_srt_table_data(srt_stat_table *rst)
588 int i;
589 GtkListStore *store;
591 for(i=0;i<rst->num_procs;i++){
592 time_stat_init(&rst->procedures[i].stats);
594 store = GTK_LIST_STORE(gtk_tree_view_get_model(rst->table));
595 gtk_list_store_clear(store);
598 void
599 free_srt_table_data(srt_stat_table *rst)
601 int i;
603 for(i=0;i<rst->num_procs;i++){
604 g_free(rst->procedures[i].procedure);
605 rst->procedures[i].procedure=NULL;
607 g_free(rst->filter_string);
608 rst->filter_string=NULL;
609 g_free(rst->procedures);
610 rst->procedures=NULL;
611 rst->num_procs=0;