[sysprof/ftrace: 14/16] More formatting



commit ca8fbf4cfa51b683113dc0bbf31275476add8cba
Author: Søren Sandmann Pedersen <sandmann daimi au dk>
Date:   Fri Aug 14 02:39:31 2009 -0400

    More formatting

 collector.c |  100 +++++++++++++++++++++++++++-------------------------------
 1 files changed, 47 insertions(+), 53 deletions(-)
---
diff --git a/collector.c b/collector.c
index 8405121..cecb2cf 100644
--- a/collector.c
+++ b/collector.c
@@ -1,6 +1,7 @@
 /* Sysprof -- Sampling, systemwide CPU profiler
  * Copyright 2004, Red Hat, Inc.
- * Copyright 2004, 2005, Soeren Sandmann
+ * Copyright 2004, 2005, 2009, Soeren Sandmann
+ * Copyright 2009, Red Hat, Inc.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -103,22 +104,6 @@ collector_new (CollectorFunc callback,
     return collector;
 }
 
-static double
-timeval_to_ms (const GTimeVal *timeval)
-{
-    return (timeval->tv_sec * G_USEC_PER_SEC + timeval->tv_usec) / 1000.0;
-}
-
-static double
-time_diff (const GTimeVal *first,
-	   const GTimeVal *second)
-{
-    double first_ms = timeval_to_ms (first);
-    double second_ms = timeval_to_ms (second);
-    
-    return first_ms - second_ms;
-}
-
 #define RESET_DEAD_PERIOD 250
 
 static void
@@ -194,6 +179,22 @@ add_trace_to_stash (const CPUInfo *info,
 	g_free (addrs);
 }
 
+static double
+timeval_to_ms (const GTimeVal *timeval)
+{
+    return (timeval->tv_sec * G_USEC_PER_SEC + timeval->tv_usec) / 1000.0;
+}
+
+static double
+time_diff (const GTimeVal *first,
+	   const GTimeVal *second)
+{
+    double first_ms = timeval_to_ms (first);
+    double second_ms = timeval_to_ms (second);
+    
+    return first_ms - second_ms;
+}
+
 static gboolean
 in_dead_period (Collector *collector)
 {
@@ -239,10 +240,7 @@ void
 collector_set_tracing (Collector *collector,
 		       gboolean	  trace)
 {
-    if (trace)
-	write_text ("/sys/kernel/debug/tracing/tracing_enabled", "1\n", NULL);
-    else
-	write_text ("/sys/kernel/debug/tracing/tracing_enabled", "0\n", NULL);
+    write_text (SYSPROF_DIR "tracing_enabled", trace? "1\n" : "0\n", NULL);
 }
 
 typedef struct Entry
@@ -301,7 +299,15 @@ process_entry (Collector *collector, Entry *entry)
 	
 	g_assert (FALSE);
     }
-	
+
+    if (entry->type == BEGIN_TRACE)
+	info = find_cpu_info (collector, -1);
+    else
+	info = find_cpu_info (collector, entry->pid);
+
+    if (!info)
+	return;
+    
     /* There can be up to N_CPU stacktraces in progress at the same
      * time, but processes can move between CPU's in the middle of
      * the stack-tracing, so we can't have CPU specific states.
@@ -312,47 +318,35 @@ process_entry (Collector *collector, Entry *entry)
     switch (entry->type)
     {
     case BEGIN_TRACE:
-	if ((info = find_cpu_info (collector, -1)))
-	{
-	    info->pid = entry->pid;
-	    info->truncated = FALSE;
-	    info->user_pos = 0;
-	    info->kernel_pos = 0;
-	}
+	info->pid = entry->pid;
+	info->truncated = FALSE;
+	info->user_pos = 0;
+	info->kernel_pos = 0;
 	break;
 	
     case KERNEL_ADDRESS:
-	if ((info = find_cpu_info (collector, entry->pid)))
-	{
-	    if (info->kernel_pos < SYSPROF_MAX_ADDRESSES)
-		info->kernel_stack[info->kernel_pos++] = (void *)entry->address;
-	    else
-		info->truncated = TRUE;
-	}
+	if (info->kernel_pos < SYSPROF_MAX_ADDRESSES)
+	    info->kernel_stack[info->kernel_pos++] = (void *)entry->address;
+	else
+	    info->truncated = TRUE;
 	break;
 	
     case USER_ADDRESS:
-	if ((info = find_cpu_info (collector, entry->pid)))
-	{
-	    if (info->user_pos < SYSPROF_MAX_ADDRESSES)
-		info->addresses[info->user_pos++] = (void *)entry->address;
-	    else
-		info->truncated = TRUE;	    
-	}
+	if (info->user_pos < SYSPROF_MAX_ADDRESSES)
+	    info->addresses[info->user_pos++] = (void *)entry->address;
+	else
+	    info->truncated = TRUE;	    
 	break;
 	
     case END_TRACE:
-	if ((info = find_cpu_info (collector, entry->pid)))
-	{
-	    info->n_kernel_words = info->kernel_pos;
-	    info->n_addresses = info->user_pos;
-
-	    add_trace_to_stash (info, collector->stash);
+	info->n_kernel_words = info->kernel_pos;
+	info->n_addresses = info->user_pos;
 	
-	    collector->n_samples++;
-
-	    info->pid = -1;
-	}
+	add_trace_to_stash (info, collector->stash);
+	
+	collector->n_samples++;
+	
+	info->pid = -1;
 	break;
 
     default:



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