Index: trunk/src/VBox/Debugger/VBoxDbgStatsQt.cpp
===================================================================
--- trunk/src/VBox/Debugger/VBoxDbgStatsQt.cpp	(revision 103466)
+++ trunk/src/VBox/Debugger/VBoxDbgStatsQt.cpp	(revision 103473)
@@ -567,4 +567,5 @@
     static void destroyTree(PDBGGUISTATSNODE a_pRoot);
 
+public:
     /**
      * Stringifies exactly one node, no children.
@@ -572,9 +573,11 @@
      * This is for logging and clipboard.
      *
-     * @param   a_pNode     The node.
-     * @param   a_rString   The string to append the stringified node to.
-     */
-    static void stringifyNodeNoRecursion(PDBGGUISTATSNODE a_pNode, QString &a_rString);
-
+     * @param   a_pNode         The node.
+     * @param   a_rString       The string to append the stringified node to.
+     * @param   a_cchNameWidth  The width of the basename.
+     */
+    static void stringifyNodeNoRecursion(PDBGGUISTATSNODE a_pNode, QString &a_rString, size_t a_cchNameWidth);
+
+protected:
     /**
      * Stringifies a node and its children.
@@ -582,8 +585,9 @@
      * This is for logging and clipboard.
      *
-     * @param   a_pNode     The node.
-     * @param   a_rString   The string to append the stringified node to.
-     */
-    static void stringifyNode(PDBGGUISTATSNODE a_pNode, QString &a_rString);
+     * @param   a_pNode         The node.
+     * @param   a_rString       The string to append the stringified node to.
+     * @param   a_cchNameWidth  The width of the basename.
+     */
+    static void stringifyNode(PDBGGUISTATSNODE a_pNode, QString &a_rString, size_t a_cchNameWidth);
 
 public:
@@ -606,23 +610,5 @@
     void xmlifyTree(QModelIndex &a_rRoot, QString &a_rString) const;
 
-    /**
-     * Puts the stringified tree on the clipboard.
-     *
-     * @param   a_rRoot         Where to start. Use QModelIndex() to start at the root.
-     */
-    void copyTreeToClipboard(QModelIndex &a_rRoot) const;
-
-
-protected:
-    /** Worker for logTree. */
-    static void logNode(PDBGGUISTATSNODE a_pNode, bool a_fReleaseLog);
-
 public:
-    /** Logs a (sub-)tree.
-     *
-     * @param   a_rRoot         Where to start. Use QModelIndex() to start at the root.
-     * @param   a_fReleaseLog   Whether to use the release log (true) or the debug log (false).
-     */
-    void logTree(QModelIndex &a_rRoot, bool a_fReleaseLog) const;
 
     /** Gets the unit. */
@@ -783,16 +769,39 @@
     void notifyFilterChanges();
 
+    /**
+     * Converts the specified tree to string.
+     *
+     * This is for logging and clipboard.
+     *
+     * @param   a_rRoot         Where to start. Use QModelIndex() to start at the root.
+     * @param   a_rString       Where to return to return the string dump.
+     * @param   a_cchNameWidth  The width of the basename.
+     */
+    void stringifyTree(QModelIndex const &a_rRoot, QString &a_rString, size_t a_cchNameWidth = 0) const;
+
 protected:
     /**
-     * Converts an index to a node pointer.
+     * Converts a source index to a node pointer.
      *
      * @returns Pointer to the node, NULL if invalid reference.
-     * @param   a_rIndex        Reference to the index
-     */
-    inline PDBGGUISTATSNODE nodeFromIndex(const QModelIndex &a_rIndex) const
-    {
-        if (RT_LIKELY(a_rIndex.isValid()))
-            return (PDBGGUISTATSNODE)a_rIndex.internalPointer();
+     * @param   a_rSrcIndex     Reference to the source index.
+     */
+    inline PDBGGUISTATSNODE nodeFromSrcIndex(const QModelIndex &a_rSrcIndex) const
+    {
+        if (RT_LIKELY(a_rSrcIndex.isValid()))
+            return (PDBGGUISTATSNODE)a_rSrcIndex.internalPointer();
         return NULL;
+    }
+
+    /**
+     * Converts a proxy index to a node pointer.
+     *
+     * @returns Pointer to the node, NULL if invalid reference.
+     * @param   a_rProxyIndex   The reference to the proxy index.
+     */
+    inline PDBGGUISTATSNODE nodeFromProxyIndex(const QModelIndex &a_rProxyIndex) const
+    {
+        QModelIndex const SrcIndex = mapToSource(a_rProxyIndex);
+        return nodeFromSrcIndex(SrcIndex);
     }
 
@@ -2982,5 +2991,5 @@
 
 /*static*/ void
-VBoxDbgStatsModel::stringifyNodeNoRecursion(PDBGGUISTATSNODE a_pNode, QString &a_rString)
+VBoxDbgStatsModel::stringifyNodeNoRecursion(PDBGGUISTATSNODE a_pNode, QString &a_rString, size_t a_cchNameWidth)
 {
     /*
@@ -2990,11 +2999,18 @@
     ssize_t off = getNodePath(a_pNode, szBuf, sizeof(szBuf) - 2);
     AssertReturnVoid(off >= 0);
-    if (off < 32)
-    {
-        memset(&szBuf[off], ' ', 32 - off);
-        szBuf[32] = '\0';
-        off = 32;
-    }
     szBuf[off++] = ' ';
+    ssize_t cchPadding = (ssize_t)(a_cchNameWidth - a_pNode->cchName);
+    if (off < 32 && 32 - off > cchPadding)
+        cchPadding = 32 - off;
+    if (cchPadding > 0)
+    {
+        if (off + (size_t)cchPadding + 1 >= sizeof(szBuf))
+            cchPadding = sizeof(szBuf) - off - 1;
+        if (cchPadding > 0)
+        {
+            memset(&szBuf[off], ' ', cchPadding);
+            off += (size_t)cchPadding;
+        }
+    }
     szBuf[off]   = '\0';
     a_rString += szBuf;
@@ -3008,5 +3024,5 @@
     {
         case STAMTYPE_COUNTER:
-            RTStrPrintf(szBuf, sizeof(szBuf), "%8llu %s", a_pNode->Data.Counter.c, a_pNode->pszUnit);
+            RTStrPrintf(szBuf, sizeof(szBuf), "%'11llu %s", a_pNode->Data.Counter.c, a_pNode->pszUnit);
             break;
 
@@ -3016,7 +3032,8 @@
             uint64_t u64 = a_pNode->Data.Profile.cPeriods ? a_pNode->Data.Profile.cPeriods : 1;
             RTStrPrintf(szBuf, sizeof(szBuf),
-                        "%8llu %s (%12llu ticks, %7llu times, max %9llu, min %7lld)",
+                        "%'11llu %s (%'14llu ticks, %'9llu times, max %'12llu, min %'9lld)",
                         a_pNode->Data.Profile.cTicks / u64, a_pNode->pszUnit,
-                        a_pNode->Data.Profile.cTicks, a_pNode->Data.Profile.cPeriods, a_pNode->Data.Profile.cTicksMax, a_pNode->Data.Profile.cTicksMin);
+                        a_pNode->Data.Profile.cTicks, a_pNode->Data.Profile.cPeriods,
+                        a_pNode->Data.Profile.cTicksMax, a_pNode->Data.Profile.cTicksMin);
             break;
         }
@@ -3025,5 +3042,5 @@
         case STAMTYPE_RATIO_U32_RESET:
             RTStrPrintf(szBuf, sizeof(szBuf),
-                        "%8u:%-8u %s",
+                        "%'8u:%-'8u %s",
                         a_pNode->Data.RatioU32.u32A, a_pNode->Data.RatioU32.u32B, a_pNode->pszUnit);
             break;
@@ -3037,40 +3054,40 @@
         case STAMTYPE_U8:
         case STAMTYPE_U8_RESET:
-            RTStrPrintf(szBuf, sizeof(szBuf), "%8u %s", a_pNode->Data.u8, a_pNode->pszUnit);
+            RTStrPrintf(szBuf, sizeof(szBuf), "%11u %s", a_pNode->Data.u8, a_pNode->pszUnit);
             break;
 
         case STAMTYPE_X8:
         case STAMTYPE_X8_RESET:
-            RTStrPrintf(szBuf, sizeof(szBuf), "%8x %s", a_pNode->Data.u8, a_pNode->pszUnit);
+            RTStrPrintf(szBuf, sizeof(szBuf), "%11x %s", a_pNode->Data.u8, a_pNode->pszUnit);
             break;
 
         case STAMTYPE_U16:
         case STAMTYPE_U16_RESET:
-            RTStrPrintf(szBuf, sizeof(szBuf), "%8u %s", a_pNode->Data.u16, a_pNode->pszUnit);
+            RTStrPrintf(szBuf, sizeof(szBuf), "%'11u %s", a_pNode->Data.u16, a_pNode->pszUnit);
             break;
 
         case STAMTYPE_X16:
         case STAMTYPE_X16_RESET:
-            RTStrPrintf(szBuf, sizeof(szBuf), "%8x %s", a_pNode->Data.u16, a_pNode->pszUnit);
+            RTStrPrintf(szBuf, sizeof(szBuf), "%11x %s", a_pNode->Data.u16, a_pNode->pszUnit);
             break;
 
         case STAMTYPE_U32:
         case STAMTYPE_U32_RESET:
-            RTStrPrintf(szBuf, sizeof(szBuf), "%8u %s", a_pNode->Data.u32, a_pNode->pszUnit);
+            RTStrPrintf(szBuf, sizeof(szBuf), "%'11u %s", a_pNode->Data.u32, a_pNode->pszUnit);
             break;
 
         case STAMTYPE_X32:
         case STAMTYPE_X32_RESET:
-            RTStrPrintf(szBuf, sizeof(szBuf), "%8x %s", a_pNode->Data.u32, a_pNode->pszUnit);
+            RTStrPrintf(szBuf, sizeof(szBuf), "%11x %s", a_pNode->Data.u32, a_pNode->pszUnit);
             break;
 
         case STAMTYPE_U64:
         case STAMTYPE_U64_RESET:
-            RTStrPrintf(szBuf, sizeof(szBuf), "%8llu %s", a_pNode->Data.u64, a_pNode->pszUnit);
+            RTStrPrintf(szBuf, sizeof(szBuf), "%'11llu %s", a_pNode->Data.u64, a_pNode->pszUnit);
             break;
 
         case STAMTYPE_X64:
         case STAMTYPE_X64_RESET:
-            RTStrPrintf(szBuf, sizeof(szBuf), "%8llx %s", a_pNode->Data.u64, a_pNode->pszUnit);
+            RTStrPrintf(szBuf, sizeof(szBuf), "%'11llx %s", a_pNode->Data.u64, a_pNode->pszUnit);
             break;
 
@@ -3090,5 +3107,5 @@
 
 /*static*/ void
-VBoxDbgStatsModel::stringifyNode(PDBGGUISTATSNODE a_pNode, QString &a_rString)
+VBoxDbgStatsModel::stringifyNode(PDBGGUISTATSNODE a_pNode, QString &a_rString, size_t a_cchNameWidth)
 {
     /* this node (if it has data) */
@@ -3097,11 +3114,15 @@
         if (!a_rString.isEmpty())
             a_rString += "\n";
-        stringifyNodeNoRecursion(a_pNode, a_rString);
+        stringifyNodeNoRecursion(a_pNode, a_rString, a_cchNameWidth);
     }
 
     /* the children */
     uint32_t const cChildren = a_pNode->cChildren;
+    a_cchNameWidth = 0;
     for (uint32_t i = 0; i < cChildren; i++)
-        stringifyNode(a_pNode->papChildren[i], a_rString);
+        if (a_cchNameWidth < a_pNode->papChildren[i]->cchName)
+            a_cchNameWidth = a_pNode->papChildren[i]->cchName;
+    for (uint32_t i = 0; i < cChildren; i++)
+        stringifyNode(a_pNode->papChildren[i], a_rString, a_cchNameWidth);
 }
 
@@ -3112,48 +3133,5 @@
     PDBGGUISTATSNODE pRoot = a_rRoot.isValid() ? nodeFromIndex(a_rRoot) : m_pRoot;
     if (pRoot)
-        stringifyNode(pRoot, a_rString);
-}
-
-
-void
-VBoxDbgStatsModel::copyTreeToClipboard(QModelIndex &a_rRoot) const
-{
-    QString String;
-    stringifyTree(a_rRoot, String);
-
-    QClipboard *pClipboard = QApplication::clipboard();
-    if (pClipboard)
-        pClipboard->setText(String, QClipboard::Clipboard);
-}
-
-
-/*static*/ void
-VBoxDbgStatsModel::logNode(PDBGGUISTATSNODE a_pNode, bool a_fReleaseLog)
-{
-    /* this node (if it has data) */
-    if (a_pNode->enmType != STAMTYPE_INVALID)
-    {
-        QString SelfStr;
-        stringifyNodeNoRecursion(a_pNode, SelfStr);
-        QByteArray SelfByteArray = SelfStr.toUtf8();
-        if (a_fReleaseLog)
-            RTLogRelPrintf("%s\n", SelfByteArray.constData());
-        else
-            RTLogPrintf("%s\n", SelfByteArray.constData());
-    }
-
-    /* the children */
-    uint32_t const cChildren = a_pNode->cChildren;
-    for (uint32_t i = 0; i < cChildren; i++)
-        logNode(a_pNode->papChildren[i], a_fReleaseLog);
-}
-
-
-void
-VBoxDbgStatsModel::logTree(QModelIndex &a_rRoot, bool a_fReleaseLog) const
-{
-    PDBGGUISTATSNODE pRoot = a_rRoot.isValid() ? nodeFromIndex(a_rRoot) : m_pRoot;
-    if (pRoot)
-        logNode(pRoot, a_fReleaseLog);
+        stringifyNode(pRoot, a_rString, 0);
 }
 
@@ -3399,5 +3377,5 @@
      * Locate the node.
      */
-    PDBGGUISTATSNODE pParent = nodeFromIndex(a_rSrcParent);
+    PDBGGUISTATSNODE pParent = nodeFromSrcIndex(a_rSrcParent);
     if (pParent)
     {
@@ -3528,6 +3506,6 @@
 VBoxDbgStatsSortFileProxyModel::lessThan(const QModelIndex &a_rSrcLeft, const QModelIndex &a_rSrcRight) const
 {
-    PCDBGGUISTATSNODE const pLeft  = nodeFromIndex(a_rSrcLeft);
-    PCDBGGUISTATSNODE const pRight = nodeFromIndex(a_rSrcRight);
+    PCDBGGUISTATSNODE const pLeft  = nodeFromSrcIndex(a_rSrcLeft);
+    PCDBGGUISTATSNODE const pRight = nodeFromSrcIndex(a_rSrcRight);
     if (pLeft == pRight)
         return false;
@@ -3591,4 +3569,40 @@
 
 
+void
+VBoxDbgStatsSortFileProxyModel::stringifyTree(QModelIndex const &a_rRoot, QString &a_rString, size_t a_cchNameWidth) const
+{
+    /* The node itself. */
+    PDBGGUISTATSNODE pNode = nodeFromProxyIndex(a_rRoot);
+    if (pNode)
+    {
+        if (pNode->enmType != STAMTYPE_INVALID)
+        {
+            if (!a_rString.isEmpty())
+                a_rString += "\n";
+            VBoxDbgStatsModel::stringifyNodeNoRecursion(pNode, a_rString, a_cchNameWidth);
+        }
+    }
+
+    /* The children. */
+    int const cChildren = rowCount(a_rRoot);
+    if (cChildren > 0)
+    {
+        a_cchNameWidth = 0;
+        for (int iChild = 0; iChild < cChildren; iChild++)
+        {
+            QModelIndex const ChildIdx = index(iChild, 0, a_rRoot);
+            pNode = nodeFromProxyIndex(ChildIdx);
+            if (pNode && a_cchNameWidth < pNode->cchName)
+                a_cchNameWidth = pNode->cchName;
+        }
+
+        for (int iChild = 0; iChild < cChildren; iChild++)
+        {
+            QModelIndex const ChildIdx = index(iChild, 0, a_rRoot);
+            stringifyTree(ChildIdx, a_rString, a_cchNameWidth);
+        }
+    }
+}
+
 #endif /* VBOXDBG_WITH_SORTED_AND_FILTERED_STATS */
 
@@ -3984,7 +3998,14 @@
 {
     QModelIndex Idx = m_pCurMenu ? m_CurIndex : currentIndex();
+
+    QString     String;
     if (m_pProxyModel)
-        Idx = m_pProxyModel->mapToSource(Idx);
-    m_pVBoxModel->copyTreeToClipboard(Idx);
+        m_pProxyModel->stringifyTree(Idx, String);
+    else
+        m_pVBoxModel->stringifyTree(Idx, String);
+
+    QClipboard *pClipboard = QApplication::clipboard();
+    if (pClipboard)
+        pClipboard->setText(String, QClipboard::Clipboard);
 }
 
@@ -3994,7 +4015,13 @@
 {
     QModelIndex Idx = m_pCurMenu ? m_CurIndex : currentIndex();
+
+    QString     String;
     if (m_pProxyModel)
-        Idx = m_pProxyModel->mapToSource(Idx);
-    m_pVBoxModel->logTree(Idx, false /* a_fReleaseLog */);
+        m_pProxyModel->stringifyTree(Idx, String);
+    else
+        m_pVBoxModel->stringifyTree(Idx, String);
+
+    QByteArray SelfByteArray = String.toUtf8();
+    RTLogPrintf("%s\n", SelfByteArray.constData());
 }
 
@@ -4004,7 +4031,13 @@
 {
     QModelIndex Idx = m_pCurMenu ? m_CurIndex : currentIndex();
+
+    QString     String;
     if (m_pProxyModel)
-        Idx = m_pProxyModel->mapToSource(Idx);
-    m_pVBoxModel->logTree(Idx, true /* a_fReleaseLog */);
+        m_pProxyModel->stringifyTree(Idx, String);
+    else
+        m_pVBoxModel->stringifyTree(Idx, String);
+
+    QByteArray SelfByteArray = String.toUtf8();
+    RTLogRelPrintf("%s\n", SelfByteArray.constData());
 }
 
