Пример #1
0
/***************************************************************************
Desc:	This routine changed a database header to native platform format.
*****************************************************************************/
void convertDbHdr(
	XFLM_DB_HDR *	pDbHdr
	)
{

	// This routine should only be called to convert a header to native
	// format.

	flmAssert( hdrIsNonNativeFormat( pDbHdr));
	convert16( &pDbHdr->ui16BlockSize);
	convert32( &pDbHdr->ui32DbVersion);
	convert64( &pDbHdr->ui64LastRflCommitID);
	convert32( &pDbHdr->ui32RflLastFileNumDeleted);
	convert32( &pDbHdr->ui32RflCurrFileNum);
	convert32( &pDbHdr->ui32RflLastTransOffset);
	convert32( &pDbHdr->ui32RflLastCPFileNum);
	convert32( &pDbHdr->ui32RflLastCPOffset);
	convert64( &pDbHdr->ui64RflLastCPTransID);
	convert32( &pDbHdr->ui32RflMinFileSize);
	convert32( &pDbHdr->ui32RflMaxFileSize);
	convert64( &pDbHdr->ui64CurrTransID);
	convert64( &pDbHdr->ui64TransCommitCnt);
	convert32( &pDbHdr->ui32RblEOF);
	convert32( &pDbHdr->ui32RblFirstCPBlkAddr);
	convert32( &pDbHdr->ui32FirstAvailBlkAddr);
	convert32( &pDbHdr->ui32FirstLFBlkAddr);
	convert32( &pDbHdr->ui32LogicalEOF);
	convert32( &pDbHdr->ui32MaxFileSize);
	convert64( &pDbHdr->ui64LastBackupTransID);
	convert32( &pDbHdr->ui32IncBackupSeqNum);
	convert32( &pDbHdr->ui32BlksChangedSinceBackup);
	convert32( &pDbHdr->ui32HdrCRC);
	pDbHdr->ui8IsLittleEndian = XFLM_NATIVE_IS_LITTLE_ENDIAN;
}
void TraceReaderBase::ReadTraceHeader(FILE *fstream, char *filename,
                                      char *tracename, TraceHeader *header)
{
    int rval = fread(header, sizeof(TraceHeader), 1, fstream);
    if (rval != 1) {
        perror(filename);
        exit(1);
    }

    if (!post_processing_ && strcmp(header->ident, TRACE_IDENT) != 0) {
        fprintf(stderr, "%s: missing trace header; run 'post_trace %s' first\n",
                filename, tracename);
        exit(1);
    }

    if (header->version != TRACE_VERSION) {
        fprintf(stderr,
                "%s: trace header version (%d) does not match compiled tools version (%d)\n",
                tracename, header->version, TRACE_VERSION);
        exit(1);
    }

    convert32(header->version);
    convert32(header->start_sec);
    convert32(header->start_usec);
    convert32(header->pdate);
    convert32(header->ptime);
    convert64(header->num_static_bb);
    convert64(header->num_static_insn);
    convert64(header->num_dynamic_bb);
    convert64(header->num_dynamic_insn);
    convert64(header->elapsed_usecs);
}
void TraceReaderBase::WriteHeader(TraceHeader *header)
{
    TraceHeader swappedHeader;

    freopen(static_filename_, "r+", static_fstream_);
    fseek(static_fstream_, 0, SEEK_SET);

    memcpy(&swappedHeader, header, sizeof(TraceHeader));

    convert32(swappedHeader.version);
    convert32(swappedHeader.start_sec);
    convert32(swappedHeader.start_usec);
    convert32(swappedHeader.pdate);
    convert32(swappedHeader.ptime);
    convert64(swappedHeader.num_static_bb);
    convert64(swappedHeader.num_static_insn);
    convert64(swappedHeader.num_dynamic_bb);
    convert64(swappedHeader.num_dynamic_insn);
    convert64(swappedHeader.elapsed_usecs);

    fwrite(&swappedHeader, sizeof(TraceHeader), 1, static_fstream_);
}
// Reads the next StaticRec from the trace file (not including the list
// of instructions).  On end-of-file, this function returns true.
int TraceReaderBase::ReadStatic(StaticRec *rec)
{
    int rval = fread(rec, sizeof(StaticRec), 1, static_fstream_);
    if (rval != 1) {
        if (feof(static_fstream_)) {
            return true;
        }
        perror(static_filename_);
        exit(1);
    }
    convert64(rec->bb_num);
    convert32(rec->bb_addr);
    convert32(rec->num_insns);
    return false;
}