import gdb-1999-12-21 snapshot
[deliverable/binutils-gdb.git] / sim / common / sim-profile.c
index 5a9805ba5dd1898c3b2f10728cdb73611085057a..9129a38a147d34ee65efc70b8f56b0fcf5459e1a 100644 (file)
@@ -56,28 +56,28 @@ enum {
 };
 
 static const OPTION profile_options[] = {
-  { {"profile", no_argument, NULL, 'p'},
-      'p', NULL, "Perform profiling",
+  { {"profile", optional_argument, NULL, 'p'},
+      'p', "on|off", "Perform profiling",
       profile_option_handler },
-  { {"profile-insn", no_argument, NULL, OPTION_PROFILE_INSN},
-      '\0', NULL, "Perform instruction profiling",
+  { {"profile-insn", optional_argument, NULL, OPTION_PROFILE_INSN},
+      '\0', "on|off", "Perform instruction profiling",
       profile_option_handler },
-  { {"profile-memory", no_argument, NULL, OPTION_PROFILE_MEMORY},
-      '\0', NULL, "Perform memory profiling",
+  { {"profile-memory", optional_argument, NULL, OPTION_PROFILE_MEMORY},
+      '\0', "on|off", "Perform memory profiling",
       profile_option_handler },
-  { {"profile-core", no_argument, NULL, OPTION_PROFILE_CORE},
-      '\0', NULL, "Perform CORE profiling",
+  { {"profile-core", optional_argument, NULL, OPTION_PROFILE_CORE},
+      '\0', "on|off", "Perform CORE profiling",
       profile_option_handler },
-  { {"profile-model", no_argument, NULL, OPTION_PROFILE_MODEL},
-      '\0', NULL, "Perform model profiling",
+  { {"profile-model", optional_argument, NULL, OPTION_PROFILE_MODEL},
+      '\0', "on|off", "Perform model profiling",
       profile_option_handler },
 
   { {"profile-file", required_argument, NULL, OPTION_PROFILE_FILE},
       '\0', "FILE NAME", "Specify profile output file",
       profile_option_handler },
 
-  { {"profile-pc", no_argument, NULL, OPTION_PROFILE_PC},
-      '\0', NULL, "Perform PC profiling",
+  { {"profile-pc", optional_argument, NULL, OPTION_PROFILE_PC},
+      '\0', "on|off", "Perform PC profiling",
       profile_option_handler },
   { {"profile-pc-frequency", required_argument, NULL, 'F'},
       'F', "PC PROFILE FREQUENCY", "Specified PC profiling frequency",
@@ -106,6 +106,88 @@ static const OPTION profile_options[] = {
   { {NULL, no_argument, NULL, 0}, '\0', NULL, NULL, NULL }
 };
 
+/* Set/reset the profile options indicated in MASK.  */
+
+SIM_RC
+set_profile_option_mask (SIM_DESC sd, const char *name, int mask, const char *arg)
+{
+  int profile_nr;
+  int cpu_nr;
+  int profile_val = 1;
+
+  if (arg != NULL)
+    {
+      if (strcmp (arg, "yes") == 0
+         || strcmp (arg, "on") == 0
+         || strcmp (arg, "1") == 0)
+       profile_val = 1;
+      else if (strcmp (arg, "no") == 0
+              || strcmp (arg, "off") == 0
+              || strcmp (arg, "0") == 0)
+       profile_val = 0;
+      else
+       {
+         sim_io_eprintf (sd, "Argument `%s' for `--profile%s' invalid, one of `on', `off', `yes', `no' expected\n", arg, name);
+         return SIM_RC_FAIL;
+       }
+    }
+
+  /* update applicable profile bits */
+  for (profile_nr = 0; profile_nr < MAX_PROFILE_VALUES; ++profile_nr)
+    {
+      if ((mask & (1 << profile_nr)) == 0)
+       continue;
+
+#if 0 /* see sim-trace.c, set flags in STATE here if/when there are any */
+      /* Set non-cpu specific values.  */
+      switch (profile_nr)
+       {
+       case ??? :
+         break;
+       }
+#endif
+
+      /* Set cpu values.  */
+      for (cpu_nr = 0; cpu_nr < MAX_NR_PROCESSORS; cpu_nr++)
+       {
+         CPU_PROFILE_FLAGS (STATE_CPU (sd, cpu_nr))[profile_nr] = profile_val;
+       }
+    }
+
+  /* Re-compute the cpu profile summary.  */
+  if (profile_val)
+    {
+      for (cpu_nr = 0; cpu_nr < MAX_NR_PROCESSORS; cpu_nr++)
+       CPU_PROFILE_DATA (STATE_CPU (sd, cpu_nr))->profile_any_p = 1;
+    }
+  else
+    {
+      for (cpu_nr = 0; cpu_nr < MAX_NR_PROCESSORS; cpu_nr++)
+       {
+         CPU_PROFILE_DATA (STATE_CPU (sd, cpu_nr))->profile_any_p = 0;
+         for (profile_nr = 0; profile_nr < MAX_PROFILE_VALUES; ++profile_nr)
+           {
+             if (CPU_PROFILE_FLAGS (STATE_CPU (sd, cpu_nr))[profile_nr])
+               {
+                 CPU_PROFILE_DATA (STATE_CPU (sd, cpu_nr))->profile_any_p = 1;
+                 break;
+               }
+           }
+       }
+    }  
+
+  return SIM_RC_OK;
+}
+
+/* Set one profile option based on its IDX value.
+   Not static as cgen-scache.c uses it.  */
+
+SIM_RC
+sim_profile_set_option (SIM_DESC sd, const char *name, int idx, const char *arg)
+{
+  return set_profile_option_mask (sd, name, 1 << idx, arg);
+}
+
 static SIM_RC
 profile_option_handler (SIM_DESC sd,
                        sim_cpu *cpu,
@@ -121,49 +203,38 @@ profile_option_handler (SIM_DESC sd,
     {
     case 'p' :
       if (! WITH_PROFILE)
-       sim_io_eprintf (sd, "Profiling not compiled in, -p option ignored\n");
+       sim_io_eprintf (sd, "Profiling not compiled in, `-p' ignored\n");
       else
-       {
-         for (cpu_nr = 0; cpu_nr < MAX_NR_PROCESSORS; ++cpu_nr)
-           for (prof_nr = 0; prof_nr < MAX_PROFILE_VALUES; ++prof_nr)
-             CPU_PROFILE_FLAGS (STATE_CPU (sd, cpu_nr))[prof_nr] = 1;
-       }
+       return set_profile_option_mask (sd, "profile", PROFILE_USEFUL_MASK,
+                                       arg);
       break;
 
     case OPTION_PROFILE_INSN :
-#if WITH_PROFILE_INSN_P
-      for (cpu_nr = 0; cpu_nr < MAX_NR_PROCESSORS; ++cpu_nr)
-       CPU_PROFILE_FLAGS (STATE_CPU (sd, cpu_nr))[PROFILE_INSN_IDX] = 1;
-#else
-      sim_io_eprintf (sd, "Instruction profiling not compiled in, `--profile-insn' ignored\n");
-#endif
+      if (WITH_PROFILE_INSN_P)
+       return sim_profile_set_option (sd, "-insn", PROFILE_INSN_IDX, arg);
+      else
+       sim_io_eprintf (sd, "Instruction profiling not compiled in, `--profile-insn' ignored\n");
       break;
 
     case OPTION_PROFILE_MEMORY :
-#if WITH_PROFILE_MEMORY_P
-      for (cpu_nr = 0; cpu_nr < MAX_NR_PROCESSORS; ++cpu_nr)
-       CPU_PROFILE_FLAGS (STATE_CPU (sd, cpu_nr))[PROFILE_MEMORY_IDX] = 1;
-#else
-      sim_io_eprintf (sd, "Memory profiling not compiled in, `--profile-memory' ignored\n");
-#endif
+      if (WITH_PROFILE_MEMORY_P)
+       return sim_profile_set_option (sd, "-memory", PROFILE_MEMORY_IDX, arg);
+      else
+       sim_io_eprintf (sd, "Memory profiling not compiled in, `--profile-memory' ignored\n");
       break;
 
     case OPTION_PROFILE_CORE :
-#if WITH_PROFILE_CORE_P
-      for (cpu_nr = 0; cpu_nr < MAX_NR_PROCESSORS; ++cpu_nr)
-       CPU_PROFILE_FLAGS (STATE_CPU (sd, cpu_nr))[PROFILE_CORE_IDX] = 1;
-#else
-      sim_io_eprintf (sd, "CORE profiling not compiled in, `--profile-core' ignored\n");
-#endif
+      if (WITH_PROFILE_CORE_P)
+       return sim_profile_set_option (sd, "-core", PROFILE_CORE_IDX, arg);
+      else
+       sim_io_eprintf (sd, "CORE profiling not compiled in, `--profile-core' ignored\n");
       break;
 
     case OPTION_PROFILE_MODEL :
-#if WITH_PROFILE_MODEL_P
-      for (cpu_nr = 0; cpu_nr < MAX_NR_PROCESSORS; ++cpu_nr)
-       CPU_PROFILE_FLAGS (STATE_CPU (sd, cpu_nr))[PROFILE_MODEL_IDX] = 1;
-#else
-      sim_io_eprintf (sd, "Model profiling not compiled in, `--profile-model' ignored\n");
-#endif
+      if (WITH_PROFILE_MODEL_P)
+       return sim_profile_set_option (sd, "-model", PROFILE_MODEL_IDX, arg);
+      else
+       sim_io_eprintf (sd, "Model profiling not compiled in, `--profile-model' ignored\n");
       break;
 
     case OPTION_PROFILE_FILE :
@@ -187,10 +258,7 @@ profile_option_handler (SIM_DESC sd,
 
     case OPTION_PROFILE_PC:
       if (WITH_PROFILE_PC_P)
-       {
-         for (cpu_nr = 0; cpu_nr < MAX_NR_PROCESSORS; ++cpu_nr)
-           CPU_PROFILE_FLAGS (STATE_CPU (sd, cpu_nr))[PROFILE_PC_IDX] = 1;
-       }
+       return sim_profile_set_option (sd, "-pc", PROFILE_PC_IDX, arg);
       else
        sim_io_eprintf (sd, "PC profiling not compiled in, `--profile-pc' ignored\n");
       break;
@@ -277,6 +345,7 @@ profile_option_handler (SIM_DESC sd,
        }
       else
        sim_io_eprintf (sd, "PC profiling not compiled in, `--profile-pc-range' ignored\n");
+      break;
 
 #ifdef SIM_HAVE_ADDR_RANGE
     case OPTION_PROFILE_RANGE :
@@ -315,20 +384,6 @@ profile_option_handler (SIM_DESC sd,
 #endif /* SIM_HAVE_ADDR_RANGE */
     }
 
-  /* Re-compute the cpu profile summary.  */
-  for (cpu_nr = 0; cpu_nr < MAX_NR_PROCESSORS; ++cpu_nr)
-    {
-      CPU_PROFILE_DATA (STATE_CPU (sd, cpu_nr))->profile_any_p = 0;
-      for (prof_nr = 0; prof_nr < MAX_PROFILE_VALUES; ++prof_nr)
-       {
-         if (CPU_PROFILE_FLAGS (STATE_CPU (sd, cpu_nr))[prof_nr])
-           {
-             CPU_PROFILE_DATA (STATE_CPU (sd, cpu_nr))->profile_any_p = 1;
-             break;
-           }
-       }
-    }
-
   return SIM_RC_OK;
 }
 \f
@@ -906,10 +961,10 @@ profile_print_addr_ranges (sim_cpu *cpu)
 
   if (asr)
     {
-      sim_io_printf (sd, "Selected address ranges:\n");
+      sim_io_printf (sd, "Selected address ranges\n\n");
       while (asr != NULL)
        {
-         sim_io_printf (sd, "0x%lx - 0x%lx\n",
+         sim_io_printf (sd, "  0x%lx - 0x%lx\n",
                         (long) asr->start, (long) asr->end);
          asr = asr->next;
        }
This page took 0.027748 seconds and 4 git commands to generate.