move init_log_stream to Executive.hh, move Executive::process_sim_args from "default data" to Executive::init

This commit is contained in:
Scott Fennell 2019-06-18 10:34:56 -05:00
parent fadda55abf
commit 97941ac073
7 changed files with 36 additions and 39 deletions

View File

@ -7,6 +7,7 @@
#define EXECUTIVE_HH
#include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <vector>
@ -42,7 +43,6 @@ namespace Trick {
*/
class Executive : public Trick::Scheduler {
protected:
/** Attempts to attach a debugger in the event a signal shuts down the simulation.\n */
bool attach_debugger; /**< trick_units(--) */
@ -155,6 +155,10 @@ namespace Trick {
/** Next scheduled jobs call time.\n */
long long job_call_time_tics; /**< trick_units(--) */
/** stream to record elapsed time of default_data,
input_processor, and initialization queues \n */
std::ofstream init_log_stream; /**< trick_units(--) */
/** Queue to hold default data jobs.\n */
Trick::ScheduledJobQueue default_data_queue ; /**< trick_io(**) */
@ -832,27 +836,21 @@ namespace Trick {
/**
* Calls the default_data jobs.
* @param open file stream for a log to record the elapsed
* time of each job.
* @return 0 for no errors or throws exception otherwise.
*/
virtual int call_default_data(std::ofstream& init_log_stream) ;
virtual int call_default_data() ;
/**
* Calls the input_processor jobs.
* @param open file stream for a log to record the elapsed
* time of each job.
* @return 0 for no errors or throws exception otherwise.
*/
virtual int call_input_processor(std::ofstream& init_log_stream) ;
virtual int call_input_processor() ;
/**
* Calls the initialization jobs.
* @param open file stream for a log to record the elapsed
* time of each job.
* @return 0 for no errors or throws exception otherwise.
*/
virtual int call_initialization(std::ofstream& init_log_stream) ;
virtual int call_initialization() ;
/**
* This job copies the job information from the executive to a checkpointable form.
@ -1270,6 +1268,11 @@ namespace Trick {
@return always 0
*/
virtual int exec_terminate(const char *file_name, const char *error);
/* deleted functions */
/* SWIG doesn't like the Executive assignment operator because of ofstream init_log_stream */
Executive& operator=(const Executive&) = delete;
} ;

View File

@ -130,8 +130,6 @@ class SysSimObject : public Trick::SimObject {
SysSimObject() {
{TRK} P0 ("default_data") sched.process_sim_args() ;
{TRK} ("default_data") sched.get_freeze_job(name + ".sched") ;
{TRK} P65534 ("initialization") exec_collect_init() ;

View File

@ -1,7 +1,6 @@
#include <iostream>
#include <sys/resource.h>
#include<fstream>
#include "trick/Executive.hh"
#include "trick/ExecutiveException.hh"
@ -17,7 +16,7 @@
returned from Trick::Executive::init().
-# If no execption is thrown return 0
*/
int Trick::Executive::call_default_data(std::ofstream& init_log_stream) {
int Trick::Executive::call_default_data() {
int ret = 0 ;
@ -29,7 +28,7 @@ int Trick::Executive::call_default_data(std::ofstream& init_log_stream) {
long long start = clock_wall_time();
ret = curr_job->call() ;
long long end = clock_wall_time();
if(init_log_stream) {
if(init_log_stream.is_open()) {
init_log_stream << "default_data," << curr_job->name << ',' << (double)(end-start)/clock_tics_per_sec() << '\n';
}
if ( ret != 0 ) {

View File

@ -1,6 +1,5 @@
#include <iostream>
#include<fstream>
#include <sys/resource.h>
#include "trick/Executive.hh"
#include "trick/ExecutiveException.hh"
@ -14,7 +13,7 @@
returned from Trick::Executive::init().
-# If no execption is thrown return 0
*/
int Trick::Executive::call_initialization(std::ofstream& init_log_stream) {
int Trick::Executive::call_initialization() {
int ret = 0 ;
@ -26,7 +25,7 @@ int Trick::Executive::call_initialization(std::ofstream& init_log_stream) {
long long start = clock_wall_time();
ret = curr_job->call() ;
long long end = clock_wall_time();
if(init_log_stream) {
if(init_log_stream.is_open()) {
init_log_stream << "init," << curr_job->name << ',' << (double)(end-start)/clock_tics_per_sec() << '\n';
}
if ( ret != 0 ) {

View File

@ -1,7 +1,6 @@
#include <iostream>
#include <sys/resource.h>
#include<fstream>
#include "trick/Executive.hh"
#include "trick/ExecutiveException.hh"
@ -15,7 +14,7 @@
returned from Trick::Executive::init().
-# If no execption is thrown return 0
*/
int Trick::Executive::call_input_processor(std::ofstream& init_log_stream) {
int Trick::Executive::call_input_processor() {
int ret = 0 ;
@ -30,7 +29,7 @@ int Trick::Executive::call_input_processor(std::ofstream& init_log_stream) {
long long start = clock_wall_time();
ret = curr_job->call() ;
long long end = clock_wall_time();
if(init_log_stream) {
if(init_log_stream.is_open()) {
init_log_stream << "input_processor," << curr_job->name << ',' << (double)(end-start)/clock_tics_per_sec() << '\n';
}
if ( ret != 0 ) {

View File

@ -2,7 +2,6 @@
#include <iostream>
#include <stdlib.h>
#include <sys/resource.h>
#include <fstream>
#include <cstring>
#include <cerrno>
@ -38,26 +37,16 @@ int Trick::Executive::init() {
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);
std::ofstream init_log_stream;
/* command line args */
process_sim_args();
/* First parse command line to see if trick is in Sie generation mode.
If not, create the init_log file and record the elapsed time of
default_data, input_processor, and init jobs */
int argc ;
char ** argv ;
argc = command_line_args_get_argc() ;
argv = command_line_args_get_argv() ;
if (argc < 2 || strcmp(argv[1], "sie")) {
init_log_stream.open((std::string(command_line_args_get_output_dir()) + std::string("/init_log.csv")).c_str(), std::ofstream::out);
init_log_stream << "class,job,duration (s)\n";
}
call_default_data(init_log_stream) ;
call_input_processor(init_log_stream) ;
call_default_data() ;
call_input_processor() ;
// If we are starting from a checkpoint, restart_called will be true. Skip init routines in this case.
if ( ! restart_called ) {
call_initialization(init_log_stream) ;
call_initialization() ;
}
init_log_stream.close();

View File

@ -25,6 +25,7 @@
simulation and exit.
-# If the argument is "help" print out a help message about the possible command line
arguments and exit.
-# If the argument is "sie" then disable init_log which records data on some job queues.
*/
int Trick::Executive::process_sim_args() {
@ -53,7 +54,7 @@ int Trick::Executive::process_sim_args() {
" trick_version Print which version of Trick is being used\n"
" to the screen.\n" ) ;
/* If there are arguments to main... */
bool open_stream = true;
if (argc > 1) {
if (!strcmp(argv[1], "trick_version")) {
@ -64,8 +65,17 @@ int Trick::Executive::process_sim_args() {
!strcmp(argv[1], "-h") || !strcmp(argv[1], "help") ) {
/* Try and help the user */
exit(0);
} else if (!strcmp(argv[1], "sie")) {
/* do not create init_log.csv if we are generating sie */
open_stream = false;
}
}
/* create a log if we are not generating an sie file (usually during trick-CP) */
if(open_stream) {
init_log_stream.open((std::string(command_line_args_get_output_dir()) + std::string("/_init_log.csv")).c_str(), std::ofstream::out);
init_log_stream << "class,job,duration (s)\n";
}
return(0) ;
}