src/ppe/tools/ppetracepp/ppe2fsp.c
//convert a ppe trace entry to an fsp trace entry
convert a ppe trace entry to an fsp trace entry
convert a ppe trace entry to an fsp trace entry
size_t pte2fte(PkTraceBuffer* ptb,
               LargestPpeEntry* pte,
               size_t pte_size,
               largest_fsp_entry_t* fte,
               uint64_t ppe_time64)
{
    size_t              entry_size;
    PkTraceGeneric*     pte_footer = &pte->footer.generic;
    uint32_t            format;
    uint32_t            hash32;
    uint32_t            hash32_partial;
    uint32_t*           parm_start;
    uint32_t            parm_bytes;
    uint64_t            fsp_time64;
    fsp_time64 = ppe2fsp_time(ppe_time64, ntohl(ptb->hz));
    fte->stamp.tbh = htonl((uint32_t)(fsp_time64 >> 32));
    fte->stamp.tbl = htonl((uint32_t)(fsp_time64 & 0x00000000ffffffffull));
    fte->stamp.tid = htonl((uint32_t)ntohs(ptb->instance_id));
    hash32 = ((uint32_t)ntohs(ptb->hash_prefix)) << 16;
    hash32 |= pte_footer->string_id;
    fte->head.hash = htonl(hash32);
    hash32_partial = ((uint32_t)ntohs(ptb->hash_prefix)) << 16;
    hash32_partial |= ntohs(ptb->partial_trace_hash);
    fte->head.line = htonl(1);
    format = PK_GET_TRACE_FORMAT(pte_footer->time_format.word32);
    if(format == PK_TRACE_FORMAT_BINARY)
    {
        fte->head.tag = htons(TRACE_FIELDBIN);
    }
    else
    {
        fte->head.tag = htons(TRACE_FIELDTRACE);
    }
    parm_start = (uint32_t*)(((char*)pte) + (sizeof(LargestPpeEntry) - pte_size));
    switch(format)
    {
        case PK_TRACE_FORMAT_TINY:
            entry_size = sizeof(trace_entry_stamp_t) +
                         sizeof(trace_entry_head_t) +
                         sizeof(uint32_t);
            fte->parms[0] = htonl((uint32_t)(pte_footer->parm16));
            fte->head.length = htons(sizeof(uint32_t));
            parm_bytes = 0;
            break;
        case PK_TRACE_FORMAT_BIG:
            If the trace entry data is incomplete (not all parm data
            had been written at the time the trace was captured) then
            we will write a trace to the fsp buffer that says
            "PARTIAL TRACE ENTRY.  HASH_ID = %d"
            if(pte_footer->complete)
            {
                parm_bytes = pte_footer->bytes_or_parms_count * sizeof(uint32_t);
                fte->head.length = htons(parm_bytes + sizeof(uint32_t));
                entry_size = sizeof(trace_entry_stamp_t) +
                             sizeof(trace_entry_head_t) + 
                             parm_bytes + sizeof(uint32_t); 
            }
            else
            {
                parm_bytes = 0;
                entry_size = sizeof(trace_entry_stamp_t) + 
                             sizeof(trace_entry_head_t) +
                             sizeof(uint32_t);
                fte->parms[0] = fte->head.hash; already corrected for endianess
                fte->head.hash = htonl(hash32_partial);
                fte->head.length = htons(sizeof(uint32_t));
            }
            break;
        case PK_TRACE_FORMAT_BINARY:
            If the trace entry data is incomplete (not all parm data
            had been written at the time the trace was captured) then
            we will write a trace to the fsp buffer that says
            "PARTIAL TRACE ENTRY.  HASH_ID = %d"
            if(pte_footer->complete)
            {
                parm_bytes = pte_footer->bytes_or_parms_count;
                fte->head.length = htons((uint16_t)parm_bytes);
                entry_size = sizeof(trace_entry_stamp_t) +
                             sizeof(trace_entry_head_t) + 
                             parm_bytes;
                pad to 4 byte boundary
                entry_size = (entry_size + 3) & ~3;
            }
            else
            {
                parm_bytes = 0;
                entry_size = sizeof(trace_entry_stamp_t) + 
                             sizeof(trace_entry_head_t) +
                             sizeof(uint32_t);
                fte->parms[0] = fte->head.hash;
                fte->head.hash = htonl(hash32_partial);
                fte->head.length = htons(sizeof(uint32_t));
                fte->head.tag = htons(TRACE_FIELDTRACE);
            }
            break;
        default:
            entry_size = 0;
            parm_bytes = 0;
            break;
    }
    copy parameter bytes to the fsp entry if necessary
    if(parm_bytes)
    {
        memcpy(fte->data, parm_start, parm_bytes);
    }
    add the entry size to the end
    if(entry_size)
    {
        uint32_t new_entry_size = entry_size + sizeof(uint32_t);
        *((uint32_t*)(((char*)fte) + entry_size)) = htonl(new_entry_size);
        entry_size = new_entry_size;
    }
    return entry_size;
}
size_t pte2fte ( PkTraceBuffer * ptb , LargestPpeEntry * pte , size_t pte_size , largest_fsp_entry_t * fte , uint64_t ppe_time64 ) { size_t entry_size ; PkTraceGeneric * pte_footer = & pte -> footer . generic ; uint32_t format ; uint32_t hash32 ; uint32_t hash32_partial ; uint32_t * parm_start ; uint32_t parm_bytes ; uint64_t fsp_time64 ; fsp_time64 = ppe2fsp_time ( ppe_time64 , ntohl ( ptb -> hz ) ) ; fte -> stamp . tbh = htonl ( ( uint32_t ) ( fsp_time64 >> 32 ) ) ; fte -> stamp . tbl = htonl ( ( uint32_t ) ( fsp_time64 & 0x00000000ffffffffull ) ) ; fte -> stamp . tid = htonl ( ( uint32_t ) ntohs ( ptb -> instance_id ) ) ; hash32 = ( ( uint32_t ) ntohs ( ptb -> hash_prefix ) ) << 16 ; hash32 |= pte_footer -> string_id ; fte -> head . hash = htonl ( hash32 ) ; hash32_partial = ( ( uint32_t ) ntohs ( ptb -> hash_prefix ) ) << 16 ; hash32_partial |= ntohs ( ptb -> partial_trace_hash ) ; fte -> head . line = htonl ( 1 ) ; format = PK_GET_TRACE_FORMAT ( pte_footer -> time_format . word32 ) ; if ( format == PK_TRACE_FORMAT_BINARY ) { fte -> head . tag = htons ( TRACE_FIELDBIN ) ; } else { fte -> head . tag = htons ( TRACE_FIELDTRACE ) ; } parm_start = ( uint32_t * ) ( ( ( char * ) pte ) + ( sizeof ( LargestPpeEntry ) - pte_size ) ) ; switch ( format ) { case PK_TRACE_FORMAT_TINY : entry_size = sizeof ( trace_entry_stamp_t ) + sizeof ( trace_entry_head_t ) + sizeof ( uint32_t ) ; fte -> parms [ 0 ] = htonl ( ( uint32_t ) ( pte_footer -> parm16 ) ) ; fte -> head . length = htons ( sizeof ( uint32_t ) ) ; parm_bytes = 0 ; break ; case PK_TRACE_FORMAT_BIG : if ( pte_footer -> complete ) { parm_bytes = pte_footer -> bytes_or_parms_count * sizeof ( uint32_t ) ; fte -> head . length = htons ( parm_bytes + sizeof ( uint32_t ) ) ; entry_size = sizeof ( trace_entry_stamp_t ) + sizeof ( trace_entry_head_t ) + parm_bytes + sizeof ( uint32_t ) ; } else { parm_bytes = 0 ; entry_size = sizeof ( trace_entry_stamp_t ) + sizeof ( trace_entry_head_t ) + sizeof ( uint32_t ) ; fte -> parms [ 0 ] = fte -> head . hash ; fte -> head . hash = htonl ( hash32_partial ) ; fte -> head . length = htons ( sizeof ( uint32_t ) ) ; } break ; case PK_TRACE_FORMAT_BINARY : if ( pte_footer -> complete ) { parm_bytes = pte_footer -> bytes_or_parms_count ; fte -> head . length = htons ( ( uint16_t ) parm_bytes ) ; entry_size = sizeof ( trace_entry_stamp_t ) + sizeof ( trace_entry_head_t ) + parm_bytes ; entry_size = ( entry_size + 3 ) & ~ 3 ; } else { parm_bytes = 0 ; entry_size = sizeof ( trace_entry_stamp_t ) + sizeof ( trace_entry_head_t ) + sizeof ( uint32_t ) ; fte -> parms [ 0 ] = fte -> head . hash ; fte -> head . hash = htonl ( hash32_partial ) ; fte -> head . length = htons ( sizeof ( uint32_t ) ) ; fte -> head . tag = htons ( TRACE_FIELDTRACE ) ; } break ; default : entry_size = 0 ; parm_bytes = 0 ; break ; } if ( parm_bytes ) { memcpy ( fte -> data , parm_start , parm_bytes ) ; } if ( entry_size ) { uint32_t new_entry_size = entry_size + sizeof ( uint32_t ) ; * ( ( uint32_t * ) ( ( ( char * ) fte ) + entry_size ) ) = htonl ( new_entry_size ) ; entry_size = new_entry_size ; } return entry_size ; }
convert a ppe trace entry to an fsp trace entry
convert a ppe trace entry to an fsp trace entry
//convert the ppe trace time to an fsp trace time //fill in the 64 bit timestamp //use the ppe instance id as the thread id. //merge the hash prefix and the string_id fields together for a 32 bit hash value //generate the 32bit hash value for a partial trace entry in case it's needed //set the line number to 1 //determine the FSP trace format //fill in the parameters/binary data and size at the end //one or 0 parameters //1 - 4 parameters // //If the trace entry data is incomplete (not all parm data //had been written at the time the trace was captured) then //we will write a trace to the fsp buffer that says //"PARTIAL TRACE ENTRY.  HASH_ID = %d" //already corrected for endianess //If the trace entry data is incomplete (not all parm data //had been written at the time the trace was captured) then //we will write a trace to the fsp buffer that says //"PARTIAL TRACE ENTRY.  HASH_ID = %d" //pad to 4 byte boundary //copy parameter bytes to the fsp entry if necessary //add the entry size to the end