2 * Routines for MTP3 Statictics summary window
4 * Copyright 2004, Michael Lum <mlum [AT] telostech.com>
5 * In association with Telos Technology Inc.
7 * Modified from gsm_map_summary.c
11 * Wireshark - Network traffic analyzer
12 * By Gerald Combs <gerald@wireshark.org>
13 * Copyright 1998 Gerald Combs
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #ifdef HAVE_SYS_TYPES_H
35 #include <sys/types.h>
41 #include "epan/packet_info.h"
42 #include "epan/epan.h"
43 #include "epan/value_string.h"
45 #include <epan/dissectors/packet-mtp3.h>
47 #include "../stat_menu.h"
48 #include "../globals.h"
50 #include "../summary.h"
52 #include "ui/gtk/gui_stat_menu.h"
53 #include "ui/gtk/dlg_utils.h"
54 #include "ui/gtk/gui_utils.h"
55 #include "ui/gtk/mtp3_stat.h"
57 #define SUM_STR_MAX 1024
60 typedef struct _my_columns_t {
63 GtkJustification just;
74 N_COLUMN /* The number of columns */
79 GtkWidget* create_list(void)
82 GtkListStore *list_store;
84 GtkTreeViewColumn *column;
85 GtkCellRenderer *renderer;
86 GtkTreeSortable *sortable;
87 GtkTreeView *list_view;
88 GtkTreeSelection *selection;
90 /* Create the store */
91 list_store = gtk_list_store_new(N_COLUMN, /* Total number of columns XXX*/
92 G_TYPE_STRING, /* SI */
93 G_TYPE_INT, /* Num MSUs */
94 G_TYPE_STRING, /* MSUs/sec */
95 G_TYPE_INT, /* Num Bytes */
96 G_TYPE_STRING, /* Bytes/MSU */
97 G_TYPE_STRING); /* Bytes/sec */
100 list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store));
102 list_view = GTK_TREE_VIEW(list);
103 sortable = GTK_TREE_SORTABLE(list_store);
105 /* Speed up the list display */
106 gtk_tree_view_set_fixed_height_mode(list_view, TRUE);
108 /* Setup the sortable columns */
109 gtk_tree_sortable_set_sort_column_id(sortable, SI_COLUMN, GTK_SORT_ASCENDING);
110 gtk_tree_view_set_headers_clickable(list_view, FALSE);
112 /* The view now holds a reference. We can get rid of our own reference */
113 g_object_unref (G_OBJECT (list_store));
116 * Create the first column packet, associating the "text" attribute of the
117 * cell_renderer to the first column of the model
120 renderer = gtk_cell_renderer_text_new ();
121 column = gtk_tree_view_column_new_with_attributes ("SI", renderer,
125 gtk_tree_view_column_set_sort_column_id(column, SI_COLUMN);
126 gtk_tree_view_column_set_resizable(column, TRUE);
127 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
128 gtk_tree_view_column_set_min_width(column, 110);
130 /* Add the column to the view. */
131 gtk_tree_view_append_column (list_view, column);
134 renderer = gtk_cell_renderer_text_new ();
135 column = gtk_tree_view_column_new_with_attributes ("Num MSUs", renderer,
136 "text", NUM_MSUS_COLUMN,
138 gtk_tree_view_column_set_sort_column_id(column, NUM_MSUS_COLUMN);
139 gtk_tree_view_column_set_resizable(column, TRUE);
140 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
141 gtk_tree_view_column_set_min_width(column, 100);
142 gtk_tree_view_append_column (list_view, column);
145 renderer = gtk_cell_renderer_text_new ();
146 column = gtk_tree_view_column_new_with_attributes ("MSUs/sec", renderer,
147 "text", NUM_MSUS_SEC_COLUMN,
149 gtk_tree_view_column_set_sort_column_id(column, NUM_MSUS_SEC_COLUMN);
150 gtk_tree_view_column_set_resizable(column, TRUE);
151 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
152 gtk_tree_view_column_set_min_width(column, 100);
153 gtk_tree_view_append_column (list_view, column);
156 renderer = gtk_cell_renderer_text_new ();
157 column = gtk_tree_view_column_new_with_attributes ("Num Bytes", renderer,
158 "text", NUM_BYTES_COLUMN,
160 gtk_tree_view_column_set_sort_column_id(column, NUM_BYTES_COLUMN);
161 gtk_tree_view_column_set_resizable(column, TRUE);
162 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
163 gtk_tree_view_column_set_min_width(column, 100);
164 gtk_tree_view_append_column (list_view, column);
167 renderer = gtk_cell_renderer_text_new ();
168 column = gtk_tree_view_column_new_with_attributes ("Bytes/MSU", renderer,
169 "text", NUM_BYTES_MSU_COLUMN,
173 gtk_tree_view_column_set_sort_column_id(column, NUM_BYTES_MSU_COLUMN);
174 gtk_tree_view_column_set_resizable(column, TRUE);
175 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
176 gtk_tree_view_column_set_min_width(column, 100);
177 gtk_tree_view_append_column (list_view, column);
180 renderer = gtk_cell_renderer_text_new ();
181 column = gtk_tree_view_column_new_with_attributes ("Bytes/sec", renderer,
182 "text", NUM_BYTES_SEC_COLUMN,
185 gtk_tree_view_column_set_sort_column_id(column, NUM_BYTES_SEC_COLUMN);
186 gtk_tree_view_column_set_resizable(column, TRUE);
187 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
188 gtk_tree_view_column_set_min_width(column, 100);
189 gtk_tree_view_append_column (list_view, column);
191 /* Now enable the sorting of each column */
192 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(list_view), TRUE);
193 gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(list_view), TRUE);
195 /* Setup the selection handler */
196 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(list));
197 gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
204 add_string_to_box(gchar *str, GtkWidget *box)
207 lb = gtk_label_new(str);
208 gtk_misc_set_alignment(GTK_MISC(lb), 0.0f, 0.5f);
209 gtk_box_pack_start(GTK_BOX(box), lb,FALSE,FALSE, 0);
220 double *tot_num_bytes_p)
222 char *entries[N_COLUMN];
226 GtkListStore *list_store = NULL;
230 *tot_num_bytes_p = 0;
232 list_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW (table))); /* Get store */
234 for (i=0; i < MTP3_NUM_SI_CODE; i++)
240 while (j < mtp3_num_used)
242 num_msus += mtp3_stat[j].si_code[i].num_msus;
243 num_bytes += mtp3_stat[j].si_code[i].size;
248 *tot_num_msus_p += num_msus;
249 *tot_num_bytes_p += num_bytes;
251 entries[2] = (seconds) ? g_strdup_printf("%.2f", (double)num_msus/seconds) : g_strdup("N/A");
252 entries[4] = (num_msus) ? g_strdup_printf("%.2f", (double)num_bytes/num_msus) : g_strdup("N/A");
253 entries[5] = (seconds) ? g_strdup_printf("%.2f", (double)num_bytes/seconds) : g_strdup("N/A");
255 gtk_list_store_insert_with_values( list_store , &iter, G_MAXINT,
256 SI_COLUMN, mtp3_service_indicator_code_short_vals[i].strptr,
257 NUM_MSUS_COLUMN, num_msus,
258 NUM_MSUS_SEC_COLUMN, entries[2],
259 NUM_BYTES_COLUMN, num_bytes,
260 NUM_BYTES_MSU_COLUMN, entries[4],
261 NUM_BYTES_SEC_COLUMN, entries[5],
271 void mtp3_sum_gtk_sum_cb(GtkAction *action _U_, gpointer user_data _U_)
273 summary_tally summary;
274 GtkWidget *sum_open_w,
275 *main_vb, *file_fr, *data_fr, *file_box,
276 *data_box, *bbox, *close_bt,
280 gchar string_buff[SUM_STR_MAX];
281 const char * file_type;
284 double tot_num_bytes;
286 /* initialize the tally */
287 summary_fill_in(&cfile, &summary);
289 /* initial compututations */
290 seconds = summary.stop_time - summary.start_time;
292 sum_open_w = dlg_window_new("MTP3 Statistics: Summary"); /* transient_for top_level */
293 gtk_window_set_destroy_with_parent (GTK_WINDOW(sum_open_w), TRUE);
295 /* Container for each row of widgets */
296 main_vb = gtk_vbox_new(FALSE, 3);
297 gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
298 gtk_container_add(GTK_CONTAINER(sum_open_w), main_vb);
299 gtk_widget_show(main_vb);
302 file_fr = gtk_frame_new("File");
303 gtk_container_add(GTK_CONTAINER(main_vb), file_fr);
304 gtk_widget_show(file_fr);
306 file_box = gtk_vbox_new(FALSE, 3);
307 gtk_container_add(GTK_CONTAINER(file_fr), file_box);
308 gtk_widget_show(file_box);
311 g_snprintf(string_buff, SUM_STR_MAX, "Name: %s", ((summary.filename) ? summary.filename : "None"));
312 add_string_to_box(string_buff, file_box);
315 g_snprintf(string_buff, SUM_STR_MAX, "Length: %" G_GINT64_MODIFIER "d", summary.file_length);
316 add_string_to_box(string_buff, file_box);
319 file_type = wtap_file_type_string(summary.file_type);
320 g_snprintf(string_buff, SUM_STR_MAX, "Format: %s", (file_type ? file_type : "N/A"));
321 add_string_to_box(string_buff, file_box);
323 if (summary.has_snap) {
324 /* snapshot length */
325 g_snprintf(string_buff, SUM_STR_MAX, "Snapshot length: %u", summary.snap);
326 add_string_to_box(string_buff, file_box);
330 data_fr = gtk_frame_new("Data");
331 gtk_container_add(GTK_CONTAINER(main_vb), data_fr);
332 gtk_widget_show(data_fr);
334 data_box = gtk_vbox_new(FALSE, 3);
335 gtk_container_add(GTK_CONTAINER(data_fr), data_box);
336 gtk_widget_show(data_box);
339 g_snprintf(string_buff, SUM_STR_MAX, "Elapsed time: %.3f seconds", summary.elapsed_time);
340 add_string_to_box(string_buff, data_box);
342 g_snprintf(string_buff, SUM_STR_MAX, "Between first and last packet: %.3f seconds", seconds);
343 add_string_to_box(string_buff, data_box);
346 g_snprintf(string_buff, SUM_STR_MAX, "Packet count: %i", summary.packet_count);
347 add_string_to_box(string_buff, data_box);
350 table_fr = gtk_frame_new("Service Indicator (SI) Totals");
351 gtk_container_add(GTK_CONTAINER(main_vb), table_fr);
352 gtk_widget_show(table_fr);
354 table = create_list();
356 gtk_container_add(GTK_CONTAINER(table_fr), table);
357 gtk_widget_show(table);
360 mtp3_sum_draw(table, seconds, &tot_num_msus, &tot_num_bytes);
363 tot_fr = gtk_frame_new("Totals");
364 gtk_container_add(GTK_CONTAINER(main_vb), tot_fr);
365 gtk_widget_show(tot_fr);
367 tot_box = gtk_vbox_new(FALSE, 3);
368 gtk_container_add(GTK_CONTAINER(tot_fr), tot_box);
369 gtk_widget_show(tot_box);
371 g_snprintf(string_buff, SUM_STR_MAX, "Total MSUs: %u", tot_num_msus);
372 add_string_to_box(string_buff, tot_box);
375 g_snprintf(string_buff, SUM_STR_MAX, "MSUs/second: %.2f", tot_num_msus/seconds);
378 g_snprintf(string_buff, SUM_STR_MAX, "MSUs/second: N/A");
380 add_string_to_box(string_buff, tot_box);
382 g_snprintf(string_buff, SUM_STR_MAX, "Total Bytes: %.0f", tot_num_bytes);
383 add_string_to_box(string_buff, tot_box);
386 g_snprintf(string_buff, SUM_STR_MAX, "Average Bytes/MSU: %.2f", tot_num_bytes/tot_num_msus);
389 g_snprintf(string_buff, SUM_STR_MAX, "Average Bytes/MSU: N/A");
391 add_string_to_box(string_buff, tot_box);
394 g_snprintf(string_buff, SUM_STR_MAX, "Bytes/second: %.2f", tot_num_bytes/seconds);
397 g_snprintf(string_buff, SUM_STR_MAX, "Bytes/second: N/A");
399 add_string_to_box(string_buff, tot_box);
402 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
403 gtk_container_add(GTK_CONTAINER(main_vb), bbox);
404 gtk_widget_show(bbox);
406 close_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
407 window_set_cancel_button(sum_open_w, close_bt, window_cancel_button_cb);
409 g_signal_connect(sum_open_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
411 gtk_widget_show_all(sum_open_w);
412 window_present(sum_open_w);
417 register_tap_listener_gtkmtp3_summary(void)