- Timestamp:
- Aug 31, 2020 10:22:50 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/mangling.h
r85894 r85949 2622 2622 # define RTTraceLogRdrEvtGetTs RT_MANGLER(RTTraceLogRdrEvtGetTs) 2623 2623 # define RTTraceLogRdrEvtIsGrouped RT_MANGLER(RTTraceLogRdrEvtIsGrouped) 2624 # define RTTraceLogRdrEvtMapToStruct RT_MANGLER(RTTraceLogRdrEvtMapToStruct) 2625 # define RTTraceLogRdrEvtMapFree RT_MANGLER(RTTraceLogRdrEvtMapFree) 2624 2626 # define RTTraceLogRdrEvtPoll RT_MANGLER(RTTraceLogRdrEvtPoll) 2625 2627 # define RTTraceLogRdrEvtQueryVal RT_MANGLER(RTTraceLogRdrEvtQueryVal) -
trunk/include/iprt/tracelog.h
r85121 r85949 214 214 215 215 216 /** 217 * Item mapping descriptor. 218 */ 219 typedef struct RTTRACELOGRDRMAPITEM 220 { 221 /** The item name. */ 222 const char *pszName; 223 /** The value type to map the item to. */ 224 RTTRACELOGTYPE enmType; 225 } RTTRACELOGRDRMAPITEM; 226 /** Pointer to a mapping item descriptor. */ 227 typedef RTTRACELOGRDRMAPITEM *PRTTRACELOGRDRMAPITEM; 228 /** Pointer to a const mapping item descriptor. */ 229 typedef const RTTRACELOGRDRMAPITEM *PCRTTRACELOGRDRMAPITEM; 230 231 232 /** 233 * Event item to value mapping descriptor for RTTraceLogRdrEvtMapToStruct(). 234 */ 235 typedef struct RTTRACELOGRDRMAPDESC 236 { 237 /** The event ID this mapping describes. */ 238 const char *pszEvtId; 239 /** Number of event items to extract. */ 240 uint32_t cEvtItems; 241 /** Pointer to the event items to extract (in the given order). */ 242 PCRTTRACELOGRDRMAPITEM paMapItems; 243 } RTTRACELOGRDRMAPDESC; 244 /** Pointer to a event mapping descriptor. */ 245 typedef RTTRACELOGRDRMAPDESC *PRTTRACELOGRDRMAPDESC; 246 /** Pointer to a const event mapping descriptor. */ 247 typedef const RTTRACELOGRDRMAPDESC *PCRTTRACELOGRDRMAPDESC; 248 249 250 /** 251 * Header for an event mapped to a binary. 252 */ 253 typedef struct RTTRACELOGRDREVTHDR 254 { 255 /** The mapping descriptor this event was mapped to. */ 256 PCRTTRACELOGRDRMAPDESC pEvtMapDesc; 257 /** The event descriptor as extracted from the event log. */ 258 PCRTTRACELOGEVTDESC pEvtDesc; 259 /** Sequence number of the descriptor. */ 260 uint64_t idSeqNo; 261 /** The timestamp of the event. */ 262 uint64_t tsEvt; 263 /** Pointer to the event data items. */ 264 PCRTTRACELOGEVTVAL paEvtItems; 265 } RTTRACELOGRDREVTHDR; 266 /** Pointer to an event header. */ 267 typedef RTTRACELOGRDREVTHDR *PRTTRACELOGRDREVTHDR; 268 /** Pointer to a const event header. */ 269 typedef const RTTRACELOGRDREVTHDR *PCRTTRACELOGRDREVTHDR; 270 271 216 272 /** Event group ID. */ 217 273 typedef uint64_t RTTRACELOGEVTGRPID; … … 517 573 518 574 /** 575 * Extracts the given number of events from the given trace log reader instance returning 576 * and array of events with the values filled in from the mapping descriptor. 577 * 578 * @returns IPRT status code. 579 * @param hTraceLogRdr The trace log reader instance handle. 580 * @param fFlags Flags controlling the behavior, MBZ. 581 * @param cEvts Number of events to extract, UINT32_MAX to map all immediately available events. 582 * @param paMapDesc Pointer to an array of mapping descriptors describing how to map events. 583 * @param ppaEvtHdr Where to return the pointer to the allocated array of event headers on success. 584 * @param pcEvts Where to store the returned number of events on success. 585 */ 586 RTDECL(int) RTTraceLogRdrEvtMapToStruct(RTTRACELOGRDR hTraceLogRdr, uint32_t fFlags, uint32_t cEvts, 587 PCRTTRACELOGRDRMAPDESC paMapDesc, PCRTTRACELOGRDREVTHDR *ppaEvtHdr, 588 uint32_t *pcEvts); 589 590 591 /** 592 * Frees all resources of the given array of event headers as allocated by RTTraceLogRdrEvtMapToStruct(). 593 * 594 * @returns nothing. 595 * @param paEvtHdr Pointer to the array of events as returned by RTTraceLogRdrEvtMapToStruct(). 596 * @param cEvts Number of events as returned by RTTraceLogRdrEvtMapToStruct(). 597 */ 598 RTDECL(void) RTTraceLogRdrEvtMapFree(PCRTTRACELOGRDREVTHDR paEvtHdr, uint32_t cEvts); 599 600 601 /** 519 602 * Frees a previously created iterator. 520 603 * -
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.