src/ppe/tools/ppetracepp/ppe2fsp.c
//retrieve a ppe trace entry from a ppe trace buffer
retrieve a ppe trace entry from a ppe trace buffer
retrieve a ppe trace entry from a ppe trace buffer
size_t ppe_get_entry(PkTraceBuffer* tb, uint32_t offset, LargestPpeEntry* pte)
{
    uint32_t            mask = ntohs(tb->size) - 1;
    PkTraceEntryFooter* footer;
    size_t              entry_size;
    size_t              parm_size;
    char*               dest = (char*)pte;
    uint32_t            format;
    uint32_t            start_index;
    uint32_t            bytes_left;
    uint32_t            bytes_to_copy;
    footer = (PkTraceEntryFooter*)(&tb->cb[(offset - sizeof(PkTraceEntryFooter)) & mask]);
    pte->footer.generic.time_format.word32 = ntohl(footer->generic.time_format.word32);
    pte->footer.generic.string_id = ntohs(footer->generic.string_id);
    pte->footer.generic.parm16 = footer->generic.parm16; 
    format = PK_GET_TRACE_FORMAT(pte->footer.generic.time_format.word32);
    switch(format)
    {
        case PK_TRACE_FORMAT_TINY:
            pte->footer.generic.parm16 = ntohs(pte->footer.generic.parm16);
            parm_size = 0;
            entry_size = sizeof(PkTraceEntryFooter);
            break;
        case PK_TRACE_FORMAT_BIG:
            parm_size = pte->footer.generic.bytes_or_parms_count * sizeof(uint32_t);
            entry_size = sizeof(PkTraceEntryFooter);
            break;
        case PK_TRACE_FORMAT_BINARY:
            parm_size = pte->footer.generic.bytes_or_parms_count;
            entry_size = sizeof(PkTraceEntryFooter); 
            break;
        default:
            entry_size = 0;
            parm_size = 0;
            break;
    }
    parm_size = (parm_size + 7) & ~0x00000007ul;
    entry_size += parm_size;
    start_index = (offset - entry_size) & mask;
    bytes_left = ntohs(tb->size) - start_index;
    if(parm_size < bytes_left)
    {
        bytes_to_copy = parm_size;
    }
    else
    {
        bytes_to_copy = bytes_left;
    }
    dest += sizeof(LargestPpeEntry) - entry_size;
    memcpy(dest, &tb->cb[start_index], bytes_to_copy);
    if(bytes_to_copy < parm_size)
    {
        memcpy(dest + bytes_to_copy, tb->cb, parm_size - bytes_to_copy);
    }
    return entry_size;
}
size_t ppe_get_entry ( PkTraceBuffer * tb , uint32_t offset , LargestPpeEntry * pte ) { uint32_t mask = ntohs ( tb -> size ) - 1 ; PkTraceEntryFooter * footer ; size_t entry_size ; size_t parm_size ; char * dest = ( char * ) pte ; uint32_t format ; uint32_t start_index ; uint32_t bytes_left ; uint32_t bytes_to_copy ; footer = ( PkTraceEntryFooter * ) ( & tb -> cb [ ( offset - sizeof ( PkTraceEntryFooter ) ) & mask ] ) ; pte -> footer . generic . time_format . word32 = ntohl ( footer -> generic . time_format . word32 ) ; pte -> footer . generic . string_id = ntohs ( footer -> generic . string_id ) ; pte -> footer . generic . parm16 = footer -> generic . parm16 ; format = PK_GET_TRACE_FORMAT ( pte -> footer . generic . time_format . word32 ) ; switch ( format ) { case PK_TRACE_FORMAT_TINY : pte -> footer . generic . parm16 = ntohs ( pte -> footer . generic . parm16 ) ; parm_size = 0 ; entry_size = sizeof ( PkTraceEntryFooter ) ; break ; case PK_TRACE_FORMAT_BIG : parm_size = pte -> footer . generic . bytes_or_parms_count * sizeof ( uint32_t ) ; entry_size = sizeof ( PkTraceEntryFooter ) ; break ; case PK_TRACE_FORMAT_BINARY : parm_size = pte -> footer . generic . bytes_or_parms_count ; entry_size = sizeof ( PkTraceEntryFooter ) ; break ; default : entry_size = 0 ; parm_size = 0 ; break ; } parm_size = ( parm_size + 7 ) & ~ 0x00000007ul ; entry_size += parm_size ; start_index = ( offset - entry_size ) & mask ; bytes_left = ntohs ( tb -> size ) - start_index ; if ( parm_size < bytes_left ) { bytes_to_copy = parm_size ; } else { bytes_to_copy = bytes_left ; } dest += sizeof ( LargestPpeEntry ) - entry_size ; memcpy ( dest , & tb -> cb [ start_index ] , bytes_to_copy ) ; if ( bytes_to_copy < parm_size ) { memcpy ( dest + bytes_to_copy , tb -> cb , parm_size - bytes_to_copy ) ; } return entry_size ; }
retrieve a ppe trace entry from a ppe trace buffer
retrieve a ppe trace entry from a ppe trace buffer
//Find the footer in the circular buffer //always correct endianess for the time and string id words //only need to byte swap the parm16 value if this is a tiny format //use footer data to determine the length of the binary data or parameters //pad to 8 byte boundary //add the parameter size to the total entry size //copy the entry from the circular buffer to pte //only copy up to the end of the circular buffer //now copy the rest of the data starting from the beginning of the //circular buffer. //return the size of the entry 