[tracker/miner-fs-refactor: 109/110] libtracker-miner: Calculate remaining time purely on extraction time



commit 21790d5c5a40e4fb89301448e7dd376d3b017335
Author: Carlos Garnacho <carlos lanedo com>
Date:   Fri Oct 21 19:28:22 2011 +0200

    libtracker-miner: Calculate remaining time purely on extraction time
    
    During crawling, the extraction queue may be mostly empty, but adding
    up time that makes the remaining time calculations to be quite off
    when little items have been processed so far.
    
    So, keep a timer only for extraction time, which can be used for more
    accurate measurements, as only extraction is left when tracker-miner-fs
    gets to report progress/remaining time.

 src/libtracker-miner/tracker-miner-fs.c |   35 +++++++++++++++++++++++++++---
 1 files changed, 31 insertions(+), 4 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index aa4ee95..6105414 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -161,6 +161,7 @@ struct _TrackerMinerFSPrivate {
 	GQuark          quark_directory_found_crawling;
 
 	GTimer         *timer;
+	GTimer         *extraction_timer;
 
 	guint           item_queues_handler_id;
 
@@ -188,6 +189,8 @@ struct _TrackerMinerFSPrivate {
 	                                       * during initial crawling. */
 	guint           initial_crawling : 1; /* TRUE if initial crawling should be
 	                                       * done */
+	guint           extraction_timer_stopped : 1; /* TRUE if the extraction
+						       * timer is stopped */
 
 	/* Statistics */
 	guint           total_directories_found;
@@ -624,6 +627,10 @@ fs_finalize (GObject *object)
 		g_timer_destroy (priv->timer);
 	}
 
+	if (priv->extraction_timer) {
+		g_timer_destroy (priv->extraction_timer);
+	}
+
 	if (priv->item_queues_handler_id) {
 		g_source_remove (priv->item_queues_handler_id);
 		priv->item_queues_handler_id = 0;
@@ -887,6 +894,8 @@ process_stop (TrackerMinerFS *fs)
 	               fs->priv->total_files_found,
 	               fs->priv->total_files_ignored);
 
+	g_timer_reset (fs->priv->extraction_timer);
+
 	if (fs->priv->timer) {
 		g_timer_destroy (fs->priv->timer);
 		fs->priv->timer = NULL;
@@ -1915,6 +1924,12 @@ item_queue_get_next_file (TrackerMinerFS  *fs,
 	if (tracker_file_notifier_is_active (fs->priv->file_notifier) ||
 	    tracker_task_pool_limit_reached (fs->priv->task_pool) ||
 	    tracker_task_pool_limit_reached (TRACKER_TASK_POOL (fs->priv->sparql_buffer))) {
+		if (fs->priv->extraction_timer &&
+		    tracker_task_pool_get_size (fs->priv->task_pool) == 0) {
+			fs->priv->extraction_timer_stopped = TRUE;
+			g_timer_stop (fs->priv->extraction_timer);
+		}
+
 		/* There are still pending items to crawl,
 		 * or extract pool limit is reached
 		 */
@@ -1990,7 +2005,6 @@ item_queue_handlers_cb (gpointer user_data)
 		 * on with the queues... */
 		tracker_sparql_buffer_flush (fs->priv->sparql_buffer,
 		                             "Queue handlers WAIT");
-
 		return FALSE;
 	}
 
@@ -2014,6 +2028,18 @@ item_queue_handlers_cb (gpointer user_data)
 		return TRUE;
 	}
 
+	if (queue == QUEUE_NONE) {
+		if (fs->priv->extraction_timer) {
+			g_timer_stop (fs->priv->extraction_timer);
+			fs->priv->extraction_timer_stopped = TRUE;
+		}
+	} else if (!fs->priv->extraction_timer) {
+		fs->priv->extraction_timer = g_timer_new ();
+	} else if (fs->priv->extraction_timer_stopped) {
+		g_timer_continue (fs->priv->extraction_timer);
+		fs->priv->extraction_timer_stopped = FALSE;
+	}
+
 	if (!fs->priv->timer) {
 		fs->priv->timer = g_timer_new ();
 	}
@@ -2026,7 +2052,7 @@ item_queue_handlers_cb (gpointer user_data)
 		gdouble progress_now;
 		static gdouble progress_last = 0.0;
 		static gint info_last = 0;
-		gdouble seconds_elapsed;
+		gdouble seconds_elapsed, extraction_elapsed;
 
 		time_last = time_now;
 
@@ -2035,6 +2061,7 @@ item_queue_handlers_cb (gpointer user_data)
 		                                        &items_processed,
 		                                        &items_remaining);
 		seconds_elapsed = g_timer_elapsed (fs->priv->timer, NULL);
+		extraction_elapsed = g_timer_elapsed (fs->priv->extraction_timer, NULL);
 
 		if (!tracker_file_notifier_is_active (fs->priv->file_notifier)) {
 			gchar *status;
@@ -2043,7 +2070,7 @@ item_queue_handlers_cb (gpointer user_data)
 			g_object_get (fs, "status", &status, NULL);
 
 			/* Compute remaining time */
-			remaining_time = (gint)tracker_seconds_estimate (seconds_elapsed,
+			remaining_time = (gint)tracker_seconds_estimate (extraction_elapsed,
 			                                                 items_processed,
 			                                                 items_remaining);
 
@@ -2076,7 +2103,7 @@ item_queue_handlers_cb (gpointer user_data)
 			progress_last = progress_now;
 
 			/* Log estimated remaining time */
-			str1 = tracker_seconds_estimate_to_string (seconds_elapsed,
+			str1 = tracker_seconds_estimate_to_string (extraction_elapsed,
 			                                           TRUE,
 			                                           items_processed,
 			                                           items_remaining);



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