VirtualBox

Changeset 72309 in vbox


Ignore:
Timestamp:
May 24, 2018 7:23:34 AM (7 years ago)
Author:
vboxsync
Message:

Runtime/tracelogwriter.cpp: Add methods taking a list of event data items

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/mangling.h

    r72285 r72309  
    23932393# define RTTraceLogWrDestroy                            RT_MANGLER(RTTraceLogWrDestroy)
    23942394# define RTTraceLogWrEvtAdd                             RT_MANGLER(RTTraceLogWrEvtAdd)
     2395# define RTTraceLogWrEvtAddL                            RT_MANGLER(RTTraceLogWrEvtAddL)
     2396# define RTTraceLogWrEvtAddLV                           RT_MANGLER(RTTraceLogWrEvtAddLV)
    23952397# define RTTraceLogWrEvtAddSg                           RT_MANGLER(RTTraceLogWrEvtAddSg)
    23962398# define RTTraceSetDefaultBuf                           RT_MANGLER(RTTraceSetDefaultBuf)
  • trunk/include/iprt/tracelog.h

    r71503 r72309  
    413413
    414414/**
     415 * Adds a new event to the trace log - list variant.
     416 *
     417 * @returns IPRT status code.
     418 * @param   hTraceLogWr         The trace log writer instance handle.
     419 * @param   pEvtDesc            The event descriptor used for formatting the data.
     420 * @param   fFlags              Flags to use for this event.
     421 * @param   uGrpId              A unique group ID for grouped events.
     422 * @param   uParentGrpId        A parent group ID this event originated from.
     423 * @param   va                  The event data as single items as described by the descriptor.
     424 *
     425 * @note The event descriptor is keyed by the pointer for faster lookup in subsequent calls,
     426 *       so don't free after this method finishes.
     427 */
     428RTDECL(int) RTTraceLogWrEvtAddLV(RTTRACELOGWR hTraceLogWr, PCRTTRACELOGEVTDESC pEvtDesc, uint32_t fFlags,
     429                                 RTTRACELOGEVTGRPID uGrpId, RTTRACELOGEVTGRPID uParentGrpId, va_list va);
     430
     431
     432/**
     433 * Adds a new event to the trace log - list variant.
     434 *
     435 * @returns IPRT status code.
     436 * @param   hTraceLogWr         The trace log writer instance handle.
     437 * @param   pEvtDesc            The event descriptor used for formatting the data.
     438 * @param   fFlags              Flags to use for this event.
     439 * @param   uGrpId              A unique group ID for grouped events.
     440 * @param   uParentGrpId        A parent group ID this event originated from.
     441 * @param   ...                 The event data as single items as described by the descriptor.
     442 *
     443 * @note The event descriptor is keyed by the pointer for faster lookup in subsequent calls,
     444 *       so don't free after this method finishes.
     445 */
     446RTDECL(int) RTTraceLogWrEvtAddL(RTTRACELOGWR hTraceLogWr, PCRTTRACELOGEVTDESC pEvtDesc, uint32_t fFlags,
     447                                RTTRACELOGEVTGRPID uGrpId, RTTRACELOGEVTGRPID uParentGrpId, ...);
     448
     449
     450/**
    415451 * Creates a new trace log reader instance.
    416452 *
  • trunk/src/VBox/Runtime/common/log/tracelogwriter.cpp

    r71502 r72309  
    6767    /** Number of non static raw binary items in the descriptor. */
    6868    uint32_t                    cRawDataNonStatic;
     69    /** Pointer to the scratch event data buffer when adding events. */
     70    uint8_t                     *pbEvt;
    6971    /** Embedded event descriptor. */
    7072    RTTRACELOGEVTDESC           EvtDesc;
     
    354356
    355357        pEvtDescInt->cbEvtData = cbEvtData;
     358        if (cbEvtData)
     359        {
     360            pEvtDescInt->pbEvt = (uint8_t *)RTMemAllocZ(cbEvtData);
     361            if (!pEvtDescInt->pbEvt)
     362            {
     363                RTMemFree(pEvtDescInt);
     364                pEvtDescInt = NULL;
     365            }
     366        }
    356367    }
    357368
     
    514525static DECLCALLBACK(int) rtTraceLogWrEvtDescsDestroy(PAVLPVNODECORE pCore, void *pvParam)
    515526{
     527    PRTTRACELOGWREVTDESC pEvtDesc = (PRTTRACELOGWREVTDESC)pCore;
    516528    RT_NOREF(pvParam);
    517529
    518     RTMemFree(pCore);
     530    RTMemFree(pEvtDesc->pbEvt);
     531    RTMemFree(pEvtDesc);
    519532    return VINF_SUCCESS;
    520533}
     
    609622
    610623/**
     624 * Fills a given buffer with the given event data as described in the given descriptor.
     625 *
     626 * @returns IPRT status code.
     627 * @param   pThis               The trace log writer instance.
     628 * @param   pEvtDescInt         Pointer to the internal event descriptor.
     629 * @param   pb                  The byte buffer to fill.
     630 * @param   va                  The event data.
     631 */
     632static int rtTraceLogWrEvtFill(PRTTRACELOGWRINT pThis, PRTTRACELOGWREVTDESC pEvtDescInt, uint8_t *pb, va_list va)
     633{
     634    int rc = VINF_SUCCESS;
     635    uint8_t *pbCur = pb;
     636
     637    RT_NOREF(pThis);
     638
     639    for (unsigned i = 0; i < pEvtDescInt->EvtDesc.cEvtItems; i++)
     640    {
     641        PCRTTRACELOGEVTITEMDESC pEvtItemDesc = &pEvtDescInt->EvtDesc.paEvtItemDesc[i];
     642
     643        size_t cbItem = rtTraceLogWrGetEvtItemDataSz(pEvtItemDesc);
     644        switch (cbItem)
     645        {
     646            case sizeof(uint8_t):
     647                *pbCur++ = va_arg(va, /*uint8_t*/ unsigned);
     648                break;
     649            case sizeof(uint16_t):
     650                *(uint16_t *)pbCur = va_arg(va, /*uint16_t*/ unsigned);
     651                pbCur += sizeof(uint16_t);
     652                break;
     653            case sizeof(uint32_t):
     654                *(uint32_t *)pbCur = va_arg(va, uint32_t);
     655                pbCur += sizeof(uint32_t);
     656                break;
     657            case sizeof(uint64_t):
     658                *(uint64_t *)pbCur = va_arg(va, uint64_t);
     659                pbCur += sizeof(uint64_t);
     660                break;
     661            default:
     662                /* Some raw data item. */
     663                Assert(pEvtItemDesc->enmType == RTTRACELOGTYPE_RAWDATA);
     664                if (cbItem != 0)
     665                {
     666                    /* Static raw data. */
     667                    void *pvSrc = va_arg(va, void *);
     668                    memcpy(pbCur, pvSrc, cbItem);
     669                    pbCur += cbItem;
     670                }
     671                else
     672                {
     673                    AssertMsgFailed(("Not implemented!\n"));
     674                    rc = VERR_NOT_IMPLEMENTED;
     675                }
     676        }
     677    }
     678
     679    return rc;
     680}
     681
     682
     683/**
    611684 * @copydoc FNRTTRACELOGWRSTREAM
    612685 */
     
    843916}
    844917
     918
     919RTDECL(int) RTTraceLogWrEvtAddLV(RTTRACELOGWR hTraceLogWr, PCRTTRACELOGEVTDESC pEvtDesc, uint32_t fFlags,
     920                                 RTTRACELOGEVTGRPID uGrpId, RTTRACELOGEVTGRPID uParentGrpId, va_list va)
     921{
     922    PRTTRACELOGWRINT pThis = hTraceLogWr;
     923    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     924
     925    int rc = VINF_SUCCESS;
     926    PRTTRACELOGWREVTDESC pEvtDescInt = rtTraceLogWrEvtDescGetInternal(pThis, pEvtDesc);
     927    if (RT_UNLIKELY(!pEvtDescInt))
     928        rc = rtTraceLogWrEvtDescAdd(pThis, pEvtDesc, &pEvtDescInt);
     929
     930    if (   RT_SUCCESS(rc)
     931        && VALID_PTR(pEvtDescInt))
     932    {
     933        TRACELOGEVT Evt;
     934        size_t cbEvtData = rtTraceLogWrEvtInit(&Evt, pEvtDescInt, fFlags, uGrpId, uParentGrpId, NULL);
     935
     936        if (cbEvtData)
     937            rc = rtTraceLogWrEvtFill(pThis, pEvtDescInt, pEvtDescInt->pbEvt, va);
     938        if (RT_SUCCESS(rc))
     939            rc = rtTraceLogWrEvtStream(pThis, &Evt, pEvtDescInt->pbEvt, cbEvtData, NULL);
     940    }
     941
     942    return rc;
     943}
     944
     945
     946RTDECL(int) RTTraceLogWrEvtAddL(RTTRACELOGWR hTraceLogWr, PCRTTRACELOGEVTDESC pEvtDesc, uint32_t fFlags,
     947                                RTTRACELOGEVTGRPID uGrpId, RTTRACELOGEVTGRPID uParentGrpId, ...)
     948{
     949    va_list va;
     950    va_start(va, uParentGrpId);
     951    int rc = RTTraceLogWrEvtAddLV(hTraceLogWr, pEvtDesc, fFlags, uGrpId, uParentGrpId, va);
     952    va_end(va);
     953    return rc;
     954}
     955
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette