VirtualBox

Changeset 88305 in vbox for trunk


Ignore:
Timestamp:
Mar 26, 2021 9:14:59 PM (4 years ago)
Author:
vboxsync
Message:

VMM/PDMDrvHlp: Made the statistics registration function automatically prefix relative statistics names. bugref:9890

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/vmm/pdmdrv.h

    r87761 r88305  
    10381038     * @param   enmType     Sample type. This indicates what pvSample is pointing at.
    10391039     * @param   pszName     Sample name. The name is on this form "/<component>/<sample>".
    1040      *                      Further nesting is possible.
     1040     *                      Further nesting is possible.  If this does not start
     1041     *                      with a '/', the default prefix will be prepended,
     1042     *                      otherwise it will be used as-is.
    10411043     * @param   enmUnit     Sample unit.
    10421044     * @param   pszDesc     Sample description.
     
    10551057     * @param   enmUnit     Sample unit.
    10561058     * @param   pszDesc     Sample description.
    1057      * @param   pszName     The sample name format string.
     1059     * @param   pszName     The sample name format string.  If this does not start
     1060     *                      with a '/', the default prefix will be prepended,
     1061     *                      otherwise it will be used as-is.
    10581062     * @param   ...         Arguments to the format string.
    10591063     */
     
    10721076     * @param   enmUnit         Sample unit.
    10731077     * @param   pszDesc         Sample description.
    1074      * @param   pszName         The sample name format string.
     1078     * @param   pszName         The sample name format string.  If this does not
     1079     *                          start with a '/', the default prefix will be prepended,
     1080     *                          otherwise it will be used as-is.
    10751081     * @param   args            Arguments to the format string.
    10761082     */
  • trunk/src/VBox/VMM/VMMR3/PDMDriver.cpp

    r87773 r88305  
    14421442{
    14431443    PDMDRV_ASSERT_DRVINS(pDrvIns);
    1444     VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
    1445 
    1446     STAM_REG(pDrvIns->Internal.s.pVMR3, pvSample, enmType, pszName, enmUnit, pszDesc);
    1447     RT_NOREF6(pDrvIns, pvSample, enmType, pszName, enmUnit, pszDesc);
    1448     /** @todo track the samples so they can be dumped & deregistered when the driver instance is destroyed.
    1449      * For now we just have to be careful not to use this call for drivers which can be unloaded. */
     1444    PVM pVM = pDrvIns->Internal.s.pVMR3;
     1445    VM_ASSERT_EMT(pVM);
     1446
     1447#ifdef VBOX_WITH_STATISTICS /** @todo rework this to always be compiled in */
     1448    if (*pszName == '/')
     1449        STAM_REG(pDrvIns->Internal.s.pVMR3, pvSample, enmType, pszName, enmUnit, pszDesc);
     1450    else
     1451        STAMR3RegisterF(pVM, pvSample, enmType, STAMVISIBILITY_ALWAYS, enmUnit, pszDesc,
     1452                        "/Drivers/%s-%u/%s", pDrvIns->pReg->szName, pDrvIns->iInstance, pszName);
     1453#else
     1454    RT_NOREF(pDrvIns, pvSample, enmType, pszName, enmUnit, pszDesc, pVM);
     1455#endif
     1456}
     1457
     1458
     1459/** @interface_method_impl{PDMDRVHLPR3,pfnSTAMRegisterV} */
     1460static DECLCALLBACK(void) pdmR3DrvHlp_STAMRegisterV(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
     1461                                                    STAMUNIT enmUnit, const char *pszDesc, const char *pszName, va_list args)
     1462{
     1463    PDMDRV_ASSERT_DRVINS(pDrvIns);
     1464    PVM pVM = pDrvIns->Internal.s.pVMR3;
     1465    VM_ASSERT_EMT(pVM);
     1466
     1467    int rc;
     1468    if (*pszName == '/')
     1469        rc = STAMR3RegisterV(pVM, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, args);
     1470    else
     1471    {
     1472        /* We need to format it to check whether it starts with a
     1473           slash or not (will rework this later). */
     1474        char szFormatted[2048];
     1475        ssize_t cchBase = RTStrPrintf2(szFormatted, sizeof(szFormatted) - 1024, "/Drivers/%s-%u/",
     1476                                       pDrvIns->pReg->szName, pDrvIns->iInstance);
     1477        AssertReturnVoid(cchBase > 0);
     1478
     1479        ssize_t cch2 = RTStrPrintf2V(&szFormatted[cchBase], sizeof(szFormatted) - cchBase, pszName, args);
     1480        AssertReturnVoid(cch2 > 0);
     1481
     1482        rc = STAMR3Register(pVM, pvSample, enmType, enmVisibility,
     1483                            &szFormatted[szFormatted[cchBase] == '/' ? cchBase : 0], enmUnit, pszDesc);
     1484    }
     1485    AssertRC(rc);
    14501486}
    14511487
     
    14551491                                                    STAMUNIT enmUnit, const char *pszDesc, const char *pszName, ...)
    14561492{
    1457     PDMDRV_ASSERT_DRVINS(pDrvIns);
    1458     VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
    1459 
    1460     va_list args;
    1461     va_start(args, pszName);
    1462     int rc = STAMR3RegisterV(pDrvIns->Internal.s.pVMR3, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, args);
    1463     va_end(args);
    1464     AssertRC(rc);
    1465 }
    1466 
    1467 
    1468 /** @interface_method_impl{PDMDRVHLPR3,pfnSTAMRegisterV} */
    1469 static DECLCALLBACK(void) pdmR3DrvHlp_STAMRegisterV(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
    1470                                                     STAMUNIT enmUnit, const char *pszDesc, const char *pszName, va_list args)
    1471 {
    1472     PDMDRV_ASSERT_DRVINS(pDrvIns);
    1473     VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
    1474 
    1475     int rc = STAMR3RegisterV(pDrvIns->Internal.s.pVMR3, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, args);
    1476     AssertRC(rc);
     1493    va_list va;
     1494    va_start(va, pszName);
     1495    pdmR3DrvHlp_STAMRegisterV(pDrvIns, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, va);
     1496    va_end(va);
    14771497}
    14781498
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette