diff options
| author | Steven Rostedt <srostedt@redhat.com> | 2010-04-06 12:24:52 -0400 |
|---|---|---|
| committer | Steven Rostedt <rostedt@goodmis.org> | 2010-04-09 11:56:19 -0400 |
| commit | 99982a54732ed10ceb1da31240e8fcbbcd430010 (patch) | |
| tree | b61e968a63f0c8633769843494d9de5201beb713 | |
| parent | 935a801c7f3eab7bad5c183a702a506540d32700 (diff) | |
kernelshark: Add status bar and status dialog
Add a status bar at the bottom of the window and show an info icon
when status exists.
Left mouse button will produce a popup to let the user display
the status information.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
| -rw-r--r-- | kernel-shark.c | 134 | ||||
| -rw-r--r-- | trace-compat.c | 13 | ||||
| -rw-r--r-- | trace-compat.h | 3 |
3 files changed, 150 insertions, 0 deletions
diff --git a/kernel-shark.c b/kernel-shark.c index 9ae90bc..7ae562c 100644 --- a/kernel-shark.c +++ b/kernel-shark.c | |||
| @@ -27,6 +27,7 @@ | |||
| 27 | #include <sys/stat.h> | 27 | #include <sys/stat.h> |
| 28 | #include <unistd.h> | 28 | #include <unistd.h> |
| 29 | #include <gtk/gtk.h> | 29 | #include <gtk/gtk.h> |
| 30 | #include <errno.h> | ||
| 30 | #include <getopt.h> | 31 | #include <getopt.h> |
| 31 | 32 | ||
| 32 | #include "trace-compat.h" | 33 | #include "trace-compat.h" |
| @@ -49,9 +50,16 @@ | |||
| 49 | #define TRACE_WIDTH 800 | 50 | #define TRACE_WIDTH 800 |
| 50 | #define TRACE_HEIGHT 600 | 51 | #define TRACE_HEIGHT 600 |
| 51 | 52 | ||
| 53 | #define DIALOG_WIDTH 500 | ||
| 54 | #define DIALOG_HEIGHT 550 | ||
| 55 | |||
| 52 | #define default_input_file "trace.dat" | 56 | #define default_input_file "trace.dat" |
| 53 | static char *input_file; | 57 | static char *input_file; |
| 54 | 58 | ||
| 59 | static GtkWidget *statusbar; | ||
| 60 | static GtkWidget *statuspix; | ||
| 61 | static GString *statusstr; | ||
| 62 | |||
| 55 | void usage(char *prog) | 63 | void usage(char *prog) |
| 56 | { | 64 | { |
| 57 | printf("Usage: %s\n", prog); | 65 | printf("Usage: %s\n", prog); |
| @@ -60,6 +68,34 @@ void usage(char *prog) | |||
| 60 | printf(" -i input_file, default is %s\n", default_input_file); | 68 | printf(" -i input_file, default is %s\n", default_input_file); |
| 61 | } | 69 | } |
| 62 | 70 | ||
| 71 | void pr_stat(char *fmt, ...) | ||
| 72 | { | ||
| 73 | GString *str; | ||
| 74 | va_list ap; | ||
| 75 | |||
| 76 | if (!statusstr) { | ||
| 77 | statusstr = g_string_new(""); | ||
| 78 | if (!statusstr) | ||
| 79 | die("Allocating status string"); | ||
| 80 | } | ||
| 81 | |||
| 82 | str = g_string_new(""); | ||
| 83 | |||
| 84 | va_start(ap, fmt); | ||
| 85 | g_string_vprintf(str, fmt, ap); | ||
| 86 | va_end(ap); | ||
| 87 | |||
| 88 | g_string_append_printf(statusstr, "%s\n", str->str); | ||
| 89 | |||
| 90 | if (statusbar) { | ||
| 91 | gtk_statusbar_push(GTK_STATUSBAR(statusbar), 1, str->str); | ||
| 92 | gtk_widget_show(statuspix); | ||
| 93 | } | ||
| 94 | |||
| 95 | g_string_free(str, TRUE); | ||
| 96 | } | ||
| 97 | |||
| 98 | |||
| 63 | /* graph callbacks */ | 99 | /* graph callbacks */ |
| 64 | 100 | ||
| 65 | /* convert_nano() and print_time() are copied from trace-graph.c for debugging | 101 | /* convert_nano() and print_time() are copied from trace-graph.c for debugging |
| @@ -715,6 +751,81 @@ button_press_event(GtkWidget *widget, GdkEventButton *event, gpointer data) | |||
| 715 | return FALSE; | 751 | return FALSE; |
| 716 | } | 752 | } |
| 717 | 753 | ||
| 754 | static void | ||
| 755 | status_display_clicked (gpointer data) | ||
| 756 | { | ||
| 757 | GtkWidget *dialog; | ||
| 758 | GtkWidget *scrollwin; | ||
| 759 | GtkWidget *viewport; | ||
| 760 | GtkWidget *textview; | ||
| 761 | GtkTextBuffer *buffer; | ||
| 762 | |||
| 763 | dialog = gtk_dialog_new_with_buttons("Status", | ||
| 764 | NULL, | ||
| 765 | GTK_DIALOG_MODAL, | ||
| 766 | "OK", | ||
| 767 | GTK_RESPONSE_ACCEPT, | ||
| 768 | NULL); | ||
| 769 | |||
| 770 | scrollwin = gtk_scrolled_window_new(NULL, NULL); | ||
| 771 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin), | ||
| 772 | GTK_POLICY_AUTOMATIC, | ||
| 773 | GTK_POLICY_AUTOMATIC); | ||
| 774 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), scrollwin, TRUE, TRUE, 0); | ||
| 775 | gtk_widget_show(scrollwin); | ||
| 776 | |||
| 777 | viewport = gtk_viewport_new(NULL, NULL); | ||
| 778 | gtk_widget_show(viewport); | ||
| 779 | |||
| 780 | gtk_container_add(GTK_CONTAINER(scrollwin), viewport); | ||
| 781 | |||
| 782 | textview = gtk_text_view_new(); | ||
| 783 | buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); | ||
| 784 | gtk_text_buffer_set_text(buffer, statusstr->str, -1); | ||
| 785 | |||
| 786 | gtk_container_add(GTK_CONTAINER(viewport), textview); | ||
| 787 | gtk_widget_show(textview); | ||
| 788 | |||
| 789 | gtk_widget_set_size_request(GTK_WIDGET(dialog), | ||
| 790 | DIALOG_WIDTH, DIALOG_HEIGHT); | ||
| 791 | |||
| 792 | gtk_dialog_run(GTK_DIALOG(dialog)); | ||
| 793 | |||
| 794 | gtk_widget_destroy(dialog); | ||
| 795 | } | ||
| 796 | |||
| 797 | static gboolean | ||
| 798 | do_status_popup(GtkWidget *widget, GdkEventButton *event, gpointer data) | ||
| 799 | { | ||
| 800 | static GtkWidget *menu; | ||
| 801 | static GtkWidget *menu_status_display; | ||
| 802 | |||
| 803 | if (!menu) { | ||
| 804 | menu = gtk_menu_new(); | ||
| 805 | menu_status_display = gtk_menu_item_new_with_label("Display Status"); | ||
| 806 | gtk_widget_show(menu_status_display); | ||
| 807 | gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_status_display); | ||
| 808 | |||
| 809 | g_signal_connect_swapped (G_OBJECT (menu_status_display), "activate", | ||
| 810 | G_CALLBACK (status_display_clicked), | ||
| 811 | data); | ||
| 812 | } | ||
| 813 | |||
| 814 | gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, | ||
| 815 | gtk_get_current_event_time()); | ||
| 816 | |||
| 817 | return TRUE; | ||
| 818 | } | ||
| 819 | |||
| 820 | static gboolean | ||
| 821 | button_press_status(GtkWidget *widget, GdkEventButton *event, gpointer data) | ||
| 822 | { | ||
| 823 | if (event->button == 1) | ||
| 824 | return do_status_popup(widget, event, data); | ||
| 825 | |||
| 826 | return FALSE; | ||
| 827 | } | ||
| 828 | |||
| 718 | void kernel_shark(int argc, char **argv) | 829 | void kernel_shark(int argc, char **argv) |
| 719 | { | 830 | { |
| 720 | struct tracecmd_input *handle; | 831 | struct tracecmd_input *handle; |
| @@ -734,6 +845,7 @@ void kernel_shark(int argc, char **argv) | |||
| 734 | GtkWidget *label; | 845 | GtkWidget *label; |
| 735 | GtkWidget *spin; | 846 | GtkWidget *spin; |
| 736 | GtkWidget *check; | 847 | GtkWidget *check; |
| 848 | GtkWidget *eventbox; | ||
| 737 | int ret; | 849 | int ret; |
| 738 | int c; | 850 | int c; |
| 739 | 851 | ||
| @@ -1187,6 +1299,28 @@ void kernel_shark(int argc, char **argv) | |||
| 1187 | 1299 | ||
| 1188 | gtk_widget_show(info->treeview); | 1300 | gtk_widget_show(info->treeview); |
| 1189 | 1301 | ||
| 1302 | /* --- Set up Status Bar --- */ | ||
| 1303 | |||
| 1304 | statusbar = gtk_statusbar_new(); | ||
| 1305 | |||
| 1306 | gtk_box_pack_start(GTK_BOX(vbox), statusbar, FALSE, FALSE, 0); | ||
| 1307 | gtk_widget_show(statusbar); | ||
| 1308 | |||
| 1309 | statuspix = gtk_image_new_from_stock(GTK_STOCK_INFO, | ||
| 1310 | GTK_ICON_SIZE_SMALL_TOOLBAR); | ||
| 1311 | |||
| 1312 | eventbox = gtk_event_box_new(); | ||
| 1313 | gtk_container_add(GTK_CONTAINER(eventbox), statuspix); | ||
| 1314 | gtk_widget_show(eventbox); | ||
| 1315 | |||
| 1316 | gtk_box_pack_end(GTK_BOX(statusbar), eventbox, FALSE, FALSE, 0); | ||
| 1317 | |||
| 1318 | if (statusstr) | ||
| 1319 | gtk_widget_show(statuspix); | ||
| 1320 | |||
| 1321 | gtk_signal_connect(GTK_OBJECT(eventbox), "button_press_event", | ||
| 1322 | (GtkSignalFunc) button_press_status, info); | ||
| 1323 | |||
| 1190 | 1324 | ||
| 1191 | /********************************************** | 1325 | /********************************************** |
| 1192 | * Main Window | 1326 | * Main Window |
diff --git a/trace-compat.c b/trace-compat.c index a1f2113..b23cf06 100644 --- a/trace-compat.c +++ b/trace-compat.c | |||
| @@ -23,6 +23,7 @@ | |||
| 23 | */ | 23 | */ |
| 24 | #include "trace-compat.h" | 24 | #include "trace-compat.h" |
| 25 | #include "trace-gui.h" | 25 | #include "trace-gui.h" |
| 26 | #include "trace-cmd.h" | ||
| 26 | 27 | ||
| 27 | #include <gdk/gdk.h> | 28 | #include <gdk/gdk.h> |
| 28 | 29 | ||
| @@ -79,6 +80,18 @@ gboolean gtk_show_uri(GdkScreen *screen, const gchar *uri, | |||
| 79 | return FALSE; | 80 | return FALSE; |
| 80 | } | 81 | } |
| 81 | 82 | ||
| 83 | void g_string_vprintf(GString *string, const gchar *format, va_list args) | ||
| 84 | { | ||
| 85 | char buf[1024]; | ||
| 86 | gint len; | ||
| 87 | |||
| 88 | len = vsnprintf(buf, 1024, format, args); | ||
| 89 | if (len >= 1024) | ||
| 90 | die("compat g_string_vprintf can not process length of %d\n", len); | ||
| 91 | |||
| 92 | g_string_printf(string, "%s", buf); | ||
| 93 | } | ||
| 94 | |||
| 82 | #endif /* version < 2.14.0 */ | 95 | #endif /* version < 2.14.0 */ |
| 83 | 96 | ||
| 84 | #if GTK_VERSION < CALC_GTK_VERSION(2,12,0) | 97 | #if GTK_VERSION < CALC_GTK_VERSION(2,12,0) |
diff --git a/trace-compat.h b/trace-compat.h index 2eed192..fa11a35 100644 --- a/trace-compat.h +++ b/trace-compat.h | |||
| @@ -22,6 +22,7 @@ | |||
| 22 | #define _TRACE_COMPAT_H | 22 | #define _TRACE_COMPAT_H |
| 23 | 23 | ||
| 24 | #include <gtk/gtk.h> | 24 | #include <gtk/gtk.h> |
| 25 | #include <stdarg.h> | ||
| 25 | 26 | ||
| 26 | #define CALC_GTK_VERSION(maj, min, ext) ((maj << 16) + (min << 8) + ext) | 27 | #define CALC_GTK_VERSION(maj, min, ext) ((maj << 16) + (min << 8) + ext) |
| 27 | 28 | ||
| @@ -46,6 +47,8 @@ gdouble gtk_adjustment_get_lower(GtkAdjustment *adj); | |||
| 46 | gboolean gtk_show_uri(GdkScreen *screen, const gchar *uri, | 47 | gboolean gtk_show_uri(GdkScreen *screen, const gchar *uri, |
| 47 | guint32 timestamp, GError **error); | 48 | guint32 timestamp, GError **error); |
| 48 | 49 | ||
| 50 | void g_string_vprintf(GString *string, const gchar *format, va_list args); | ||
| 51 | |||
| 49 | #endif /* version < 2.14.0 */ | 52 | #endif /* version < 2.14.0 */ |
| 50 | 53 | ||
| 51 | #if GTK_VERSION < CALC_GTK_VERSION(2,12,0) | 54 | #if GTK_VERSION < CALC_GTK_VERSION(2,12,0) |
