Index: /trunk/src/VBox/Devices/VMMDev/VMMDev.cpp
===================================================================
--- /trunk/src/VBox/Devices/VMMDev/VMMDev.cpp	(revision 90265)
+++ /trunk/src/VBox/Devices/VMMDev/VMMDev.cpp	(revision 90266)
@@ -4699,8 +4699,8 @@
         PDMDevHlpSTAMRegisterF(pDevIns, &pThisCC->aHgcmAcc[idx].cbHeapBudgetConfig, STAMTYPE_U64, STAMVISIBILITY_ALWAYS,
                                STAMUNIT_BYTES, "Configured budget",          "HGCM-%s/BudgetConfig", pszCatName);
-        PDMDevHlpSTAMRegisterF(pDevIns, &pThisCC->aHgcmAcc[idx].cbHeapTotal, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS,
-                               STAMUNIT_BYTES, "Total heap usage",           "HGCM-%s/cbHeapTotal", pszCatName);
-        PDMDevHlpSTAMRegisterF(pDevIns, &pThisCC->aHgcmAcc[idx].cTotalMessages, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS,
-                               STAMUNIT_COUNT, "Total messages",             "HGCM-%s/cTotalMessages", pszCatName);
+        PDMDevHlpSTAMRegisterF(pDevIns, &pThisCC->aHgcmAcc[idx].StateMsgHeapUsage, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS,
+                               STAMUNIT_BYTES, "Message heap usage",         "HGCM-%s/MessageHeapUsage", pszCatName);
+        PDMDevHlpSTAMRegisterF(pDevIns, &pThisCC->aHgcmAcc[idx].StatBudgetOverruns, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS,
+                               STAMUNIT_BYTES, "Budget overruns and allocation errors", "HGCM-%s/BudgetOverruns", pszCatName);
     }
 #endif
Index: /trunk/src/VBox/Devices/VMMDev/VMMDevHGCM.cpp
===================================================================
--- /trunk/src/VBox/Devices/VMMDev/VMMDevHGCM.cpp	(revision 90265)
+++ /trunk/src/VBox/Devices/VMMDev/VMMDevHGCM.cpp	(revision 90266)
@@ -355,4 +355,5 @@
             LogFunc(("Heap budget overrun: sizeof(*pCmdCached)=%#zx aHgcmAcc[%zu].cbHeapBudget=%#RX64 - enmCmdType=%d\n",
                      sizeof(*pCmdCached), idxHeapAcc, pThisCC->aHgcmAcc[idxHeapAcc].cbHeapBudget, enmCmdType));
+        STAM_REL_COUNTER_INC(&pThisCC->aHgcmAcc[idxHeapAcc].StatBudgetOverruns);
         return NULL;
     }
@@ -397,4 +398,5 @@
         return pCmd;
     }
+    STAM_REL_COUNTER_INC(&pThisCC->aHgcmAcc[idxHeapAcc].StatBudgetOverruns);
     LogFunc(("Heap budget overrun: cbCmd=%#x aHgcmAcc[%zu].cbHeapBudget=%#RX64 - enmCmdType=%d\n",
              cbCmd, idxHeapAcc, pThisCC->aHgcmAcc[idxHeapAcc].cbHeapBudget, enmCmdType));
@@ -516,6 +518,5 @@
     uintptr_t idx = pCmd->idxHeapAcc;
     AssertStmt(idx < RT_ELEMENTS(pThisCC->aHgcmAcc), idx %= RT_ELEMENTS(pThisCC->aHgcmAcc));
-    STAM_REL_COUNTER_ADD(&pThisCC->aHgcmAcc[idx].cbHeapTotal, pCmd->cbHeapCost);
-    STAM_REL_COUNTER_INC(&pThisCC->aHgcmAcc[idx].cTotalMessages);
+    STAM_REL_PROFILE_ADD_PERIOD(&pThisCC->aHgcmAcc[idx].StateMsgHeapUsage, pCmd->cbHeapCost);
 
     /* Automatically enable HGCM events, if there are HGCM commands. */
@@ -940,4 +941,7 @@
 static void *vmmdevR3HgcmCallMemAllocEx(PVMMDEVCC pThisCC, PVBOXHGCMCMD pCmd, size_t cbRequested, bool fZero)
 {
+    uintptr_t idx = pCmd->idxHeapAcc;
+    AssertStmt(idx < RT_ELEMENTS(pThisCC->aHgcmAcc), idx %= RT_ELEMENTS(pThisCC->aHgcmAcc));
+
     /* Check against max heap costs for this request. */
     Assert(pCmd->cbHeapCost <= VMMDEV_MAX_HGCM_DATA_SIZE);
@@ -945,6 +949,4 @@
     {
         /* Check heap budget (we're under lock). */
-        uintptr_t idx = pCmd->idxHeapAcc;
-        AssertStmt(idx < RT_ELEMENTS(pThisCC->aHgcmAcc), idx %= RT_ELEMENTS(pThisCC->aHgcmAcc));
         if (cbRequested <= pThisCC->aHgcmAcc[idx].cbHeapBudget)
         {
@@ -968,4 +970,5 @@
         LogFunc(("Request too big: cbRequested=%#zx cbHeapCost=%#x - enmCmdType=%d\n",
                  cbRequested, pCmd->cbHeapCost, pCmd->enmCmdType));
+    STAM_REL_COUNTER_INC(&pThisCC->aHgcmAcc[idx].StatBudgetOverruns);
     return NULL;
 }
Index: /trunk/src/VBox/Devices/VMMDev/VMMDevState.h
===================================================================
--- /trunk/src/VBox/Devices/VMMDev/VMMDevState.h	(revision 90265)
+++ /trunk/src/VBox/Devices/VMMDev/VMMDevState.h	(revision 90266)
@@ -422,8 +422,8 @@
         /** The currently available heap budget.   */
         uint64_t                    cbHeapBudget;
-        /** Total sum of all heap usage.   */
-        STAMCOUNTER                 cbHeapTotal;
-        /** Total number of message. */
-        STAMCOUNTER                 cTotalMessages;
+        /** Message stats. */
+        STAMPROFILE                 StateMsgHeapUsage;
+        /** Budget overruns.   */
+        STAMCOUNTER                 StatBudgetOverruns;
     } aHgcmAcc[VMMDEV_HGCM_CATEGORY_MAX];
     STAMPROFILE                     StatHgcmCmdArrival;
