VirtualBox

Ignore:
Timestamp:
Jul 22, 2020 8:29:51 AM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9686, bugref:9510. Adding a toolbar for the performance monitor pane.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIActionPool.cpp

    r82968 r85406  
    22532253
    22542254
    2255 
     2255/** Simple action extension, used as 'Export' action class. */
     2256class UIActionMenuPerformanceMonitorExport : public UIActionSimple
     2257{
     2258    Q_OBJECT;
     2259
     2260public:
     2261
     2262    /** Constructs action passing @a pParent to the base-class. */
     2263    UIActionMenuPerformanceMonitorExport(UIActionPool *pParent)
     2264        : UIActionSimple(pParent,
     2265                         ":/log_viewer_save_32px.png", ":/log_viewer_save_16px.png",
     2266                         ":/log_viewer_save_disabled_32px.png", ":/log_viewer_save_disabled_16px.png")
     2267    {
     2268        setShortcutContext(Qt::WidgetWithChildrenShortcut);
     2269    }
     2270
     2271protected:
     2272
     2273    /** Returns shortcut extra-data ID. */
     2274    virtual QString shortcutExtraDataID() const /* override */
     2275    {
     2276        return QString("ExportCharts");
     2277    }
     2278
     2279    /** Returns default shortcut. */
     2280    virtual QKeySequence defaultShortcut(UIActionPoolType) const /* override */
     2281    {
     2282        return QKeySequence();
     2283    }
     2284
     2285    /** Handles translation event. */
     2286    virtual void retranslateUi() /* override */
     2287    {
     2288        setName(QApplication::translate("UIActionPool", "Export..."));
     2289        setShortcutScope(QApplication::translate("UIActionPool", "Performance Monitor"));
     2290        setStatusTip(QApplication::translate("UIActionPool", "Export the chart data into a text file"));
     2291        setToolTip(  QApplication::translate("UIActionPool", "Export the chart data into a text file")
     2292                   + (shortcut().isEmpty() ? QString() : QString(" (%1)").arg(shortcut().toString())));
     2293    }
     2294};
    22562295
    22572296
     
    25042543    m_pool[UIActionIndex_M_FileManager_S_Guest_ShowProperties] = new UIActionMenuFileManagerShowProperties(this);
    25052544
     2545    /* Create 'Performance Monitor' actions: */
     2546    m_pool[UIActionIndex_M_PerformanceMonitor_S_Export] = new UIActionMenuPerformanceMonitorExport(this);
     2547
    25062548
    25072549    /* Prepare update-handlers for known menus: */
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIActionPool.h

    r82968 r85406  
    136136    UIActionIndex_M_FileManager_S_Guest_ShowProperties,
    137137
     138    /* Machine performance monitor actions. */
     139    UIActionIndex_M_PerformanceMonitor_S_Export,
    138140
    139141
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIToolPaneMachine.cpp

    r85398 r85406  
    193193            case UIToolType_Performance:
    194194            {
    195                 m_pPanePerformanceMonitor = new UIPerformanceMonitor(0, m_comMachine);
     195                m_pPanePerformanceMonitor = new UIPerformanceMonitor(EmbedTo_Stack, 0, m_comMachine, false /* Show toolbar */);
    196196                AssertPtrReturnVoid(m_pPanePerformanceMonitor);
    197197#ifndef VBOX_WS_MAC
     
    298298    if (isToolOpened(UIToolType_Performance))
    299299    {
    300         // AssertPtrReturnVoid(m_pPanePerformanceMonitor);
    301         // // CSession comSession = uiCommon().openSession(m_comMachine.GetId(), KLockType_Shared);
    302         // // AssertReturnVoid(!comSession.isNull());
    303         // // CConsole comConsole = comSession.GetConsole();
    304         // AssertReturnVoid(!comConsole.isNull());
    305 
    306         //m_pPaneLogViewer->setMachine(m_comMachine);
     300        AssertPtrReturnVoid(m_pPanePerformanceMonitor);
     301        m_pPanePerformanceMonitor->setMachine(m_comMachine);
    307302    }
    308303}
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManagerWidget.cpp

    r85398 r85406  
    830830                case UIToolType_Performance:
    831831                {
     832                    m_pToolBar->addAction(actionPool()->action(UIActionIndex_M_PerformanceMonitor_S_Export));
    832833                    break;
    833834                }
  • trunk/src/VBox/Frontends/VirtualBox/src/monitor/performance/UIPerformanceMonitor.cpp

    r85396 r85406  
    3030#include "UICommon.h"
    3131#include "UIPerformanceMonitor.h"
     32#include "UIToolBar.h"
     33#include "UIVirtualBoxEventHandler.h"
    3234
    3335/* COM includes: */
     
    539541}
    540542
    541 
    542543void UIChart::sltCreateContextMenu(const QPoint &point)
    543544{
     
    699700*********************************************************************************************************************************/
    700701
    701 UIPerformanceMonitor::UIPerformanceMonitor(QWidget *pParent, const CMachine &machine)
     702UIPerformanceMonitor::UIPerformanceMonitor(EmbedTo enmEmbedding, QWidget *pParent,
     703                                           const CMachine &machine, bool fShowToolbar /* = false */)
    702704    : QIWithRetranslateUI<QWidget>(pParent)
    703705    , m_fGuestAdditionsAvailable(false)
    704706    , m_pMainLayout(0)
    705707    , m_pTimer(0)
     708    , m_pToolBar(0)
    706709    , m_strCPUMetricName("CPU Load")
    707710    , m_strRAMMetricName("RAM Usage")
     
    711714    , m_strVMExitMetricName("VMExits")
    712715    , m_iTimeStep(0)
    713 {
    714     setMachine(machine);
    715     m_fGuestAdditionsAvailable = guestAdditionsAvailable(6 /* minimum major version */);
    716 
     716    , m_enmEmbedding(enmEmbedding)
     717    , m_fShowToolbar(fShowToolbar)
     718{
    717719    prepareMetrics();
    718720    prepareObjects();
    719     enableDisableGuestAdditionDependedWidgets(m_fGuestAdditionsAvailable);
     721    if (fShowToolbar)
     722        prepareToolBar();
    720723    retranslateUi();
     724    connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigMachineStateChange, this, &UIPerformanceMonitor::sltMachineStateChange);
     725    setMachine(machine);
    721726}
    722727
     
    727732void UIPerformanceMonitor::setMachine(const CMachine &comMachine)
    728733{
     734    reset();
    729735    if (comMachine.isNull())
    730736        return;
     
    734740
    735741    m_comMachine = comMachine;
     742
     743    if (m_comMachine.GetState() == KMachineState_Running)
     744    {
     745        openSession();
     746        start();
     747    }
     748}
     749
     750void UIPerformanceMonitor::openSession()
     751{
    736752    m_comSession = uiCommon().openSession(m_comMachine.GetId(), KLockType_Shared);
    737753    AssertReturnVoid(!m_comSession.isNull());
     
    806822        }
    807823    }
    808     sltTimeout();
    809824}
    810825
     
    818833    m_pTimer = new QTimer(this);
    819834    if (m_pTimer)
    820     {
    821835        connect(m_pTimer, &QTimer::timeout, this, &UIPerformanceMonitor::sltTimeout);
    822         m_pTimer->start(1000 * g_iPeriod);
    823     }
    824836
    825837    QScrollArea *pScrollArea = new QScrollArea(this);
     
    920932        UIMonitorCommon::getVMMExitCount(m_comMachineDebugger, cTotalVMExits);
    921933        updateVMExitMetric(cTotalVMExits);
     934    }
     935}
     936
     937void UIPerformanceMonitor::sltMachineStateChange(const QUuid &uId)
     938{
     939    if (m_comMachine.isNull())
     940        return;
     941    if (m_comMachine.GetId() != uId)
     942        return;
     943    reset();
     944    if (m_comMachine.GetState() == KMachineState_Running)
     945    {
     946        openSession();
     947        start();
    922948    }
    923949}
     
    9781004}
    9791005
     1006void UIPerformanceMonitor::prepareToolBar()
     1007{
     1008    /* Create toolbar: */
     1009    m_pToolBar = new UIToolBar(parentWidget());
     1010    AssertPtrReturnVoid(m_pToolBar);
     1011    {
     1012        /* Configure toolbar: */
     1013        const int iIconMetric = (int)(QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize));
     1014        m_pToolBar->setIconSize(QSize(iIconMetric, iIconMetric));
     1015        m_pToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
     1016
     1017#ifdef VBOX_WS_MAC
     1018        /* Check whether we are embedded into a stack: */
     1019        if (m_enmEmbedding == EmbedTo_Stack)
     1020        {
     1021            /* Add into layout: */
     1022            layout()->addWidget(m_pToolBar);
     1023        }
     1024#else
     1025        /* Add into layout: */
     1026        layout()->addWidget(m_pToolBar);
     1027#endif
     1028    }
     1029}
     1030
    9801031bool UIPerformanceMonitor::guestAdditionsAvailable(int iMinimumMajorVersion)
    9811032{
     
    11911242}
    11921243
     1244void UIPerformanceMonitor::reset()
     1245{
     1246    m_fGuestAdditionsAvailable = false;
     1247    if (m_pTimer)
     1248        m_pTimer->stop();
     1249    for (QMap<QString, UIMetric>::iterator iterator =  m_metrics.begin();
     1250         iterator != m_metrics.end(); ++iterator)
     1251        iterator.value().reset();
     1252    for (QMap<QString, UIChart*>::iterator iterator =  m_charts.begin();
     1253         iterator != m_charts.end(); ++iterator)
     1254        iterator.value()->update();
     1255}
     1256
     1257void UIPerformanceMonitor::start()
     1258{
     1259    if (m_comMachine.isNull() || m_comMachine.GetState() != KMachineState_Running)
     1260        return;
     1261
     1262    m_fGuestAdditionsAvailable = guestAdditionsAvailable(6 /* minimum major version */);
     1263    enableDisableGuestAdditionDependedWidgets(m_fGuestAdditionsAvailable);
     1264    if (m_pTimer)
     1265        m_pTimer->start(1000 * g_iPeriod);
     1266}
     1267
     1268
    11931269#include "UIPerformanceMonitor.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/monitor/performance/UIPerformanceMonitor.h

    r85396 r85406  
    3636
    3737/* GUI includes: */
     38#include "QIManagerDialog.h"
    3839#include "QIWithRetranslateUI.h"
    3940#include "UIMonitorCommon.h"
     
    4647class UISession;
    4748class UIRuntimeInfoWidget;
     49class UIToolBar;
    4850
    4951#define DATA_SERIES_SIZE 2
     
    110112    /** Constructs information-tab passing @a pParent to the QWidget base-class constructor.
    111113      * @param machine is machine reference. */
    112     UIPerformanceMonitor(QWidget *pParent, const CMachine &machine);
     114    UIPerformanceMonitor(EmbedTo enmEmbedding, QWidget *pParent, const CMachine &machine, bool fShowToolbar = false);
    113115    ~UIPerformanceMonitor();
    114116    void setMachine(const CMachine &machine);
    115117
     118#ifdef VBOX_WS_MAC
     119    UIToolBar *toolbar() const { return m_pToolBar; }
     120#endif
     121
    116122 public slots:
    117123
     
    129135    /** Reads the metric values for several sources and calls corresponding update functions. */
    130136    void sltTimeout();
     137    /** Stop updating the charts if/when the machine state changes something other than KMachineState_Running. */
     138    void sltMachineStateChange(const QUuid &uId);
    131139
    132140private:
     
    134142    void prepareObjects();
    135143    void prepareMetrics();
     144    void prepareToolBar();
    136145    bool guestAdditionsAvailable(int iMinimumMajorVersion);
    137146    void enableDisableGuestAdditionDependedWidgets(bool fEnable);
     
    148157    /** Returns a QColor for the chart with @p strChartName and data series with @p iDataIndex. */
    149158    QString dataColorString(const QString &strChartName, int iDataIndex);
     159    /* Starts the timer which in return collects data and updates charts/graphs. */
     160    void start();
     161    void reset();
     162    void openSession();
    150163
    151164    bool m_fGuestAdditionsAvailable;
     
    158171    /** Holds the instance of layout we create. */
    159172    QVBoxLayout *m_pMainLayout;
    160     QTimer *m_pTimer;
     173    QTimer      *m_pTimer;
     174    UIToolBar   *m_pToolBar;
    161175
    162176    /** @name The following are used during UIPerformanceCollector::QueryMetricsData(..)
     
    210224    /** @} */
    211225    quint64 m_iTimeStep;
     226    EmbedTo m_enmEmbedding;
     227    bool    m_fShowToolbar;
    212228};
    213229
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIVMInformationDialog.cpp

    r85396 r85406  
    200200        /* Create Performance Monitor tab: */
    201201        UIPerformanceMonitor *pPerformanceMonitorWidget =
    202             new UIPerformanceMonitor(this, m_pMachineWindow->machine());
     202            new UIPerformanceMonitor(EmbedTo_Dialog, this, m_pMachineWindow->machine());
    203203        if (pPerformanceMonitorWidget)
    204204        {
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