mirror of
https://github.com/nasa/trick.git
synced 2024-12-18 20:57:55 +00:00
data record buffering optimizations
Added a loop to set each 1024th byte in the recording array to 1 once the memory has been allocated. Need to test if this is good enough to get Linux to allocate the memory. Added a current recording buffer pointer to use instead of using array offsets. This should be more cpu cache efficient. Changed the memcpy calls to direct casted integer assignments based on the size of the parameter. If the parameter is not size 1,2,4,or 8 we fall back to a memcpy. refs #155
This commit is contained in:
parent
a08b313457
commit
903ff05960
@ -45,6 +45,7 @@ namespace Trick {
|
||||
class DataRecordBuffer {
|
||||
public:
|
||||
char *buffer; /* ** generic holding buffer for data */
|
||||
char *curr_buffer; /* ** current position in the buffer */
|
||||
char *last_value; /* ** holding buffer for last value, used for DR_Changes_step */
|
||||
REF2 * ref ; /* ** size/address/units information of variable */
|
||||
bool ref_searched ; /* ** reference information has been searched */
|
||||
|
@ -57,6 +57,13 @@ int Trick::DRAscii::format_specific_init() {
|
||||
/* Calculate a "worst case" for space used for 1 record. */
|
||||
writer_buff = (char *)calloc(1 , record_size * rec_buffer.size()) ;
|
||||
|
||||
/* This loop touches all of the memory locations in the allocation forcing the
|
||||
system to actually do the allocation */
|
||||
for ( jj= 0 ; jj < record_size * rec_buffer.size() ; jj += 1024 ) {
|
||||
writer_buff[jj] = 1 ;
|
||||
}
|
||||
writer_buff[record_size * rec_buffer.size() - 1] = 1 ;
|
||||
|
||||
out_stream.open(file_name.c_str(), std::fstream::out | std::fstream::app ) ;
|
||||
if ( !out_stream || !out_stream.good() ) {
|
||||
message_publish(MSG_ERROR, "Can't open Data Record file %s.\n", file_name.c_str()) ;
|
||||
|
@ -64,6 +64,13 @@ int Trick::DRBinary::format_specific_init() {
|
||||
/* Calculate a "worst case" for space used for 1 record. */
|
||||
writer_buff = (char *)calloc(1 , record_size * rec_buffer.size()) ;
|
||||
|
||||
/* This loop touches all of the memory locations in the allocation forcing the
|
||||
system to actually do the allocation */
|
||||
for ( jj= 0 ; jj < record_size * rec_buffer.size() ; jj += 1024 ) {
|
||||
writer_buff[jj] = 1 ;
|
||||
}
|
||||
writer_buff[record_size * rec_buffer.size() - 1] = 1 ;
|
||||
|
||||
/* 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) {
|
||||
record = false ;
|
||||
|
@ -542,10 +542,33 @@ int Trick::DataRecordGroup::data_record(double in_time) {
|
||||
buffer_offset = buffer_num % max_num ;
|
||||
for (jj = 0; jj < rec_buffer.size() ; jj++) {
|
||||
drb = rec_buffer[jj] ;
|
||||
if ( drb->ref->pointer_present == 1 ) {
|
||||
drb->ref->address = follow_address_path(drb->ref) ;
|
||||
REF2 * ref = drb->ref ;
|
||||
if ( ref->pointer_present == 1 ) {
|
||||
ref->address = follow_address_path(ref) ;
|
||||
}
|
||||
int param_size = ref->attr->size ;
|
||||
if ( buffer_offset == 0 ) {
|
||||
drb->curr_buffer = drb->buffer ;
|
||||
} else {
|
||||
drb->curr_buffer += param_size ;
|
||||
}
|
||||
switch ( param_size ) {
|
||||
case 8:
|
||||
*(int64_t *)drb->curr_buffer = *(int64_t *)ref->address ;
|
||||
break ;
|
||||
case 4:
|
||||
*(int32_t *)drb->curr_buffer = *(int32_t *)ref->address ;
|
||||
break ;
|
||||
case 2:
|
||||
*(int16_t *)drb->curr_buffer = *(int16_t *)ref->address ;
|
||||
break ;
|
||||
case 1:
|
||||
*(int8_t *)drb->curr_buffer = *(int8_t *)ref->address ;
|
||||
break ;
|
||||
default:
|
||||
memcpy( drb->curr_buffer , ref->address , param_size ) ;
|
||||
break ;
|
||||
}
|
||||
memcpy( drb->buffer + (buffer_offset * drb->ref->attr->size) , drb->ref->address , drb->ref->attr->size ) ;
|
||||
}
|
||||
buffer_num++ ;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user