* sim-utils.c (sim_add_commas): New function.
* sim-basics.h (sim_add_commas): Add prototype. * cgen-scache.c (scache_print_profile): Print commas in numbers. * sim-profile.c (COMMAS): New macro. (print_*): Use it to print commas in numbers.
This commit is contained in:
parent
3e324f89cd
commit
2317a49939
5 changed files with 137 additions and 33 deletions
|
@ -1,5 +1,11 @@
|
||||||
Thu May 1 10:40:47 1997 Doug Evans <dje@canuck.cygnus.com>
|
Thu May 1 10:40:47 1997 Doug Evans <dje@canuck.cygnus.com>
|
||||||
|
|
||||||
|
* sim-utils.c (sim_add_commas): New function.
|
||||||
|
* sim-basics.h (sim_add_commas): Add prototype.
|
||||||
|
* cgen-scache.c (scache_print_profile): Print commas in numbers.
|
||||||
|
* sim-profile.c (COMMAS): New macro.
|
||||||
|
(print_*): Use it to print commas in numbers.
|
||||||
|
|
||||||
* configure: Regenerated.
|
* configure: Regenerated.
|
||||||
|
|
||||||
* cgen-sim.h (sim_signal_type): Add SIM_SIGINT.
|
* cgen-sim.h (sim_signal_type): Add SIM_SIGINT.
|
||||||
|
|
|
@ -182,13 +182,17 @@ scache_print_profile (SIM_CPU *cpu, int verbose)
|
||||||
SIM_DESC sd = CPU_STATE (cpu);
|
SIM_DESC sd = CPU_STATE (cpu);
|
||||||
unsigned long hits = CPU_SCACHE_HITS (cpu);
|
unsigned long hits = CPU_SCACHE_HITS (cpu);
|
||||||
unsigned long misses = CPU_SCACHE_MISSES (cpu);
|
unsigned long misses = CPU_SCACHE_MISSES (cpu);
|
||||||
|
char buf[20];
|
||||||
|
|
||||||
sim_io_printf (sd, "Simulator Cache Statistics\n\n");
|
sim_io_printf (sd, "Simulator Cache Statistics\n\n");
|
||||||
|
|
||||||
/* One could use PROFILE_LABEL_WIDTH here. I chose not to. */
|
/* One could use PROFILE_LABEL_WIDTH here. I chose not to. */
|
||||||
sim_io_printf (sd, " Cache size: %d\n", CPU_SCACHE_SIZE (cpu));
|
sim_io_printf (sd, " Cache size: %d\n",
|
||||||
sim_io_printf (sd, " Hits: %d\n", hits);
|
sim_add_commas (buf, sizeof (buf), CPU_SCACHE_SIZE (cpu)));
|
||||||
sim_io_printf (sd, " Misses: %d\n", misses);
|
sim_io_printf (sd, " Hits: %s\n",
|
||||||
|
sim_add_commas (buf, sizeof (buf), hits));
|
||||||
|
sim_io_printf (sd, " Misses: %s\n",
|
||||||
|
sim_add_commas (buf, sizeof (buf), misses));
|
||||||
if (hits + misses != 0)
|
if (hits + misses != 0)
|
||||||
sim_io_printf (sd, " Hit rate: %.2f%%\n",
|
sim_io_printf (sd, " Hit rate: %.2f%%\n",
|
||||||
((double) hits / ((double) hits + (double) misses)) * 100);
|
((double) hits / ((double) hits + (double) misses)) * 100);
|
||||||
|
|
|
@ -64,6 +64,9 @@ void *zalloc (unsigned long size);
|
||||||
|
|
||||||
void zfree(void*);
|
void zfree(void*);
|
||||||
|
|
||||||
|
/* Turn VALUE into a string with commas. */
|
||||||
|
char *sim_add_commas (char *, int, unsigned long);
|
||||||
|
|
||||||
|
|
||||||
/* Utilities for elapsed time reporting. */
|
/* Utilities for elapsed time reporting. */
|
||||||
/* Opaque type, known only inside sim_elapsed_time_foo fns. */
|
/* Opaque type, known only inside sim_elapsed_time_foo fns. */
|
||||||
|
@ -114,8 +117,11 @@ typedef enum _attach_type {
|
||||||
|
|
||||||
#include "sim-config.h"
|
#include "sim-config.h"
|
||||||
|
|
||||||
#include "sim-base.h"
|
#include "sim-module.h"
|
||||||
#include "sim-trace.h"
|
#include "sim-trace.h"
|
||||||
|
#include "sim-profile.h"
|
||||||
|
#include "sim-model.h"
|
||||||
|
#include "sim-base.h"
|
||||||
|
|
||||||
#include "sim-inline.h"
|
#include "sim-inline.h"
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
#include "sim-io.h"
|
#include "sim-io.h"
|
||||||
#include "sim-options.h"
|
#include "sim-options.h"
|
||||||
|
|
||||||
|
#define COMMAS(n) sim_add_commas (comma_buf, sizeof (comma_buf), (n))
|
||||||
|
|
||||||
static MODULE_UNINSTALL_FN profile_uninstall;
|
static MODULE_UNINSTALL_FN profile_uninstall;
|
||||||
|
|
||||||
static void print_bar (SIM_DESC, unsigned int, unsigned int, unsigned int);
|
static void print_bar (SIM_DESC, unsigned int, unsigned int, unsigned int);
|
||||||
|
@ -158,6 +160,8 @@ profile_option_handler (SIM_DESC sd, int opt, char *arg)
|
||||||
|
|
||||||
return SIM_RC_OK;
|
return SIM_RC_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Install profiling support in the simulator. */
|
||||||
|
|
||||||
SIM_RC
|
SIM_RC
|
||||||
profile_install (SIM_DESC sd)
|
profile_install (SIM_DESC sd)
|
||||||
|
@ -184,6 +188,8 @@ profile_uninstall (SIM_DESC sd)
|
||||||
fclose (PROFILE_FILE (data));
|
fclose (PROFILE_FILE (data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Summary printing support. */
|
||||||
|
|
||||||
#if WITH_PROFILE_INSN_P
|
#if WITH_PROFILE_INSN_P
|
||||||
|
|
||||||
|
@ -193,6 +199,7 @@ profile_print_insn (sim_cpu *cpu, int verbose)
|
||||||
unsigned int i, n, total, max_val, max_name_len;
|
unsigned int i, n, total, max_val, max_name_len;
|
||||||
SIM_DESC sd = CPU_STATE (cpu);
|
SIM_DESC sd = CPU_STATE (cpu);
|
||||||
PROFILE_DATA *data = CPU_PROFILE_DATA (cpu);
|
PROFILE_DATA *data = CPU_PROFILE_DATA (cpu);
|
||||||
|
char comma_buf[20];
|
||||||
|
|
||||||
sim_io_printf (sd, "Instruction Statistics\n\n");
|
sim_io_printf (sd, "Instruction Statistics\n\n");
|
||||||
|
|
||||||
|
@ -208,7 +215,7 @@ profile_print_insn (sim_cpu *cpu, int verbose)
|
||||||
max_name_len = n;
|
max_name_len = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
sim_io_printf (sd, " Total: %d insns\n", total);
|
sim_io_printf (sd, " Total: %s insns\n", COMMAS (total));
|
||||||
|
|
||||||
if (verbose && max_val != 0)
|
if (verbose && max_val != 0)
|
||||||
{
|
{
|
||||||
|
@ -218,10 +225,10 @@ profile_print_insn (sim_cpu *cpu, int verbose)
|
||||||
{
|
{
|
||||||
if (PROFILE_INSN_COUNT (data) [i] != 0)
|
if (PROFILE_INSN_COUNT (data) [i] != 0)
|
||||||
{
|
{
|
||||||
sim_io_printf (sd, " %*s: %*d: ",
|
sim_io_printf (sd, " %*s: %*s: ",
|
||||||
max_name_len, INSN_NAME (i),
|
max_name_len, INSN_NAME (i),
|
||||||
max_val < 10000 ? 4 : 8,
|
max_val < 10000 ? 5 : 10,
|
||||||
PROFILE_INSN_COUNT (data) [i]);
|
COMMAS (PROFILE_INSN_COUNT (data) [i]));
|
||||||
print_bar (sd, PROFILE_HISTOGRAM_WIDTH,
|
print_bar (sd, PROFILE_HISTOGRAM_WIDTH,
|
||||||
PROFILE_INSN_COUNT (data) [i],
|
PROFILE_INSN_COUNT (data) [i],
|
||||||
max_val);
|
max_val);
|
||||||
|
@ -246,6 +253,7 @@ profile_print_memory (sim_cpu *cpu, int verbose)
|
||||||
/* FIXME: Need to add smp support. */
|
/* FIXME: Need to add smp support. */
|
||||||
SIM_DESC sd = CPU_STATE (cpu);
|
SIM_DESC sd = CPU_STATE (cpu);
|
||||||
PROFILE_DATA *data = CPU_PROFILE_DATA (cpu);
|
PROFILE_DATA *data = CPU_PROFILE_DATA (cpu);
|
||||||
|
char comma_buf[20];
|
||||||
|
|
||||||
sim_io_printf (sd, "Memory Access Statistics\n\n");
|
sim_io_printf (sd, "Memory Access Statistics\n\n");
|
||||||
|
|
||||||
|
@ -265,8 +273,10 @@ profile_print_memory (sim_cpu *cpu, int verbose)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* One could use PROFILE_LABEL_WIDTH here. I chose not to. */
|
/* One could use PROFILE_LABEL_WIDTH here. I chose not to. */
|
||||||
sim_io_printf (sd, " Total read: %d accesses\n", total_read);
|
sim_io_printf (sd, " Total read: %s accesses\n",
|
||||||
sim_io_printf (sd, " Total write: %d accesses\n", total_write);
|
COMMAS (total_read));
|
||||||
|
sim_io_printf (sd, " Total write: %s accesses\n",
|
||||||
|
COMMAS (total_write));
|
||||||
|
|
||||||
if (verbose && max_val != 0)
|
if (verbose && max_val != 0)
|
||||||
{
|
{
|
||||||
|
@ -278,10 +288,10 @@ profile_print_memory (sim_cpu *cpu, int verbose)
|
||||||
{
|
{
|
||||||
if (PROFILE_READ_COUNT (data) [i] != 0)
|
if (PROFILE_READ_COUNT (data) [i] != 0)
|
||||||
{
|
{
|
||||||
sim_io_printf (sd, " %*s read: %*d: ",
|
sim_io_printf (sd, " %*s read: %*s: ",
|
||||||
max_name_len, MODE_NAME (i),
|
max_name_len, MODE_NAME (i),
|
||||||
max_val < 10000 ? 4 : 8,
|
max_val < 10000 ? 5 : 10,
|
||||||
PROFILE_READ_COUNT (data) [i]);
|
COMMAS (PROFILE_READ_COUNT (data) [i]));
|
||||||
print_bar (sd, PROFILE_HISTOGRAM_WIDTH,
|
print_bar (sd, PROFILE_HISTOGRAM_WIDTH,
|
||||||
PROFILE_READ_COUNT (data) [i],
|
PROFILE_READ_COUNT (data) [i],
|
||||||
max_val);
|
max_val);
|
||||||
|
@ -289,10 +299,10 @@ profile_print_memory (sim_cpu *cpu, int verbose)
|
||||||
}
|
}
|
||||||
if (PROFILE_WRITE_COUNT (data) [i] != 0)
|
if (PROFILE_WRITE_COUNT (data) [i] != 0)
|
||||||
{
|
{
|
||||||
sim_io_printf (sd, " %*s write: %*d: ",
|
sim_io_printf (sd, " %*s write: %*s: ",
|
||||||
max_name_len, MODE_NAME (i),
|
max_name_len, MODE_NAME (i),
|
||||||
max_val < 10000 ? 4 : 8,
|
max_val < 10000 ? 5 : 10,
|
||||||
PROFILE_WRITE_COUNT (data) [i]);
|
COMMAS (PROFILE_WRITE_COUNT (data) [i]));
|
||||||
print_bar (sd, PROFILE_HISTOGRAM_WIDTH,
|
print_bar (sd, PROFILE_HISTOGRAM_WIDTH,
|
||||||
PROFILE_WRITE_COUNT (data) [i],
|
PROFILE_WRITE_COUNT (data) [i],
|
||||||
max_val);
|
max_val);
|
||||||
|
@ -317,24 +327,25 @@ profile_print_model (sim_cpu *cpu, int verbose)
|
||||||
unsigned long load_stalls = PROFILE_MODEL_LOAD_STALL_COUNT (data);
|
unsigned long load_stalls = PROFILE_MODEL_LOAD_STALL_COUNT (data);
|
||||||
unsigned long total = PROFILE_MODEL_CYCLE_COUNT (data)
|
unsigned long total = PROFILE_MODEL_CYCLE_COUNT (data)
|
||||||
+ cti_stalls + load_stalls;
|
+ cti_stalls + load_stalls;
|
||||||
|
char comma_buf[20];
|
||||||
|
|
||||||
sim_io_printf (sd, "Model %s Timing Information\n\n",
|
sim_io_printf (sd, "Model %s Timing Information\n\n",
|
||||||
MODEL_NAME (STATE_MODEL (sd)));
|
MODEL_NAME (STATE_MODEL (sd)));
|
||||||
sim_io_printf (sd, " %-*s %ld\n",
|
sim_io_printf (sd, " %-*s %s\n",
|
||||||
PROFILE_LABEL_WIDTH, "Taken branches:",
|
PROFILE_LABEL_WIDTH, "Taken branches:",
|
||||||
PROFILE_MODEL_TAKEN_COUNT (data));
|
COMMAS (PROFILE_MODEL_TAKEN_COUNT (data)));
|
||||||
sim_io_printf (sd, " %-*s %ld\n",
|
sim_io_printf (sd, " %-*s %s\n",
|
||||||
PROFILE_LABEL_WIDTH, "Untaken branches:",
|
PROFILE_LABEL_WIDTH, "Untaken branches:",
|
||||||
PROFILE_MODEL_UNTAKEN_COUNT (data));
|
COMMAS (PROFILE_MODEL_UNTAKEN_COUNT (data)));
|
||||||
sim_io_printf (sd, " %-*s %ld\n",
|
sim_io_printf (sd, " %-*s %s\n",
|
||||||
PROFILE_LABEL_WIDTH, "Cycles stalled due to branches:",
|
PROFILE_LABEL_WIDTH, "Cycles stalled due to branches:",
|
||||||
cti_stalls);
|
COMMAS (cti_stalls));
|
||||||
sim_io_printf (sd, " %-*s %ld\n",
|
sim_io_printf (sd, " %-*s %s\n",
|
||||||
PROFILE_LABEL_WIDTH, "Cycles stalled due to loads:",
|
PROFILE_LABEL_WIDTH, "Cycles stalled due to loads:",
|
||||||
load_stalls);
|
COMMAS (load_stalls));
|
||||||
sim_io_printf (sd, " %-*s %ld\n",
|
sim_io_printf (sd, " %-*s %s\n",
|
||||||
PROFILE_LABEL_WIDTH, "Total cycles (*approximate*):",
|
PROFILE_LABEL_WIDTH, "Total cycles (*approximate*):",
|
||||||
total);
|
COMMAS (total));
|
||||||
sim_io_printf (sd, "\n");
|
sim_io_printf (sd, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,23 +372,30 @@ profile_print_speed (sim_cpu *cpu)
|
||||||
PROFILE_DATA *data = CPU_PROFILE_DATA (cpu);
|
PROFILE_DATA *data = CPU_PROFILE_DATA (cpu);
|
||||||
unsigned long milliseconds = PROFILE_EXEC_TIME (data);
|
unsigned long milliseconds = PROFILE_EXEC_TIME (data);
|
||||||
unsigned long total = PROFILE_TOTAL_INSN_COUNT (data);
|
unsigned long total = PROFILE_TOTAL_INSN_COUNT (data);
|
||||||
|
char comma_buf[20];
|
||||||
|
|
||||||
sim_io_printf (sd, "Simulator Execution Speed\n\n");
|
sim_io_printf (sd, "Simulator Execution Speed\n\n");
|
||||||
|
|
||||||
if (total != 0)
|
if (total != 0)
|
||||||
sim_io_printf (sd, " Total instructions: %ld\n", total);
|
sim_io_printf (sd, " Total instructions: %s\n", COMMAS (total));
|
||||||
|
|
||||||
if (milliseconds < 1000)
|
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
|
else
|
||||||
{
|
{
|
||||||
sim_io_printf (sd, " Total Execution Time: %.2f seconds\n",
|
/* The printing of the time rounded to 2 decimal places makes the speed
|
||||||
(double) milliseconds / 1000);
|
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) (unsigned long) (secs * 100 + .5)) / 100;
|
||||||
|
sim_io_printf (sd, " Total Execution Time: %.2f seconds\n", secs);
|
||||||
/* Don't confuse things with data that isn't useful.
|
/* Don't confuse things with data that isn't useful.
|
||||||
If we ran for less than two seconds, only use the data if we
|
If we ran for less than 2 seconds, only use the data if we
|
||||||
executed more than 100,000 insns. */
|
executed more than 100,000 insns. */
|
||||||
if (milliseconds >= 2000 || total >= 100000)
|
if (secs >= 2 || total >= 100000)
|
||||||
sim_io_printf (sd, " Simulator Speed: %.0f insns/second\n\n",
|
sim_io_printf (sd, " Simulator Speed: %s insns/second\n\n",
|
||||||
(double) total / ((double) milliseconds / 1000));
|
COMMAS ((unsigned long) ((double) total / secs)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
#ifdef HAVE_STDLIB_H
|
#ifdef HAVE_STDLIB_H
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_TIME_H
|
||||||
|
#include <time.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_SYS_TIME_H
|
||||||
|
#include <sys/time.h> /* needed by sys/resource.h */
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_SYS_RESOURCE_H
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#endif
|
||||||
#include "libiberty.h"
|
#include "libiberty.h"
|
||||||
#include "bfd.h"
|
#include "bfd.h"
|
||||||
|
|
||||||
|
@ -65,6 +74,28 @@ sim_state_free (SIM_DESC sd)
|
||||||
zfree (sd);
|
zfree (sd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Turn VALUE into a string with commas. */
|
||||||
|
|
||||||
|
char *
|
||||||
|
sim_add_commas (char *buf, int sizeof_buf, unsigned long value)
|
||||||
|
{
|
||||||
|
int comma = 3;
|
||||||
|
char *endbuf = buf + sizeof_buf - 1;
|
||||||
|
|
||||||
|
*--endbuf = '\0';
|
||||||
|
do {
|
||||||
|
if (comma-- == 0)
|
||||||
|
{
|
||||||
|
*--endbuf = ',';
|
||||||
|
comma = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
*--endbuf = (value % 10) + '0';
|
||||||
|
} while ((value /= 10) != 0);
|
||||||
|
|
||||||
|
return endbuf;
|
||||||
|
}
|
||||||
|
|
||||||
/* Make a copy of ARGV.
|
/* Make a copy of ARGV.
|
||||||
This can also be used to copy the environment vector.
|
This can also be used to copy the environment vector.
|
||||||
The result is a pointer to the malloc'd copy or NULL if insufficient
|
The result is a pointer to the malloc'd copy or NULL if insufficient
|
||||||
|
@ -121,3 +152,42 @@ sim_analyze_program (sd, prog_bfd)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Simulator timing support. */
|
||||||
|
|
||||||
|
/* Called before sim_elapsed_time_since to get a reference point. */
|
||||||
|
|
||||||
|
SIM_ELAPSED_TIME
|
||||||
|
sim_elapsed_time_get ()
|
||||||
|
{
|
||||||
|
#ifdef HAVE_GETRUSAGE
|
||||||
|
struct rusage mytime;
|
||||||
|
if (getrusage (RUSAGE_SELF, &mytime) == 0)
|
||||||
|
return (SIM_ELAPSED_TIME) (((double) mytime.ru_utime.tv_sec * 1000) + (((double) mytime.ru_utime.tv_usec + 500) / 1000));
|
||||||
|
return 0;
|
||||||
|
#else
|
||||||
|
#ifdef HAVE_TIME
|
||||||
|
return (SIM_ELAPSED_TIME) time ((time_t) 0);
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return the elapsed time in milliseconds since START.
|
||||||
|
The actual time may be cpu usage (prefered) or wall clock. */
|
||||||
|
|
||||||
|
unsigned long
|
||||||
|
sim_elapsed_time_since (start)
|
||||||
|
SIM_ELAPSED_TIME start;
|
||||||
|
{
|
||||||
|
#ifdef HAVE_GETRUSAGE
|
||||||
|
return sim_elapsed_time_get () - start;
|
||||||
|
#else
|
||||||
|
#ifdef HAVE_TIME
|
||||||
|
return (sim_elapsed_time_get () - start) * 1000;
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue