VirtualBox

Changeset 90974 in vbox


Ignore:
Timestamp:
Aug 28, 2021 12:45:58 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
146613
Message:

IPRT/log,VMM: Changed RTLogBulkWrite to take a before/after marker texts. Fixed buffer switching bug in rtlogFlush where we would write terminator to the previous buffer instead of the next. bugref:10086

Location:
trunk
Files:
3 edited

Legend:

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

    r90969 r90974  
    23182318 *
    23192319 * @returns IRPT status code.
    2320  * @param   pLogger     The logger instance (NULL for default logger).
    2321  * @param   pch         Pointer to the block of bulk log text to write.
    2322  * @param   cch         Size of the block of bulk log text to write.
    2323  */
    2324 RTDECL(int) RTLogBulkWrite(PRTLOGGER pLogger, const char *pch, size_t cch);
     2320 * @param   pLogger             The logger instance (NULL for default logger).
     2321 * @param   pszBefore           Text to log before the bulk text.  Optional.
     2322 * @param   pch                 Pointer to the block of bulk log text to write.
     2323 * @param   cch                 Size of the block of bulk log text to write.
     2324 * @param   pszAfter            Text to log after the bulk text.  Optional.
     2325 */
     2326RTDECL(int) RTLogBulkWrite(PRTLOGGER pLogger, const char *pszBefore, const char *pch, size_t cch, const char *pszAfter);
    23252327
    23262328/**
  • trunk/src/VBox/Runtime/common/log/log.cpp

    r90969 r90974  
    279279static FNRTLOGPHASEMSG rtlogPhaseMsgNormal;
    280280#endif
     281static void rtlogLoggerExFLocked(PRTLOGGERINTERNAL pLoggerInt, unsigned fFlags, unsigned iGroup, const char *pszFormat, ...);
    281282
    282283
     
    29842985 * @returns IRPT status code.
    29852986 * @param   pLogger             The logger instance (NULL for default logger).
     2987 * @param   pszBefore           Text to log before the bulk text.  Optional.
    29862988 * @param   pch                 Pointer to the block of bulk log text to write.
    29872989 * @param   cch                 Size of the block of bulk log text to write.
    2988  */
    2989 RTDECL(int) RTLogBulkWrite(PRTLOGGER pLogger, const char *pch, size_t cch)
     2990 * @param   pszAfter            Text to log after the bulk text.  Optional.
     2991 */
     2992RTDECL(int) RTLogBulkWrite(PRTLOGGER pLogger, const char *pszBefore, const char *pch, size_t cch, const char *pszAfter)
    29902993{
    29912994    PRTLOGGERINTERNAL pLoggerInt = (PRTLOGGERINTERNAL)pLogger;
     
    29983001    if (RT_SUCCESS(rc))
    29993002    {
    3000         /*
    3001          * Do the copying.
    3002          */
    3003         while (cch > 0)
    3004         {
    3005             PRTLOGBUFFERDESC const  pBufDesc = pLoggerInt->pBufDesc;
    3006             char * const            pchBuf   = pBufDesc->pchBuf;
    3007             uint32_t const          cbBuf    = pBufDesc->cbBuf;
    3008             uint32_t                offBuf   = pBufDesc->offBuf;
    3009             if (cch + 1 < cbBuf - offBuf)
     3003        if (cch > 0)
     3004        {
     3005            /*
     3006             * Heading/marker.
     3007             */
     3008            if (pszBefore)
     3009                rtlogLoggerExFLocked(pLoggerInt, RTLOGGRPFLAGS_LEVEL_1, UINT32_MAX, "%s", pszBefore);
     3010
     3011            /*
     3012             * Do the copying.
     3013             */
     3014            do
    30103015            {
    3011                 memcpy(&pchBuf[offBuf], pch, cch);
    3012                 offBuf += (uint32_t)cch;
    3013                 pchBuf[offBuf] = '\0';
    3014                 pBufDesc->offBuf = offBuf;
    3015                 if (pBufDesc->pAux)
    3016                     pBufDesc->pAux->offBuf = offBuf;
    3017                 if (!(pLoggerInt->fDestFlags & RTLOGFLAGS_BUFFERED))
    3018                     rtlogFlush(pLoggerInt, false /*fNeedSpace*/);
    3019                 break;
    3020             }
    3021 
    3022             /* Not enough space. */
    3023             if (offBuf + 1 < cbBuf)
    3024             {
    3025                 uint32_t cbToCopy = cbBuf - offBuf - 1;
    3026                 memcpy(&pchBuf[offBuf], pch, cbToCopy);
    3027                 offBuf += cbToCopy;
    3028                 pchBuf[offBuf] = '\0';
    3029                 pBufDesc->offBuf = offBuf;
    3030                 if (pBufDesc->pAux)
    3031                     pBufDesc->pAux->offBuf = offBuf;
    3032                 pch += cbToCopy;
    3033                 cch -= cbToCopy;
    3034             }
    3035 
    3036             rtlogFlush(pLoggerInt, false /*fNeedSpace*/);
     3016                PRTLOGBUFFERDESC const  pBufDesc = pLoggerInt->pBufDesc;
     3017                char * const            pchBuf   = pBufDesc->pchBuf;
     3018                uint32_t const          cbBuf    = pBufDesc->cbBuf;
     3019                uint32_t                offBuf   = pBufDesc->offBuf;
     3020                if (cch + 1 < cbBuf - offBuf)
     3021                {
     3022                    memcpy(&pchBuf[offBuf], pch, cch);
     3023                    offBuf += (uint32_t)cch;
     3024                    pchBuf[offBuf] = '\0';
     3025                    pBufDesc->offBuf = offBuf;
     3026                    if (pBufDesc->pAux)
     3027                        pBufDesc->pAux->offBuf = offBuf;
     3028                    if (!(pLoggerInt->fDestFlags & RTLOGFLAGS_BUFFERED))
     3029                        rtlogFlush(pLoggerInt, false /*fNeedSpace*/);
     3030                    break;
     3031                }
     3032
     3033                /* Not enough space. */
     3034                if (offBuf + 1 < cbBuf)
     3035                {
     3036                    uint32_t cbToCopy = cbBuf - offBuf - 1;
     3037                    memcpy(&pchBuf[offBuf], pch, cbToCopy);
     3038                    offBuf += cbToCopy;
     3039                    pchBuf[offBuf] = '\0';
     3040                    pBufDesc->offBuf = offBuf;
     3041                    if (pBufDesc->pAux)
     3042                        pBufDesc->pAux->offBuf = offBuf;
     3043                    pch += cbToCopy;
     3044                    cch -= cbToCopy;
     3045                }
     3046
     3047                rtlogFlush(pLoggerInt, false /*fNeedSpace*/);
     3048            } while (cch > 0);
     3049
     3050            /*
     3051             * Footer/marker.
     3052             */
     3053            if (pszAfter)
     3054                rtlogLoggerExFLocked(pLoggerInt, RTLOGGRPFLAGS_LEVEL_1, UINT32_MAX, "%s", pszAfter);
    30373055        }
    30383056
     
    31093127    PRTLOGBUFFERDESC    pBufDesc   = pLoggerInt->pBufDesc;
    31103128    uint32_t            cchToFlush = pBufDesc->offBuf;
    3111     char * const        pchToFlush = pBufDesc->pchBuf;
     3129    char *              pchToFlush = pBufDesc->pchBuf;
    31123130    uint32_t const      cbBuf      = pBufDesc->cbBuf;
    31133131    Assert(pBufDesc->u32Magic == RTLOGBUFFERDESC_MAGIC);
     
    31993217                pLoggerInt->idxBufDesc = (uint8_t)idxBufDesc;
    32003218                pLoggerInt->pBufDesc   = pBufDesc = &pLoggerInt->paBufDescs[idxBufDesc];
     3219                pchToFlush = pBufDesc->pchBuf;
    32013220            }
    32023221        }
  • trunk/src/VBox/VMM/VMMR3/VMM.cpp

    r90972 r90974  
    873873                             * Do the flushing.
    874874                             */
    875                             LogAlways(("*FLUSH* idCpu=%u idxLogger=%u idxBuffer=%u cbToFlush=%#x fFlushed=%RTbool cbDropped=%#x\n",
    876                                        Item.s.idCpu, Item.s.idxLogger, Item.s.idxBuffer, cbToFlush,
    877                                        pShared->aBufs[Item.s.idxBuffer].AuxDesc.fFlushedIndicator, pShared->cbDropped));
    878875                            PRTLOGGER const pLogger = Item.s.idxLogger == VMMLOGGER_IDX_REGULAR
    879876                                                    ? RTLogGetDefaultInstance() : RTLogRelGetDefaultInstance();
    880877                            if (pLogger)
    881                                 RTLogBulkWrite(pLogger, pchBufR3, cbToFlush);
    882                             LogAlways(("*FLUSH DONE*\n"));
     878                            {
     879                                char szBefore[128];
     880                                RTStrPrintf(szBefore, sizeof(szBefore),
     881                                            "*FLUSH* idCpu=%u idxLogger=%u idxBuffer=%u cbToFlush=%#x fFlushed=%RTbool cbDropped=%#x\n",
     882                                            Item.s.idCpu, Item.s.idxLogger, Item.s.idxBuffer, cbToFlush,
     883                                            pShared->aBufs[Item.s.idxBuffer].AuxDesc.fFlushedIndicator, pShared->cbDropped);
     884                                RTLogBulkWrite(pLogger, szBefore, pchBufR3, cbToFlush, "*FLUSH DONE*\n");
     885                            }
    883886                        }
    884887                        else
     
    945948static void vmmR3LogReturnFlush(PVMMR3CPULOGGER pShared, size_t idxBuf, PRTLOGGER pDstLogger)
    946949{
     950    uint32_t const cbToFlush = pShared->aBufs[idxBuf].AuxDesc.offBuf;
     951    const char    *pszBefore = cbToFlush < 256 ? NULL : "*FLUSH*\n";
     952    const char    *pszAfter  = cbToFlush < 256 ? NULL : "*END*\n";
    947953#if VMMLOGGER_BUFFER_COUNT > 1
    948954    /*
     
    955961        for (uint32_t iTry = 0; iTry < 32 && pShared->cFlushing != 0; iTry++)
    956962        {
    957             RTLogBulkWrite(pDstLogger, "", 0); /* A no-op, but it takes the lock and the hope is */
    958             if (pShared->cFlushing != 0)       /* that we end up waiting on the flusher finish up. */
     963            RTLogBulkWrite(pDstLogger, NULL, "", 0, NULL); /* A no-op, but it takes the lock and the hope is */
     964            if (pShared->cFlushing != 0)                   /* that we end up waiting on the flusher finish up. */
    959965                RTThreadYield();
    960966        }
    961967        if (pShared->cFlushing != 0)
    962968        {
    963             RTLogLoggerEx(pDstLogger, RTLOGGRPFLAGS_LEVEL_1, UINT32_MAX, "*MAYBE WRONG ORDER*\n");
    964             if (pShared->cFlushing != 0)
    965                 STAM_REL_COUNTER_INC(&pShared->StatRacesReal);
    966         }
    967     }
    968 #endif
    969     RTLogBulkWrite(pDstLogger, pShared->aBufs[idxBuf].pchBufR3, pShared->aBufs[idxBuf].AuxDesc.offBuf);
     969            pszBefore = "*MAYBE MISPLACED*\n";
     970            pszAfter  = "*END MISPLACED*\n";
     971            STAM_REL_COUNTER_INC(&pShared->StatRacesReal);
     972        }
     973    }
     974#endif
     975    RTLogBulkWrite(pDstLogger, pszBefore, pShared->aBufs[idxBuf].pchBufR3, cbToFlush, pszAfter);
    970976    pShared->aBufs[idxBuf].AuxDesc.fFlushedIndicator = true;
    971977}
Note: See TracChangeset for help on using the changeset viewer.

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