VirtualBox

Changeset 83493 in vbox for trunk/src


Ignore:
Timestamp:
Mar 31, 2020 9:04:49 AM (5 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9686. Collecting some host stats.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/monitor/resource/UIResourceMonitor.cpp

    r83491 r83493  
    134134
    135135/*********************************************************************************************************************************
     136*   Class UIVMResouceMonitorHostStats definition.                                                                           *
     137*********************************************************************************************************************************/
     138
     139class UIVMResouceMonitorHostStats
     140{
     141
     142public:
     143
     144    UIVMResouceMonitorHostStats();
     145    quint64 m_fCPUUserLoad;
     146    quint64 m_fCPUKernelLoad;
     147    quint64 m_iTotalRAM;
     148    quint64 m_iFreeRAM;
     149};
     150
     151/*********************************************************************************************************************************
    136152*   Class UIVMResouceMonitorCheckBox definition.                                                                           *
    137153*********************************************************************************************************************************/
     154
    138155class UIVMResouceMonitorCheckBox : public QCheckBox
    139156{
     
    209226    void initializeItems();
    210227    void setupPerformanceCollector();
    211     void queryRAMLoad();
     228    void queryPerformanceCollector();
    212229    void addItem(const QUuid& uMachineId, const QString& strMachineName);
    213230    void removeItem(const QUuid& uMachineId);
     231    void getHostRAMStats();
    214232
    215233    QVector<UIResourceMonitorItem> m_itemList;
     
    228246      *  when the widget is visible in the main UI. */
    229247    bool m_fShouldUpdate;
     248    UIVMResouceMonitorHostStats m_hostStats;
    230249};
    231250
     
    396415
    397416/*********************************************************************************************************************************
     417*   Class UIVMResouceMonitorHostStats implementation.                                                                            *
     418*********************************************************************************************************************************/
     419
     420UIVMResouceMonitorHostStats::UIVMResouceMonitorHostStats()
     421    : m_fCPUUserLoad(0)
     422    , m_fCPUKernelLoad(0)
     423    , m_iTotalRAM(0)
     424    , m_iFreeRAM(0)
     425{
     426}
     427
     428
     429/*********************************************************************************************************************************
    398430*   Class UIVMResouceMonitorCheckBox implementation.                                                                             *
    399431*********************************************************************************************************************************/
     
    595627}
    596628
     629void UIResourceMonitorModel::getHostRAMStats()
     630{
     631    CHost comHost = uiCommon().host();
     632    m_hostStats.m_iTotalRAM = _1M * (quint64)comHost.GetMemorySize();
     633    m_hostStats.m_iFreeRAM = _1M * (quint64)comHost.GetMemoryAvailable();
     634}
     635
    597636void UIResourceMonitorModel::sltTimeout()
    598637{
     
    603642    ULONG aPctVMM;
    604643
    605     bool fRAMColumns = columnVisible(VMResouceMonitorColumn_RAMUsedAndTotal)
    606         || columnVisible(VMResouceMonitorColumn_RAMUsedPercentage);
     644    // bool fRAMColumns = columnVisible(VMResouceMonitorColumn_RAMUsedAndTotal)
     645    //     || columnVisible(VMResouceMonitorColumn_RAMUsedPercentage);
    607646    bool fCPUColumns = columnVisible(VMResouceMonitorColumn_CPUVMMLoad) || columnVisible(VMResouceMonitorColumn_CPUGuestLoad);
    608647    bool fNetworkColumns = columnVisible(VMResouceMonitorColumn_NetworkUpRate)
     
    616655    bool fVMExitColumn = columnVisible(VMResouceMonitorColumn_VMExits);
    617656
    618     /* RAM usage: */
    619     if (!m_performanceMonitor.isNull() && fRAMColumns)
    620         queryRAMLoad();
     657    getHostRAMStats();
     658
     659    /* RAM usage and Host CPU: */
     660    //if (!m_performanceMonitor.isNull() && fRAMColumns)
     661    queryPerformanceCollector();
    621662
    622663    for (int i = 0; i < m_itemList.size(); ++i)
     
    677718    for (int i = 0; i < m_itemList.size(); ++i)
    678719        m_nameList << "Guest/RAM/Usage*";
     720    /* This is for the host: */
     721    m_nameList << "CPU/Load/User:avg";
     722    m_nameList << "CPU/Load/Kernel:avg";
    679723    m_objectList = QVector<CUnknown>(m_nameList.size(), CUnknown());
    680724    m_performanceMonitor.SetupMetrics(m_nameList, m_objectList, iPeriod, iMetricSetupCount);
    681725}
    682726
    683 void UIResourceMonitorModel::queryRAMLoad()
     727void UIResourceMonitorModel::queryPerformanceCollector()
    684728{
    685729    QVector<QString>  aReturnNames;
     
    690734    QVector<ULONG>  aReturnDataIndices;
    691735    QVector<ULONG>  aReturnDataLengths;
    692     /* Make a query to CPerformanceCollector to fetch some metrics (e.g RAM usage): */
     736
    693737    QVector<LONG> returnData = m_performanceMonitor.QueryMetricsData(m_nameList,
    694738                                                                        m_objectList,
     
    708752        float fData = returnData[aReturnDataIndices[i] + aReturnDataLengths[i] - 1] / (float)aReturnScales[i];
    709753        if (aReturnNames[i].contains("RAM", Qt::CaseInsensitive) && !aReturnNames[i].contains(":"))
     754        {
    710755            if (aReturnNames[i].contains("Total", Qt::CaseInsensitive) || aReturnNames[i].contains("Free", Qt::CaseInsensitive))
    711756            {
     
    723768                }
    724769            }
     770        }
     771        else if (aReturnNames[i].contains("CPU/Load/User", Qt::CaseInsensitive))
     772        {
     773            CHost comHost = (CHost)aReturnObjects[i];
     774            if (!comHost.isNull())
     775                m_hostStats.m_fCPUUserLoad = fData;
     776        }
     777        else if (aReturnNames[i].contains("CPU/Load/Kernel", Qt::CaseInsensitive))
     778        {
     779            CHost comHost = (CHost)aReturnObjects[i];
     780            if (!comHost.isNull())
     781                m_hostStats.m_fCPUKernelLoad = fData;
     782        }
    725783    }
    726784    for (int i = 0; i < m_itemList.size(); ++i)
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