[sysprof/ftrace: 3/16] Simplify the read routine



commit 4dd807896f4a09a37386a1c8a7e415d658eb471e
Author: Soren Sandmann <sandmann daimi au dk>
Date:   Sat May 10 21:54:44 2008 +0000

    Simplify the read routine

 collector.c |   43 +++++++++++++++++++++++++++----------------
 1 files changed, 27 insertions(+), 16 deletions(-)
---
diff --git a/collector.c b/collector.c
index 8f4b28f..8b61494 100644
--- a/collector.c
+++ b/collector.c
@@ -583,29 +583,46 @@ on_read (gpointer data)
     int n_bytes;
     gboolean first;
     int i;
-    static int n_reads;
 
     memset (input, '1', sizeof input);
-    
-    n_bytes = read (collector->fd, input, sizeof (input));
 
-    g_assert (data == collector);
+    while ((n_bytes = read (collector->fd, input, sizeof (input))) > 0)
+    {
+	g_assert (data == collector);
+
+	if (!in_dead_period (collector))
+	{
+	    g_string_append_len (collector->input, input, n_bytes);
+	    
+	    first = collector->n_samples == 0;
+
+	    parse_input (collector);
+	    
+	    if (collector->callback && collector->n_samples > 0)
+		collector->callback (first, collector->data);
+	}
+    }
+
+    if (n_bytes == -1 && errno != EAGAIN)
+    {
+	g_warning ("Read from trace pipe: %s\n", strerror (errno));
+    }
+
+
+
     
+    
+#if 0
     if (n_bytes <= 0)
     {
 	g_print ("result: %d\n", n_bytes);
 	return;
     }
 
-    n_reads++;
-    if (n_reads % 10000 == 0)
-	g_print ("%d reads\n", n_reads);
-    
     if (in_dead_period (collector))
 	return;
+#endif
     
-    first = collector->n_samples == 0;
-
 #if 0
     /* Sometimes we get nul bytes in the input. This is inconvenient, so
      * replace them with newlines.
@@ -617,12 +634,6 @@ on_read (gpointer data)
     }
 #endif
     
-    g_string_append_len (collector->input, input, n_bytes);
-
-    parse_input (collector);
-    
-    if (collector->callback && collector->n_samples > 0)
-	collector->callback (first, collector->data);
 }
 
 static gboolean



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