From 2ac342cfc59fb400ba6421b4f17028dc5ffcd00c Mon Sep 17 00:00:00 2001 From: Hong Chen Date: Thu, 29 Feb 2024 14:52:41 -0600 Subject: [PATCH] More rusage info added to the end of the run summary output enhancement (#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. --- include/trick/Executive.hh | 6 ++++ .../sim_services/Executive/Executive_init.cpp | 4 +++ .../Executive/Executive_shutdown.cpp | 35 ++++++++++++------- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/include/trick/Executive.hh b/include/trick/Executive.hh index a545253e..2be2d27e 100644 --- a/include/trick/Executive.hh +++ b/include/trick/Executive.hh @@ -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(--) */ diff --git a/trick_source/sim_services/Executive/Executive_init.cpp b/trick_source/sim_services/Executive/Executive_init.cpp index 88c61872..66ecd46a 100644 --- a/trick_source/sim_services/Executive/Executive_init.cpp +++ b/trick_source/sim_services/Executive/Executive_init.cpp @@ -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. */ diff --git a/trick_source/sim_services/Executive/Executive_shutdown.cpp b/trick_source/sim_services/Executive/Executive_shutdown.cpp index 9e431eb4..1ba3ff42 100644 --- a/trick_source/sim_services/Executive/Executive_shutdown.cpp +++ b/trick_source/sim_services/Executive/Executive_shutdown.cpp @@ -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. */ @@ -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++) {