📄 slog_irec_common.c
字号:
SLOG_typesz[ stime_t ], 1, fbuf ); if ( ierr < 1 ) { fprintf( errfile, __FILE__":SLOG_Irec_WithdrawFromFbuf() - Cannot " "withdraw the STARTtime from the SLOG filebuffer, " fmt_ui32" bytes read so far\n", Nbytes_read ); fprintf( errfile, " ""irec = " ); SLOG_Irec_Print( irec, errfile ); fprintf( errfile, "\n" ); fflush( errfile ); free( irec ); return NULL; } Nbytes_read += ierr * SLOG_typesz[ stime_t ]; ierr = fbuf_withdraw( &( irec->duration ), SLOG_typesz[ dura_t ], 1, fbuf ); if ( ierr < 1 ) { fprintf( errfile, __FILE__":SLOG_Irec_WithdrawFromFbuf() - Cannot " "withdraw the DURATION from the SLOG filebuffer, " fmt_ui32" bytes read so far\n", Nbytes_read ); fprintf( errfile, " ""irec = " ); SLOG_Irec_Print( irec, errfile ); fprintf( errfile, "\n" ); fflush( errfile ); free( irec ); return NULL; } Nbytes_read += ierr * SLOG_typesz[ dura_t ]; ierr = SLOG_TaskID_WithdrawFromFbuf( &( irec->origID ), fbuf ); if ( ierr < (int)SLOG_typesz[ taskID_t ] ) { fprintf( errfile, __FILE__":SLOG_Irec_WithdrawFromFbuf() - Cannot " "withdraw the Origin Task IDs from the SLOG " "filebuffer, "fmt_ui32" bytes read so far\n", Nbytes_read ); fprintf( errfile, " ""irec = " ); SLOG_Irec_Print( irec, errfile ); fprintf( errfile, "\n" ); fflush( errfile ); free( irec ); return NULL; } Nbytes_read += ierr; if ( SLOG_global_IsOffDiagRec( irec->rectype ) ) { ierr = SLOG_TaskID_WithdrawFromFbuf( &( irec->destID ), fbuf ); if ( ierr < (int)SLOG_typesz[ taskID_t ] ) { fprintf( errfile, __FILE__":SLOG_Irec_WithdrawFromFbuf() - Cannot " "withdraw the Destination Task IDs from the SLOG " "filebuffer, "fmt_ui32" bytes read so far\n", Nbytes_read ); fprintf( errfile, " ""irec = " ); SLOG_Irec_Print( irec, errfile ); fprintf( errfile, "\n" ); fflush( errfile ); free( irec ); return NULL; } Nbytes_read += ierr; }#if ! defined( NOINSTRUCTION ) ierr = fbuf_withdraw( &( irec->instr_addr ), SLOG_typesz[ iaddr_t ], 1, fbuf ); if ( ierr < 1 ) { fprintf( errfile, __FILE__":SLOG_Irec_WithdrawFromFbuf() - Cannot " "withdraw the Instruction Address from the SLOG " "filebuffer, " fmt_ui32" bytes read so far\n", Nbytes_read ); fprintf( errfile, " ""irec = " ); SLOG_Irec_Print( irec, errfile ); fprintf( errfile, "\n" ); fflush( errfile ); free( irec ); return NULL; } Nbytes_read += ierr * SLOG_typesz[ iaddr_t ];#else irec->instr_addr = SLOG_iaddr_NULL;#endif ierr = SLOG_RecDef_NumOfAssocs( slog_recdefs, irec->intvltype, irec->bebits[0], irec->bebits[1] ); if ( ierr == SLOG_FAIL ) { fprintf( errfile, __FILE__":SLOG_Irec_WithdrawFromFbuf() - " "SLOG_RecDef_NumOfAssocs() fails !!\n" ); fprintf( errfile, " ""irec = " ); SLOG_Irec_Print( irec, errfile ); fprintf( errfile, "\n" ); fflush( errfile ); free( irec ); return NULL; } if ( ierr > 0 ) irec->N_assocs = ierr; else irec->N_assocs = 0; if ( irec->N_assocs > 0 ) { irec->assocs = ( SLOG_assoc_t * ) malloc( irec->N_assocs * sizeof( SLOG_assoc_t ) ); if ( irec->N_assocs > 0 && irec->assocs == NULL ) { fprintf( errfile, __FILE__":SLOG_Irec_WithdrawFromFbuf() - " "malloc() for irec->assocs fails\n" ); fflush( errfile ); free( irec ); return NULL; } ierr = fbuf_withdraw( irec->assocs, SLOG_typesz[ assoc_t ], irec->N_assocs, fbuf ); if ( ierr < irec->N_assocs ) { fprintf( errfile, __FILE__":SLOG_Irec_WithdrawFromFbuf() - Cannot " "withdraw the ASSOCIATIONs from the SLOG " "filebuffer, "fmt_ui32" bytes read so far\n", Nbytes_read ); fprintf( errfile, " ""irec = " ); SLOG_Irec_Print( irec, errfile ); fprintf( errfile, "\n" ); fflush( errfile ); free( irec ); return NULL; } Nbytes_read += ierr * SLOG_typesz[ assoc_t ]; } /* Endof if ( irec->N_assocs > 0 ) */ if ( SLOG_global_IsVarRec( irec->rectype ) ) { for ( count = 0; Nbytes_read < irec->bytesize; count ++ ) { ierr = fbuf_withdraw( &N_args, SLOG_typesz[ Nargs_t ], 1, fbuf ); if ( ierr < 1 ) { fprintf( errfile, __FILE__":SLOG_Irec_WithdrawFromFbuf() - " "Cannot withdraw the %d-th ARGS's size " "to the SLOG filebuffer\n", count ); fprintf( errfile, " ""The Irec's bytesize = "fmt_sz_t"\n", irec->bytesize ); fprintf( errfile, " "fmt_ui32" bytes read so far\n", Nbytes_read ); fprintf( errfile, " ""irec = " ); SLOG_Irec_Print( irec, errfile ); fprintf( errfile, "\n" ); fflush( errfile ); free( irec ); return NULL; } Nbytes_read += ierr * SLOG_typesz[ Nargs_t ]; vtr_args = SLOG_Varg_Create( N_args, NULL ); if ( vtr_args != NULL ) { ierr = fbuf_withdraw( vtr_args->values, SLOG_typesz[ arg_t ], vtr_args->size, fbuf ); if ( ierr < vtr_args->size ) { fprintf( errfile, __FILE__":SLOG_Irec_WithdrawFromFbuf() - " "Cannot withdraw the %d-th " "ARGS[0:"fmt_Nargs_t"-1] to the SLOG " "filebuffer\n", count, vtr_args->size ); fprintf( errfile, " ""The Irec's bytesize = " fmt_sz_t"\n", irec->bytesize ); fprintf( errfile, " "fmt_ui32" bytes read so far\n", Nbytes_read ); fprintf( errfile, " ""irec = " ); SLOG_Irec_Print( irec, errfile ); fprintf( errfile, "\n" ); fflush( errfile ); free( irec ); return NULL; } Nbytes_read += ierr * SLOG_typesz[ arg_t ]; } if ( SLOG_Irec_AddVtrArgs( irec, vtr_args ) != SLOG_SUCCESS ) { fprintf( errfile, __FILE__":SLOG_Irec_WithdrawFromFbuf() - " "The %d-th SLOG_Irec_AddVtrArgs() fails\n", count ); fprintf( errfile, " ""irec = " ); SLOG_Irec_Print( irec, errfile ); fprintf( errfile, "\n" ); fflush( errfile ); free( irec ); return NULL; } } /* for ( count = 0; Nbytes_read < irec->bytesize; count ++ ) */ } else { /* if ( SLOG_global_IsVarRec( irec->rectype ) ) */ ierr = SLOG_RecDef_NumOfArgs( slog_recdefs, irec->intvltype, irec->bebits[0], irec->bebits[1] ); if ( ierr == SLOG_FAIL ) { fprintf( errfile, __FILE__":SLOG_Irec_WithdrawFromFbuf() - " "SLOG_RecDef_NumOfArgs() fails !!\n" ); fprintf( errfile, " ""irec = " ); SLOG_Irec_Print( irec, errfile ); fprintf( errfile, "\n" ); fflush( errfile ); free( irec ); return NULL; } if ( ierr > 0 ) N_args = ierr; else N_args = 0; vtr_args = SLOG_Varg_Create( N_args, NULL ); if ( vtr_args != NULL ) { ierr = fbuf_withdraw( vtr_args->values, SLOG_typesz[ arg_t ], vtr_args->size, fbuf ); if ( ierr < vtr_args->size ) { fprintf( errfile, __FILE__":SLOG_Irec_WithdrawFromFbuf() - " "Cannot withdraw " "ARGS[0:"fmt_Nargs_t"-1] to the SLOG " "filebuffer\n", vtr_args->size ); fprintf( errfile, " ""The Irec's bytesize = " fmt_sz_t"\n", irec->bytesize ); fprintf( errfile, " "fmt_ui32" bytes read so far\n", Nbytes_read ); fprintf( errfile, " ""irec = " ); SLOG_Irec_Print( irec, errfile ); fprintf( errfile, "\n" ); fflush( errfile ); free( irec ); return NULL; } Nbytes_read += ierr * SLOG_typesz[ arg_t ]; } if ( SLOG_Irec_AddVtrArgs( irec, vtr_args ) != SLOG_SUCCESS ) { fprintf( errfile, __FILE__":SLOG_Irec_WithdrawFromFbuf() - " "SLOG_Irec_AddVtrArgs() fails\n" ); fprintf( errfile, " ""irec = " ); SLOG_Irec_Print( irec, errfile ); fprintf( errfile, "\n" ); fflush( errfile ); free( irec ); return NULL; } } /* Endof if ( SLOG_global_IsVarRec( irec->rectype ) ) */#if defined (DEBUG) /* Consistency check if withdrawn number of bytes is as expected */ if ( Nbytes_read != irec->bytesize ) { fprintf( errfile, __FILE__":SLOG_Irec_WithdrawFromFbuf() - " "Nbytes_read = "fmt_ui32", but irec->bytesize = " fmt_sz_t"\n", Nbytes_read, irec->bytesize ); fprintf( errfile, " ""irec = " ); SLOG_Irec_Print( irec, errfile ); fprintf( errfile, "\n" ); fflush( errfile ); }#endif return irec;} /* Routines which interact with SLOG_Varg(i.e. SLOG_vtrarg_t *) class */int SLOG_Irec_AddVtrArgs( SLOG_intvlrec_t *irec, const SLOG_vtrarg_t *varg ){ SLOG_vtrarg_lptr_t *cur_node; if ( varg == NULL ) return SLOG_SUCCESS; cur_node = ( SLOG_vtrarg_lptr_t * ) malloc( sizeof( SLOG_vtrarg_lptr_t ) ); if ( cur_node == NULL ) { fprintf( errfile, __FILE__":SLOG_Irec_AddVtrArgs() - " "malloc() for cur_node fails\n" ); fflush( errfile ); return SLOG_FAIL; } /* Copy the input vtr_arg, varg, to the newly allocated cur_node->vtr */ cur_node->vtr = SLOG_Varg_Copy( varg ); if ( cur_node->vtr == NULL ) { fprintf( errfile, __FILE__":SLOG_Irec_AddVtrArgs() - " "SLOG_Varg_Copy() fails\n" ); fflush( errfile ); return SLOG_FAIL; } /* Attach the node to the bi-directional linked list */ cur_node->prev = irec->vtail; cur_node->next = NULL; /* this line gurantees bi-directional linked list */ if ( cur_node->prev != NULL ) /* Check if the cur_node is Irec's head, vhead->prev == NULL */ ( cur_node->prev )->next = cur_node; irec->vtail = cur_node; /* this line gurantees that the lhead is pointing at the head */ if ( irec->vhead == NULL ) irec->vhead = irec->vtail; return SLOG_SUCCESS;}/* For identical interval record, this routine returns the Vector Arguments of the interval record one by one. The return sequence is as follows: return sequence = vhead, ..., vtail, NULL, vhead, ..., vtail, NULL, ... So it is crucial that the vptr in SLOG_intvlrec_t is initialized to NULL And the routine does NOT advance the vptr before returning. The vptr is advanced when entering the routine. If the irec has NO vector arguments, i.e. vhead = NULL, the routine will always return NULL.*/const SLOG_vtrarg_t *SLOG_Irec_GetVtrArgs( SLOG_intvlrec_t *irec ){ SLOG_vtrarg_t *varg = NULL; if ( irec->vptr == NULL ) irec->vptr = irec->vhead; else irec->vptr = irec->vptr->next; if ( irec->vptr != NULL ) varg = irec->vptr->vtr; else return NULL; return varg;}void SLOG_Irec_DelAllVtrArgs( SLOG_intvlrec_t *irec ){ SLOG_vtrarg_lptr_t *vptr; if ( irec != NULL ) { while ( irec->vtail != NULL ) { vptr = irec->vtail; irec->vtail = ( irec->vtail )->prev; SLOG_Varg_Free( vptr->vtr ); free( vptr ); } irec->vhead = NULL; irec->vtail = NULL; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -