diff --git a/sim_timer.c b/sim_timer.c index 7e662418..48d49884 100644 --- a/sim_timer.c +++ b/sim_timer.c @@ -553,6 +553,16 @@ return 0; } #endif +t_stat sim_os_process_cpu_times (double *system, double *user) +{ +t_uint64 ftCreation, ftExit, ftKernel, ftUser; + +GetProcessTimes (GetCurrentProcess(), (FILETIME *)&ftCreation, (FILETIME *)&ftExit, (FILETIME *)&ftKernel, (FILETIME *)&ftUser); +*system = (double)(ftKernel / 10000000) + (((double)(ftKernel % 10000000)) / 10000000.0); +*user = (double)(ftUser / 10000000) + (((double)(ftUser % 10000000)) / 10000000.0); +return SCPE_OK; +} + #else /* UNIX routines */ @@ -586,6 +596,22 @@ uint32 sim_os_ms_sleep_init (void) return _compute_minimum_sleep (); } +#include +#include + +t_stat sim_os_process_cpu_times (double *system, double *user) +{ +struct rusage usage; + +*system = 0.0; +*user = 0.0; +if (0 == getrusage (RUSAGE_SELF, &usage)) { + *system = ((double)usage.ru_stime.tv_sec) + ((double)usage.ru_stime.tv_usec / 1000000.0); + *user = ((double)usage.ru_utime.tv_sec) + ((double)usage.ru_utime.tv_usec / 1000000.0); + } +return SCPE_OK; +} + #if !defined(_POSIX_SOURCE) #ifdef NEED_CLOCK_GETTIME typedef int clockid_t; diff --git a/sim_timer.h b/sim_timer.h index 50eed93a..c2940024 100644 --- a/sim_timer.h +++ b/sim_timer.h @@ -159,6 +159,7 @@ uint32 sim_get_rom_delay_factor (void); void sim_set_rom_delay_factor (uint32 delay); int32 sim_rom_read_with_delay (int32 val); double sim_host_speed_factor (void); +t_stat sim_os_process_cpu_times (double *system, double *user); extern t_bool sim_idle_enab; /* idle enabled flag */ extern volatile t_bool sim_idle_wait; /* idle waiting flag */