/* Default profiling support.
- Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
+ Copyright (C) 1996, 1997, 1998, 2000, 2001, 2007, 2008, 2009, 2010
+ Free Software Foundation, Inc.
Contributed by Cygnus Support.
This file is part of GDB, the GNU debugger.
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
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License along
-with this program; if not, write to the Free Software Foundation, Inc.,
-59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "sim-main.h"
#include "sim-io.h"
#include <strings.h>
#endif
#endif
+#include <ctype.h>
#define COMMAS(n) sim_add_commas (comma_buf, sizeof (comma_buf), (n))
OPTION_PROFILE_MODEL,
OPTION_PROFILE_FILE,
OPTION_PROFILE_CORE,
+ OPTION_PROFILE_CPU_FREQUENCY,
OPTION_PROFILE_PC,
OPTION_PROFILE_PC_RANGE,
OPTION_PROFILE_PC_GRANULARITY,
{ {"profile-model", optional_argument, NULL, OPTION_PROFILE_MODEL},
'\0', "on|off", "Perform model profiling",
profile_option_handler },
+ { {"profile-cpu-frequency", required_argument, NULL,
+ OPTION_PROFILE_CPU_FREQUENCY},
+ '\0', "CPU FREQUENCY", "Specify the speed of the simulated cpu clock",
+ profile_option_handler },
{ {"profile-file", required_argument, NULL, OPTION_PROFILE_FILE},
'\0', "FILE NAME", "Specify profile output file",
return set_profile_option_mask (sd, name, 1 << idx, arg);
}
+static SIM_RC
+parse_frequency (SIM_DESC sd, const char *arg, unsigned long *freq)
+{
+ const char *ch;
+ /* First, parse a decimal number. */
+ *freq = 0;
+ ch = arg;
+ if (isdigit (*arg))
+ {
+ for (/**/; *ch != '\0'; ++ch)
+ {
+ if (! isdigit (*ch))
+ break;
+ *freq = *freq * 10 + (*ch - '0');
+ }
+
+ /* Accept KHz, MHz or Hz as a suffix. */
+ if (tolower (*ch) == 'm')
+ {
+ *freq *= 1000000;
+ ++ch;
+ }
+ else if (tolower (*ch) == 'k')
+ {
+ *freq *= 1000;
+ ++ch;
+ }
+
+ if (tolower (*ch) == 'h')
+ {
+ ++ch;
+ if (tolower (*ch) == 'z')
+ ++ch;
+ }
+ }
+
+ if (*ch != '\0')
+ {
+ sim_io_eprintf (sd, "Invalid argument for --profile-cpu-frequency: %s\n",
+ arg);
+ *freq = 0;
+ return SIM_RC_FAIL;
+ }
+
+ return SIM_RC_OK;
+}
+
static SIM_RC
profile_option_handler (SIM_DESC sd,
sim_cpu *cpu,
char *arg,
int is_command)
{
- int cpu_nr,prof_nr;
+ int cpu_nr;
/* FIXME: Need to handle `cpu' arg. */
sim_io_eprintf (sd, "Model profiling not compiled in, `--profile-model' ignored\n");
break;
+ case OPTION_PROFILE_CPU_FREQUENCY :
+ {
+ unsigned long val;
+ SIM_RC rc = parse_frequency (sd, arg, &val);
+ if (rc == SIM_RC_OK)
+ {
+ for (cpu_nr = 0; cpu_nr < MAX_NR_PROCESSORS; ++cpu_nr)
+ PROFILE_CPU_FREQ (CPU_PROFILE_DATA (STATE_CPU (sd,cpu_nr))) = val;
+ }
+ return rc;
+ }
+
case OPTION_PROFILE_FILE :
/* FIXME: Might want this to apply to pc profiling only,
or have two profile file options. */
int bucket_size;
/* fill in the frequency if not specified */
if (PROFILE_PC_FREQ (data) == 0)
- PROFILE_PC_FREQ (data) = 256;
+ PROFILE_PC_FREQ (data) = 257;
/* fill in the start/end if not specified */
if (PROFILE_PC_END (data) == 0)
{
+ PROFILE_PC_NR_BUCKETS (data) - 1)
/ PROFILE_PC_NR_BUCKETS (data));
PROFILE_PC_SHIFT (data) = 0;
- while (bucket_size < PROFILE_PC_BUCKET_SIZE (data))
+ while (bucket_size > PROFILE_PC_BUCKET_SIZE (data))
{
PROFILE_PC_SHIFT (data) += 1;
}
}
/* size of sample buffer (+ header) */
header[2] = PROFILE_PC_NR_BUCKETS (profile) * 2 + sizeof (header);
+
+ /* Header must be written out in target byte order. */
+ H2T (header[0]);
+ H2T (header[1]);
+ H2T (header[2]);
+
ok = fwrite (&header, sizeof (header), 1, pf);
for (loop = 0;
ok && (loop < PROFILE_PC_NR_BUCKETS (profile));
sample = 0xffff;
else
sample = PROFILE_PC_COUNT (profile) [loop];
+ H2T (sample);
ok = fwrite (&sample, sizeof (sample), 1, pf);
}
if (ok == 0)
PROFILE_DATA *data = CPU_PROFILE_DATA (cpu);
unsigned long milliseconds = sim_events_elapsed_time (sd);
unsigned long total = PROFILE_TOTAL_INSN_COUNT (data);
+ double clock;
+ double secs;
char comma_buf[20];
sim_io_printf (sd, "Simulator Execution Speed\n\n");
if (total != 0)
- sim_io_printf (sd, " Total instructions: %s\n", COMMAS (total));
+ sim_io_printf (sd, " Total instructions: %s\n", COMMAS (total));
if (milliseconds < 1000)
- sim_io_printf (sd, " Total execution time: < 1 second\n\n");
+ sim_io_printf (sd, " Total execution time: < 1 second\n\n");
else
{
/* The printing of the time rounded to 2 decimal places makes the speed
calculation seem incorrect [even though it is correct]. So round
MILLISECONDS first. This can marginally affect the result, but it's
better that the user not perceive there's a math error. */
- double secs = (double) milliseconds / 1000;
+ secs = (double) milliseconds / 1000;
secs = ((double) (unsigned long) (secs * 100 + .5)) / 100;
- sim_io_printf (sd, " Total execution time: %.2f seconds\n", secs);
+ sim_io_printf (sd, " Total execution time : %.2f seconds\n", secs);
/* Don't confuse things with data that isn't useful.
If we ran for less than 2 seconds, only use the data if we
executed more than 100,000 insns. */
if (secs >= 2 || total >= 100000)
- sim_io_printf (sd, " Simulator speed: %s insns/second\n\n",
+ sim_io_printf (sd, " Simulator speed: %s insns/second\n",
COMMAS ((unsigned long) ((double) total / secs)));
}
+
+ /* Print simulated execution time if the cpu frequency has been specified. */
+ clock = PROFILE_CPU_FREQ (data);
+ if (clock != 0)
+ {
+ if (clock >= 1000000)
+ sim_io_printf (sd, " Simulated cpu frequency: %.2f MHz\n",
+ clock / 1000000);
+ else
+ sim_io_printf (sd, " Simulated cpu frequency: %.2f Hz\n", clock);
+
+#if WITH_PROFILE_MODEL_P
+ if (PROFILE_FLAGS (data) [PROFILE_MODEL_IDX])
+ {
+ /* The printing of the time rounded to 2 decimal places makes the
+ speed calculation seem incorrect [even though it is correct].
+ So round SECS first. This can marginally affect the result,
+ but it's better that the user not perceive there's a math
+ error. */
+ secs = PROFILE_MODEL_TOTAL_CYCLES (data) / clock;
+ secs = ((double) (unsigned long) (secs * 100 + .5)) / 100;
+ sim_io_printf (sd, " Simulated execution time: %.2f seconds\n",
+ secs);
+ }
+#endif /* WITH_PROFILE_MODEL_P */
+ }
}
/* Print selected address ranges. */