Changeset 37409 in vbox for trunk/src/VBox
- Timestamp:
- Jun 10, 2011 3:10:29 PM (14 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/Makefile.kmk
r37396 r37409 1452 1452 common/log/logcom.cpp \ 1453 1453 common/log/logformat.cpp \ 1454 common/log/tracebuf.cpp \ 1455 common/log/tracedefault.cpp \ 1454 1456 common/misc/RTAssertMsg1Weak.cpp \ 1455 1457 common/misc/RTAssertMsg2.cpp \ … … 1464 1466 common/misc/sanity-cpp.cpp \ 1465 1467 common/misc/term.cpp \ 1468 common/path/RTPathFilename.cpp \ 1466 1469 common/string/strncmp.cpp \ 1467 1470 common/string/strpbrk.cpp \ … … 1933 1936 common/log/logformat.cpp \ 1934 1937 common/log/tracebuf.cpp \ 1938 common/log/tracedefault.cpp \ 1935 1939 common/misc/RTAssertMsg1Weak.cpp \ 1936 1940 common/misc/RTAssertMsg2.cpp \ … … 1944 1948 common/misc/sanity-c.c \ 1945 1949 common/misc/sanity-cpp.cpp \ 1950 common/path/RTPathFilename.cpp \ 1946 1951 common/string/strformat.cpp \ 1947 1952 common/string/strformatnum.cpp \ … … 1951 1956 common/string/strpbrk.cpp \ 1952 1957 common/string/strprintf.cpp \ 1958 common/string/RTStrCopy.cpp \ 1959 common/string/RTStrCopyEx.cpp \ 1953 1960 common/table/avllu32.cpp \ 1954 1961 common/table/avlou32.cpp \ -
trunk/src/VBox/Runtime/common/log/tracebuf.cpp
r37400 r37409 14 14 # include <iprt/mem.h> 15 15 #endif 16 #if defined(IN_RING0) || (!defined(RT_ARCH_AMD64) && !defined(RT_ARCH_X86)) 17 # include <iprt/mp.h> 18 #else 19 # include <iprt/asm-amd64-x86.h> 20 #endif 21 #include <iprt/path.h> 16 22 #include <iprt/string.h> 17 23 #include <iprt/time.h> … … 50 56 /** Reference counter. */ 51 57 uint32_t volatile cRefs; 52 /** The current entry. */58 /** The next entry to make use of. */ 53 59 uint32_t volatile iEntry; 54 60 } RTTRACEBUFVOLATILE; … … 64 70 /** The nano second entry time stamp. */ 65 71 uint64_t NanoTS; 72 /** The ID of the CPU the event was recorded. */ 73 RTCPUID idCpu; 66 74 /** The message. */ 67 char szMsg[RTTRACEBUF_ALIGNMENT - sizeof(uint64_t) ];75 char szMsg[RTTRACEBUF_ALIGNMENT - sizeof(uint64_t) - sizeof(RTCPUID)]; 68 76 } RTTRACEBUFENTRY; 69 77 AssertCompile(sizeof(RTTRACEBUFENTRY) <= RTTRACEBUF_ALIGNMENT); … … 104 112 * Defined Constants And Macros * 105 113 *******************************************************************************/ 114 /** 115 * Get the current CPU Id. 116 */ 117 #if defined(IN_RING0) || (!defined(RT_ARCH_AMD64) && !defined(RT_ARCH_X86)) 118 # define RTTRACEBUF_CUR_CPU() RTMpCpuId() 119 #else 120 # define RTTRACEBUF_CUR_CPU() ASMGetApicId() 121 #endif 122 106 123 /** Calculates the address of the volatile trace buffer members. */ 107 124 #define RTTRACEBUF_TO_VOLATILE(a_pThis) ((PRTTRACEBUFVOLATILE)((uint8_t *)(a_pThis) + (a_pThis)->offVolatile)) … … 144 161 \ 145 162 cRefs = ASMAtomicIncU32(&RTTRACEBUF_TO_VOLATILE(a_pThis)->cRefs); \ 146 if (RT_UNLIKELY(cRefs > 1 && cRefs <_1M)) \163 if (RT_UNLIKELY(cRefs < 1 || cRefs >= _1M)) \ 147 164 { \ 148 165 ASMAtomicDecU32(&RTTRACEBUF_TO_VOLATILE(a_pThis)->cRefs); \ … … 192 209 return VERR_NOT_FOUND; \ 193 210 } \ 194 else \211 else if ((a_hTraceBuf) != NIL_RTTRACEBUF) \ 195 212 { \ 196 213 pThis = (a_hTraceBuf); \ 197 214 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); \ 198 215 } \ 216 else \ 217 return VERR_INVALID_HANDLE; \ 218 \ 199 219 AssertReturn(pThis->u32Magic == RTTRACEBUF_MAGIC, VERR_INVALID_HANDLE); \ 220 if (pThis->fFlags & RTTRACEBUF_FLAGS_DISABLED) \ 221 return VINF_SUCCESS; \ 200 222 AssertReturn(pThis->offVolatile < RTTRACEBUF_ALIGNMENT * 2, VERR_INVALID_HANDLE); \ 201 223 pVolatile = RTTRACEBUF_TO_VOLATILE(pThis); \ … … 203 225 /* Grab a reference. */ \ 204 226 cRefs = ASMAtomicIncU32(&pVolatile->cRefs); \ 205 if (RT_UNLIKELY(cRefs > 1 && cRefs <_1M)) \227 if (RT_UNLIKELY(cRefs < 1 || cRefs >= _1M)) \ 206 228 { \ 207 229 ASMAtomicDecU32(&pVolatile->cRefs); \ … … 210 232 \ 211 233 /* Grab the next entry and set the time stamp. */ \ 212 iEntry = ASMAtomicIncU32(&pVolatile->iEntry) ; \234 iEntry = ASMAtomicIncU32(&pVolatile->iEntry) - 1; \ 213 235 iEntry %= pThis->cEntries; \ 214 pEntry = RTTRACEBUF_TO_ENTRY(pThis, iEntry); \236 pEntry = RTTRACEBUF_TO_ENTRY(pThis, iEntry); \ 215 237 pEntry->NanoTS = RTTimeNanoTS(); \ 216 pszBuf = &pEntry->szMsg[0]; \ 238 pEntry->idCpu = RTTRACEBUF_CUR_CPU(); \ 239 pszBuf = &pEntry->szMsg[0]; \ 217 240 *pszBuf = '\0'; \ 218 cchBuf = pThis->cbEntry - RT_OFFSETOF(RTTRACEBUFENTRY, szMsg) - 1; \219 rc = VINF_SUCCESS241 cchBuf = pThis->cbEntry - RT_OFFSETOF(RTTRACEBUFENTRY, szMsg) - 1; \ 242 rc = VINF_SUCCESS 220 243 221 244 … … 230 253 do { \ 231 254 /* file(line): - no path */ \ 232 size_t cchPos = RTStrPrintf(pszBuf, cchBuf, "% Rfn(%d): ", pszFile, iLine); \255 size_t cchPos = RTStrPrintf(pszBuf, cchBuf, "%s(%d): ", RTPathFilename(pszFile), iLine); \ 233 256 pszBuf += cchPos; \ 234 257 cchBuf -= cchPos; \ … … 253 276 { 254 277 AssertPtrReturn(phTraceBuf, VERR_INVALID_POINTER); 255 AssertReturn(! fFlags, VERR_INVALID_PARAMETER);278 AssertReturn(!(fFlags & ~(RTTRACEBUF_FLAGS_MASK & ~ RTTRACEBUF_FLAGS_FREE_ME)), VERR_INVALID_PARAMETER); 256 279 AssertMsgReturn(cbEntry <= RTTRACEBUF_MAX_ENTRIES, ("%#x\n", cbEntry), VERR_OUT_OF_RANGE); 257 280 AssertMsgReturn(cEntries <= RTTRACEBUF_MAX_ENTRY_SIZE, ("%#x\n", cEntries), VERR_OUT_OF_RANGE); … … 304 327 AssertMsgReturn(cbEntry <= RTTRACEBUF_MAX_ENTRIES, ("%#x\n", cbEntry), VERR_OUT_OF_RANGE); 305 328 AssertMsgReturn(cEntries <= RTTRACEBUF_MAX_ENTRY_SIZE, ("%#x\n", cEntries), VERR_OUT_OF_RANGE); 306 AssertPtrReturn(pvBlock, VERR_INVALID_POINTER);307 329 AssertPtrReturn(pcbBlock, VERR_INVALID_POINTER); 330 size_t const cbBlock = *pcbBlock; 331 AssertReturn(RT_VALID_PTR(pvBlock) || !cbBlock, VERR_INVALID_POINTER); 308 332 309 333 /* … … 311 335 * This code can be made a bit more clever, if someone feels like it. 312 336 */ 313 size_t const cbBlock = *pcbBlock;314 337 size_t const cbHdr = RT_ALIGN_Z(sizeof(RTTRACEBUFINT), RTTRACEBUF_ALIGNMENT) 315 338 + RT_ALIGN_Z(sizeof(RTTRACEBUFVOLATILE), RTTRACEBUF_ALIGNMENT); … … 513 536 514 537 515 516 RTDECL(int) RTTraceBufDumpToLog(RTTRACEBUF hTraceBuf) 517 { 538 RTDECL(int) RTTraceBufEnumEntries(RTTRACEBUF hTraceBuf, PFNRTTRACEBUFCALLBACK pfnCallback, void *pvUser) 539 { 540 int rc = VINF_SUCCESS; 518 541 uint32_t iBase; 519 542 uint32_t cLeft; … … 530 553 pEntry = RTTRACEBUF_TO_ENTRY(pThis, iBase); 531 554 if (pEntry->NanoTS) 532 RTLogPrintf("%u/%'llu: %s\n", cLeft, pEntry->NanoTS, pEntry->szMsg); 555 { 556 rc = pfnCallback((RTTRACEBUF)pThis, cLeft, pEntry->NanoTS, pEntry->idCpu, pEntry->szMsg, pvUser); 557 if (rc != VINF_SUCCESS) 558 break; 559 } 533 560 534 561 /* next */ … … 537 564 538 565 RTTRACEBUF_DROP_REFERENCE(pThis); 539 return VINF_SUCCESS; 540 } 541 542 543 RTDECL(int) RTTraceBufDumpToAssert(RTTRACEBUF hTraceBuf) 566 return rc; 567 } 568 569 570 RTDECL(uint32_t) RTTraceBufGetEntrySize(RTTRACEBUF hTraceBuf) 571 { 572 PCRTTRACEBUFINT pThis = hTraceBuf; 573 RTTRACEBUF_VALID_RETURN_RC(pThis, 0); 574 return pThis->cbEntry; 575 } 576 577 578 RTDECL(uint32_t) RTTraceBufGetEntryCount(RTTRACEBUF hTraceBuf) 579 { 580 PCRTTRACEBUFINT pThis = hTraceBuf; 581 RTTRACEBUF_VALID_RETURN_RC(pThis, 0); 582 return pThis->cEntries; 583 } 584 585 586 RTDECL(bool) RTTraceBufDisable(RTTRACEBUF hTraceBuf) 587 { 588 PCRTTRACEBUFINT pThis = hTraceBuf; 589 RTTRACEBUF_VALID_RETURN_RC(pThis, false); 590 return !ASMAtomicBitTestAndSet((void volatile *)&pThis->fFlags, RTTRACEBUF_FLAGS_DISABLED_BIT); 591 } 592 593 594 RTDECL(bool) RTTraceBufEnable(RTTRACEBUF hTraceBuf) 595 { 596 PCRTTRACEBUFINT pThis = hTraceBuf; 597 RTTRACEBUF_VALID_RETURN_RC(pThis, false); 598 return !ASMAtomicBitTestAndClear((void volatile *)&pThis->fFlags, RTTRACEBUF_FLAGS_DISABLED_BIT); 599 } 600 601 602 /* 603 * 604 * Move the following to a separate file, consider using the enumerator. 605 * 606 */ 607 608 RTDECL(int) RTTraceBufDumpToLog(RTTRACEBUF hTraceBuf) 544 609 { 545 610 uint32_t iBase; … … 557 622 pEntry = RTTRACEBUF_TO_ENTRY(pThis, iBase); 558 623 if (pEntry->NanoTS) 559 RT AssertMsg2Add("%u/%'llu: %s\n", cLeft, pEntry->NanoTS, pEntry->szMsg);624 RTLogPrintf("%04u/%'llu/%02x: %s\n", cLeft, pEntry->NanoTS, pEntry->idCpu, pEntry->szMsg); 560 625 561 626 /* next */ … … 567 632 } 568 633 634 635 RTDECL(int) RTTraceBufDumpToAssert(RTTRACEBUF hTraceBuf) 636 { 637 uint32_t iBase; 638 uint32_t cLeft; 639 PCRTTRACEBUFINT pThis; 640 RTTRACEBUF_RESOLVE_VALIDATE_RETAIN_RETURN(hTraceBuf, pThis); 641 642 iBase = ASMAtomicReadU32(&RTTRACEBUF_TO_VOLATILE(pThis)->iEntry); 643 cLeft = pThis->cEntries; 644 while (cLeft--) 645 { 646 PRTTRACEBUFENTRY pEntry; 647 648 iBase %= pThis->cEntries; 649 pEntry = RTTRACEBUF_TO_ENTRY(pThis, iBase); 650 if (pEntry->NanoTS) 651 RTAssertMsg2AddWeak("%u/%'llu/%02x: %s\n", cLeft, pEntry->NanoTS, pEntry->idCpu, pEntry->szMsg); 652 653 /* next */ 654 iBase += 1; 655 } 656 657 RTTRACEBUF_DROP_REFERENCE(pThis); 658 return VINF_SUCCESS; 659 } 660 661 662 -
trunk/src/VBox/Runtime/common/log/tracedefault.cpp
r37396 r37409 30 30 31 31 RTTRACEBUF hOldTraceBuf; 32 #ifdef IN_RC 33 hOldTraceBuf = (RTTRACEBUF)ASMAtomicXchgPtr((void **)&g_hDefaultTraceBuf, hTraceBuf); 34 #else 32 35 ASMAtomicXchgHandle(&g_hDefaultTraceBuf, hTraceBuf, &hOldTraceBuf); 36 #endif 33 37 34 38 if ( hOldTraceBuf != NIL_RTTRACEBUF … … 36 40 { 37 41 /* Race prevention kludge. */ 42 #ifndef IN_RC 38 43 RTThreadSleep(33); 44 #endif 39 45 RTTraceBufRelease(hOldTraceBuf); 40 46 }
Note:
See TracChangeset
for help on using the changeset viewer.