VirtualBox

Ignore:
Timestamp:
Jul 31, 2020 12:45:54 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
139647
Message:

VBoxManage: Added 'cpu-profiles' subcommand to 'list'.

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

Legend:

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

    r85178 r85575  
    480480                     "                            groups|webcams|screenshotformats|cloudproviders|\n"
    481481#if defined(VBOX_WITH_CLOUD_NET)
    482                      "                            cloudprofiles|cloudnets\n"
     482                     "                            cloudprofiles|cloudnets|cpu-profiles\n"
    483483#else
    484                      "                            cloudprofiles\n"
     484                     "                            cloudprofiles|cpu-profiles\n"
    485485#endif
    486486                     "\n", SEP);
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageList.cpp

    r83169 r85575  
    11551155 * @param   pVirtualBox         Reference to the IVirtualBox pointer.
    11561156 */
    1157 static HRESULT listVideoInputDevices(const ComPtr<IVirtualBox> pVirtualBox)
     1157static HRESULT listVideoInputDevices(const ComPtr<IVirtualBox> &pVirtualBox)
    11581158{
    11591159    HRESULT rc;
     
    11831183 * @param   pVirtualBox         Reference to the IVirtualBox pointer.
    11841184 */
    1185 static HRESULT listScreenShotFormats(const ComPtr<IVirtualBox> pVirtualBox)
     1185static HRESULT listScreenShotFormats(const ComPtr<IVirtualBox> &pVirtualBox)
    11861186{
    11871187    HRESULT rc = S_OK;
     
    12121212 * @param   pVirtualBox         Reference to the IVirtualBox pointer.
    12131213 */
    1214 static HRESULT listCloudProviders(const ComPtr<IVirtualBox> pVirtualBox)
     1214static HRESULT listCloudProviders(const ComPtr<IVirtualBox> &pVirtualBox)
    12151215{
    12161216    HRESULT rc = S_OK;
     
    12461246 * @param   fOptLong            If true, list all profile properties.
    12471247 */
    1248 static HRESULT listCloudProfiles(const ComPtr<IVirtualBox> pVirtualBox, bool fOptLong)
     1248static HRESULT listCloudProfiles(const ComPtr<IVirtualBox> &pVirtualBox, bool fOptLong)
    12491249{
    12501250    HRESULT rc = S_OK;
     
    12951295}
    12961296
     1297static HRESULT displayCPUProfile(ICPUProfile *pProfile, size_t idx, int cchIdx, bool fOptLong, HRESULT hrc)
     1298{
     1299    /* Retrieve the attributes needed for both long and short display. */
     1300    Bstr bstrName;
     1301    CHECK_ERROR2I_RET(pProfile, COMGETTER(Name)(bstrName.asOutParam()), hrcCheck);
     1302
     1303    CPUArchitecture_T enmArchitecture = CPUArchitecture_Any;
     1304    CHECK_ERROR2I_RET(pProfile, COMGETTER(Architecture)(&enmArchitecture), hrcCheck);
     1305    const char *pszArchitecture = "???";
     1306    switch (enmArchitecture)
     1307    {
     1308        case CPUArchitecture_x86:       pszArchitecture = "x86"; break;
     1309        case CPUArchitecture_AMD64:     pszArchitecture = "AMD64"; break;
     1310
     1311        case CPUArchitecture_32BitHack:
     1312        case CPUArchitecture_Any:
     1313            break;
     1314    }
     1315
     1316    /* Print what we've got. */
     1317    if (!fOptLong)
     1318        RTPrintf("#%0*zu: %ls [%s]\n", cchIdx, idx, bstrName.raw(), pszArchitecture);
     1319    else
     1320    {
     1321        RTPrintf("CPU Profile #%02zu:\n", idx);
     1322        RTPrintf("  Architecture: %s\n", pszArchitecture);
     1323        RTPrintf("  Name:         %ls\n", bstrName.raw());
     1324        CHECK_ERROR2I_RET(pProfile, COMGETTER(FullName)(bstrName.asOutParam()), hrcCheck);
     1325        RTPrintf("  Full Name:    %ls\n", bstrName.raw());
     1326    }
     1327    return hrc;
     1328}
     1329
     1330
     1331/**
     1332 * List all CPU profiles.
     1333 *
     1334 * @returns See produceList.
     1335 * @param   ptrVirtualBox       Reference to the smart IVirtualBox pointer.
     1336 * @param   fOptLong            If true, list all profile properties.
     1337 * @param   fOptSorted          Sort the output if true, otherwise display in
     1338 *                              system order.
     1339 */
     1340static HRESULT listCPUProfiles(const ComPtr<IVirtualBox> &ptrVirtualBox, bool fOptLong, bool fOptSorted)
     1341{
     1342    ComPtr<ISystemProperties> ptrSysProps;
     1343    CHECK_ERROR2I_RET(ptrVirtualBox, COMGETTER(SystemProperties)(ptrSysProps.asOutParam()), hrcCheck);
     1344    com::SafeIfaceArray<ICPUProfile> aCPUProfiles;
     1345    CHECK_ERROR2I_RET(ptrSysProps, GetCPUProfiles(CPUArchitecture_Any, Bstr().raw(),
     1346                                                  ComSafeArrayAsOutParam(aCPUProfiles)), hrcCheck);
     1347
     1348    int const cchIdx = 1 + (aCPUProfiles.size() >= 10) + (aCPUProfiles.size() >= 100);
     1349
     1350    HRESULT hrc = S_OK;
     1351    if (!fOptSorted)
     1352        for (size_t i = 0; i < aCPUProfiles.size(); i++)
     1353            hrc = displayCPUProfile(aCPUProfiles[i], i, cchIdx, fOptLong, hrc);
     1354    else
     1355    {
     1356        std::vector<std::pair<com::Bstr, ICPUProfile *> > vecSortedProfiles;
     1357        for (size_t i = 0; i < aCPUProfiles.size(); ++i)
     1358        {
     1359            Bstr bstrName;
     1360            CHECK_ERROR2I_RET(aCPUProfiles[i], COMGETTER(Name)(bstrName.asOutParam()), hrcCheck);
     1361            try
     1362            {
     1363                vecSortedProfiles.push_back(std::pair<com::Bstr, ICPUProfile *>(bstrName, aCPUProfiles[i]));
     1364            }
     1365            catch (std::bad_alloc &)
     1366            {
     1367                return E_OUTOFMEMORY;
     1368            }
     1369        }
     1370
     1371        std::sort(vecSortedProfiles.begin(), vecSortedProfiles.end());
     1372
     1373        for (size_t i = 0; i < vecSortedProfiles.size(); i++)
     1374            hrc = displayCPUProfile(vecSortedProfiles[i].second, i, cchIdx, fOptLong, hrc);
     1375    }
     1376
     1377    return hrc;
     1378}
     1379
    12971380
    12981381/**
    12991382 * The type of lists we can produce.
    13001383 */
    1301 enum enmListType
     1384enum ListType_T
    13021385{
    13031386    kListNotSpecified = 1000,
     
    13321415    kListCloudProviders,
    13331416    kListCloudProfiles,
     1417    kListCPUProfiles
    13341418};
    13351419
     
    13431427 * @param   pVirtualBox         Reference to the IVirtualBox smart pointer.
    13441428 */
    1345 static HRESULT produceList(enum enmListType enmCommand, bool fOptLong, bool fOptSorted, const ComPtr<IVirtualBox> &pVirtualBox)
     1429static HRESULT produceList(enum ListType_T enmCommand, bool fOptLong, bool fOptSorted, const ComPtr<IVirtualBox> &pVirtualBox)
    13461430{
    13471431    HRESULT rc = S_OK;
     
    16841768            break;
    16851769
     1770        case kListCPUProfiles:
     1771            rc = listCPUProfiles(pVirtualBox, fOptLong, fOptSorted);
     1772            break;
     1773
    16861774        /* No default here, want gcc warnings. */
    16871775
     
    17021790    bool                fOptMultiple  = false;
    17031791    bool                fOptSorted    = false;
    1704     enum enmListType    enmOptCommand = kListNotSpecified;
     1792    enum ListType_T     enmOptCommand = kListNotSpecified;
    17051793
    17061794    static const RTGETOPTDEF s_aListOptions[] =
     
    17411829        { "cloudproviders",     kListCloudProviders,     RTGETOPT_REQ_NOTHING },
    17421830        { "cloudprofiles",      kListCloudProfiles,      RTGETOPT_REQ_NOTHING },
     1831        { "cpu-profiles",       kListCPUProfiles,        RTGETOPT_REQ_NOTHING },
    17431832    };
    17441833
     
    17971886            case kListCloudProviders:
    17981887            case kListCloudProfiles:
    1799                 enmOptCommand = (enum enmListType)ch;
     1888            case kListCPUProfiles:
     1889                enmOptCommand = (enum ListType_T)ch;
    18001890                if (fOptMultiple)
    18011891                {
    1802                     HRESULT hrc = produceList((enum enmListType)ch, fOptLong, fOptSorted, a->virtualBox);
     1892                    HRESULT hrc = produceList(enmOptCommand, fOptLong, fOptSorted, a->virtualBox);
    18031893                    if (FAILED(hrc))
    18041894                        return RTEXITCODE_FAILURE;
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