mirror of
https://github.com/simh/simh.git
synced 2026-02-26 16:54:22 +00:00
TIMER: Provide API to determine host OS Process CPU times
This commit is contained in:
26
sim_timer.c
26
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 <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
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;
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user