VirtualBox

Changeset 102746 in vbox


Ignore:
Timestamp:
Jan 2, 2024 4:47:48 PM (11 months ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10501. Improving memoru usage chart.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/activity/vmactivity
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/activity/vmactivity/UIVMActivityMonitor.cpp

    r102655 r102746  
    5151/* COM includes: */
    5252#include "CConsole.h"
     53#include "CForm.h"
     54#include "CFormValue.h"
    5355#include "CGuest.h"
    5456#include "CPerformanceCollector.h"
    5557#include "CPerformanceMetric.h"
    5658#include "CStringArray.h"
     59#include "CRangedIntegerFormValue.h"
    5760#include <iprt/string.h>
     61#include <VBox/com/VirtualBox.h>
    5862
    5963/* External includes: */
     
    725729        return QString::number(iValue).append("%");
    726730    if (m_pMetric->unit().compare("kb", Qt::CaseInsensitive) == 0)
    727         return UITranslator::formatSize(_1K * (quint64)iValue, g_iDecimalCount);
     731        return UITranslator::formatSize(_1K * iValue, g_iDecimalCount);
    728732    if (   m_pMetric->unit().compare("b", Qt::CaseInsensitive) == 0
    729733        || m_pMetric->unit().compare("b/s", Qt::CaseInsensitive) == 0)
     
    731735    if (m_pMetric->unit().compare("times", Qt::CaseInsensitive) == 0)
    732736        return UITranslator::addMetricSuffixToNumber(iValue);
     737    if (m_pMetric->unit().compare("gb", Qt::CaseInsensitive) == 0)
     738        return QString::number(iValue).append(" GB");
    733739    return QString();
    734740}
     
    10441050
    10451051    addData(iDataSeriesIndex, iData);
    1046 
    10471052    if (iDataSeriesIndex == 0)
    10481053    {
     
    19311936    m_metricTypeNames[KMetricType_NetworksBytesOut] = m_strNetworkMetricName;
    19321937
     1938    setMachine(machine);
     1939    determineTotalRAMAmount();
     1940
    19331941    prepareMetrics();
    19341942    prepareWidgets();
    19351943    retranslateUi();
    19361944    prepareActions();
    1937     setMachine(machine);
    19381945    resetCPUInfoLabel();
    19391946    resetNetworkInfoLabel();
     
    19411948}
    19421949
     1950void UIVMActivityMonitorCloud::determineTotalRAMAmount()
     1951{
     1952    CForm comForm = m_comMachine.GetDetailsForm();
     1953    /* Ignore cloud machine errors: */
     1954    if (m_comMachine.isOk())
     1955    {
     1956        /* Common anchor for all fields: */
     1957        const QString strAnchorType = "cloud";
     1958
     1959        /* For each form value: */
     1960        const QVector<CFormValue> values = comForm.GetValues();
     1961        foreach (const CFormValue &comIteratedValue, values)
     1962        {
     1963            /* Ignore invisible values: */
     1964            if (!comIteratedValue.GetVisible())
     1965                continue;
     1966
     1967            /* Acquire label: */
     1968            const QString strLabel = comIteratedValue.GetLabel();
     1969            if (strLabel != "RAM")
     1970                continue;
     1971
     1972            AssertReturnVoid((comIteratedValue.GetType() == KFormValueType_RangedInteger));
     1973
     1974            CRangedIntegerFormValue comValue(comIteratedValue);
     1975            m_iTotalRAM = comValue.GetInteger();
     1976            QString strRAMUnit = comValue.GetSuffix();
     1977            if (strRAMUnit.compare("gb", Qt::CaseInsensitive) == 0)
     1978                m_iTotalRAM *= _1G / _1K;
     1979            else if (strRAMUnit.compare("mb", Qt::CaseInsensitive) == 0)
     1980                m_iTotalRAM *= _1M / _1K;
     1981            if (!comValue.isOk())
     1982                m_iTotalRAM = 0;
     1983        }
     1984    }
     1985}
    19431986
    19441987void UIVMActivityMonitorCloud::setMachine(const CCloudMachine &comMachine)
     
    19882031        else if (enmMetricType == KMetricType_DiskBytesWritten)
    19892032            cacheDiskWrite(timeStamps[i], (int)data[i].toFloat());
     2033        else if (enmMetricType == KMetricType_MemoryUtilization)
     2034        {
     2035            if (m_iTotalRAM != 0)
     2036            {
     2037                /* calculate used RAM amount in kb: */
     2038                quint64 iUsedRAM = data[i].toFloat() * (m_iTotalRAM / 100.f);
     2039                updateRAMChart(iUsedRAM, timeStamps[i]);
     2040            }
     2041        }
    19902042    }
    19912043    sender()->deleteLater();
     
    20892141        m_infoLabels[m_strNetworkMetricName]->setText(strInfo);
    20902142    }
     2143    if (m_charts.contains(m_strNetworkMetricName))
     2144        m_charts[m_strNetworkMetricName]->update();
    20912145}
    20922146
     
    21102164    if (m_charts.contains(m_strDiskIOMetricName))
    21112165        m_charts[m_strDiskIOMetricName]->update();
     2166}
     2167
     2168void UIVMActivityMonitorCloud::updateRAMChart(quint64 iUsedRAM, const QString &strLabel)
     2169{
     2170    UIMetric &RAMMetric = m_metrics[m_strRAMMetricName];
     2171    RAMMetric.setMaximum(m_iTotalRAM);
     2172    RAMMetric.addData(0, iUsedRAM, strLabel);
     2173
     2174    if (m_infoLabels.contains(m_strRAMMetricName)  && m_infoLabels[m_strRAMMetricName])
     2175    {
     2176        QString strInfo;
     2177        strInfo = QString("<b>%1</b><br/>%2: %3<br/>%4: %5<br/>%6: %7").arg(m_strRAMInfoLabelTitle)
     2178            .arg(m_strRAMInfoLabelTotal).arg(UITranslator::formatSize(_1K * m_iTotalRAM, g_iDecimalCount))
     2179            .arg(m_strRAMInfoLabelFree).arg(UITranslator::formatSize(_1K * (m_iTotalRAM - iUsedRAM), g_iDecimalCount))
     2180            .arg(m_strRAMInfoLabelUsed).arg(UITranslator::formatSize(_1K * iUsedRAM, g_iDecimalCount));
     2181        m_infoLabels[m_strRAMMetricName]->setText(strInfo);
     2182    }
     2183
     2184    if (m_charts.contains(m_strRAMMetricName))
     2185        m_charts[m_strRAMMetricName]->update();
    21122186}
    21132187
     
    21322206void UIVMActivityMonitorCloud::prepareMetrics()
    21332207{
    2134     // UIMetric ramMetric(m_strRAMMetricName, metrics[i].GetUnit(), m_iMaximumQueueSize);
    2135     // ramMetric.setDataSeriesName(0, "Free");
    2136     // ramMetric.setDataSeriesName(1, "Used");
    2137     // ramMetric.setRequiresGuestAdditions(true);
    2138     // m_metrics.insert(m_strRAMMetricName, ramMetric);
     2208    /* RAM Metric: */
     2209    if (m_iTotalRAM != 0)
     2210    {
     2211        UIMetric ramMetric(m_strRAMMetricName, "kb", m_iMaximumQueueSize);
     2212        ramMetric.setDataSeriesName(0, "Used");
     2213        m_metrics.insert(m_strRAMMetricName, ramMetric);
     2214    }
    21392215
    21402216    /* CPU Metric: */
  • trunk/src/VBox/Frontends/VirtualBox/src/activity/vmactivity/UIVMActivityMonitor.h

    r102655 r102746  
    338338    /** @name The following functions update corresponding metric charts and labels with new values
    339339      * @{ */
    340         virtual void updateCPUChart(ULONG iLoadPercentage, const QString &strLabel);
    341         virtual void updateNetworkChart(quint64 uReceive, quint64 uTransmit, const QString &strLabel);
    342         virtual void updateDiskIOChart(quint64 uWriteRate, quint64 uReadRate, const QString &strLabel);
     340        void updateCPUChart(ULONG iLoadPercentage, const QString &strLabel);
     341        void updateNetworkChart(quint64 uReceive, quint64 uTransmit, const QString &strLabel);
     342        void updateDiskIOChart(quint64 uWriteRate, quint64 uReadRate, const QString &strLabel);
     343        void updateRAMChart(quint64 iUsagePercentage, const QString &strLabel);
    343344    /** @} */
    344345    virtual void resetCPUInfoLabel();
     
    356357    bool findMetric(KMetricType enmMetricType, UIMetric &metric, int &iDataSeriesIndex) const;
    357358    void prepareMetrics();
     359    void determineTotalRAMAmount();
    358360
    359361    CCloudMachine m_comMachine;
     
    370372    QMap<QString, quint64> m_networkReceiveCache;
    371373    QMap<QString, quint64> m_networkTransmitCache;
    372 
     374    /** Total amount of RAM in kb. */
     375    quint64 m_iTotalRAM;
    373376};
    374377#endif /* !FEQT_INCLUDED_SRC_activity_vmactivity_UIVMActivityMonitor_h */
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