Changeset 85949 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Aug 31, 2020 10:22:50 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/log/tracelogreader.cpp
r85160 r85949 1202 1202 * @param ppEvtItemDesc Where to store the event item descriptor. 1203 1203 */ 1204 static int rtTraceLogRdrEvtResolveData(P RTTRACELOGRDREVTINT pEvt, const char *pszName, uint32_t *poffData,1204 static int rtTraceLogRdrEvtResolveData(PCRTTRACELOGRDREVTINT pEvt, const char *pszName, uint32_t *poffData, 1205 1205 size_t *pcbEvtData, PPCRTTRACELOGEVTITEMDESC ppEvtItemDesc) 1206 1206 { … … 1238 1238 * @param pVal The value to fill. 1239 1239 */ 1240 static int rtTraceLogRdrEvtFillVal(P RTTRACELOGRDREVTINT pEvt, uint32_t offData, size_t cbData, PCRTTRACELOGEVTITEMDESC pEvtItemDesc,1240 static int rtTraceLogRdrEvtFillVal(PCRTTRACELOGRDREVTINT pEvt, uint32_t offData, size_t cbData, PCRTTRACELOGEVTITEMDESC pEvtItemDesc, 1241 1241 PRTTRACELOGEVTVAL pVal) 1242 1242 { 1243 1243 PRTTRACELOGRDRINT pThis = pEvt->pRdr; 1244 uint8_t *pbData = &pEvt->abEvtData[offData];1244 const uint8_t *pbData = &pEvt->abEvtData[offData]; 1245 1245 1246 1246 pVal->pItemDesc = pEvtItemDesc; … … 1452 1452 1453 1453 return VINF_SUCCESS; 1454 } 1455 1456 1457 /** 1458 * Finds the mapping descriptor for the given event. 1459 * 1460 * @returns Pointer to the mapping descriptor or NULL if not found. 1461 * @param paMapDesc Pointer to the array of mapping descriptors. 1462 * @param pEvt The event to look for the matching mapping descriptor. 1463 */ 1464 static PCRTTRACELOGRDRMAPDESC rtTraceLogRdrMapDescFindForEvt(PCRTTRACELOGRDRMAPDESC paMapDesc, PCRTTRACELOGRDREVTINT pEvt) 1465 { 1466 AssertPtrReturn(paMapDesc, NULL); 1467 AssertPtrReturn(pEvt, NULL); 1468 1469 while (paMapDesc->pszEvtId) 1470 { 1471 if (!RTStrCmp(paMapDesc->pszEvtId, pEvt->pEvtDesc->EvtDesc.pszId)) 1472 return paMapDesc; 1473 1474 paMapDesc++; 1475 } 1476 1477 return NULL; 1478 } 1479 1480 1481 /** 1482 * Fills the given event header with data from the given event using the matching mapping descriptor. 1483 * 1484 * @returns IPRT statsu code. 1485 * @param pEvtHdr The event header to fill. 1486 * @param pMapDesc The mapping descriptor to use. 1487 * @param pEvt The raw event to get the data from. 1488 */ 1489 static int rtTraceLogRdrMapFillEvt(PRTTRACELOGRDREVTHDR pEvtHdr, PCRTTRACELOGRDRMAPDESC pMapDesc, PCRTTRACELOGRDREVTINT pEvt) 1490 { 1491 int rc = VINF_SUCCESS; 1492 1493 /* Fill in the status parts. */ 1494 pEvtHdr->pEvtMapDesc = pMapDesc; 1495 pEvtHdr->pEvtDesc = &pEvt->pEvtDesc->EvtDesc; 1496 pEvtHdr->idSeqNo = pEvt->u64SeqNo; 1497 pEvtHdr->tsEvt = pEvt->u64Ts; 1498 pEvtHdr->paEvtItems = NULL; 1499 1500 /* Now the individual items if any. */ 1501 if (pMapDesc->cEvtItems) 1502 { 1503 /* Allocate values for the items. */ 1504 pEvtHdr->paEvtItems = (PCRTTRACELOGEVTVAL)RTMemAllocZ(pMapDesc->cEvtItems * sizeof(RTTRACELOGEVTVAL)); 1505 if (RT_LIKELY(pEvtHdr->paEvtItems)) 1506 { 1507 for (uint32_t i = 0; (i < pMapDesc->cEvtItems) && RT_SUCCESS(rc); i++) 1508 { 1509 uint32_t offData = 0; 1510 size_t cbData = 0; 1511 PCRTTRACELOGEVTITEMDESC pEvtItemDesc = NULL; 1512 rc = rtTraceLogRdrEvtResolveData(pEvt, pMapDesc->paMapItems[i].pszName, &offData, &cbData, &pEvtItemDesc); 1513 if (RT_SUCCESS(rc)) 1514 rc = rtTraceLogRdrEvtFillVal(pEvt, offData, cbData, pEvtItemDesc, (PRTTRACELOGEVTVAL)&pEvtHdr->paEvtItems[i]); 1515 } 1516 1517 if (RT_FAILURE(rc)) 1518 { 1519 RTMemFree((void *)pEvtHdr->paEvtItems); 1520 pEvtHdr->paEvtItems = NULL; 1521 } 1522 } 1523 else 1524 rc = VERR_NO_MEMORY; 1525 } 1526 1527 return rc; 1454 1528 } 1455 1529 … … 1619 1693 1620 1694 1695 RTDECL(int) RTTraceLogRdrEvtMapToStruct(RTTRACELOGRDR hTraceLogRdr, uint32_t fFlags, uint32_t cEvts, 1696 PCRTTRACELOGRDRMAPDESC paMapDesc, PCRTTRACELOGRDREVTHDR *ppaEvtHdr, 1697 uint32_t *pcEvts) 1698 { 1699 RT_NOREF(fFlags); 1700 1701 PRTTRACELOGRDRINT pThis = hTraceLogRdr; 1702 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 1703 AssertPtrReturn(paMapDesc, VERR_INVALID_PARAMETER); 1704 AssertPtrReturn(ppaEvtHdr, VERR_INVALID_POINTER); 1705 AssertPtrReturn(pcEvts, VERR_INVALID_POINTER); 1706 1707 int rc = VINF_SUCCESS; 1708 uint32_t cEvtsAlloc = cEvts != UINT32_MAX ? cEvts : _4K; 1709 PRTTRACELOGRDREVTHDR paEvtHdr = (PRTTRACELOGRDREVTHDR)RTMemAllocZ(cEvtsAlloc * sizeof(*paEvtHdr)); 1710 if (RT_LIKELY(paEvtHdr)) 1711 { 1712 uint32_t cEvtsRecv = 0; 1713 1714 while ( RT_SUCCESS(rc) 1715 && cEvtsRecv < cEvts) 1716 { 1717 RTTRACELOGRDRPOLLEVT enmEvt = RTTRACELOGRDRPOLLEVT_INVALID; 1718 rc = RTTraceLogRdrEvtPoll(pThis, &enmEvt, 0 /*cMsTimeout*/); 1719 if ( RT_SUCCESS(rc) 1720 && enmEvt == RTTRACELOGRDRPOLLEVT_TRACE_EVENT_RECVD) 1721 { 1722 /* Find the mapping descriptor. */ 1723 PRTTRACELOGRDREVTINT pEvt = NULL; 1724 rc = RTTraceLogRdrQueryLastEvt(hTraceLogRdr, &pEvt); 1725 if (RT_SUCCESS(rc)) 1726 { 1727 PCRTTRACELOGRDRMAPDESC pMapDesc = rtTraceLogRdrMapDescFindForEvt(paMapDesc, pEvt); 1728 if (pMapDesc) 1729 { 1730 if (cEvtsRecv == cEvtsAlloc) 1731 { 1732 Assert(cEvts == UINT32_MAX); 1733 PRTTRACELOGRDREVTHDR paEvtHdrNew = (PRTTRACELOGRDREVTHDR)RTMemRealloc(paEvtHdr, (cEvtsAlloc + _4K) * sizeof(*paEvtHdr)); 1734 if (RT_LIKELY(paEvtHdrNew)) 1735 { 1736 paEvtHdr = paEvtHdrNew; 1737 cEvtsAlloc += _4K; 1738 } 1739 else 1740 rc = VERR_NO_MEMORY; 1741 } 1742 1743 if (RT_SUCCESS(rc)) 1744 rc = rtTraceLogRdrMapFillEvt(&paEvtHdr[cEvtsRecv++], pMapDesc, pEvt); 1745 cEvtsRecv++; 1746 } 1747 else 1748 rc = VERR_NOT_FOUND; 1749 } 1750 } 1751 } 1752 1753 if (RT_SUCCESS(rc)) 1754 { 1755 *ppaEvtHdr = paEvtHdr; 1756 *pcEvts = cEvtsRecv; 1757 } 1758 else 1759 RTTraceLogRdrEvtMapFree(paEvtHdr, cEvtsRecv); 1760 } 1761 else 1762 rc = VERR_NO_MEMORY; 1763 1764 return rc; 1765 } 1766 1767 1768 RTDECL(void) RTTraceLogRdrEvtMapFree(PCRTTRACELOGRDREVTHDR paEvtHdr, uint32_t cEvts) 1769 { 1770 for (uint32_t i = 0; i < cEvts; i++) 1771 { 1772 if (paEvtHdr[i].paEvtItems) 1773 RTMemFree((void *)paEvtHdr[i].paEvtItems); 1774 } 1775 1776 RTMemFree((void *)paEvtHdr); 1777 } 1778 1779 1621 1780 RTDECL(void) RTTraceLogRdrIteratorFree(RTTRACELOGRDRIT hIt) 1622 1781 {
Note:
See TracChangeset
for help on using the changeset viewer.