Skip to content

Commit

Permalink
1592 send hs run stats improvement (#1604)
Browse files Browse the repository at this point in the history
* Added system CPU time and initialization system CPU time and added user wording for existing CPU time to distinguish it from system CPU time used for trick run summary.

* Updated the order of a couple of times of shutdown messages printed on screen and sim/cpu time ratio to both user and system cpu time.

* Minor change for lining up the shutdown message.
  • Loading branch information
hchen99 authored Oct 31, 2023
1 parent 763b52f commit 9076a3e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 deletions.
14 changes: 10 additions & 4 deletions include/trick/Executive.hh
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,17 @@ namespace Trick {
/** Next software frame time in integer tics.\n */
long long next_frame_check_tics ; /**< trick_units(--) */

/** Usage time at executive initialization.\n */
double cpu_init; /**< trick_io(**) trick_units(s) */
/** Usage time at executive initialization in user mode.\n */
double user_cpu_init; /**< trick_io(**) trick_units(s) */

/** CPU usage time at cyclic sim process startup.\n */
double cpu_start; /**< trick_io(**) trick_units(s) */
/** Usage time at executive initialization in kernal mode.\n */
double kernal_cpu_init; /**< trick_io(**) trick_units(s) */

/** CPU usage time at cyclic sim process startup in user mode.\n */
double user_cpu_start; /**< trick_io(**) trick_units(s) */

/** CPU usage time at cyclic sim process startup in kernal mode.\n */
double kernal_cpu_start; /**< trick_io(**) trick_units(s) */

/** Simulation control mode.\n */
SIM_MODE mode; /**< trick_io(*o) trick_units(--) */
Expand Down
7 changes: 5 additions & 2 deletions trick_source/sim_services/Executive/Executive_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ int Trick::Executive::init() {
/* Start the cpu usage meter */
struct rusage cpu_usage_buf ;
getrusage(RUSAGE_SELF, &cpu_usage_buf);
cpu_start = ((double) cpu_usage_buf.ru_utime.tv_sec) + ((double) cpu_usage_buf.ru_utime.tv_usec / 1000000.0);
user_cpu_start = ((double) cpu_usage_buf.ru_utime.tv_sec) + ((double) cpu_usage_buf.ru_utime.tv_usec / 1000000.0);

/* command line args */
process_sim_args();
Expand All @@ -55,7 +55,10 @@ int Trick::Executive::init() {
/* Record the cpu usage for initialization */
getrusage(RUSAGE_SELF, &cpu_usage_buf);
cpu_time = ((double) cpu_usage_buf.ru_utime.tv_sec) + ((double) cpu_usage_buf.ru_utime.tv_usec / 1000000.0);
cpu_init = cpu_time - cpu_start;
user_cpu_init = cpu_time - user_cpu_start;

cpu_time = ((double) cpu_usage_buf.ru_stime.tv_sec) + ((double) cpu_usage_buf.ru_stime.tv_usec / 1000000.0);
kernal_cpu_init = cpu_time - kernal_cpu_start;

initialization_complete = true ;

Expand Down
37 changes: 23 additions & 14 deletions trick_source/sim_services/Executive/Executive_shutdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int Trick::Executive::shutdown() {

double sim_elapsed_time;
double cpu_time;
double actual_cpu_time;
double user_cpu_time, kernal_cpu_time;
double sim_to_cpu;
unsigned int ii;
int process_id = 0 ;
Expand Down Expand Up @@ -92,11 +92,16 @@ int Trick::Executive::shutdown() {

/* Calculate simulation elapsed sim time and actual cpu time */
sim_elapsed_time = get_sim_time() - sim_start;
actual_cpu_time = cpu_time - cpu_start;
if (actual_cpu_time <= 1e-6) {
user_cpu_time = cpu_time - user_cpu_start;

/* */
cpu_time = ((double) cpu_usage_buf.ru_stime.tv_sec) + ((double) cpu_usage_buf.ru_stime.tv_usec / 1000000.0);
kernal_cpu_time = cpu_time - kernal_cpu_start;

if ((user_cpu_time + kernal_cpu_time) <= 1e-6) {
sim_to_cpu = 1e8;
} else {
sim_to_cpu = sim_elapsed_time / actual_cpu_time;
sim_to_cpu = sim_elapsed_time / (user_cpu_time + kernal_cpu_time);
}

/* Print a shutdown message. */
Expand All @@ -105,16 +110,20 @@ int Trick::Executive::shutdown() {
" PROCESS: %d\n"
" ROUTINE: %s\n"
" DIAGNOSTIC: %s\n\n"
" SIMULATION START TIME: %12.3f\n"
" SIMULATION STOP TIME: %12.3f\n"
" SIMULATION ELAPSED TIME: %12.3f\n"
" ACTUAL CPU TIME USED: %12.3f\n"
" SIMULATION / CPU TIME: %12.3f\n"
" INITIALIZATION CPU TIME: %12.3f\n"
" SIMULATION RAM USAGE: %12.3fMB\n"
" (External program RAM usage not included!)\n",
process_id, except_file.c_str(), except_message.c_str() ,
sim_start , get_sim_time() , sim_elapsed_time , actual_cpu_time , sim_to_cpu , cpu_init, sim_mem ) ;
" SIMULATION START TIME: %12.3f\n"
" SIMULATION STOP TIME: %12.3f\n"
" SIMULATION ELAPSED TIME: %12.3f\n"
" USER CPU TIME USED: %12.3f\n"
" SYSTEM CPU TIME USED: %12.3f\n"
" SIMULATION / CPU TIME: %12.3f\n"
" INITIALIZATION USER CPU TIME: %12.3f\n"
" INITIALIZATION SYSTEM CPU TIME: %12.3f\n"
" SIMULATION RAM USAGE: %12.3fMB\n"
" (External program RAM usage not included!)\n",
process_id, except_file.c_str(), except_message.c_str(),
sim_start, get_sim_time(), sim_elapsed_time,
user_cpu_time, kernal_cpu_time, sim_to_cpu,
user_cpu_init, kernal_cpu_init, sim_mem) ;

/* Kill all threads. */
for (ii = 1; ii < threads.size() ; ii++) {
Expand Down

0 comments on commit 9076a3e

Please sign in to comment.