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 "gtk/gui_stat_menu.h"
53 #include "gtk/dlg_utils.h"
54 #include "gtk/gui_utils.h"
55 #include "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 #ifdef MAIN_MENU_USE_UIMANAGER
272 void mtp3_sum_gtk_sum_cb(GtkAction *action _U_, gpointer user_data _U_)
275 mtp3_sum_gtk_sum_cb(GtkWidget *w _U_, gpointer d _U_)
278 summary_tally summary;
279 GtkWidget *sum_open_w,
280 *main_vb, *file_fr, *data_fr, *file_box,
281 *data_box, *bbox, *close_bt,
285 gchar string_buff[SUM_STR_MAX];
286 const char * file_type;
289 double tot_num_bytes;
291 /* initialize the tally */
292 summary_fill_in(&cfile, &summary);
294 /* initial compututations */
295 seconds = summary.stop_time - summary.start_time;
297 sum_open_w = dlg_window_new("MTP3 Statistics: Summary"); /* transient_for top_level */
298 gtk_window_set_destroy_with_parent (GTK_WINDOW(sum_open_w), TRUE);
300 /* Container for each row of widgets */
301 main_vb = gtk_vbox_new(FALSE, 3);
302 gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
303 gtk_container_add(GTK_CONTAINER(sum_open_w), main_vb);
304 gtk_widget_show(main_vb);
307 file_fr = gtk_frame_new("File");
308 gtk_container_add(GTK_CONTAINER(main_vb), file_fr);
309 gtk_widget_show(file_fr);
311 file_box = gtk_vbox_new(FALSE, 3);
312 gtk_container_add(GTK_CONTAINER(file_fr), file_box);
313 gtk_widget_show(file_box);
316 g_snprintf(string_buff, SUM_STR_MAX, "Name: %s", ((summary.filename) ? summary.filename : "None"));
317 add_string_to_box(string_buff, file_box);
320 g_snprintf(string_buff, SUM_STR_MAX, "Length: %" G_GINT64_MODIFIER "d", summary.file_length);
321 add_string_to_box(string_buff, file_box);
324 file_type = wtap_file_type_string(summary.file_type);
325 g_snprintf(string_buff, SUM_STR_MAX, "Format: %s", (file_type ? file_type : "N/A"));
326 add_string_to_box(string_buff, file_box);
328 if (summary.has_snap) {
329 /* snapshot length */
330 g_snprintf(string_buff, SUM_STR_MAX, "Snapshot length: %u", summary.snap);
331 add_string_to_box(string_buff, file_box);
335 data_fr = gtk_frame_new("Data");
336 gtk_container_add(GTK_CONTAINER(main_vb), data_fr);
337 gtk_widget_show(data_fr);
339 data_box = gtk_vbox_new(FALSE, 3);
340 gtk_container_add(GTK_CONTAINER(data_fr), data_box);
341 gtk_widget_show(data_box);
344 g_snprintf(string_buff, SUM_STR_MAX, "Elapsed time: %.3f seconds", summary.elapsed_time);
345 add_string_to_box(string_buff, data_box);
347 g_snprintf(string_buff, SUM_STR_MAX, "Between first and last packet: %.3f seconds", seconds);
348 add_string_to_box(string_buff, data_box);
351 g_snprintf(string_buff, SUM_STR_MAX, "Packet count: %i", summary.packet_count);
352 add_string_to_box(string_buff, data_box);
355 table_fr = gtk_frame_new("Service Indicator (SI) Totals");
356 gtk_container_add(GTK_CONTAINER(main_vb), table_fr);
357 gtk_widget_show(table_fr);
359 table = create_list();
361 gtk_container_add(GTK_CONTAINER(table_fr), table);
362 gtk_widget_show(table);
365 mtp3_sum_draw(table, seconds, &tot_num_msus, &tot_num_bytes);
368 tot_fr = gtk_frame_new("Totals");
369 gtk_container_add(GTK_CONTAINER(main_vb), tot_fr);
370 gtk_widget_show(tot_fr);
372 tot_box = gtk_vbox_new(FALSE, 3);
373 gtk_container_add(GTK_CONTAINER(tot_fr), tot_box);
374 gtk_widget_show(tot_box);
376 g_snprintf(string_buff, SUM_STR_MAX, "Total MSUs: %u", tot_num_msus);
377 add_string_to_box(string_buff, tot_box);
380 g_snprintf(string_buff, SUM_STR_MAX, "MSUs/second: %.2f", tot_num_msus/seconds);
383 g_snprintf(string_buff, SUM_STR_MAX, "MSUs/second: N/A");
385 add_string_to_box(string_buff, tot_box);
387 g_snprintf(string_buff, SUM_STR_MAX, "Total Bytes: %.0f", tot_num_bytes);
388 add_string_to_box(string_buff, tot_box);
391 g_snprintf(string_buff, SUM_STR_MAX, "Average Bytes/MSU: %.2f", tot_num_bytes/tot_num_msus);
394 g_snprintf(string_buff, SUM_STR_MAX, "Average Bytes/MSU: N/A");
396 add_string_to_box(string_buff, tot_box);
399 g_snprintf(string_buff, SUM_STR_MAX, "Bytes/second: %.2f", tot_num_bytes/seconds);
402 g_snprintf(string_buff, SUM_STR_MAX, "Bytes/second: N/A");
404 add_string_to_box(string_buff, tot_box);
407 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
408 gtk_container_add(GTK_CONTAINER(main_vb), bbox);
409 gtk_widget_show(bbox);
411 close_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
412 window_set_cancel_button(sum_open_w, close_bt, window_cancel_button_cb);
414 g_signal_connect(sum_open_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
416 gtk_widget_show_all(sum_open_w);
417 window_present(sum_open_w);
422 register_tap_listener_gtkmtp3_summary(void)
424 #ifdef MAIN_MENU_USE_UIMANAGER
426 register_stat_menu_item("_MTP3/MSU Summary", REGISTER_STAT_GROUP_TELEPHONY,
427 mtp3_sum_gtk_sum_cb, NULL, NULL, NULL);