This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GDB / SIM 7.3.1 Cosmetic patch for profile title


> As a side note, it took me a while to understand some of the logic.
> It looks like `print_title_p' really means `we-have-some-profile-data'.
> 
> So, if it was me, [...]

In fact, here is what I meant. If someone can test it and confirm
that I didn't screw something up, we could commit that. I think
it's a lot clearer this way, no?

-- 
Joel
commit 0e2091a0b6727c5ffb874df6c19bb08d7654f8d8
Author: Joel Brobecker <brobecker@adacore.com>
Date:   Tue Oct 18 18:01:04 2011 -0700

    [sim] minor cleanup of sim-profile.c:profile_info
    
    Re-arange the code a little bit to make it clearer what the intent
    of each piece is.
    
    sim/common/ChangeLog:
    
            * sim-profile.c (sim_desc_has_profile_data): New function,
            mostly extracted out of profile_info.
            (profile_info): Rename `print_title_p' into
            `profile_data_collected_p'. Replace extracted-out code by
            call to sim_desc_has_profile_data.

diff --git a/sim/common/sim-profile.c b/sim/common/sim-profile.c
index 83e964d..3221ecf 100644
--- a/sim/common/sim-profile.c
+++ b/sim/common/sim-profile.c
@@ -1109,6 +1109,32 @@ profile_print_addr_ranges (sim_cpu *cpu)
 }
 #endif
 
+/* Return nonzero if some profile data has been collected, zero
+   otherwise.  */
+
+static int
+sim_desc_has_profile_data (SIM_DESC sd)
+{
+  int i, c;
+
+  /* FIXME: If the number of processors can be selected on the command line,
+     then MAX_NR_PROCESSORS will need to take an argument of `sd'.  */
+
+  for (c = 0; c < MAX_NR_PROCESSORS; ++c)
+    {
+      sim_cpu *cpu = STATE_CPU (sd, c);
+      PROFILE_DATA *data = CPU_PROFILE_DATA (cpu);
+
+      for (i = 0; i < MAX_PROFILE_VALUES; ++i)
+	if (PROFILE_FLAGS (data) [i])
+	  return 1;
+    }
+
+  /* No profile data found.  Return zero.  */
+  return 0;
+
+}
+
 /* Top level function to print all summary profile information.
    It is [currently] intended that all such data is printed by this function.
    I'd rather keep it all in one place for now.  To that end, MISC_CPU and
@@ -1124,27 +1150,14 @@ profile_print_addr_ranges (sim_cpu *cpu)
 static void
 profile_info (SIM_DESC sd, int verbose)
 {
-  int i,c;
-  int print_title_p = 0;
+  int c;
+  const int profile_data_collected_p = sim_desc_has_profile_data (sd);
 
-  /* Only print the title if some data has been collected.  */
   /* ??? Why don't we just exit if no data collected?  */
-  /* FIXME: If the number of processors can be selected on the command line,
-     then MAX_NR_PROCESSORS will need to take an argument of `sd'.  */
-
-  for (c = 0; c < MAX_NR_PROCESSORS && !print_title_p; ++c)
-    {
-      sim_cpu *cpu = STATE_CPU (sd, c);
-      PROFILE_DATA *data = CPU_PROFILE_DATA (cpu);
 
-      for (i = 0; i < MAX_PROFILE_VALUES; ++i)
-	if (PROFILE_FLAGS (data) [i])
-	  {
-	    profile_printf (sd, cpu, "Summary profiling results:\n\n");
-	    print_title_p = 1;
-	    break;
-	  }
-    }
+  /* Only print the title if some data has been collected.  */
+  if (profile_data_collected_p)
+    profile_printf (sd, cpu, "Summary profiling results:\n\n");
 
   /* Loop, cpu by cpu, printing results.  */
 
@@ -1179,7 +1192,7 @@ profile_info (SIM_DESC sd, int verbose)
 	}
 
 #ifdef SIM_HAVE_ADDR_RANGE
-      if (print_title_p
+      if (profile_data_collected_p
 	  && (PROFILE_INSN_P (cpu)
 	      || PROFILE_MODEL_P (cpu)))
 	profile_print_addr_ranges (cpu);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]