[tracker] Added information about Indexer progress and Stats updates to tracker-status



commit 257dffe6b09bbe73dc8ec23f5683081f388d99a0
Author: Martyn Russell <martyn imendio com>
Date:   Thu Apr 16 11:04:05 2009 +0100

    Added information about Indexer progress and Stats updates to tracker-status
---
 src/tracker-utils/tracker-status.c |  255 +++++++++++++++++++++++++++++++++++-
 1 files changed, 254 insertions(+), 1 deletions(-)

diff --git a/src/tracker-utils/tracker-status.c b/src/tracker-utils/tracker-status.c
index ede791d..95e5f63 100644
--- a/src/tracker-utils/tracker-status.c
+++ b/src/tracker-utils/tracker-status.c
@@ -32,10 +32,14 @@
 
 #include <libtracker/tracker.h>
 
+#define TRACKER_TYPE_G_STRV_ARRAY  (dbus_g_type_get_collection ("GPtrArray", G_TYPE_STRV))
+
 #define DETAIL_MAX_WIDTH 30
 
 #define g_marshal_value_peek_boolean(v)  g_value_get_boolean (v)
 #define g_marshal_value_peek_string(v)	 (char*) g_value_get_string (v)
+#define g_marshal_value_peek_int(v)      g_value_get_int (v)
+#define g_marshal_value_peek_double(v)   g_value_get_double (v)
 
 static GMainLoop *main_loop;
 static gchar     *last_state;   
@@ -61,6 +65,178 @@ static GOptionEntry entries[] = {
 	{ NULL }
 };
 
+static gchar *
+seconds_to_string (gdouble  seconds_elapsed,
+		   gboolean short_string)
+{
+	GString *s;
+	gchar	*str;
+	gdouble  total;
+	gint	 days, hours, minutes, seconds;
+
+	g_return_val_if_fail (seconds_elapsed >= 0.0, g_strdup (_("less than one second")));
+
+	total	 = seconds_elapsed;
+
+	seconds  = (gint) total % 60;
+	total	/= 60;
+	minutes  = (gint) total % 60;
+	total	/= 60;
+	hours	 = (gint) total % 24;
+	days	 = (gint) total / 24;
+
+	s = g_string_new ("");
+
+	if (short_string) {
+		if (days) {
+			g_string_append_printf (s, " %dd", days);
+		}
+
+		if (hours) {
+			g_string_append_printf (s, " %2.2dh", hours);
+		}
+
+		if (minutes) {
+			g_string_append_printf (s, " %2.2dm", minutes);
+		}
+
+		if (seconds) {
+			g_string_append_printf (s, " %2.2ds", seconds);
+		}
+	} else {
+		if (days) {
+			g_string_append_printf (s, " %d day%s",
+						days,
+						days == 1 ? "" : "s");
+		}
+
+		if (hours) {
+			g_string_append_printf (s, " %2.2d hour%s",
+						hours,
+						hours == 1 ? "" : "s");
+		}
+
+		if (minutes) {
+			g_string_append_printf (s, " %2.2d minute%s",
+						minutes,
+						minutes == 1 ? "" : "s");
+		}
+
+		if (seconds) {
+			g_string_append_printf (s, " %2.2d second%s",
+						seconds,
+						seconds == 1 ? "" : "s");
+		}
+	}
+
+	str = g_string_free (s, FALSE);
+
+	if (str[0] == '\0') {
+		g_free (str);
+		str = g_strdup (_("less than one second"));
+	} else {
+		g_strchug (str);
+	}
+
+	return str;
+}
+
+static gchar *
+seconds_estimate_to_string (gdouble  seconds_elapsed,
+			    gboolean short_string,
+			    guint    items_done,
+			    guint    items_remaining)
+{
+	gdouble per_item;
+	gdouble total;
+
+	g_return_val_if_fail (seconds_elapsed >= 0.0, g_strdup (_("unknown time")));
+
+	/* We don't want division by 0 or if total is 0 because items
+	 * remaining is 0 then, equally pointless.
+	 */
+	if (items_done < 1 ||
+	    items_remaining < 1) {
+		return g_strdup (_("unknown time"));
+	}
+
+	per_item = seconds_elapsed / items_done;
+	total = per_item * items_remaining;
+
+	return seconds_to_string (total, short_string);
+}
+
+static void
+index_service_stats_updated (DBusGProxy *proxy,
+                             GPtrArray  *new_stats,
+                             gpointer    user_data)
+{
+	gint i;
+	
+	g_print ("%s:\n", _("Statistics have been updated"));
+
+	for (i = 0; i < new_stats->len; i++) {
+                const gchar **p;
+                const gchar  *service_type = NULL;
+		gchar        *str;
+                
+                p = g_ptr_array_index (new_stats, i);
+                
+                service_type = p[0];
+		
+                if (!service_type) {
+                        continue;
+                }
+		
+		str = g_strdup_printf (_("Updating '%s' with new count:%s"), 
+				       service_type,
+				       p[1]);
+		g_print ("  %s\n", str);
+		g_free (str);
+        }
+}
+
+static void
+index_progress_changed (DBusGProxy  *proxy,
+			const gchar *current_service,
+			const gchar *uri,
+			gint	     items_processed,
+			gint	     items_remaining,
+			gint	     items_total,
+			gdouble      seconds_elapsed,
+			gpointer     user_data)
+{
+	gchar *str1, *str2, *str3;
+
+	str1 = seconds_estimate_to_string (seconds_elapsed,
+					   TRUE,
+					   items_processed,
+					   items_remaining);
+	str2 = seconds_to_string (seconds_elapsed, TRUE);
+
+	str3 = g_strdup_printf (_("Processed %d/%d, current service:'%s', %s left, %s elapsed"),
+				items_processed,
+				items_total,
+				current_service,
+				str1,
+				str2);
+
+	g_free (str2);
+	g_free (str1);
+
+	g_print ("%s\n", str3);
+	g_free (str3);
+
+	if (detailed && uri && *uri) {
+		gchar *str;
+
+		str = g_strdup_printf (_("Last file to be indexed was '%s'"),
+				       uri);
+		g_print ("  %s\n", str);
+		g_free (str);
+	}
+}
+
 static void
 index_state_changed (DBusGProxy  *proxy,
 		     const gchar *state,
@@ -188,6 +364,51 @@ tracker_VOID__STRING_BOOLEAN_BOOLEAN_BOOLEAN_BOOLEAN_BOOLEAN (GClosure	   *closu
 		  data2);
 }
 
+/* VOID:STRING,STRING,INT,INT,INT,DOUBLE (tracker-marshal.list:2) */
+static void
+tracker_VOID__STRING_STRING_INT_INT_INT_DOUBLE (GClosure     *closure,
+						GValue       *return_value G_GNUC_UNUSED,
+						guint         n_param_values,
+						const GValue *param_values,
+						gpointer      invocation_hint G_GNUC_UNUSED,
+						gpointer      marshal_data)
+{
+	typedef void (*GMarshalFunc_VOID__STRING_STRING_INT_INT_INT_DOUBLE) (gpointer     data1,
+									     gpointer     arg_1,
+									     gpointer     arg_2,
+									     gint         arg_3,
+									     gint         arg_4,
+									     gint         arg_5,
+									     gdouble      arg_6,
+									     gpointer     data2);
+	register GMarshalFunc_VOID__STRING_STRING_INT_INT_INT_DOUBLE callback;
+	register GCClosure *cc = (GCClosure*) closure;
+	register gpointer data1, data2;
+	
+	g_return_if_fail (n_param_values == 7);
+	
+	if (G_CCLOSURE_SWAP_DATA (closure))
+	{
+		data1 = closure->data;
+		data2 = g_value_peek_pointer (param_values + 0);
+	}
+	else
+	{
+		data1 = g_value_peek_pointer (param_values + 0);
+		data2 = closure->data;
+	}
+	callback = (GMarshalFunc_VOID__STRING_STRING_INT_INT_INT_DOUBLE) (marshal_data ? marshal_data : cc->callback);
+	
+	callback (data1,
+		  g_marshal_value_peek_string (param_values + 1),
+		  g_marshal_value_peek_string (param_values + 2),
+		  g_marshal_value_peek_int (param_values + 3),
+		  g_marshal_value_peek_int (param_values + 4),
+		  g_marshal_value_peek_int (param_values + 5),
+		  g_marshal_value_peek_double (param_values + 6),
+		  data2);
+}
+
 static void
 signal_handler (int signo)
 {
@@ -300,7 +521,16 @@ main (gint argc, gchar *argv[])
 						   G_TYPE_BOOLEAN,
 						   G_TYPE_BOOLEAN,
 						   G_TYPE_INVALID);
-			
+		dbus_g_object_register_marshaller (tracker_VOID__STRING_STRING_INT_INT_INT_DOUBLE,
+						   G_TYPE_NONE,
+						   G_TYPE_STRING,
+						   G_TYPE_STRING,
+						   G_TYPE_INT,
+						   G_TYPE_INT,
+						   G_TYPE_INT,
+						   G_TYPE_DOUBLE,
+						   G_TYPE_INVALID);
+	
 		dbus_g_proxy_add_signal (proxy,
 					 "IndexStateChange",
 					 G_TYPE_STRING,
@@ -311,12 +541,35 @@ main (gint argc, gchar *argv[])
 					 G_TYPE_BOOLEAN,
 					 G_TYPE_BOOLEAN,
 					 G_TYPE_INVALID);
+		dbus_g_proxy_add_signal (proxy,
+					 "IndexProgress",
+					 G_TYPE_STRING,
+					 G_TYPE_STRING,
+					 G_TYPE_INT,
+					 G_TYPE_INT,
+					 G_TYPE_INT,
+					 G_TYPE_DOUBLE,
+					 G_TYPE_INVALID);
+		dbus_g_proxy_add_signal (proxy,
+					 "ServiceStatisticsUpdated",
+					 TRACKER_TYPE_G_STRV_ARRAY,
+					 G_TYPE_INVALID);
 				
 		dbus_g_proxy_connect_signal (proxy,
 					     "IndexStateChange",
 					     G_CALLBACK (index_state_changed),
 					     NULL,
 					     NULL);
+		dbus_g_proxy_connect_signal (proxy,
+					     "IndexProgress",
+					     G_CALLBACK (index_progress_changed),
+					     NULL,
+					     NULL);
+		dbus_g_proxy_connect_signal (proxy,
+					     "ServiceStatisticsUpdated",
+					     G_CALLBACK (index_service_stats_updated),
+					     NULL,
+					     NULL);
 
 		initialize_signal_handler ();
 			



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