📄 slog_irec_write.c
字号:
SLOG_Irec_ToOutputStream() are called in pair for each interval record created */ if ( slog->reserve != NULL ) { if ( slog->reserve->Nrec_eff != 0 ) { fprintf( errfile, __FILE__":SLOG_CloseOutputStream() - " "Warning !!!!\n" "\t""Number of outstanding intervals = " fmt_i32"\n", slog->reserve->Nrec_eff ); fflush( errfile ); } if ( slog->reserve->Nbytes_eff != 0 ) { fprintf( errfile, __FILE__":SLOG_CloseOutputStream() - " "Warning !!!!\n" "\t""Bytesize of all outstanding intervals, " "slog->reserve->Nbytes_eff = " fmt_i32"\n", slog->reserve->Nbytes_eff ); fflush( errfile ); } } /* Endif ( slog->reserve != NULL ) */ /* Write the updated statistics info onto the disk again */ ierr = SLOG_PSTAT_Close( slog ); if ( ierr != SLOG_SUCCESS ) { fprintf( errfile, __FILE__":SLOG_CloseOutputStream() - " "SLOG_PSTAT_Close( slog ) fails!!\n" ); fflush( errfile ); return SLOG_FAIL; } } /* Endof if ( slog->HasIrec2IOStreamBeenUsed == SLOG_TRUE ) */ ierr = SLOG_CloseStream( slog ); if ( ierr != SLOG_SUCCESS ) { fprintf( errfile, __FILE__":SLOG_CloseOutputStream() - " "SLOG_CloseStream( slog ) fails!!\n" ); fflush( errfile ); return SLOG_FAIL; }#if defined( DEBUG )fprintf( stdout, __FILE__":SLOG_CloseOutputStream() - End\n" );fflush( stdout );#endif return SLOG_SUCCESS;}int SLOG_STM_2ndPass( SLOG_STREAM *slog ){ const SLOG_uint32 zero = (SLOG_uint32) 0; SLOG_uint32 Nbytes_read; SLOG_uint32 Nbytes_changed; /* SLOG_uint32 Nbytes_written; */ int idx; int ierr; fflush( slog->fd ); /* Reinitialize the Frame Header for next frame buffer */ SLOG_STM_UpdateFrameHdrGiven( slog, zero, zero, zero, zero, zero, zero, zero, zero ); /* Free all the nodes in all the bbufs */ SLOG_Bbuf_DelAllNodes( slog->cur_bbuf ); SLOG_Bbuf_DelAllNodes( slog->inc_bbuf ); SLOG_Bbuf_DelAllNodes( slog->pas_bbuf ); SLOG_Bbuf_DelAllNodes( slog->out_bbuf ); SLOG_Bbuf_DelAllNodes( slog->tmp_bbuf ); /* Reinitialize the bi-directional list buffers & related variables */ SLOG_Bbuf_Init( slog->cur_bbuf ); SLOG_Bbuf_Init( slog->inc_bbuf ); SLOG_Bbuf_Init( slog->pas_bbuf ); SLOG_Bbuf_Init( slog->out_bbuf ); SLOG_Bbuf_Init( slog->tmp_bbuf ); /* Reopen slog->fbuf */ fbuf_free( slog->fbuf ); slog->fbuf = fbuf_create( slog->hdr->frame_bytesize ); if ( slog->fbuf == NULL ) { fprintf( errfile, __FILE__":SLOG_STM_2ndPass() - " "fbuf_create( %d bytes ) fails\n", slog->hdr->frame_bytesize ); fflush( errfile ); SLOG_CloseStream( slog ); return SLOG_FAIL; } /* Set the file buffer's file descriptor equal to the SLOG_STREAM's */ fbuf_filedesc( slog->fbuf, slog->fd ); for ( idx = ( slog->frame_dir ).Nframe-1; idx >= 0; idx-- ) { ierr = SLOG_STM_ReadFRAMEatIdx( slog, idx ); if ( ierr == SLOG_FAIL || ierr == SLOG_EOF ) { fprintf( errfile, __FILE__":SLOG_STM_2ndPass() - " "Unexpected termination of " "SLOG_STM_ReadFRAMEatIdx(%d)\n", idx ); fflush( errfile ); return SLOG_FAIL; } Nbytes_read = ierr; ierr = SLOG_STM_UpdateFrameDirEntry_Backward( slog, idx ); if ( ierr != SLOG_SUCCESS ) { fprintf( errfile, __FILE__":SLOG_STM_2ndPass() - " "SLOG_STM_UpdateFrameDirEntry_Backward(%d) fails\n", idx ); fflush( errfile ); return SLOG_FAIL; } ierr = SLOG_STM_UpdateFRAME_Backward( slog ); if ( ierr == SLOG_FAIL ) { fprintf( errfile, __FILE__":SLOG_STM_2ndPass() - " "SLOG_STM_UpdateFRAME_Backward(%d) fails\n", idx ); fflush( errfile ); return SLOG_FAIL; } Nbytes_changed = ierr; if ( Nbytes_read + Nbytes_changed > slog->hdr->frame_bytesize ) { fprintf( errfile, __FILE__":SLOG_STM_2ndPass() - " "At frame index = %d :\n", idx ); fprintf( errfile, "\t""The patched Bbufs are too big to fit " "into a frame buffer\n" "\t""Nbytes_read("fmt_ui32") + " "Nbytes_changed("fmt_ui32") > " "frame_bytesize("fmt_ui32")\n", Nbytes_read, Nbytes_changed, slog->hdr->frame_bytesize ); fprintf( errfile, "\t""Check the printout of the logfile at " "frame index = %d and %d or maybe earlier ones\n", idx, idx+1 ); fflush( errfile ); return SLOG_FAIL; } fbuf_ptr2head( slog->fbuf ); ierr = SLOG_STM_WriteFRAMEatIdx( slog, idx ); if ( ierr == SLOG_FAIL || ierr == SLOG_EOF ) { fprintf( errfile, __FILE__":SLOG_STM_2ndPass() - " "SLOG_STM_WriteFRAMEatIdx(%d) fails\n", idx ); fflush( errfile ); return SLOG_FAIL; } /* Nbytes_written = ierr; */ /* Since the irec's are arranged in increasing order of endtime stamps, only cur_bbuf and inc_bbuf contain REAL records. So statistics are collected in these 2 Bbufs. */ ierr = SLOG_PSTAT_Update( slog->pstat, slog->cur_bbuf ); if ( ierr != SLOG_SUCCESS ) { fprintf( errfile, __FILE__":SLOG_STM_2ndPass() - " "SLOG_PSTAT_Update( _CUR_ ) fails\n" ); fflush( errfile ); return SLOG_FAIL; } ierr = SLOG_PSTAT_Update( slog->pstat, slog->inc_bbuf ); if ( ierr != SLOG_SUCCESS ) { fprintf( errfile, __FILE__":SLOG_STM_2ndPass() - " "SLOG_PSTAT_Update( _INC_ ) fails\n" ); fflush( errfile ); return SLOG_FAIL; } /* For the 1st frame in the logfile */ if ( idx == 0 ) { /* Set slog->file_dir_cur pointing at the 1st entry of FrameDirEntry */ slog->file_dir_cur = slog->file_dir_hdr + SLOG_typesz[ FrameDirHdr ]; ierr = SLOG_WriteUpdatedFrameDirEntry( slog ); if ( ierr != SLOG_SUCCESS ) { fprintf( errfile, __FILE__":SLOG_STM_2ndPass() - " "SLOG_WriteUpdatedFrameDirEntry( slog ) " "fails!!\n" ); fflush( errfile ); return SLOG_FAIL; } } else SLOG_STM_InitAgainBeforePatchFrame( slog ); } /* for ( (slog->frame_dir).Nframe > idx >= 0 ) */ return SLOG_SUCCESS;}/*@C SLOG_Irec_ReserveSpace - Reserve space in the current frame for the current interval record identified by record type ID and interval record type ID. Modified Input Variables :. slog - pointer to the SLOG_STREAM where the interval record locates. Unmodified Input Variables :. rectype - interval record's record field which determines if the record is a FIXED, VARIABLE or Message record, this in turns will determine the number of association and the number of sets of MPI call arguments or the extra space needed for Message record.. intvltype - interval record's interval type field.. bebit_0 - interval record's first bebit.. bebit_1 - interval record's second bebit.. starttime - interval record's start time, used to check if the interval follows the time order rule set by SLOG_SetIncreasingEndtimeOrder() or SLOG_SetIncreasingStarttimeOrder(). The checking is only done when user turns on the corresponding compiler flag. If not, this input variable will not be used. Modified Output Variables :. returned value - integer return status. Usage Notes on this subroutine : *** IMPORTANT ***, this routine is totally optional. User doesn't have to use this routine to use the API. And this routine can only be called when the completed interval records are arranged in increasing endtime order. The subroutine allocates space in the current frame for the interval record. Typically, the routine is called when user knows only __start_event__ of an interval record without the knowledge of the __end_event__. So the routine must be called before calling SLOG_Irec_ToOutputStream(). For completed interval records which are arranged in increasing endtime stamp order, each interval record may be called with SLOG_Irec_ReserveSpace() first when the time of the corresponding __start_event__ is known and called with SLOG_Irec_ToOutputStream() when the time of the corresponding __end_event__ is known. Also the routine will check if the starttime supplied is called in increasing time order which is a sufficient condition to guarantee that space reservation for every pseudo record in each frame. Include File Needed : slog.h.N SLOG_RETURN_STATUS@*/int SLOG_Irec_ReserveSpace( SLOG_STREAM *slog, const SLOG_rectype_t rectype, const SLOG_intvltype_t intvltype, const SLOG_bebit_t bebit_0, const SLOG_bebit_t bebit_1, const SLOG_starttime_t starttime ){/* SLOG_uint32 old_buf_Nbytes_in_file; SLOG_uint32 new_buf_Nbytes_in_file;*/ SLOG_uint32 irec_bytesize_estimate; int ierr; if ( slog->reserve == NULL ) { if ( slog->hdr->IsIncreasingEndtime != SLOG_TRUE ) { fprintf( errfile, __FILE__":SLOG_Irec_ReserveSpace() - \n" "SLOG_SetIncreasingEndtimeOrder() has NOT been " "called!\n" ); fflush( errfile ); return SLOG_SUCCESS; } slog->hdr->HasReserveSpaceBeenUsed = SLOG_TRUE; ierr = SLOG_WriteUpdatedHeader( slog ); if ( ierr != SLOG_SUCCESS ) { fprintf( errfile, __FILE__":SLOG_Irec_ReserveSpace() - " "SLOG_WriteUpdatedHeader() fails\n" ); fflush( errfile ); return ierr; } /* Allocate SLOG_reserve_info_t which stores all the bookkeeping info about status of space utilization of reserved Irec in a frame. */ slog->reserve = ( SLOG_reserve_info_t * ) malloc( sizeof ( SLOG_reserve_info_t ) ); if ( slog->reserve == NULL ) { fprintf( errfile, __FILE__":SLOG_Irec_ReserveSpace() - " "malloc() for SLOG_reserve_info_t fails\n" ); fflush( errfile ); return ierr; } /* Initialize the SLOG_reserve_info_t's component Nrec_eff : effective No of Irec reserved in a frame. This number is decremented by 1 for each SLOG_Irec_ToOutputStream() call. But increment by 1 as SLOG_Irec_ReserveSpace() is called. Nbytes_eff : companion variable to store bytesize of Nrec_eff Nrec_tot : Total No. of Irec reserved in a frame. This number is incremented by 1 for each SLOG_Irec_ReserveSpace() call. And it is reinitialized to zero after the frame Bbufs are dumped to the disk( or when new frame bbufs are allocated ) Nbytes_tot : companion variable to store bytesize of Nrec_tot */ slog->reserve->Nrec_eff = 0; slog->reserve->Nbytes_eff = 0; slog->reserve->Nrec_tot = 0; slog->reserve->Nbytes_tot = 0;#if defined( CHECKTIMEORDER ) slog->prev_starttime = starttime;#endif } ierr = SLOG_RecDef_SizeOfIrecInFile( slog->rec_defs, rectype, intvltype, bebit_0, bebit_1 ); if ( ierr == SLOG_FAIL ) { fprintf( errfile, __FILE__":SLOG_Irec_ReserveSpace() - \n" "\t""SLOG_Irec_SizeOf("fmt_rtype_t","fmt_itype_t ","fmt_bebit_t","fmt_bebit_t") fails!\n", rectype, intvltype, bebit_0, bebit_1 ); fflush( errfile ); return SLOG_FAIL; } irec_bytesize_estimate = ierr; /* Update the content in SLOG_reserve_info_t */ slog->reserve->Nrec_eff++; slog->reserve->Nbytes_eff += irec_bytesize_estimate; slog->reserve->Nrec_tot++; slog->reserve->Nbytes_tot += irec_bytesize_estimate;/* if ( slog->HasIrec2IOStreamBeenUsed == SLOG_TRUE ) { old_buf_Nbytes_in_file = SLOG_typesz[ FrameHdr ] + slog->hdr->frame_reserved_size + slog->reserve->Nbytes_tot; if ( old_buf_Nbytes_in_file > fbuf_bufsz( slog->fbuf ) ) { fprintf( errfile, __FILE__":SLOG_Irec_ReserveSpace() - Warning!!!\n" "\t""When SLOG_Irec_ToOutputStream( " fmt_rtype_t", " fmt_itype_t", "fmt_bebit_t", " fmt_bebit_t", " fmt_stime_t" ) \n" "\t""is called for the corresponding " "_End_Event_, it may fail!!\n", rectype, intvltype, bebit_0, bebit_1, starttime ); fprintf( errfile, "\t""reserve->Nbytes_tot = "fmt_i32", " "old_buf_Nbytes_in_file = "fmt_ui32", "
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -