mirror of
https://github.com/nasa/trick.git
synced 2025-06-01 15:10:59 +00:00
Merge branch 'master' into Issue595
This commit is contained in:
commit
ad05aad2d2
@ -117,7 +117,7 @@ namespace Trick {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
/** The log file.\n */
|
/** The log file.\n */
|
||||||
int fp ; /**< trick_io(**) trick_units(--) */
|
int fd ; /**< trick_io(**) trick_units(--) */
|
||||||
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
@ -100,6 +100,12 @@ namespace Trick {
|
|||||||
/** @brief Disable a group or all groups */
|
/** @brief Disable a group or all groups */
|
||||||
int record_now_group( const char * in_name ) ;
|
int record_now_group( const char * in_name ) ;
|
||||||
|
|
||||||
|
/** @brief set max file size for group */
|
||||||
|
int set_group_max_file_size(const char * in_name, uint64_t bytes) ;
|
||||||
|
|
||||||
|
/** @brief set max file size for all groups */
|
||||||
|
int set_max_file_size(uint64_t bytes) ;
|
||||||
|
|
||||||
// override the default Schduler::add_sim_object
|
// override the default Schduler::add_sim_object
|
||||||
virtual int add_sim_object( Trick::SimObject * in_object ) ;
|
virtual int add_sim_object( Trick::SimObject * in_object ) ;
|
||||||
|
|
||||||
|
@ -115,6 +115,12 @@ namespace Trick {
|
|||||||
/** Current write to file record number.\n */
|
/** Current write to file record number.\n */
|
||||||
unsigned int writer_num; /**< trick_io(**) trick_units(--) */
|
unsigned int writer_num; /**< trick_io(**) trick_units(--) */
|
||||||
|
|
||||||
|
/** Maximum file size for data record file in bytes.\n */
|
||||||
|
uint64_t max_file_size; /**< trick_io(**) trick_units(--) */
|
||||||
|
|
||||||
|
/** Current file size for data record file in bytes.\n */
|
||||||
|
uint64_t total_bytes_written; /**< trick_io(**) trick_units(--) */
|
||||||
|
|
||||||
/** Buffer to hold formatted data ready for disk or other destination.\n */
|
/** Buffer to hold formatted data ready for disk or other destination.\n */
|
||||||
char * writer_buff ; /**< trick_io(**) trick_units(--) */
|
char * writer_buff ; /**< trick_io(**) trick_units(--) */
|
||||||
|
|
||||||
@ -207,6 +213,17 @@ namespace Trick {
|
|||||||
*/
|
*/
|
||||||
virtual int set_buffer_type(int buffer_type) ;
|
virtual int set_buffer_type(int buffer_type) ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief @userdesc Command to set the max file size in bytes.
|
||||||
|
This tells the data record group when it stops writing to the disk.
|
||||||
|
@par Python Usage:
|
||||||
|
@code <dr_group>.set_max_file_size(<buffer_type>) @endcode
|
||||||
|
@param type - the file size in bytes
|
||||||
|
@return always 0
|
||||||
|
*/
|
||||||
|
virtual int set_max_file_size(uint64_t bytes) ;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief @userdesc Command to print double variable values as single precision (float) in the log file to save space.
|
@brief @userdesc Command to print double variable values as single precision (float) in the log file to save space.
|
||||||
@par Python Usage:
|
@par Python Usage:
|
||||||
|
@ -14,7 +14,10 @@ int dr_disable() ;
|
|||||||
int dr_enable_group( const char * in_name ) ;
|
int dr_enable_group( const char * in_name ) ;
|
||||||
int dr_disable_group( const char * in_name ) ;
|
int dr_disable_group( const char * in_name ) ;
|
||||||
int dr_record_now_group( const char * in_name ) ;
|
int dr_record_now_group( const char * in_name ) ;
|
||||||
|
int dr_set_max_file_size ( uint64_t bytes ) ;
|
||||||
void remove_all_data_record_groups() ;
|
void remove_all_data_record_groups() ;
|
||||||
|
int set_max_size_record_group (const char * in_name, uint64_t bytes ) ;
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
int add_data_record_group( Trick::DataRecordGroup * in_group, Trick::DR_Buffering buffering = Trick::DR_Not_Specified ) ;
|
int add_data_record_group( Trick::DataRecordGroup * in_group, Trick::DR_Buffering buffering = Trick::DR_Not_Specified ) ;
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
PURPOSE:
|
PURPOSE:
|
||||||
(Data record in ascii format.)
|
(Data record in ascii format.)
|
||||||
@ -46,6 +46,7 @@ int Trick::DRAscii::format_specific_header( std::fstream & out_st ) {
|
|||||||
int Trick::DRAscii::format_specific_init() {
|
int Trick::DRAscii::format_specific_init() {
|
||||||
|
|
||||||
unsigned int jj ;
|
unsigned int jj ;
|
||||||
|
std::streampos before_write;
|
||||||
|
|
||||||
/* Store log information in csv/txt file */
|
/* Store log information in csv/txt file */
|
||||||
if ( ! delimiter.empty() && delimiter.compare(",") != 0 ) {
|
if ( ! delimiter.empty() && delimiter.compare(",") != 0 ) {
|
||||||
@ -70,7 +71,7 @@ int Trick::DRAscii::format_specific_init() {
|
|||||||
record = false ;
|
record = false ;
|
||||||
return -1 ;
|
return -1 ;
|
||||||
}
|
}
|
||||||
|
before_write = out_stream.tellp();
|
||||||
// Write out the title line of the recording file
|
// Write out the title line of the recording file
|
||||||
/* Start with the 1st item in the buffer which should be "sys.exec.out.time" */
|
/* Start with the 1st item in the buffer which should be "sys.exec.out.time" */
|
||||||
out_stream << rec_buffer[0]->ref->reference ;
|
out_stream << rec_buffer[0]->ref->reference ;
|
||||||
@ -81,6 +82,7 @@ int Trick::DRAscii::format_specific_init() {
|
|||||||
out_stream << " {" << rec_buffer[0]->ref->attr->units << "}" ;
|
out_stream << " {" << rec_buffer[0]->ref->attr->units << "}" ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write out specified recorded parameters */
|
/* Write out specified recorded parameters */
|
||||||
for (jj = 1; jj < rec_buffer.size() ; jj++) {
|
for (jj = 1; jj < rec_buffer.size() ; jj++) {
|
||||||
out_stream << delimiter << rec_buffer[jj]->ref->reference ;
|
out_stream << delimiter << rec_buffer[jj]->ref->reference ;
|
||||||
@ -94,7 +96,7 @@ int Trick::DRAscii::format_specific_init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
out_stream << std::endl ;
|
out_stream << std::endl ;
|
||||||
|
total_bytes_written += out_stream.tellp() - before_write;
|
||||||
return(0) ;
|
return(0) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,6 +107,7 @@ int Trick::DRAscii::format_specific_init() {
|
|||||||
-# Write out each of the other parameter values preceded by the delimiter to the temporary #writer_buff
|
-# Write out each of the other parameter values preceded by the delimiter to the temporary #writer_buff
|
||||||
-# Write #writer_buff to the output file
|
-# Write #writer_buff to the output file
|
||||||
-# Flush the output file stream
|
-# Flush the output file stream
|
||||||
|
-# Return the number of bytes written
|
||||||
*/
|
*/
|
||||||
int Trick::DRAscii::format_specific_write_data(unsigned int writer_offset) {
|
int Trick::DRAscii::format_specific_write_data(unsigned int writer_offset) {
|
||||||
unsigned int ii ;
|
unsigned int ii ;
|
||||||
@ -128,8 +131,8 @@ int Trick::DRAscii::format_specific_write_data(unsigned int writer_offset) {
|
|||||||
|
|
||||||
/*! Flush the output */
|
/*! Flush the output */
|
||||||
out_stream.flush() ;
|
out_stream.flush() ;
|
||||||
|
/*! +1 for endl */
|
||||||
return(0) ;
|
return(strlen(writer_buff) + 1) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,6 +53,8 @@ int Trick::DRBinary::format_specific_init() {
|
|||||||
|
|
||||||
unsigned int jj ;
|
unsigned int jj ;
|
||||||
int write_value ;
|
int write_value ;
|
||||||
|
/* number of bytes written to data record */
|
||||||
|
int bytes = 0 ;
|
||||||
|
|
||||||
union {
|
union {
|
||||||
long l;
|
long l;
|
||||||
@ -72,45 +74,48 @@ int Trick::DRBinary::format_specific_init() {
|
|||||||
writer_buff[record_size * rec_buffer.size() - 1] = 1 ;
|
writer_buff[record_size * rec_buffer.size() - 1] = 1 ;
|
||||||
|
|
||||||
/* start header information in trk file */
|
/* start header information in trk file */
|
||||||
if ((fp = creat(file_name.c_str(), S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)) == -1) {
|
if ((fd = creat(file_name.c_str(), S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)) == -1) {
|
||||||
record = false ;
|
record = false ;
|
||||||
return (-1) ;
|
return (-1) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Check to see if data is being recorded in little endian
|
/* Check to see if data is being recorded in little endian
|
||||||
* byte order, and add little endian line if so.
|
* byte order, and add little endian line if so.
|
||||||
*/
|
*/
|
||||||
byte_order_union.l = 1 ;
|
byte_order_union.l = 1 ;
|
||||||
if (byte_order_union.c[sizeof(long)-1] != 1) {
|
if (byte_order_union.c[sizeof(long)-1] != 1) {
|
||||||
write( fp , "Trick-10-L", (size_t)10 ) ;
|
bytes += write( fd , "Trick-10-L", (size_t)10 ) ;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
write( fp , "Trick-10-B", (size_t)10 ) ;
|
bytes += write( fd , "Trick-10-B", (size_t)10 ) ;
|
||||||
}
|
}
|
||||||
write_value = rec_buffer.size() ;
|
write_value = rec_buffer.size() ;
|
||||||
write( fp , &write_value , sizeof(int) ) ;
|
bytes += write( fd , &write_value , sizeof(int) ) ;
|
||||||
|
|
||||||
for (jj = 0; jj < rec_buffer.size(); jj++) {
|
for (jj = 0; jj < rec_buffer.size(); jj++) {
|
||||||
/* name */
|
/* name */
|
||||||
write_value = strlen(rec_buffer[jj]->ref->reference) ;
|
write_value = strlen(rec_buffer[jj]->ref->reference) ;
|
||||||
write( fp , &write_value , sizeof(int)) ;
|
bytes += write( fd , &write_value , sizeof(int)) ;
|
||||||
write( fp , rec_buffer[jj]->ref->reference , write_value ) ;
|
bytes += write( fd , rec_buffer[jj]->ref->reference , write_value ) ;
|
||||||
|
|
||||||
/* units */
|
/* units */
|
||||||
if ( rec_buffer[jj]->ref->attr->mods & TRICK_MODS_UNITSDASHDASH ) {
|
if ( rec_buffer[jj]->ref->attr->mods & TRICK_MODS_UNITSDASHDASH ) {
|
||||||
write_value = strlen("--") ;
|
write_value = strlen("--") ;
|
||||||
write( fp , &write_value , sizeof(int)) ;
|
bytes += write( fd , &write_value , sizeof(int)) ;
|
||||||
write( fp , "--" , write_value ) ;
|
bytes += write( fd , "--" , write_value ) ;
|
||||||
} else {
|
} else {
|
||||||
write_value = strlen(rec_buffer[jj]->ref->attr->units) ;
|
write_value = strlen(rec_buffer[jj]->ref->attr->units) ;
|
||||||
write( fp , &write_value , sizeof(int)) ;
|
bytes += write( fd , &write_value , sizeof(int)) ;
|
||||||
write( fp , rec_buffer[jj]->ref->attr->units , write_value ) ;
|
bytes += write( fd , rec_buffer[jj]->ref->attr->units , write_value ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
write_value = rec_buffer[jj]->ref->attr->type ;
|
write_value = rec_buffer[jj]->ref->attr->type ;
|
||||||
write( fp , &write_value , sizeof(int)) ;
|
bytes += write( fd , &write_value , sizeof(int)) ;
|
||||||
|
|
||||||
write( fp , &rec_buffer[jj]->ref->attr->size , sizeof(int)) ;
|
bytes += write( fd , &rec_buffer[jj]->ref->attr->size , sizeof(int)) ;
|
||||||
}
|
}
|
||||||
|
total_bytes_written += bytes;
|
||||||
return(0) ;
|
return(0) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,6 +124,7 @@ int Trick::DRBinary::format_specific_init() {
|
|||||||
-# While there is data in memory that has not been written to disk
|
-# While there is data in memory that has not been written to disk
|
||||||
-# Write out each of the other parameter values to the temporary #writer_buff
|
-# Write out each of the other parameter values to the temporary #writer_buff
|
||||||
-# Write #writer_buff to the output file
|
-# Write #writer_buff to the output file
|
||||||
|
-# return the number of bytes written
|
||||||
*/
|
*/
|
||||||
int Trick::DRBinary::format_specific_write_data(unsigned int writer_offset) {
|
int Trick::DRBinary::format_specific_write_data(unsigned int writer_offset) {
|
||||||
|
|
||||||
@ -171,9 +177,7 @@ int Trick::DRBinary::format_specific_write_data(unsigned int writer_offset) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
write( fp , writer_buff , len) ;
|
return write( fd , writer_buff , len) ;
|
||||||
|
|
||||||
return(0) ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -183,8 +187,7 @@ int Trick::DRBinary::format_specific_write_data(unsigned int writer_offset) {
|
|||||||
int Trick::DRBinary::format_specific_shutdown() {
|
int Trick::DRBinary::format_specific_shutdown() {
|
||||||
|
|
||||||
if ( inited ) {
|
if ( inited ) {
|
||||||
close(fp) ;
|
close(fd) ;
|
||||||
}
|
}
|
||||||
return(0) ;
|
return(0) ;
|
||||||
}
|
}
|
||||||
|
|
@ -313,6 +313,23 @@ int Trick::DataRecordDispatcher::record_now_group( const char * in_name ) {
|
|||||||
return 0 ;
|
return 0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Trick::DataRecordDispatcher::set_group_max_file_size(const char * in_name, uint64_t bytes){
|
||||||
|
unsigned int ii ;
|
||||||
|
for ( ii = 0 ; ii < groups.size() ; ii++ ) {
|
||||||
|
if ( in_name == NULL or !groups[ii]->get_group_name().compare(in_name) )
|
||||||
|
groups[ii]->set_max_file_size(bytes) ;
|
||||||
|
}
|
||||||
|
return 0 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Trick::DataRecordDispatcher::set_max_file_size(uint64_t bytes) {
|
||||||
|
unsigned int ii ;
|
||||||
|
for ( ii = 0 ; ii < groups.size() ; ii++ ) {
|
||||||
|
groups[ii]->set_max_file_size(bytes) ;
|
||||||
|
}
|
||||||
|
return 0 ;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@details
|
@details
|
||||||
-# Call every group's init job - only needed when restoring checkpoint
|
-# Call every group's init job - only needed when restoring checkpoint
|
||||||
@ -325,3 +342,4 @@ int Trick::DataRecordDispatcher::init_groups() {
|
|||||||
}
|
}
|
||||||
return 0 ;
|
return 0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,6 +71,8 @@ Trick::DataRecordGroup::DataRecordGroup( std::string in_name ) :
|
|||||||
max_num(100000),
|
max_num(100000),
|
||||||
buffer_num(0),
|
buffer_num(0),
|
||||||
writer_num(0),
|
writer_num(0),
|
||||||
|
max_file_size(1<<30), // 1 GB
|
||||||
|
total_bytes_written(0),
|
||||||
writer_buff(NULL),
|
writer_buff(NULL),
|
||||||
single_prec_only(false),
|
single_prec_only(false),
|
||||||
buffer_type(DR_Buffer),
|
buffer_type(DR_Buffer),
|
||||||
@ -193,6 +195,15 @@ int Trick::DataRecordGroup::set_buffer_type( int in_buffer_type ) {
|
|||||||
return(0) ;
|
return(0) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Trick::DataRecordGroup::set_max_file_size( uint64_t bytes ) {
|
||||||
|
if(bytes == 0) {
|
||||||
|
max_file_size = UINT64_MAX ;
|
||||||
|
} else {
|
||||||
|
max_file_size = bytes ;
|
||||||
|
}
|
||||||
|
return(0) ;
|
||||||
|
}
|
||||||
|
|
||||||
int Trick::DataRecordGroup::set_single_prec_only( bool in_single_prec_only ) {
|
int Trick::DataRecordGroup::set_single_prec_only( bool in_single_prec_only ) {
|
||||||
single_prec_only = in_single_prec_only ;
|
single_prec_only = in_single_prec_only ;
|
||||||
return(0) ;
|
return(0) ;
|
||||||
@ -248,7 +259,7 @@ int Trick::DataRecordGroup::add_variable( std::string in_name , std::string alia
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Trick::DataRecordGroup::remove_variable( std::string in_name ) {
|
void Trick::DataRecordGroup::remove_variable( std::string in_name ) {
|
||||||
// Trim leading spaces
|
// Trim leading spaces++
|
||||||
in_name.erase( 0, in_name.find_first_not_of( " \t" ) );
|
in_name.erase( 0, in_name.find_first_not_of( " \t" ) );
|
||||||
// Trim trailing spaces
|
// Trim trailing spaces
|
||||||
in_name.erase( in_name.find_last_not_of( " \t" ) + 1);
|
in_name.erase( in_name.find_last_not_of( " \t" ) + 1);
|
||||||
@ -342,7 +353,7 @@ int Trick::DataRecordGroup::init() {
|
|||||||
int ret ;
|
int ret ;
|
||||||
|
|
||||||
// reset counter here so we can "re-init" our recording
|
// reset counter here so we can "re-init" our recording
|
||||||
buffer_num = writer_num = 0 ;
|
buffer_num = writer_num = total_bytes_written = 0 ;
|
||||||
|
|
||||||
output_dir = command_line_args_get_output_dir() ;
|
output_dir = command_line_args_get_output_dir() ;
|
||||||
/* this is the common part of the record file name, the format specific will add the correct suffix */
|
/* this is the common part of the record file name, the format specific will add the correct suffix */
|
||||||
@ -632,7 +643,7 @@ int Trick::DataRecordGroup::write_data(bool must_write) {
|
|||||||
unsigned int num_to_write ;
|
unsigned int num_to_write ;
|
||||||
unsigned int writer_offset ;
|
unsigned int writer_offset ;
|
||||||
|
|
||||||
if ( record and inited and (buffer_type == DR_No_Buffer or must_write)) {
|
if ( record and inited and (buffer_type == DR_No_Buffer or must_write) and (total_bytes_written <= max_file_size)) {
|
||||||
|
|
||||||
// buffer_mutex is used in this one place to prevent forced calls of write_data
|
// buffer_mutex is used in this one place to prevent forced calls of write_data
|
||||||
// to not overwrite data being written by the asynchronous thread.
|
// to not overwrite data being written by the asynchronous thread.
|
||||||
@ -649,7 +660,8 @@ int Trick::DataRecordGroup::write_data(bool must_write) {
|
|||||||
while ( writer_num != local_buffer_num ) {
|
while ( writer_num != local_buffer_num ) {
|
||||||
|
|
||||||
writer_offset = writer_num % max_num ;
|
writer_offset = writer_num % max_num ;
|
||||||
format_specific_write_data(writer_offset) ;
|
//! keep record of bytes written to file. Default max is 1GB
|
||||||
|
total_bytes_written += format_specific_write_data(writer_offset) ;
|
||||||
writer_num++ ;
|
writer_num++ ;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -78,3 +78,17 @@ extern "C" Trick::DataRecordGroup * get_data_record_group( std::string in_name )
|
|||||||
}
|
}
|
||||||
return NULL ;
|
return NULL ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" int set_max_size_record_group (const char * in_name, uint64_t bytes ) {
|
||||||
|
if ( the_drd != NULL ) {
|
||||||
|
return the_drd->set_group_max_file_size(in_name, bytes ) ;
|
||||||
|
}
|
||||||
|
return -1 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" int dr_set_max_file_size ( uint64_t bytes ) {
|
||||||
|
if ( the_drd != NULL ) {
|
||||||
|
return the_drd->set_max_file_size( bytes ) ;
|
||||||
|
}
|
||||||
|
return -1 ;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user