Skip to content

Commit

Permalink
More rusage info added to the end of the run summary output enhanceme…
Browse files Browse the repository at this point in the history
…nt (#1645)

* Added additional resource usage info for sim run.

* Fixed so voluntary context switches output uses corresponding ru_nvcsw instead of ru_nivcsw due to copy and paste error.

* Removed added resource usage data for page faults and block operations due to inconsistency on different OS.

* Updated to have voluntary and involuntary usage data for both initilization and run for sim shutdown run summary.
  • Loading branch information
hchen99 committed Feb 29, 2024
1 parent df5bdc3 commit 2ac342c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
6 changes: 6 additions & 0 deletions include/trick/Executive.hh
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ namespace Trick {
/** CPU usage time at cyclic sim process startup in kernal mode.\n */
double kernal_cpu_start; /**< trick_io(**) trick_units(s) */

/** Voluntary context switche usage at executive initialization.\n */
long v_context_switch_init; /**< trick_units(--) */

/** Involuntary context switche usage at executive initialization.\n */
long iv_context_switch_init; /**< trick_units(--) */

/** Simulation control mode.\n */
SIM_MODE mode; /**< trick_io(*o) trick_units(--) */

Expand Down
4 changes: 4 additions & 0 deletions trick_source/sim_services/Executive/Executive_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ int Trick::Executive::init() {
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;

/* Record both voluntary and involuntary context switches usage for initialization */
v_context_switch_init = cpu_usage_buf.ru_nvcsw;
iv_context_switch_init = cpu_usage_buf.ru_nivcsw;

initialization_complete = true ;

/* Print as much error information avaiable for all exception and exit. */
Expand Down
35 changes: 23 additions & 12 deletions trick_source/sim_services/Executive/Executive_shutdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ int Trick::Executive::shutdown() {
int process_id = 0 ;
struct rusage cpu_usage_buf ;
double sim_mem;

long v_context_switch_run, iv_context_switch_run;

SIM_MODE prev_mode = mode ;

/* Set mode to ExitMode. */
Expand Down Expand Up @@ -104,26 +105,36 @@ int Trick::Executive::shutdown() {
sim_to_cpu = sim_elapsed_time / (user_cpu_time + kernal_cpu_time);
}

/* Calculate voluntary and involuntary context switch usage during run */
v_context_switch_run = cpu_usage_buf.ru_nvcsw - v_context_switch_init ;
iv_context_switch_run = cpu_usage_buf.ru_nivcsw - iv_context_switch_init ;

/* Print a shutdown message. */
message_publish(MSG_NORMAL , "\n"
"SIMULATION TERMINATED IN\n"
" 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"
" 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",
" 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"
" VOLUNTARY CONTEXT SWITCHES (INIT): %12ld\n"
"INVOLUNTARY CONTEXT SWITCHES (INIT): %12ld\n"
" VOLUNTARY CONTEXT SWITCHES (RUN): %12ld\n"
" INVOLUNTARY CONTEXT SWITCHES (RUN): %12ld\n\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) ;
user_cpu_init, kernal_cpu_init, sim_mem,
v_context_switch_init, iv_context_switch_init,
v_context_switch_run, iv_context_switch_run) ;

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

0 comments on commit 2ac342c

Please sign in to comment.