📄 slog_impl.c
字号:
#include <stdio.h>#ifdef HAVE_SLOGCONF_H#include "slog_config.h"#endif#ifdef HAVE_SLOG_WINCONFIG_H#include "slog_winconfig.h"#endif#if defined( STDC_HEADERS ) || defined( HAVE_STDLIB_H )#include <stdlib.h>#endif#if defined( STDC_HEADERS ) || defined( HAVE_STRING_H )#include <string.h>#endif#if defined( HAVE_UNISTD_H )#include <unistd.h>#endif#include "fbuf.h"#include "bswp_fileio.h"#include "slog_fileio.h"#include "slog_bbuf.h"#include "slog_bebits.h"#include "slog_vtrarg.h"#include "slog_header.h"#include "slog_preview.h"#include "slog_pstat.h"#include "slog_ttable.h"#include "slog_recdefs.h"#include "slog_profile.h"#include "slog_impl.h"/* Define the Global data structure */SLOG_global_t SLOG_global;SLOG_uint32 SLOG_typesz[ SLOG_MAX_TYPES ];/* Global Static Methdos *//* Check if the given intvltype has an entry for the number of associations and the number of call arguments*/int SLOG_global_IsVarRec( const SLOG_rectype_t rectype ){ return ( rectype >= SLOG_global.MinRectype4VarDiagRec && rectype <= SLOG_global.MaxRectype4VarDiagRec ) || ( rectype >= SLOG_global.MinRectype4VarOffdRec && rectype <= SLOG_global.MaxRectype4VarOffdRec );}int SLOG_global_IsOffDiagRec( const SLOG_rectype_t rectype ){ return ( rectype >= SLOG_global.MinRectype4VarOffdRec && rectype <= SLOG_global.MaxRectype4VarOffdRec ) || ( rectype >= SLOG_global.MinRectype4FixOffdRec && rectype <= SLOG_global.MaxRectype4FixOffdRec );}/* Low Level API */void SLOG_InitGlobalData( void ){ /* Initialize the GLOBAL constant and variables */ /* Define the byte size of the basic type used in SLOG */ SLOG_typesz[ bit ] = sizeof( SLOG_bit ); SLOG_typesz[ ui8 ] = sizeof( SLOG_uint8 ); SLOG_typesz[ ui16 ] = sizeof( SLOG_uint16 ); SLOG_typesz[ ui32 ] = sizeof( SLOG_uint32 ); SLOG_typesz[ ui64 ] = sizeof( SLOG_uint64 ); SLOG_typesz[ ts ] = sizeof( SLOG_time ); SLOG_typesz[ fptr ] = sizeof( SLOG_fptr ); SLOG_typesz[ sbin ] = sizeof( SLOG_statbintype ); /* Define the byte size of the basic type used in SLOG's Interval Rec */ SLOG_typesz[ sz_t ] = sizeof( SLOG_bytesize_t ); SLOG_typesz[ rtype_t ] = sizeof( SLOG_rectype_t ); SLOG_typesz[ itype_t ] = sizeof( SLOG_intvltype_t ); SLOG_typesz[ bebit_t ] = sizeof( SLOG_bebit_t ); SLOG_typesz[ bebits_t ] = sizeof( SLOG_bebits_t ); SLOG_typesz[ stime_t ] = sizeof( SLOG_starttime_t ); SLOG_typesz[ dura_t ] = sizeof( SLOG_duration_t ); SLOG_typesz[ nodeID_t ] = sizeof( SLOG_nodeID_t ); SLOG_typesz[ cpuID_t ] = sizeof( SLOG_cpuID_t ); SLOG_typesz[ thID_t ] = sizeof( SLOG_threadID_t ); SLOG_typesz[ taskID_t ] = SLOG_typesz[ nodeID_t ]#if ! defined( NOCPUID ) + SLOG_typesz[ cpuID_t ]#endif + SLOG_typesz[ thID_t ]; SLOG_typesz[ iaddr_t ] = sizeof( SLOG_iaddr_t ); SLOG_typesz[ Nassocs_t ] = sizeof( SLOG_N_assocs_t ); SLOG_typesz[ assoc_t ] = sizeof( SLOG_assoc_t ); SLOG_typesz[ Nargs_t ] = sizeof( SLOG_N_args_t ); SLOG_typesz[ arg_t ] = sizeof( SLOG_arg_t ); /* Define the byte size of the Often used datatype */ SLOG_typesz[ Header ] = SLOG_typesz[ ui32 ] * 2 + SLOG_typesz[ ui32 ] * 3 + SLOG_typesz[ ui16 ] * 3 + SLOG_typesz[ fptr ] * 6; SLOG_typesz[ FrameDirHdr ] = SLOG_typesz[ fptr ] * 2 + SLOG_typesz[ ui32 ]; SLOG_typesz[ FrameDirEntry ] = SLOG_typesz[ fptr ] + SLOG_typesz[ ts ] * 2; SLOG_typesz[ FrameHdr ] = SLOG_typesz[ ui32 ] * 8; SLOG_typesz[ min_IntvlRec ] = SLOG_typesz[ sz_t ] + SLOG_typesz[ rtype_t ] + SLOG_typesz[ itype_t ] + SLOG_typesz[ bebits_t ] + SLOG_typesz[ stime_t ] + SLOG_typesz[ dura_t ] + SLOG_typesz[ taskID_t ]#if ! defined( NOINSTRUCTION ) + SLOG_typesz[ iaddr_t ]#endif ; /* SLOG_typesz[ min_IntvlRec ] has to match actual bytesize written to the slogfile for a minimal interval record */ SLOG_global.MinRectype4VarDiagRec = 0; SLOG_global.MaxRectype4VarDiagRec = 63; SLOG_global.MinRectype4FixDiagRec = 64; SLOG_global.MaxRectype4FixDiagRec = 127; SLOG_global.MinRectype4VarOffdRec = 128; SLOG_global.MaxRectype4VarOffdRec = 191; SLOG_global.MinRectype4FixOffdRec = 192; SLOG_global.MaxRectype4FixOffdRec = 255;}/* Create/allocate the data structure SLOG_STREAM and open the file descriptor*/SLOG_STREAM *SLOG_OpenStream( const char *path, const char *mode ){ SLOG_STREAM *slog; if ( strlen( mode ) < 2 ) { fprintf( errfile, __FILE__":SLOG_OpenStream( %s, %s ) - " "The input file mode string %s is too short\n", path, mode, mode ); fflush( errfile ); return NULL; } if ( strchr( mode, 'b' ) == NULL ) { fprintf( errfile, __FILE__":SLOG_OpenStream( %s, %s ) - " "The input file mode string %s does NOT specify " "binary file mode(b)\n", path, mode, mode ); fflush( errfile ); return NULL; } slog = ( SLOG_STREAM * ) malloc ( sizeof ( SLOG_STREAM ) ); if ( slog == NULL ) { fprintf( errfile, __FILE__":SLOG_OpenStream( %s, %s ) - " "malloc() fails\n", path, mode ); fflush( errfile ); return NULL; } slog->fd = fopen( path, mode ); if ( slog->fd == NULL ) { fprintf( errfile, __FILE__":SLOG_OpenStream( %s, %s ) - " "fopen() fails\n", path, mode ); fflush( errfile ); SLOG_CloseStream( slog ); return NULL; } if ( mode[0] != 'w' && mode[0] != 'r' ) { fprintf( errfile, __FILE__":SLOG_OpenStream( %s, %s ) - " "The input file mode string %s is NEITHER for " "writing(w) NOR for reading(r)\n", path, mode, mode ); fflush( errfile ); SLOG_CloseStream( slog ); return NULL; } /* Initialize the various pointers in SLOG_STREAM */ slog->HasIrec2IOStreamBeenUsed = SLOG_FALSE; slog->prev_starttime = SLOG_time_NULL; slog->prev_endtime = SLOG_time_NULL; slog->fbuf = NULL; slog->hdr = NULL; slog->pstat = NULL; slog->pview = NULL; slog->prof = NULL; slog->thread_tab = NULL; slog->rec_defs = NULL; slog->cur_bbuf = NULL; slog->inc_bbuf = NULL; slog->pas_bbuf = NULL; slog->out_bbuf = NULL; slog->tmp_bbuf = NULL; /* For Write API */ slog->ptr2bbuf = NULL; /* For Read API */ slog->reserve = NULL; /* For Write API */ return slog;}/* Close/free the components of data structre SLOG_STREAM*/int SLOG_CloseStream( SLOG_STREAM *slog ){#if defined( DEBUG ) int ierr; /* error return code */#endif if ( ( slog->frame_dir ).entries != NULL ) { free( ( slog->frame_dir ).entries ); ( slog->frame_dir ).entries = NULL; } /* The order of the following subroutine calls here is in reverse order of that in SLOG_OpenStream() */ SLOG_STM_FreeBbufs( slog ); SLOG_RDEF_Free( slog->rec_defs ); SLOG_TTAB_Free( slog->thread_tab ); SLOG_PROF_Free( slog->prof ); SLOG_PVIEW_Free( slog->pview ); SLOG_PSTAT_Free( slog->pstat ); SLOG_HDR_Free( slog->hdr );#if defined( DEBUG ) ierr = fclose( slog->fd ); if ( ierr ) { fprintf( errfile, __FILE__":SLOG_CloseStream() - fclose() " "fails with ierr = %d\n", ierr ); fflush( errfile ); return SLOG_FAIL; } #else fclose( slog->fd );#endif if ( slog != NULL ) { free( slog ); slog = NULL; } return SLOG_SUCCESS;}int SLOG_STM_CreateBbufs( SLOG_STREAM *slog ){ /* allocate the file buffer data structure for IO buffering */ slog->fbuf = fbuf_create( slog->hdr->frame_bytesize ); if ( slog->fbuf == NULL ) { fprintf( errfile, __FILE__":SLOG_STM_CreateBbufs() - " "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 ); /* Create the various linked lists in the SLOG_STREAM */ slog->cur_bbuf = ( SLOG_intvlrec_blist_t * ) malloc( sizeof( SLOG_intvlrec_blist_t ) ); if ( slog->cur_bbuf == NULL ) { fprintf( errfile, __FILE__":SLOG_STM_CreateBbufs() - " "malloc( CUR_BBUF ) fails\n" ); fflush( errfile ); SLOG_CloseStream( slog ); return SLOG_FAIL; } slog->inc_bbuf = ( SLOG_intvlrec_blist_t * ) malloc( sizeof( SLOG_intvlrec_blist_t ) ); if ( slog->inc_bbuf == NULL ) { fprintf( errfile, __FILE__":SLOG_STM_CreateBbufs() - " "malloc( INC_BBUF ) fails\n" ); fflush( errfile ); SLOG_CloseStream( slog ); return SLOG_FAIL; } slog->pas_bbuf = ( SLOG_intvlrec_blist_t * ) malloc( sizeof( SLOG_intvlrec_blist_t ) ); if ( slog->pas_bbuf == NULL ) { fprintf( errfile, __FILE__":SLOG_STM_CreateBbufs() - " "malloc( PAS_BBUF ) fails\n" ); fflush( errfile ); SLOG_CloseStream( slog ); return SLOG_FAIL; } slog->out_bbuf = ( SLOG_intvlrec_blist_t * ) malloc( sizeof( SLOG_intvlrec_blist_t ) ); if ( slog->out_bbuf == NULL ) { fprintf( errfile, __FILE__":SLOG_STM_CreateBbufs() - " "malloc( OUT_BBUF ) fails\n" ); fflush( errfile ); SLOG_CloseStream( slog ); return SLOG_FAIL; } slog->tmp_bbuf = ( SLOG_intvlrec_blist_t * ) malloc( sizeof( SLOG_intvlrec_blist_t ) ); if ( slog->tmp_bbuf == NULL ) { fprintf( errfile, __FILE__":SLOG_STM_CreateBbufs() - " "malloc( TMP_BBUF ) fails\n" ); fflush( errfile ); SLOG_CloseStream( slog ); return SLOG_FAIL; } return SLOG_SUCCESS;}void SLOG_STM_FreeBbufs( SLOG_STREAM *slog ){ SLOG_Bbuf_Free( slog->tmp_bbuf ); SLOG_Bbuf_Free( slog->out_bbuf ); SLOG_Bbuf_Free( slog->pas_bbuf ); SLOG_Bbuf_Free( slog->inc_bbuf ); SLOG_Bbuf_Free( slog->cur_bbuf ); fbuf_free( slog->fbuf );}int SLOG_WriteInitFrameDir( SLOG_STREAM *slog ){ int ii; /* Initialization of the frame directory */ ( slog->frame_dir ).prevdir = SLOG_fptr_NULL; ( slog->frame_dir ).nextdir = SLOG_fptr_NULL; ( slog->frame_dir ).Nframe = 0; ( slog->frame_dir ).entries = ( SLOG_dir_entry_t * ) malloc( slog->hdr->max_Ndirframe * sizeof( SLOG_dir_entry_t ) ); if ( slog->hdr->max_Ndirframe > 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -