aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2010-01-11 22:32:55 -0500
committerSteven Rostedt <rostedt@goodmis.org>2010-01-11 22:32:55 -0500
commit3f2351075d720c2430ef5d29427b9bd6cefc4dcd (patch)
treee498af6e96e85fa60eced10432f815af2ec44378
parent755a4ccf14ddcfe3a3c864b78e7a58027127ddf9 (diff)
kernel-shark: Add loading of data at run time
Now the kernel shark interface does not need a file to start with, and it can load new data later on. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r--kernel-shark.c65
-rw-r--r--kernel-shark.h1
2 files changed, 61 insertions, 5 deletions
diff --git a/kernel-shark.c b/kernel-shark.c
index 6742da9..f6b71cf 100644
--- a/kernel-shark.c
+++ b/kernel-shark.c
@@ -23,10 +23,11 @@
23#include <string.h> 23#include <string.h>
24#include <stdarg.h> 24#include <stdarg.h>
25#include <fcntl.h> 25#include <fcntl.h>
26#include <sys/types.h>
27#include <sys/stat.h>
26#include <unistd.h> 28#include <unistd.h>
27#include <gtk/gtk.h> 29#include <gtk/gtk.h>
28#include <getopt.h> 30#include <getopt.h>
29#include <string.h>
30 31
31#include "trace-compat.h" 32#include "trace-compat.h"
32#include "trace-cmd.h" 33#include "trace-cmd.h"
@@ -48,7 +49,7 @@
48#define TRACE_HEIGHT 600 49#define TRACE_HEIGHT 600
49 50
50#define default_input_file "trace.dat" 51#define default_input_file "trace.dat"
51static char *input_file = default_input_file; 52static char *input_file;
52 53
53void usage(char *prog) 54void usage(char *prog)
54{ 55{
@@ -119,6 +120,35 @@ static void free_info(struct shark_info *info)
119 free(info); 120 free(info);
120} 121}
121 122
123/* Callback for the clicked signal of the Load button */
124static void
125load_clicked (gpointer data)
126{
127 struct shark_info *info = data;
128 struct tracecmd_input *handle;
129 GtkWidget *dialog;
130 gchar *filename;
131
132 dialog = gtk_file_chooser_dialog_new("Load File",
133 NULL,
134 GTK_FILE_CHOOSER_ACTION_OPEN,
135 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
136 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
137 NULL);
138 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
139 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
140 handle = tracecmd_open(filename);
141 if (handle) {
142 tracecmd_close(info->handle);
143 info->handle = handle;
144 trace_graph_load_handle(info->ginfo, handle);
145 trace_view_reload(info->treeview, handle, info->spin);
146 }
147 g_free(filename);
148 }
149 gtk_widget_destroy(dialog);
150}
151
122/* Callback for the clicked signal of the Exit button */ 152/* Callback for the clicked signal of the Exit button */
123static void 153static void
124exit_clicked (gpointer data) 154exit_clicked (gpointer data)
@@ -505,6 +535,7 @@ void kernel_shark(int argc, char **argv)
505{ 535{
506 struct tracecmd_input *handle; 536 struct tracecmd_input *handle;
507 struct shark_info *info; 537 struct shark_info *info;
538 struct stat st;
508 GtkWidget *window; 539 GtkWidget *window;
509 GtkWidget *vbox; 540 GtkWidget *vbox;
510 GtkWidget *vbox2; 541 GtkWidget *vbox2;
@@ -518,6 +549,7 @@ void kernel_shark(int argc, char **argv)
518 GtkWidget *widget; 549 GtkWidget *widget;
519 GtkWidget *label; 550 GtkWidget *label;
520 GtkWidget *spin; 551 GtkWidget *spin;
552 int ret;
521 int c; 553 int c;
522 554
523 while ((c = getopt(argc, argv, "hvi:")) != -1) { 555 while ((c = getopt(argc, argv, "hvi:")) != -1) {
@@ -543,9 +575,14 @@ void kernel_shark(int argc, char **argv)
543 if (!info) 575 if (!info)
544 die("Unable to allocate info"); 576 die("Unable to allocate info");
545 577
546 handle = tracecmd_open(input_file); 578 if (!input_file) {
547 if (!handle) 579 ret = stat(default_input_file, &st);
548 die("error reading header"); 580 if (ret >= 0)
581 input_file = default_input_file;
582 }
583 if (handle)
584 handle = tracecmd_open(input_file);
585
549 info->handle = handle; 586 info->handle = handle;
550 587
551 gtk_init(&argc, &argv); 588 gtk_init(&argc, &argv);
@@ -577,6 +614,22 @@ void kernel_shark(int argc, char **argv)
577 menu = gtk_menu_new(); /* Don't need to show menus */ 614 menu = gtk_menu_new(); /* Don't need to show menus */
578 615
579 616
617 /* --- File - Load Option --- */
618
619 sub_item = gtk_menu_item_new_with_label("Load info");
620
621 /* Add them to the menu */
622 gtk_menu_shell_append(GTK_MENU_SHELL (menu), sub_item);
623
624 /* We can attach the Quit menu item to our exit function */
625 g_signal_connect_swapped (G_OBJECT (sub_item), "activate",
626 G_CALLBACK (load_clicked),
627 (gpointer) info);
628
629 /* We do need to show menu items */
630 gtk_widget_show(sub_item);
631
632
580 /* --- File - Quit Option --- */ 633 /* --- File - Quit Option --- */
581 634
582 sub_item = gtk_menu_item_new_with_label("Quit"); 635 sub_item = gtk_menu_item_new_with_label("Quit");
@@ -731,6 +784,8 @@ void kernel_shark(int argc, char **argv)
731 gtk_box_pack_start(GTK_BOX(hbox), spin, FALSE, FALSE, 0); 784 gtk_box_pack_start(GTK_BOX(hbox), spin, FALSE, FALSE, 0);
732 gtk_widget_show(spin); 785 gtk_widget_show(spin);
733 786
787 info->spin = spin;
788
734 /* --- Search --- */ 789 /* --- Search --- */
735 790
736 /* The tree needs its columns loaded now */ 791 /* The tree needs its columns loaded now */
diff --git a/kernel-shark.h b/kernel-shark.h
index 34b2031..f04e902 100644
--- a/kernel-shark.h
+++ b/kernel-shark.h
@@ -9,6 +9,7 @@ struct shark_info {
9 struct graph_info *ginfo; 9 struct graph_info *ginfo;
10 struct tracecmd_input *handle; 10 struct tracecmd_input *handle;
11 GtkWidget *treeview; 11 GtkWidget *treeview;
12 GtkWidget *spin;
12 struct graph_callbacks graph_cbs; 13 struct graph_callbacks graph_cbs;
13 gint selected_task; 14 gint selected_task;
14 gboolean list_filter_enabled; 15 gboolean list_filter_enabled;