Changeset 103473 in vbox
- Timestamp:
- Feb 20, 2024 10:09:11 AM (11 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Debugger/VBoxDbgStatsQt.cpp
r103466 r103473 567 567 static void destroyTree(PDBGGUISTATSNODE a_pRoot); 568 568 569 public: 569 570 /** 570 571 * Stringifies exactly one node, no children. … … 572 573 * This is for logging and clipboard. 573 574 * 574 * @param a_pNode The node. 575 * @param a_rString The string to append the stringified node to. 576 */ 577 static void stringifyNodeNoRecursion(PDBGGUISTATSNODE a_pNode, QString &a_rString); 578 575 * @param a_pNode The node. 576 * @param a_rString The string to append the stringified node to. 577 * @param a_cchNameWidth The width of the basename. 578 */ 579 static void stringifyNodeNoRecursion(PDBGGUISTATSNODE a_pNode, QString &a_rString, size_t a_cchNameWidth); 580 581 protected: 579 582 /** 580 583 * Stringifies a node and its children. … … 582 585 * This is for logging and clipboard. 583 586 * 584 * @param a_pNode The node. 585 * @param a_rString The string to append the stringified node to. 586 */ 587 static void stringifyNode(PDBGGUISTATSNODE a_pNode, QString &a_rString); 587 * @param a_pNode The node. 588 * @param a_rString The string to append the stringified node to. 589 * @param a_cchNameWidth The width of the basename. 590 */ 591 static void stringifyNode(PDBGGUISTATSNODE a_pNode, QString &a_rString, size_t a_cchNameWidth); 588 592 589 593 public: … … 606 610 void xmlifyTree(QModelIndex &a_rRoot, QString &a_rString) const; 607 611 608 /**609 * Puts the stringified tree on the clipboard.610 *611 * @param a_rRoot Where to start. Use QModelIndex() to start at the root.612 */613 void copyTreeToClipboard(QModelIndex &a_rRoot) const;614 615 616 protected:617 /** Worker for logTree. */618 static void logNode(PDBGGUISTATSNODE a_pNode, bool a_fReleaseLog);619 620 612 public: 621 /** Logs a (sub-)tree.622 *623 * @param a_rRoot Where to start. Use QModelIndex() to start at the root.624 * @param a_fReleaseLog Whether to use the release log (true) or the debug log (false).625 */626 void logTree(QModelIndex &a_rRoot, bool a_fReleaseLog) const;627 613 628 614 /** Gets the unit. */ … … 783 769 void notifyFilterChanges(); 784 770 771 /** 772 * Converts the specified tree to string. 773 * 774 * This is for logging and clipboard. 775 * 776 * @param a_rRoot Where to start. Use QModelIndex() to start at the root. 777 * @param a_rString Where to return to return the string dump. 778 * @param a_cchNameWidth The width of the basename. 779 */ 780 void stringifyTree(QModelIndex const &a_rRoot, QString &a_rString, size_t a_cchNameWidth = 0) const; 781 785 782 protected: 786 783 /** 787 * Converts a nindex to a node pointer.784 * Converts a source index to a node pointer. 788 785 * 789 786 * @returns Pointer to the node, NULL if invalid reference. 790 * @param a_r Index Reference to the index791 */ 792 inline PDBGGUISTATSNODE nodeFrom Index(const QModelIndex &a_rIndex) const793 { 794 if (RT_LIKELY(a_r Index.isValid()))795 return (PDBGGUISTATSNODE)a_r Index.internalPointer();787 * @param a_rSrcIndex Reference to the source index. 788 */ 789 inline PDBGGUISTATSNODE nodeFromSrcIndex(const QModelIndex &a_rSrcIndex) const 790 { 791 if (RT_LIKELY(a_rSrcIndex.isValid())) 792 return (PDBGGUISTATSNODE)a_rSrcIndex.internalPointer(); 796 793 return NULL; 794 } 795 796 /** 797 * Converts a proxy index to a node pointer. 798 * 799 * @returns Pointer to the node, NULL if invalid reference. 800 * @param a_rProxyIndex The reference to the proxy index. 801 */ 802 inline PDBGGUISTATSNODE nodeFromProxyIndex(const QModelIndex &a_rProxyIndex) const 803 { 804 QModelIndex const SrcIndex = mapToSource(a_rProxyIndex); 805 return nodeFromSrcIndex(SrcIndex); 797 806 } 798 807 … … 2982 2991 2983 2992 /*static*/ void 2984 VBoxDbgStatsModel::stringifyNodeNoRecursion(PDBGGUISTATSNODE a_pNode, QString &a_rString )2993 VBoxDbgStatsModel::stringifyNodeNoRecursion(PDBGGUISTATSNODE a_pNode, QString &a_rString, size_t a_cchNameWidth) 2985 2994 { 2986 2995 /* … … 2990 2999 ssize_t off = getNodePath(a_pNode, szBuf, sizeof(szBuf) - 2); 2991 3000 AssertReturnVoid(off >= 0); 2992 if (off < 32)2993 {2994 memset(&szBuf[off], ' ', 32 - off);2995 szBuf[32] = '\0';2996 off = 32;2997 }2998 3001 szBuf[off++] = ' '; 3002 ssize_t cchPadding = (ssize_t)(a_cchNameWidth - a_pNode->cchName); 3003 if (off < 32 && 32 - off > cchPadding) 3004 cchPadding = 32 - off; 3005 if (cchPadding > 0) 3006 { 3007 if (off + (size_t)cchPadding + 1 >= sizeof(szBuf)) 3008 cchPadding = sizeof(szBuf) - off - 1; 3009 if (cchPadding > 0) 3010 { 3011 memset(&szBuf[off], ' ', cchPadding); 3012 off += (size_t)cchPadding; 3013 } 3014 } 2999 3015 szBuf[off] = '\0'; 3000 3016 a_rString += szBuf; … … 3008 3024 { 3009 3025 case STAMTYPE_COUNTER: 3010 RTStrPrintf(szBuf, sizeof(szBuf), "% 8llu %s", a_pNode->Data.Counter.c, a_pNode->pszUnit);3026 RTStrPrintf(szBuf, sizeof(szBuf), "%'11llu %s", a_pNode->Data.Counter.c, a_pNode->pszUnit); 3011 3027 break; 3012 3028 … … 3016 3032 uint64_t u64 = a_pNode->Data.Profile.cPeriods ? a_pNode->Data.Profile.cPeriods : 1; 3017 3033 RTStrPrintf(szBuf, sizeof(szBuf), 3018 "% 8llu %s (%12llu ticks, %7llu times, max %9llu, min %7lld)",3034 "%'11llu %s (%'14llu ticks, %'9llu times, max %'12llu, min %'9lld)", 3019 3035 a_pNode->Data.Profile.cTicks / u64, a_pNode->pszUnit, 3020 a_pNode->Data.Profile.cTicks, a_pNode->Data.Profile.cPeriods, a_pNode->Data.Profile.cTicksMax, a_pNode->Data.Profile.cTicksMin); 3036 a_pNode->Data.Profile.cTicks, a_pNode->Data.Profile.cPeriods, 3037 a_pNode->Data.Profile.cTicksMax, a_pNode->Data.Profile.cTicksMin); 3021 3038 break; 3022 3039 } … … 3025 3042 case STAMTYPE_RATIO_U32_RESET: 3026 3043 RTStrPrintf(szBuf, sizeof(szBuf), 3027 "% 8u:%-8u %s",3044 "%'8u:%-'8u %s", 3028 3045 a_pNode->Data.RatioU32.u32A, a_pNode->Data.RatioU32.u32B, a_pNode->pszUnit); 3029 3046 break; … … 3037 3054 case STAMTYPE_U8: 3038 3055 case STAMTYPE_U8_RESET: 3039 RTStrPrintf(szBuf, sizeof(szBuf), "% 8u %s", a_pNode->Data.u8, a_pNode->pszUnit);3056 RTStrPrintf(szBuf, sizeof(szBuf), "%11u %s", a_pNode->Data.u8, a_pNode->pszUnit); 3040 3057 break; 3041 3058 3042 3059 case STAMTYPE_X8: 3043 3060 case STAMTYPE_X8_RESET: 3044 RTStrPrintf(szBuf, sizeof(szBuf), "% 8x %s", a_pNode->Data.u8, a_pNode->pszUnit);3061 RTStrPrintf(szBuf, sizeof(szBuf), "%11x %s", a_pNode->Data.u8, a_pNode->pszUnit); 3045 3062 break; 3046 3063 3047 3064 case STAMTYPE_U16: 3048 3065 case STAMTYPE_U16_RESET: 3049 RTStrPrintf(szBuf, sizeof(szBuf), "% 8u %s", a_pNode->Data.u16, a_pNode->pszUnit);3066 RTStrPrintf(szBuf, sizeof(szBuf), "%'11u %s", a_pNode->Data.u16, a_pNode->pszUnit); 3050 3067 break; 3051 3068 3052 3069 case STAMTYPE_X16: 3053 3070 case STAMTYPE_X16_RESET: 3054 RTStrPrintf(szBuf, sizeof(szBuf), "% 8x %s", a_pNode->Data.u16, a_pNode->pszUnit);3071 RTStrPrintf(szBuf, sizeof(szBuf), "%11x %s", a_pNode->Data.u16, a_pNode->pszUnit); 3055 3072 break; 3056 3073 3057 3074 case STAMTYPE_U32: 3058 3075 case STAMTYPE_U32_RESET: 3059 RTStrPrintf(szBuf, sizeof(szBuf), "% 8u %s", a_pNode->Data.u32, a_pNode->pszUnit);3076 RTStrPrintf(szBuf, sizeof(szBuf), "%'11u %s", a_pNode->Data.u32, a_pNode->pszUnit); 3060 3077 break; 3061 3078 3062 3079 case STAMTYPE_X32: 3063 3080 case STAMTYPE_X32_RESET: 3064 RTStrPrintf(szBuf, sizeof(szBuf), "% 8x %s", a_pNode->Data.u32, a_pNode->pszUnit);3081 RTStrPrintf(szBuf, sizeof(szBuf), "%11x %s", a_pNode->Data.u32, a_pNode->pszUnit); 3065 3082 break; 3066 3083 3067 3084 case STAMTYPE_U64: 3068 3085 case STAMTYPE_U64_RESET: 3069 RTStrPrintf(szBuf, sizeof(szBuf), "% 8llu %s", a_pNode->Data.u64, a_pNode->pszUnit);3086 RTStrPrintf(szBuf, sizeof(szBuf), "%'11llu %s", a_pNode->Data.u64, a_pNode->pszUnit); 3070 3087 break; 3071 3088 3072 3089 case STAMTYPE_X64: 3073 3090 case STAMTYPE_X64_RESET: 3074 RTStrPrintf(szBuf, sizeof(szBuf), "% 8llx %s", a_pNode->Data.u64, a_pNode->pszUnit);3091 RTStrPrintf(szBuf, sizeof(szBuf), "%'11llx %s", a_pNode->Data.u64, a_pNode->pszUnit); 3075 3092 break; 3076 3093 … … 3090 3107 3091 3108 /*static*/ void 3092 VBoxDbgStatsModel::stringifyNode(PDBGGUISTATSNODE a_pNode, QString &a_rString )3109 VBoxDbgStatsModel::stringifyNode(PDBGGUISTATSNODE a_pNode, QString &a_rString, size_t a_cchNameWidth) 3093 3110 { 3094 3111 /* this node (if it has data) */ … … 3097 3114 if (!a_rString.isEmpty()) 3098 3115 a_rString += "\n"; 3099 stringifyNodeNoRecursion(a_pNode, a_rString );3116 stringifyNodeNoRecursion(a_pNode, a_rString, a_cchNameWidth); 3100 3117 } 3101 3118 3102 3119 /* the children */ 3103 3120 uint32_t const cChildren = a_pNode->cChildren; 3121 a_cchNameWidth = 0; 3104 3122 for (uint32_t i = 0; i < cChildren; i++) 3105 stringifyNode(a_pNode->papChildren[i], a_rString); 3123 if (a_cchNameWidth < a_pNode->papChildren[i]->cchName) 3124 a_cchNameWidth = a_pNode->papChildren[i]->cchName; 3125 for (uint32_t i = 0; i < cChildren; i++) 3126 stringifyNode(a_pNode->papChildren[i], a_rString, a_cchNameWidth); 3106 3127 } 3107 3128 … … 3112 3133 PDBGGUISTATSNODE pRoot = a_rRoot.isValid() ? nodeFromIndex(a_rRoot) : m_pRoot; 3113 3134 if (pRoot) 3114 stringifyNode(pRoot, a_rString); 3115 } 3116 3117 3118 void 3119 VBoxDbgStatsModel::copyTreeToClipboard(QModelIndex &a_rRoot) const 3120 { 3121 QString String; 3122 stringifyTree(a_rRoot, String); 3123 3124 QClipboard *pClipboard = QApplication::clipboard(); 3125 if (pClipboard) 3126 pClipboard->setText(String, QClipboard::Clipboard); 3127 } 3128 3129 3130 /*static*/ void 3131 VBoxDbgStatsModel::logNode(PDBGGUISTATSNODE a_pNode, bool a_fReleaseLog) 3132 { 3133 /* this node (if it has data) */ 3134 if (a_pNode->enmType != STAMTYPE_INVALID) 3135 { 3136 QString SelfStr; 3137 stringifyNodeNoRecursion(a_pNode, SelfStr); 3138 QByteArray SelfByteArray = SelfStr.toUtf8(); 3139 if (a_fReleaseLog) 3140 RTLogRelPrintf("%s\n", SelfByteArray.constData()); 3141 else 3142 RTLogPrintf("%s\n", SelfByteArray.constData()); 3143 } 3144 3145 /* the children */ 3146 uint32_t const cChildren = a_pNode->cChildren; 3147 for (uint32_t i = 0; i < cChildren; i++) 3148 logNode(a_pNode->papChildren[i], a_fReleaseLog); 3149 } 3150 3151 3152 void 3153 VBoxDbgStatsModel::logTree(QModelIndex &a_rRoot, bool a_fReleaseLog) const 3154 { 3155 PDBGGUISTATSNODE pRoot = a_rRoot.isValid() ? nodeFromIndex(a_rRoot) : m_pRoot; 3156 if (pRoot) 3157 logNode(pRoot, a_fReleaseLog); 3135 stringifyNode(pRoot, a_rString, 0); 3158 3136 } 3159 3137 … … 3399 3377 * Locate the node. 3400 3378 */ 3401 PDBGGUISTATSNODE pParent = nodeFrom Index(a_rSrcParent);3379 PDBGGUISTATSNODE pParent = nodeFromSrcIndex(a_rSrcParent); 3402 3380 if (pParent) 3403 3381 { … … 3528 3506 VBoxDbgStatsSortFileProxyModel::lessThan(const QModelIndex &a_rSrcLeft, const QModelIndex &a_rSrcRight) const 3529 3507 { 3530 PCDBGGUISTATSNODE const pLeft = nodeFrom Index(a_rSrcLeft);3531 PCDBGGUISTATSNODE const pRight = nodeFrom Index(a_rSrcRight);3508 PCDBGGUISTATSNODE const pLeft = nodeFromSrcIndex(a_rSrcLeft); 3509 PCDBGGUISTATSNODE const pRight = nodeFromSrcIndex(a_rSrcRight); 3532 3510 if (pLeft == pRight) 3533 3511 return false; … … 3591 3569 3592 3570 3571 void 3572 VBoxDbgStatsSortFileProxyModel::stringifyTree(QModelIndex const &a_rRoot, QString &a_rString, size_t a_cchNameWidth) const 3573 { 3574 /* The node itself. */ 3575 PDBGGUISTATSNODE pNode = nodeFromProxyIndex(a_rRoot); 3576 if (pNode) 3577 { 3578 if (pNode->enmType != STAMTYPE_INVALID) 3579 { 3580 if (!a_rString.isEmpty()) 3581 a_rString += "\n"; 3582 VBoxDbgStatsModel::stringifyNodeNoRecursion(pNode, a_rString, a_cchNameWidth); 3583 } 3584 } 3585 3586 /* The children. */ 3587 int const cChildren = rowCount(a_rRoot); 3588 if (cChildren > 0) 3589 { 3590 a_cchNameWidth = 0; 3591 for (int iChild = 0; iChild < cChildren; iChild++) 3592 { 3593 QModelIndex const ChildIdx = index(iChild, 0, a_rRoot); 3594 pNode = nodeFromProxyIndex(ChildIdx); 3595 if (pNode && a_cchNameWidth < pNode->cchName) 3596 a_cchNameWidth = pNode->cchName; 3597 } 3598 3599 for (int iChild = 0; iChild < cChildren; iChild++) 3600 { 3601 QModelIndex const ChildIdx = index(iChild, 0, a_rRoot); 3602 stringifyTree(ChildIdx, a_rString, a_cchNameWidth); 3603 } 3604 } 3605 } 3606 3593 3607 #endif /* VBOXDBG_WITH_SORTED_AND_FILTERED_STATS */ 3594 3608 … … 3984 3998 { 3985 3999 QModelIndex Idx = m_pCurMenu ? m_CurIndex : currentIndex(); 4000 4001 QString String; 3986 4002 if (m_pProxyModel) 3987 Idx = m_pProxyModel->mapToSource(Idx); 3988 m_pVBoxModel->copyTreeToClipboard(Idx); 4003 m_pProxyModel->stringifyTree(Idx, String); 4004 else 4005 m_pVBoxModel->stringifyTree(Idx, String); 4006 4007 QClipboard *pClipboard = QApplication::clipboard(); 4008 if (pClipboard) 4009 pClipboard->setText(String, QClipboard::Clipboard); 3989 4010 } 3990 4011 … … 3994 4015 { 3995 4016 QModelIndex Idx = m_pCurMenu ? m_CurIndex : currentIndex(); 4017 4018 QString String; 3996 4019 if (m_pProxyModel) 3997 Idx = m_pProxyModel->mapToSource(Idx); 3998 m_pVBoxModel->logTree(Idx, false /* a_fReleaseLog */); 4020 m_pProxyModel->stringifyTree(Idx, String); 4021 else 4022 m_pVBoxModel->stringifyTree(Idx, String); 4023 4024 QByteArray SelfByteArray = String.toUtf8(); 4025 RTLogPrintf("%s\n", SelfByteArray.constData()); 3999 4026 } 4000 4027 … … 4004 4031 { 4005 4032 QModelIndex Idx = m_pCurMenu ? m_CurIndex : currentIndex(); 4033 4034 QString String; 4006 4035 if (m_pProxyModel) 4007 Idx = m_pProxyModel->mapToSource(Idx); 4008 m_pVBoxModel->logTree(Idx, true /* a_fReleaseLog */); 4036 m_pProxyModel->stringifyTree(Idx, String); 4037 else 4038 m_pVBoxModel->stringifyTree(Idx, String); 4039 4040 QByteArray SelfByteArray = String.toUtf8(); 4041 RTLogRelPrintf("%s\n", SelfByteArray.constData()); 4009 4042 } 4010 4043
Note:
See TracChangeset
for help on using the changeset viewer.