[Nautilus-list] eazel-tools - proj patch ...



Hi there,

	This patch adds some cmdline options I found useful, and adds the
ability to dump the statistics to a file [ sadly hardcoded due to lack of
time ]. While not perfect, this makes gprof much more useful for me,

	May I commit ?

	Regards,

		Michael.

? 1.diff
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/eazel-tools/ChangeLog,v
retrieving revision 1.31
diff -u -r1.31 ChangeLog
--- ChangeLog	2001/04/19 23:16:01	1.31
+++ ChangeLog	2001/06/22 08:41:18
@@ -1,3 +1,13 @@
+2001-06-22  Michael Meeks  <michael ximian com>
+
+	* prof/front.c (save_callback): impl.
+	(on_save_button_clicked): impl.
+	(main): add collate-self / collate-all arguments for easy
+	cmdline operation.
+	(create_process_window): tie 'proc' to the current window.
+	(delete_process_window): free final dump.
+	(reclaim_callback): dump at the end.
+
 2001-04-19  John Harper  <jsh eazel com>
 
 	* prof/Makefile.am: when installing prof.desktop, install under
Index: prof/front.c
===================================================================
RCS file: /cvs/gnome/eazel-tools/prof/front.c,v
retrieving revision 1.4
diff -u -r1.4 front.c
--- prof/front.c	2001/03/04 01:51:30	1.4
+++ prof/front.c	2001/06/22 08:41:20
@@ -58,6 +58,8 @@
     GnomeCanvasItem *canvas_group;
 
     int timeout_tag;
+
+    GString *final_dump;
 };
 
 static GSList *window_list;
@@ -67,6 +69,8 @@
 static int collation_type = PROF_COLLATE_ALL;
 
 static gboolean throbber_enabled = FALSE;
+static gboolean collate_self = FALSE;
+static gboolean collate_all  = FALSE;
 
 static void set_status (const char *fmt, ...);
 static void delete_process_window (prof_window *pw);
@@ -108,7 +112,7 @@
 
     { int max_percent = (coll->value_max * 100) / coll->value_sum;
       char buf[64];
-      sprintf (buf, "%d %s, %d %s",
+      sprintf (buf, "%ld %s, %d %s",
 	       coll->value_sum,
 	       coll->value_sum == 1 ? _("sample") : _("samples"),
 	       proc->total_threads,
@@ -235,7 +239,73 @@
     }
 }
 
+static void
+stringify_callback (prof_collated *coll, void *data)
+{
+    GString *str = data;
+    int i;
+    int max_percent;
+
+    if (coll->value_sum == 0)
+	return;
+
+    switch (collation_type) {
+    case PROF_COLLATE_SELF:
+        g_string_sprintfa (str, "Per function collation\n");
+	break;
+    case PROF_COLLATE_ALL:
+        g_string_sprintfa (str, "Cumulative collation\n");
+	break;
+    }
+
+    g_string_sprintfa (str, "\n");
+
+    g_string_sprintfa (str, "%ld %s\n",
+		       coll->value_sum,
+		       coll->value_sum == 1 ? _("sample") : _("samples"));
+    
+    max_percent = (coll->value_max * 100) / coll->value_sum;
+
+    g_string_sprintfa (str, "Max Percent: %d%%\n", max_percent);
+    
+    for (i = 0; i < coll->ndata && coll->data[i].value > 0; i++)
+    {
+         double percentage = (((double) coll->data[i].value)
+			      / coll->value_sum) * 100.0;
+	 g_string_sprintfa (str, "%-64s : %3.2g%% ( %ld )\n",
+			    coll->data[i].fun->function,
+			    percentage, coll->data[i].value);
+    }
+}
+
 void
+on_save_button_clicked (GtkWidget *button)
+{
+    FILE *file = stderr;
+    GString *str;
+    prof_process *proc;
+
+    g_return_if_fail (current_window != NULL);
+
+    if ((str = current_window->final_dump))
+        fprintf (file, "%s", str->str);
+    else {
+        g_return_if_fail (current_window->proc != NULL);
+
+	str = g_string_new ("");
+	proc = current_window->proc;
+
+	if (!proc->disconnected)
+		collate_profile (proc, collation_type,
+				 stringify_callback, str);
+
+        fprintf (file, "%s", str->str);
+
+	g_string_free (str, TRUE);
+    }
+}
+
+void
 on_about_activate (GtkWidget *w)
 {
     GladeXML *xml = glade_xml_new (glade_file, "about_dialog");
@@ -358,6 +428,7 @@
 
     pw = g_new0 (prof_window, 1);
     proc->user_data = pw;
+    pw->proc = proc;
 
     pw->page = gtk_vbox_new (FALSE, 0);
     pw->title = process_title (proc);
@@ -405,6 +476,9 @@
 	pw->timeout_tag = 0;
     }
 
+    if (pw->final_dump)
+        g_string_free (pw->final_dump, TRUE);
+
     g_free (pw->title);
     g_free (pw);
 
@@ -492,6 +566,11 @@
     prof_window *pw = proc->user_data;
     if (pw != 0)
     {
+        pw->final_dump = g_string_new ("");
+	collate_profile (proc, collation_type,
+			 stringify_callback,
+			 pw->final_dump);
+	    
 	pw->proc = 0;
 	set_status (_("%s exited."), pw->title);
 	if (pw->timeout_tag != 0)
@@ -536,13 +615,17 @@
 {
     static const struct poptOption popt_options [] = {
       { "interval", 0, POPT_ARG_INT, &profile_interval, 0,
-	N_("Period between profile sampling"), "MICROSECONDS" },
+	N_("Period between profile sampling (def. 10)"), "MICROSECONDS" },
       { "follow-fork", 0, POPT_ARG_NONE, &follow_fork, 0,
 	N_("Profile processes created by fork ()"), NULL },
       { "follow-exec", 0, POPT_ARG_NONE, &follow_exec, 0,
 	N_("Keep profiling processes after they call exec ()"), NULL },
       { "enable-throbber", 0, POPT_ARG_NONE, &throbber_enabled, 0,
 	N_("Show profiling activity on standard output."), NULL },
+      { "collate-self", 0, POPT_ARG_NONE, &collate_self, 0,
+	N_("Show each function's time slice"), NULL },
+      { "collate-all", 0, POPT_ARG_NONE, &collate_all, 0,
+	N_("Show cumulative function time slice"), NULL },
       { NULL, '\0', 0, NULL, 0 },
     };
     poptContext ctx;
@@ -556,6 +639,13 @@
     gnome_init_with_popt_table ("prof", VERSION,
 				argc, argv,
 				popt_options, 0, &ctx);
+
+    if (collate_self)
+	    collation_type = PROF_COLLATE_SELF;
+
+    if (collate_all)
+	    collation_type = PROF_COLLATE_ALL;
+
     glade_gnome_init ();
 
     glade_file = "./prof.glade";
Index: prof/prof.glade
===================================================================
RCS file: /cvs/gnome/eazel-tools/prof/prof.glade,v
retrieving revision 1.3
diff -u -r1.3 prof.glade
--- prof/prof.glade	2000/12/05 19:56:07	1.3
+++ prof/prof.glade	2001/06/22 08:41:21
@@ -230,7 +230,7 @@
 	      </signal>
 	      <label>Follow _fork ()</label>
 	      <active>False</active>
-	      <always_show_toggle>False</always_show_toggle>
+	      <always_show_toggle>True</always_show_toggle>
 	    </widget>
 
 	    <widget>
@@ -243,7 +243,7 @@
 	      </signal>
 	      <label>Follow _exec ()</label>
 	      <active>False</active>
-	      <always_show_toggle>False</always_show_toggle>
+	      <always_show_toggle>True</always_show_toggle>
 	    </widget>
 	  </widget>
 	</widget>
@@ -357,6 +357,23 @@
 	<widget>
 	  <class>GtkButton</class>
 	  <child_name>Toolbar:button</child_name>
+	  <name>save_button</name>
+	  <tooltip>Execute a program under the profiler.</tooltip>
+	  <signal>
+	    <name>clicked</name>
+	    <handler>on_save_button_clicked</handler>
+	    <last_modification_time>Fri, 22 Jun 2001 08:36:28 GMT</last_modification_time>
+	  </signal>
+	  <label>Save</label>
+	  <stock_pixmap>GNOME_STOCK_PIXMAP_SAVE_AS</stock_pixmap>
+	  <child>
+	    <new_group>True</new_group>
+	  </child>
+	</widget>
+
+	<widget>
+	  <class>GtkButton</class>
+	  <child_name>Toolbar:button</child_name>
 	  <name>button1</name>
 	  <tooltip>Disconnect from the current program.</tooltip>
 	  <signal>
@@ -366,9 +383,6 @@
 	  </signal>
 	  <label>Close</label>
 	  <stock_pixmap>GNOME_STOCK_PIXMAP_CLOSE</stock_pixmap>
-	  <child>
-	    <new_group>True</new_group>
-	  </child>
 	</widget>
 
 	<widget>



-- 
 mmeeks gnu org  <><, Pseudo Engineer, itinerant idiot





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]