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/common/sim-utils.c | |
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/common/sim-utils.c')
-rw-r--r-- | sim/common/sim-utils.c | 70 |
1 files changed, 70 insertions, 0 deletions
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 +} |