diff options
author | David Edelsohn <dje.gcc@gmail.com> | 1997-05-02 00:32:05 +0000 |
---|---|---|
committer | David Edelsohn <dje.gcc@gmail.com> | 1997-05-02 00:32:05 +0000 |
commit | 2317a49939905f8aeb16b62ee6bd5e1f661f1357 (patch) | |
tree | df20e2ea7999f8c468bda6f24938ebc163f65007 /sim | |
parent | 3e324f89cd814b515a6de171197708c3c4dcac73 (diff) | |
download | gdb-2317a49939905f8aeb16b62ee6bd5e1f661f1357.zip gdb-2317a49939905f8aeb16b62ee6bd5e1f661f1357.tar.gz gdb-2317a49939905f8aeb16b62ee6bd5e1f661f1357.tar.bz2 |
* 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.
Diffstat (limited to 'sim')
-rw-r--r-- | sim/common/ChangeLog | 6 | ||||
-rw-r--r-- | sim/common/cgen-scache.c | 10 | ||||
-rw-r--r-- | sim/common/sim-basics.h | 8 | ||||
-rw-r--r-- | sim/common/sim-profile.c | 76 | ||||
-rw-r--r-- | sim/common/sim-utils.c | 70 |
5 files changed, 137 insertions, 33 deletions
diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog index ff5c131..925db91 100644 --- a/sim/common/ChangeLog +++ b/sim/common/ChangeLog @@ -1,5 +1,11 @@ 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. * cgen-sim.h (sim_signal_type): Add SIM_SIGINT. diff --git a/sim/common/cgen-scache.c b/sim/common/cgen-scache.c index 05ce399..e205c9b 100644 --- a/sim/common/cgen-scache.c +++ b/sim/common/cgen-scache.c @@ -182,13 +182,17 @@ scache_print_profile (SIM_CPU *cpu, int verbose) SIM_DESC sd = CPU_STATE (cpu); unsigned long hits = CPU_SCACHE_HITS (cpu); unsigned long misses = CPU_SCACHE_MISSES (cpu); + char buf[20]; sim_io_printf (sd, "Simulator Cache Statistics\n\n"); /* 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, " Hits: %d\n", hits); - sim_io_printf (sd, " Misses: %d\n", misses); + sim_io_printf (sd, " Cache size: %d\n", + sim_add_commas (buf, sizeof (buf), CPU_SCACHE_SIZE (cpu))); + 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) sim_io_printf (sd, " Hit rate: %.2f%%\n", ((double) hits / ((double) hits + (double) misses)) * 100); diff --git a/sim/common/sim-basics.h b/sim/common/sim-basics.h index 00f83a1..d33a0d5 100644 --- a/sim/common/sim-basics.h +++ b/sim/common/sim-basics.h @@ -64,6 +64,9 @@ void *zalloc (unsigned long size); void zfree(void*); +/* Turn VALUE into a string with commas. */ +char *sim_add_commas (char *, int, unsigned long); + /* Utilities for elapsed time reporting. */ /* Opaque type, known only inside sim_elapsed_time_foo fns. */ @@ -114,8 +117,11 @@ typedef enum _attach_type { #include "sim-config.h" -#include "sim-base.h" +#include "sim-module.h" #include "sim-trace.h" +#include "sim-profile.h" +#include "sim-model.h" +#include "sim-base.h" #include "sim-inline.h" diff --git a/sim/common/sim-profile.c b/sim/common/sim-profile.c index 7c164ad..f92c673 100644 --- a/sim/common/sim-profile.c +++ b/sim/common/sim-profile.c @@ -22,6 +22,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "sim-io.h" #include "sim-options.h" +#define COMMAS(n) sim_add_commas (comma_buf, sizeof (comma_buf), (n)) + static MODULE_UNINSTALL_FN profile_uninstall; 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; } + +/* Install profiling support in the simulator. */ SIM_RC profile_install (SIM_DESC sd) @@ -184,6 +188,8 @@ profile_uninstall (SIM_DESC sd) fclose (PROFILE_FILE (data)); } } + +/* Summary printing support. */ #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; SIM_DESC sd = CPU_STATE (cpu); PROFILE_DATA *data = CPU_PROFILE_DATA (cpu); + char comma_buf[20]; sim_io_printf (sd, "Instruction Statistics\n\n"); @@ -208,7 +215,7 @@ profile_print_insn (sim_cpu *cpu, int verbose) 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) { @@ -218,10 +225,10 @@ profile_print_insn (sim_cpu *cpu, int verbose) { 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_val < 10000 ? 4 : 8, - PROFILE_INSN_COUNT (data) [i]); + max_val < 10000 ? 5 : 10, + COMMAS (PROFILE_INSN_COUNT (data) [i])); print_bar (sd, PROFILE_HISTOGRAM_WIDTH, PROFILE_INSN_COUNT (data) [i], max_val); @@ -246,6 +253,7 @@ profile_print_memory (sim_cpu *cpu, int verbose) /* FIXME: Need to add smp support. */ SIM_DESC sd = CPU_STATE (cpu); PROFILE_DATA *data = CPU_PROFILE_DATA (cpu); + char comma_buf[20]; 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. */ - sim_io_printf (sd, " Total read: %d accesses\n", total_read); - sim_io_printf (sd, " Total write: %d accesses\n", total_write); + sim_io_printf (sd, " Total read: %s accesses\n", + COMMAS (total_read)); + sim_io_printf (sd, " Total write: %s accesses\n", + COMMAS (total_write)); if (verbose && max_val != 0) { @@ -278,10 +288,10 @@ profile_print_memory (sim_cpu *cpu, int verbose) { 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_val < 10000 ? 4 : 8, - PROFILE_READ_COUNT (data) [i]); + max_val < 10000 ? 5 : 10, + COMMAS (PROFILE_READ_COUNT (data) [i])); print_bar (sd, PROFILE_HISTOGRAM_WIDTH, PROFILE_READ_COUNT (data) [i], max_val); @@ -289,10 +299,10 @@ profile_print_memory (sim_cpu *cpu, int verbose) } 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_val < 10000 ? 4 : 8, - PROFILE_WRITE_COUNT (data) [i]); + max_val < 10000 ? 5 : 10, + COMMAS (PROFILE_WRITE_COUNT (data) [i])); print_bar (sd, PROFILE_HISTOGRAM_WIDTH, PROFILE_WRITE_COUNT (data) [i], 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 total = PROFILE_MODEL_CYCLE_COUNT (data) + cti_stalls + load_stalls; + char comma_buf[20]; sim_io_printf (sd, "Model %s Timing Information\n\n", 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_MODEL_TAKEN_COUNT (data)); - sim_io_printf (sd, " %-*s %ld\n", + COMMAS (PROFILE_MODEL_TAKEN_COUNT (data))); + sim_io_printf (sd, " %-*s %s\n", PROFILE_LABEL_WIDTH, "Untaken branches:", - PROFILE_MODEL_UNTAKEN_COUNT (data)); - sim_io_printf (sd, " %-*s %ld\n", + COMMAS (PROFILE_MODEL_UNTAKEN_COUNT (data))); + sim_io_printf (sd, " %-*s %s\n", PROFILE_LABEL_WIDTH, "Cycles stalled due to branches:", - cti_stalls); - sim_io_printf (sd, " %-*s %ld\n", + COMMAS (cti_stalls)); + sim_io_printf (sd, " %-*s %s\n", PROFILE_LABEL_WIDTH, "Cycles stalled due to loads:", - load_stalls); - sim_io_printf (sd, " %-*s %ld\n", + COMMAS (load_stalls)); + sim_io_printf (sd, " %-*s %s\n", PROFILE_LABEL_WIDTH, "Total cycles (*approximate*):", - total); + COMMAS (total)); sim_io_printf (sd, "\n"); } @@ -361,23 +372,30 @@ profile_print_speed (sim_cpu *cpu) PROFILE_DATA *data = CPU_PROFILE_DATA (cpu); unsigned long milliseconds = PROFILE_EXEC_TIME (data); unsigned long total = PROFILE_TOTAL_INSN_COUNT (data); + char comma_buf[20]; sim_io_printf (sd, "Simulator Execution Speed\n\n"); 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) sim_io_printf (sd, " Total Execution Time: < 1 second\n\n"); else { - sim_io_printf (sd, " Total Execution Time: %.2f seconds\n", - (double) milliseconds / 1000); + /* 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) (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. - 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. */ - if (milliseconds >= 2000 || total >= 100000) - sim_io_printf (sd, " Simulator Speed: %.0f insns/second\n\n", - (double) total / ((double) milliseconds / 1000)); + if (secs >= 2 || total >= 100000) + sim_io_printf (sd, " Simulator Speed: %s insns/second\n\n", + COMMAS ((unsigned long) ((double) total / secs))); } } diff --git a/sim/common/sim-utils.c b/sim/common/sim-utils.c index 29a059c..fbb61d4 100644 --- a/sim/common/sim-utils.c +++ b/sim/common/sim-utils.c @@ -23,6 +23,15 @@ with this program; if not, write to the Free Software Foundation, Inc., #ifdef HAVE_STDLIB_H #include <stdlib.h> #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 "bfd.h" @@ -65,6 +74,28 @@ sim_state_free (SIM_DESC 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. This can also be used to copy the environment vector. 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; } } + +/* 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 +} |