Changeset 5189 in vbox
- Timestamp:
- Oct 8, 2007 6:27:24 PM (18 years ago)
- svn:sync-xref-src-repo-rev:
- 25116
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/stam.h
r4071 r5189 1197 1197 * @param pszPat The name matching pattern. See somewhere_where_this_is_described_in_detail. 1198 1198 * If NULL all samples are reset. 1199 * @param fWithDesc Whether to include the descriptions. 1199 1200 * @param ppszSnapshot Where to store the pointer to the snapshot data. 1200 1201 * The format of the snapshot should be XML, but that will have to be discussed 1201 1202 * when this function is implemented. 1202 1203 * The returned pointer must be freed by calling STAMR3SnapshotFree(). 1203 * @param cchSnapshotWhere to store the size of the snapshot data. (Excluding the trailing '\0')1204 */ 1205 STAMR3DECL(int) STAMR3Snapshot(PVM pVM, const char *pszPat, char **ppszSnapshot, size_t *pcchSnapshot);1204 * @param pcchSnapshot Where to store the size of the snapshot data. (Excluding the trailing '\0') 1205 */ 1206 STAMR3DECL(int) STAMR3Snapshot(PVM pVM, const char *pszPat, char **ppszSnapshot, size_t *pcchSnapshot, bool fWithDesc); 1206 1207 1207 1208 /** -
trunk/src/VBox/VMM/STAM.cpp
r4116 r5189 60 60 61 61 62 /** 63 * The snapshot status structure. 64 * Argument package passed to stamR3SnapshotOne, stamR3SnapshotPrintf and stamR3SnapshotOutput. 65 */ 66 typedef struct STAMR3SNAPSHOTONE 67 { 68 /** Pointer to the buffer start. */ 69 char *pszStart; 70 /** Pointer to the buffer end. */ 71 char *pszEnd; 72 /** Pointer to the current buffer position. */ 73 char *psz; 74 /** The VM handle (just in case). */ 75 PVM pVM; 76 /** The number of bytes allocated. */ 77 size_t cbAllocated; 78 /** The status code. */ 79 int rc; 80 /** Whether to include the description strings. */ 81 bool fWithDesc; 82 } STAMR3SNAPSHOTONE, *PSTAMR3SNAPSHOTONE; 83 84 62 85 /******************************************************************************* 63 86 * Internal Functions * … … 69 92 static DECLCALLBACK(void) stamR3EnumRelLogPrintf(PSTAMR3PRINTONEARGS pvArg, const char *pszFormat, ...); 70 93 static DECLCALLBACK(void) stamR3EnumPrintf(PSTAMR3PRINTONEARGS pvArg, const char *pszFormat, ...); 94 static int stamR3SnapshotOne(PSTAMDESC pDesc, void *pvArg); 95 static int stamR3SnapshotPrintf(PSTAMR3SNAPSHOTONE pThis, const char *pszFormat, ...); 71 96 static int stamR3PrintOne(PSTAMDESC pDesc, void *pvArg); 72 97 static int stamR3EnumOne(PSTAMDESC pDesc, void *pvArg); … … 566 591 * @param pszPat The name matching pattern. See somewhere_where_this_is_described_in_detail. 567 592 * If NULL all samples are reset. 593 * @param fWithDesc Whether to include the descriptions. 568 594 * @param ppszSnapshot Where to store the pointer to the snapshot data. 569 595 * The format of the snapshot should be XML, but that will have to be discussed … … 572 598 * @param pcchSnapshot Where to store the size of the snapshot data. (Excluding the trailing '\0') 573 599 */ 574 STAMR3DECL(int) STAMR3Snapshot(PVM pVM, const char *pszPat, char **ppszSnapshot, size_t *pcchSnapshot) 575 { 576 AssertMsgFailed(("not implemented yet\n")); 577 return VERR_NOT_IMPLEMENTED; 600 STAMR3DECL(int) STAMR3Snapshot(PVM pVM, const char *pszPat, char **ppszSnapshot, size_t *pcchSnapshot, bool fWithDesc) 601 { 602 STAMR3SNAPSHOTONE State = { NULL, NULL, NULL, pVM, 0, VINF_SUCCESS, fWithDesc }; 603 604 /* 605 * Write the XML header. 606 */ 607 /** @todo Make this proper & valid XML. */ 608 stamR3SnapshotPrintf(&State, "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"); 609 610 /* 611 * Write the content. 612 */ 613 stamR3SnapshotPrintf(&State, "<Statistics>\n"); 614 STAM_LOCK_RD(pVM); 615 stamR3Enum(pVM, pszPat, stamR3SnapshotOne, &State); 616 STAM_UNLOCK_RD(pVM); 617 stamR3SnapshotPrintf(&State, "</Statistics>\n"); 618 619 /* 620 * Done. 621 */ 622 *ppszSnapshot = State.pszStart; 623 if (pcchSnapshot) 624 *pcchSnapshot = State.psz - State.pszStart; 625 return State.rc; 626 } 627 628 629 /** 630 * stamR3Enum callback employed by STAMR3Snapshot. 631 * 632 * @returns VBox status code, but it's interpreted as 0 == success / !0 == failure by enmR3Enum. 633 * @param pDesc The sample. 634 * @param pvArg The snapshot status structure. 635 */ 636 static int stamR3SnapshotOne(PSTAMDESC pDesc, void *pvArg) 637 { 638 PSTAMR3SNAPSHOTONE pThis = (PSTAMR3SNAPSHOTONE)pvArg; 639 640 switch (pDesc->enmType) 641 { 642 case STAMTYPE_COUNTER: 643 stamR3SnapshotPrintf(pThis, "<Counter c=\"%lld\"", pDesc->u.pCounter->c); 644 break; 645 646 case STAMTYPE_PROFILE: 647 case STAMTYPE_PROFILE_ADV: 648 stamR3SnapshotPrintf(pThis, "<Profile cPeriods=\"%lld\" cTicks=\"%lld\" cTicksMin=\"%lld\" cTicksMax=\"%lld\"", 649 pDesc->u.pProfile->cPeriods, pDesc->u.pProfile->cTicks, pDesc->u.pProfile->cTicksMin, 650 pDesc->u.pProfile->cTicksMax); 651 break; 652 653 case STAMTYPE_RATIO_U32: 654 case STAMTYPE_RATIO_U32_RESET: 655 stamR3SnapshotPrintf(pThis, "<Ratio32 u32A=\"%lld\" u32B=\"%lld\"", 656 pDesc->u.pRatioU32->u32A, pDesc->u.pRatioU32->u32B); 657 break; 658 659 case STAMTYPE_CALLBACK: 660 { 661 char szBuf[512]; 662 pDesc->u.Callback.pfnPrint(pThis->pVM, pDesc->u.Callback.pvSample, szBuf, sizeof(szBuf)); 663 stamR3SnapshotPrintf(pThis, "<Callback val=\"%s\"", szBuf); 664 break; 665 } 666 667 case STAMTYPE_U8: 668 case STAMTYPE_U8_RESET: 669 stamR3SnapshotPrintf(pThis, "<U8 val=\"%u\"", *pDesc->u.pu8); 670 break; 671 672 case STAMTYPE_X8: 673 case STAMTYPE_X8_RESET: 674 stamR3SnapshotPrintf(pThis, "<X8 val=\"%#x\"", *pDesc->u.pu8); 675 break; 676 677 case STAMTYPE_U16: 678 case STAMTYPE_U16_RESET: 679 stamR3SnapshotPrintf(pThis, "<U16 val=\"%u\"", *pDesc->u.pu16); 680 break; 681 682 case STAMTYPE_X16: 683 case STAMTYPE_X16_RESET: 684 stamR3SnapshotPrintf(pThis, "<X16 val=\"%#x\"", *pDesc->u.pu16); 685 break; 686 687 case STAMTYPE_U32: 688 case STAMTYPE_U32_RESET: 689 stamR3SnapshotPrintf(pThis, "<U32 val=\"%u\"", *pDesc->u.pu32); 690 break; 691 692 case STAMTYPE_X32: 693 case STAMTYPE_X32_RESET: 694 stamR3SnapshotPrintf(pThis, "<X32 val=\"%#x\"", *pDesc->u.pu32); 695 break; 696 697 case STAMTYPE_U64: 698 case STAMTYPE_U64_RESET: 699 stamR3SnapshotPrintf(pThis, "<U64 val=\"%llu\"", *pDesc->u.pu64); 700 break; 701 702 case STAMTYPE_X64: 703 case STAMTYPE_X64_RESET: 704 stamR3SnapshotPrintf(pThis, "<X64 val=\"%#llx\"", *pDesc->u.pu64); 705 break; 706 707 default: 708 AssertMsgFailed(("%d\n", pDesc->enmType)); 709 return 0; 710 } 711 712 stamR3SnapshotPrintf(pThis, " unit=\"%s\"", STAMR3GetUnit(pDesc->enmUnit)); 713 714 switch (pDesc->enmVisibility) 715 { 716 default: 717 case STAMVISIBILITY_ALWAYS: 718 break; 719 case STAMVISIBILITY_USED: 720 stamR3SnapshotPrintf(pThis, " vis=\"used\""); 721 break; 722 case STAMVISIBILITY_NOT_GUI: 723 stamR3SnapshotPrintf(pThis, " vis=\"not-gui\""); 724 break; 725 } 726 727 stamR3SnapshotPrintf(pThis, " name=\"%s\"", pDesc->pszName); 728 729 if (pThis->fWithDesc && pDesc->pszDesc) 730 return stamR3SnapshotPrintf(pThis, " desc=\"%s\"/>\n", pDesc->pszDesc); 731 return stamR3SnapshotPrintf(pThis, "/>\n"); 732 } 733 734 735 /** 736 * Output callback for stamR3SnapshotPrintf. 737 * 738 * @returns number of bytes written. 739 * @param pvArg The snapshot status structure. 740 * @param pach Pointer to an array of characters (bytes). 741 * @param cch The number or chars (bytes) to write from the array. 742 */ 743 static DECLCALLBACK(size_t) stamR3SnapshotOutput(void *pvArg, const char *pach, size_t cch) 744 { 745 PSTAMR3SNAPSHOTONE pThis = (PSTAMR3SNAPSHOTONE)pvArg; 746 747 /* 748 * Make sure we've got space for it. 749 */ 750 if (RT_UNLIKELY((uintptr_t)pThis->pszEnd - (uintptr_t)pThis->psz < cch + 1)) 751 { 752 if (RT_FAILURE(pThis->rc)) 753 return 0; 754 755 size_t cbNewSize = pThis->cbAllocated; 756 if (cbNewSize > cch) 757 cbNewSize *= 2; 758 else 759 cbNewSize += RT_ALIGN(cch + 1, 0x1000); 760 char *pszNew = (char *)RTMemRealloc(pThis->pszStart, cbNewSize); 761 if (!pszNew) 762 { 763 /* 764 * Free up immediately, out-of-memory is bad news and this 765 * isn't an important allocations / API. 766 */ 767 pThis->rc = VERR_NO_MEMORY; 768 RTMemFree(pThis->pszStart); 769 pThis->pszStart = pThis->pszEnd = pThis->psz = NULL; 770 pThis->cbAllocated = 0; 771 return 0; 772 } 773 774 pThis->psz = pszNew + (pThis->psz - pThis->pszStart); 775 pThis->pszStart = pszNew; 776 pThis->pszEnd = pszNew + cbNewSize; 777 pThis->cbAllocated = cbNewSize; 778 } 779 780 /* 781 * Copy the chars to the buffer and terminate it. 782 */ 783 memcpy(pThis->psz, pach, cch); 784 pThis->psz += cch; 785 *pThis->psz = '\0'; 786 return cch; 787 } 788 789 790 /** 791 * Wrapper around RTStrFormatV for use by the snapshot API. 792 * 793 * @returns VBox status code. 794 * @param pThis The snapshot status structure. 795 * @param pszFormat The format string. 796 * @param ... Optional arguments. 797 */ 798 static int stamR3SnapshotPrintf(PSTAMR3SNAPSHOTONE pThis, const char *pszFormat, ...) 799 { 800 va_list va; 801 va_start(va, pszFormat); 802 RTStrFormatV(stamR3SnapshotOutput, pThis, NULL, NULL, pszFormat, va); 803 va_end(va); 804 return pThis->rc; 578 805 } 579 806
Note:
See TracChangeset
for help on using the changeset viewer.