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



commit 57d0077a3fffb1013f76e6c16dfccc5cb7d05cce
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 2d113d3..d04bd36 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;
@@ -636,6 +639,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;
@@ -909,6 +916,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;
@@ -1937,6 +1946,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
 		 */
@@ -2017,7 +2032,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;
 	}
 
@@ -2041,6 +2055,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 ();
 	}
@@ -2053,7 +2079,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;
 
@@ -2062,6 +2088,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;
@@ -2070,7 +2097,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);
 
@@ -2103,7 +2130,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]