VirtualBox

Ignore:
Timestamp:
Feb 24, 2011 9:10:09 AM (14 years ago)
Author:
vboxsync
Message:

VBoxManage: added internal command gueststats

Location:
trunk/src/VBox/Frontends/VBoxManage
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp

    r35238 r36067  
    137137        "Commands:\n"
    138138        "\n"
    139         "%s%s%s%s%s%s%s%s%s%s%s%s%s%s"
     139        "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"
    140140        "WARNING: This is a development tool and shall only be used to analyse\n"
    141141        "         problems. It is completely unsupported and will change in\n"
     
    242242          "       Generates a password hash.\n"
    243243          "\n"
    244         :
    245           ""
     244        : "",
     245        (u64Cmd & USAGE_GUESTSTATS)
     246        ? "  gueststats <vmname>|<uuid> [--interval <seconds>]\n"
     247          "       Obtains and prints internal guest statistics.\n"
     248          "       Sets the update interval if specified.\n"
     249          "\n"
     250        : ""
    246251        );
    247252}
     
    20182023
    20192024/**
     2025 * Print internal guest statistics or
     2026 * set internal guest statistics update interval if specified
     2027 */
     2028int CmdGuestStats(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
     2029{
     2030    /* one parameter, guest name */
     2031    if (argc < 1)
     2032        return errorSyntax(USAGE_GUESTSTATS, "Missing VM name/UUID");
     2033
     2034    /*
     2035     * Parse the command.
     2036     */
     2037    ULONG aUpdateInterval = 0;
     2038
     2039    static const RTGETOPTDEF s_aOptions[] =
     2040    {
     2041        { "--interval", 'i', RTGETOPT_REQ_UINT32  }
     2042    };
     2043
     2044    int ch;
     2045    RTGETOPTUNION ValueUnion;
     2046    RTGETOPTSTATE GetState;
     2047    RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0);
     2048    while ((ch = RTGetOpt(&GetState, &ValueUnion)))
     2049    {
     2050        switch (ch)
     2051        {
     2052            case 'i':
     2053                aUpdateInterval = ValueUnion.u32;
     2054                break;
     2055
     2056            default:
     2057                return errorGetOpt(USAGE_GUESTSTATS , ch, &ValueUnion);
     2058        }
     2059    }
     2060
     2061    if (argc > 1 && aUpdateInterval == 0)
     2062        return errorSyntax(USAGE_GUESTSTATS, "Invalid update interval specified");
     2063
     2064    RTPrintf("argc=%d interval=%u\n", argc, aUpdateInterval);
     2065
     2066    ComPtr<IMachine> ptrMachine;
     2067    HRESULT rc;
     2068    CHECK_ERROR_RET(aVirtualBox, FindMachine(Bstr(argv[0]).raw(),
     2069                                             ptrMachine.asOutParam()), 1);
     2070
     2071    CHECK_ERROR_RET(ptrMachine, LockMachine(aSession, LockType_Shared), 1);
     2072
     2073    /*
     2074     * Get the guest interface.
     2075     */
     2076    ComPtr<IConsole> ptrConsole;
     2077    CHECK_ERROR_RET(aSession, COMGETTER(Console)(ptrConsole.asOutParam()), 1);
     2078
     2079    ComPtr<IGuest> ptrGuest;
     2080    CHECK_ERROR_RET(ptrConsole, COMGETTER(Guest)(ptrGuest.asOutParam()), 1);
     2081
     2082    if (aUpdateInterval)
     2083        CHECK_ERROR_RET(ptrGuest, COMSETTER(StatisticsUpdateInterval)(aUpdateInterval), 1);
     2084    else
     2085    {
     2086        ULONG mCpuUser, mCpuKernel, mCpuIdle;
     2087        ULONG mMemTotal, mMemFree, mMemBalloon, mMemShared, mMemCache, mPageTotal;
     2088        ULONG ulMemAllocTotal, ulMemFreeTotal, ulMemBalloonTotal, ulMemSharedTotal;
     2089
     2090        ptrGuest->InternalGetStatistics(&mCpuUser, &mCpuKernel, &mCpuIdle,
     2091                                        &mMemTotal, &mMemFree, &mMemBalloon, &mMemShared, &mMemCache,
     2092                                        &mPageTotal, &ulMemAllocTotal, &ulMemFreeTotal, &ulMemBalloonTotal, &ulMemSharedTotal);
     2093        RTPrintf("mCpuUser=%u mCpuKernel=%u mCpuIdle=%u\n"
     2094                 "mMemTotal=%u mMemFree=%u mMemBalloon=%u mMemShared=%u mMemCache=%u\n"
     2095                 "mPageTotal=%u ulMemAllocTotal=%u ulMemFreeTotal=%u ulMemBalloonTotal=%u ulMemSharedTotal=%u\n",
     2096                 mCpuUser, mCpuKernel, mCpuIdle,
     2097                 mMemTotal, mMemFree, mMemBalloon, mMemShared, mMemCache,
     2098                 mPageTotal, ulMemAllocTotal, ulMemFreeTotal, ulMemBalloonTotal, ulMemSharedTotal);
     2099
     2100    }
     2101
     2102    return 0;
     2103}
     2104
     2105
     2106/**
    20202107 * Wrapper for handling internal commands
    20212108 */
     
    20582145    if (!strcmp(pszCmd, "passwordhash"))
    20592146        return CmdGeneratePasswordHash(a->argc - 1, &a->argv[1], a->virtualBox, a->session);
     2147    if (!strcmp(pszCmd, "gueststats"))
     2148        return CmdGuestStats(a->argc - 1, &a->argv[1], a->virtualBox, a->session);
    20602149
    20612150    /* default: */
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h

    r35907 r36067  
    9898#define USAGE_EXTPACK               RT_BIT_64(55)
    9999#define USAGE_BANDWIDTHCONTROL      RT_BIT_64(56)
     100#define USAGE_GUESTSTATS            RT_BIT_64(57)
    100101#define USAGE_ALL                   (~(uint64_t)0)
    101102/** @} */
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