- Timestamp:
- Apr 2, 2020 3:28:21 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/monitor/resource/UIResourceMonitor.cpp
r83509 r83512 64 64 65 65 ///#define DEBUG_BACKGROUND 66 /********************************************************************************************************************************* 67 * Class UIVMResourceMonitorHostStats definition. * 66 67 68 /********************************************************************************************************************************* 69 * Class UIVMResourceMonitorHostStats definition. * 68 70 *********************************************************************************************************************************/ 69 71 … … 106 108 quint64 m_iCPUKernelLoad; 107 109 quint64 m_iCPUFreq; 108 int m_iMinimumHeight;109 110 int m_iMargin; 110 111 QColor m_CPUUserColor; … … 114 115 115 116 /********************************************************************************************************************************* 117 * Class UIVMResourceMonitorHostRAMWidget definition. * 118 *********************************************************************************************************************************/ 119 120 class UIVMResourceMonitorHostRAMWidget : public QWidget 121 { 122 123 Q_OBJECT; 124 125 public: 126 127 UIVMResourceMonitorHostRAMWidget(QWidget *pParent = 0); 128 void setRAMStats(quint64 iTotalRAM, quint64 iFreeRAM); 129 void setChartColors(const QColor &RAMFreeColor, const QColor &RAMUsedColor); 130 131 protected: 132 133 virtual void paintEvent(QPaintEvent *pEvent) /* override */; 134 135 private: 136 137 quint64 m_iTotalRAM; 138 quint64 m_iFreeRAM; 139 140 int m_iMargin; 141 QColor m_RAMFreeColor; 142 QColor m_RAMUsedColor; 143 }; 144 145 146 /********************************************************************************************************************************* 116 147 * Class UIVMResourceMonitorHostStatsWidget definition. * 117 148 *********************************************************************************************************************************/ … … 137 168 138 169 UIVMResourceMonitorHostCPUWidget *m_pHostCPUChart; 170 UIVMResourceMonitorHostRAMWidget *m_pHostRAMChart; 139 171 QLabel *m_pCPUTitleLabel; 140 172 QLabel *m_pCPUUserLabel; 141 173 QLabel *m_pCPUKernelLabel; 142 174 QLabel *m_pCPUTotalLabel; 175 176 QLabel *m_pRAMTitleLabel; 177 QLabel *m_pRAMUsedLabel; 178 QLabel *m_pRAMFreeLabel; 179 QLabel *m_pRAMTotalLabel; 180 143 181 QColor m_CPUUserColor; 144 182 QColor m_CPUKernelColor; 183 QColor m_RAMFreeColor; 184 QColor m_RAMUsedColor; 185 145 186 UIVMResourceMonitorHostStats m_hostStats; 146 187 }; 147 188 148 /********************************************************************************************************************************* 149 * Class UIVMResourceMonitorTableView definition. * 189 190 /********************************************************************************************************************************* 191 * Class UIVMResourceMonitorTableView definition. * 150 192 *********************************************************************************************************************************/ 151 193 … … 175 217 176 218 /********************************************************************************************************************************* 177 * Class UIVMResourceMonitorItem definition. *178 *********************************************************************************************************************************/219 * Class UIVMResourceMonitorItem definition. * 220 *********************************************************************************************************************************/ 179 221 class UIResourceMonitorItem 180 222 { … … 218 260 219 261 /********************************************************************************************************************************* 220 * Class UIVMResourceMonitorCheckBox definition. *221 *********************************************************************************************************************************/262 * Class UIVMResourceMonitorCheckBox definition. * 263 *********************************************************************************************************************************/ 222 264 223 265 class UIVMResourceMonitorCheckBox : public QCheckBox … … 307 349 QTimer *m_pTimer; 308 350 /** @name The following are used during UIPerformanceCollector::QueryMetricsData(..) 309 310 311 351 * @{ */ 352 QVector<QString> m_nameList; 353 QVector<CUnknown> m_objectList; 312 354 /** @} */ 313 355 CPerformanceCollector m_performanceMonitor; 314 356 QMap<int, bool> m_columnVisible; 315 357 /** If true the table data and corresponding view is updated. Possibly set by host widget to true only 316 358 * when the widget is visible in the main UI. */ 317 359 bool m_fShouldUpdate; 318 360 UIVMResourceMonitorHostStats m_hostStats; … … 346 388 { 347 389 m_iMargin = 3; 348 m_iMinimumHeight = 3 * QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize);349 setMinimumSize(m_iMinimumHeight, m_iMinimumHeight);350 390 } 351 391 … … 371 411 painter.setRenderHint(QPainter::Antialiasing); 372 412 373 int iFrameHeight = m_iMinimumHeight- 2 * m_iMargin;413 int iFrameHeight = height()- 2 * m_iMargin; 374 414 QRectF outerRect = QRectF(QPoint(m_iMargin,m_iMargin), QSize(iFrameHeight, iFrameHeight)); 375 415 QRectF innerRect = UIMonitorCommon::getScaledRect(outerRect, 0.6f, 0.6f); … … 386 426 387 427 /********************************************************************************************************************************* 428 * Class UIVMResourceMonitorHostRAMWidget implementation. * 429 *********************************************************************************************************************************/ 430 431 UIVMResourceMonitorHostRAMWidget::UIVMResourceMonitorHostRAMWidget(QWidget *pParent /* = 0 */) 432 :QWidget(pParent) 433 , m_iTotalRAM(0) 434 , m_iFreeRAM(0) 435 { 436 m_iMargin = 3; 437 } 438 void UIVMResourceMonitorHostRAMWidget::setRAMStats(quint64 iTotalRAM, quint64 iFreeRAM) 439 { 440 m_iTotalRAM = iTotalRAM; 441 m_iFreeRAM = iFreeRAM; 442 update(); 443 } 444 445 void UIVMResourceMonitorHostRAMWidget::setChartColors(const QColor &RAMFreeColor, const QColor &RAMUsedColor) 446 { 447 m_RAMFreeColor = RAMFreeColor; 448 m_RAMUsedColor = RAMUsedColor; 449 } 450 451 void UIVMResourceMonitorHostRAMWidget::paintEvent(QPaintEvent *pEvent) 452 { 453 454 QWidget::paintEvent(pEvent); 455 456 QPainter painter(this); 457 painter.setRenderHint(QPainter::Antialiasing); 458 459 int iFrameHeight = height()- 2 * m_iMargin; 460 QRectF outerRect = QRectF(QPoint(m_iMargin,m_iMargin), QSize(iFrameHeight, iFrameHeight)); 461 QRectF innerRect = UIMonitorCommon::getScaledRect(outerRect, 0.6f, 0.6f); 462 quint64 iUsedRAM = m_iTotalRAM - m_iFreeRAM; 463 464 UIMonitorCommon::drawCombinedDoughnutChart(iUsedRAM, m_RAMUsedColor, 465 m_iFreeRAM, m_RAMFreeColor, 466 painter, m_iTotalRAM, 467 outerRect, innerRect, 80); 468 469 if (m_iTotalRAM != 0) 470 { 471 float mul = 1.f / 1.4f; 472 QRectF textRect = UIMonitorCommon::getScaledRect(innerRect, mul, mul); 473 painter.setPen(Qt::black); 474 int iPercent = 100 * (iUsedRAM / (float) m_iTotalRAM); 475 painter.drawText(textRect, Qt::AlignCenter, QString("%1%\nUsed").arg(QString::number(iPercent))); 476 } 477 478 } 479 480 481 /********************************************************************************************************************************* 388 482 * Class UIVMResourceMonitorHostStatsWidget implementation. * 389 483 *********************************************************************************************************************************/ … … 392 486 : QIWithRetranslateUI<QWidget>(pParent) 393 487 , m_pHostCPUChart(0) 488 , m_pHostRAMChart(0) 394 489 , m_pCPUTitleLabel(0) 395 490 , m_pCPUUserLabel(0) 396 491 , m_pCPUKernelLabel(0) 397 492 , m_pCPUTotalLabel(0) 493 , m_pRAMTitleLabel(0) 494 , m_pRAMUsedLabel(0) 495 , m_pRAMFreeLabel(0) 496 , m_pRAMTotalLabel(0) 398 497 , m_CPUUserColor(Qt::red) 399 498 , m_CPUKernelColor(Qt::blue) 499 , m_RAMFreeColor(Qt::blue) 500 , m_RAMUsedColor(Qt::red) 400 501 { 401 502 prepare(); … … 414 515 if (m_pHostCPUChart) 415 516 m_pHostCPUChart->setCPULoad(m_hostStats.m_iCPUUserLoad, m_hostStats.m_iCPUKernelLoad, m_hostStats.m_iCPUFreq); 517 if (m_pHostRAMChart) 518 m_pHostRAMChart->setRAMStats(m_hostStats.m_iTotalRAM, m_hostStats.m_iFreeRAM); 416 519 updateLabels(); 417 520 } … … 426 529 QHBoxLayout *pLayout = new QHBoxLayout; 427 530 setLayout(pLayout); 428 429 /* Host CPU Labels: */ 430 QWidget *pCPULabelContainer = new QWidget; 431 pCPULabelContainer->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); 531 int iMinimumSize = 3 * QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize); 532 533 /* CPU Stuff: */ 534 { 535 /* Host CPU Labels: */ 536 QWidget *pCPULabelContainer = new QWidget; 537 pCPULabelContainer->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); 432 538 433 539 #ifdef DEBUG_BACKGROUND 434 QPalette pal = pCPULabelContainer->palette();435 pal.setColor(QPalette::Background, Qt::yellow);436 pCPULabelContainer->setAutoFillBackground(true);437 pCPULabelContainer->setPalette(pal);540 QPalette pal = pCPULabelContainer->palette(); 541 pal.setColor(QPalette::Background, Qt::yellow); 542 pCPULabelContainer->setAutoFillBackground(true); 543 pCPULabelContainer->setPalette(pal); 438 544 #endif 439 pLayout->addWidget(pCPULabelContainer); 440 QVBoxLayout *pCPULabelsLayout = new QVBoxLayout; 441 pCPULabelsLayout->setContentsMargins(0, 0, 0, 0); 442 pCPULabelContainer->setLayout(pCPULabelsLayout); 443 m_pCPUTitleLabel = new QLabel; 444 pCPULabelsLayout->addWidget(m_pCPUTitleLabel); 445 m_pCPUUserLabel = new QLabel; 446 pCPULabelsLayout->addWidget(m_pCPUUserLabel); 447 m_pCPUKernelLabel = new QLabel; 448 pCPULabelsLayout->addWidget(m_pCPUKernelLabel); 449 m_pCPUTotalLabel = new QLabel; 450 pCPULabelsLayout->addWidget(m_pCPUTotalLabel); 451 pCPULabelsLayout->setAlignment(Qt::AlignTop); 452 //pLayout->setAlignment(Qt::AlignTop); 453 pCPULabelsLayout->setSpacing(0); 454 /* Host CPU chart widget: */ 455 m_pHostCPUChart = new UIVMResourceMonitorHostCPUWidget; 456 if (m_pHostCPUChart) 457 { 458 pLayout->addWidget(m_pHostCPUChart); 459 m_pHostCPUChart->setChartColors(m_CPUUserColor, m_CPUKernelColor); 545 pLayout->addWidget(pCPULabelContainer); 546 QVBoxLayout *pCPULabelsLayout = new QVBoxLayout; 547 pCPULabelsLayout->setContentsMargins(0, 0, 0, 0); 548 pCPULabelContainer->setLayout(pCPULabelsLayout); 549 m_pCPUTitleLabel = new QLabel; 550 pCPULabelsLayout->addWidget(m_pCPUTitleLabel); 551 m_pCPUUserLabel = new QLabel; 552 pCPULabelsLayout->addWidget(m_pCPUUserLabel); 553 m_pCPUKernelLabel = new QLabel; 554 pCPULabelsLayout->addWidget(m_pCPUKernelLabel); 555 m_pCPUTotalLabel = new QLabel; 556 pCPULabelsLayout->addWidget(m_pCPUTotalLabel); 557 pCPULabelsLayout->setAlignment(Qt::AlignTop); 558 //pLayout->setAlignment(Qt::AlignTop); 559 pCPULabelsLayout->setSpacing(0); 560 /* Host CPU chart widget: */ 561 m_pHostCPUChart = new UIVMResourceMonitorHostCPUWidget; 562 if (m_pHostCPUChart) 563 { 564 m_pHostCPUChart->setMinimumSize(iMinimumSize, iMinimumSize); 565 pLayout->addWidget(m_pHostCPUChart); 566 m_pHostCPUChart->setChartColors(m_CPUUserColor, m_CPUKernelColor); 567 } 568 } 569 /* RAM Stuff: */ 570 { 571 QWidget *pRAMLabelContainer = new QWidget; 572 pRAMLabelContainer->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); 573 574 pLayout->addWidget(pRAMLabelContainer); 575 QVBoxLayout *pRAMLabelsLayout = new QVBoxLayout; 576 pRAMLabelsLayout->setContentsMargins(0, 0, 0, 0); 577 pRAMLabelContainer->setLayout(pRAMLabelsLayout); 578 m_pRAMTitleLabel = new QLabel; 579 pRAMLabelsLayout->addWidget(m_pRAMTitleLabel); 580 m_pRAMUsedLabel = new QLabel; 581 pRAMLabelsLayout->addWidget(m_pRAMUsedLabel); 582 m_pRAMFreeLabel = new QLabel; 583 pRAMLabelsLayout->addWidget(m_pRAMFreeLabel); 584 m_pRAMTotalLabel = new QLabel; 585 pRAMLabelsLayout->addWidget(m_pRAMTotalLabel); 586 587 m_pHostRAMChart = new UIVMResourceMonitorHostRAMWidget; 588 if (m_pHostRAMChart) 589 { 590 m_pHostRAMChart->setMinimumSize(iMinimumSize, iMinimumSize); 591 pLayout->addWidget(m_pHostRAMChart); 592 m_pHostRAMChart->setChartColors(m_RAMFreeColor, m_RAMUsedColor); 593 } 460 594 } 461 595 pLayout->addStretch(2); … … 478 612 if (m_pCPUTotalLabel) 479 613 m_pCPUTotalLabel->setText(QString("%1:%2%").arg(tr("Total")).arg(m_hostStats.m_iCPUUserLoad + m_hostStats.m_iCPUKernelLoad)); 614 if (m_pRAMTitleLabel) 615 m_pRAMTitleLabel->setText(QString("<b>%1</b>").arg(tr("Host RAM Usage"))); 616 if (m_pRAMFreeLabel) 617 { 618 QString strRAM = uiCommon().formatSize(m_hostStats.m_iFreeRAM); 619 QString strColor = QColor(m_RAMFreeColor).name(QColor::HexRgb); 620 m_pRAMFreeLabel->setText(QString("<font color=\"%1\">%2:%3</font>").arg(strColor).arg(tr("Free")).arg(strRAM)); 621 } 622 623 if (m_pRAMUsedLabel) 624 { 625 QString strRAM = uiCommon().formatSize(m_hostStats.m_iTotalRAM - m_hostStats.m_iFreeRAM); 626 QString strColor = QColor(m_RAMUsedColor).name(QColor::HexRgb); 627 m_pRAMUsedLabel->setText(QString("<font color=\"%1\">%2:%3</font>").arg(strColor).arg(tr("Used")).arg(strRAM)); 628 } 629 if (m_pRAMTotalLabel) 630 { 631 QString strRAM = uiCommon().formatSize(m_hostStats.m_iTotalRAM); 632 m_pRAMTotalLabel->setText(QString("%1:%2").arg(tr("Total")).arg(strRAM)); 633 } 634 480 635 } 481 636 … … 541 696 542 697 /********************************************************************************************************************************* 543 * Class UIVMResourceMonitorItem implementation. *544 *********************************************************************************************************************************/698 * Class UIVMResourceMonitorItem implementation. * 699 *********************************************************************************************************************************/ 545 700 UIResourceMonitorItem::UIResourceMonitorItem(const QUuid &uid, const QString &strVMName) 546 701 : m_VMuid(uid) … … 744 899 break; 745 900 case VMResourceMonitorColumn_CPUGuestLoad: 746 return m_itemList[index.row()].m_uCPUGuestLoad;901 return QString("%1%").arg(QString::number(m_itemList[index.row()].m_uCPUGuestLoad)); 747 902 break; 748 903 case VMResourceMonitorColumn_CPUVMMLoad: 749 return m_itemList[index.row()].m_uCPUVMMLoad;904 return QString("%1%").arg(QString::number(m_itemList[index.row()].m_uCPUVMMLoad)); 750 905 break; 751 906 case VMResourceMonitorColumn_RAMUsedAndTotal: … … 787 942 break; 788 943 case VMResourceMonitorColumn_VMExits: 789 return QString("%1/%2").arg(UICommon::addMetricSuffixToNumber(m_itemList[index.row()].m_uVMExitRate)).790 arg(UICommon::addMetricSuffixToNumber(m_itemList[index.row()].m_uVMExitTotal));944 return QString("%1/%2").arg(UICommon::addMetricSuffixToNumber(m_itemList[index.row()].m_uVMExitRate)). 945 arg(UICommon::addMetricSuffixToNumber(m_itemList[index.row()].m_uVMExitTotal)); 791 946 break; 792 947 default: … … 909 1064 m_itemList[i].m_uDiskReadRate = m_itemList[i].m_uDiskReadTotal - uPrevReadTotal; 910 1065 } 911 /* VM Exits: */912 if (fVMExitColumn)913 {914 quint64 uPrevVMExitsTotal = m_itemList[i].m_uVMExitTotal;915 UIMonitorCommon::getVMMExitCount(m_itemList[i].m_comDebugger, m_itemList[i].m_uVMExitTotal);916 m_itemList[i].m_uVMExitRate = m_itemList[i].m_uVMExitTotal - uPrevVMExitsTotal;917 }1066 /* VM Exits: */ 1067 if (fVMExitColumn) 1068 { 1069 quint64 uPrevVMExitsTotal = m_itemList[i].m_uVMExitTotal; 1070 UIMonitorCommon::getVMMExitCount(m_itemList[i].m_comDebugger, m_itemList[i].m_uVMExitTotal); 1071 m_itemList[i].m_uVMExitRate = m_itemList[i].m_uVMExitTotal - uPrevVMExitsTotal; 1072 } 918 1073 } 919 1074 } … … 951 1106 952 1107 QVector<LONG> returnData = m_performanceMonitor.QueryMetricsData(m_nameList, 953 954 955 956 957 958 959 960 1108 m_objectList, 1109 aReturnNames, 1110 aReturnObjects, 1111 aReturnUnits, 1112 aReturnScales, 1113 aReturnSequenceNumbers, 1114 aReturnDataIndices, 1115 aReturnDataLengths); 961 1116 /* Parse the result we get from CPerformanceCollector to get respective values: */ 962 1117 for (int i = 0; i < aReturnNames.size(); ++i) … … 1044 1199 1045 1200 UIResourceMonitorWidget::UIResourceMonitorWidget(EmbedTo enmEmbedding, UIActionPool *pActionPool, 1046 1201 bool fShowToolbar /* = true */, QWidget *pParent /* = 0 */) 1047 1202 : QIWithRetranslateUI<QWidget>(pParent) 1048 1203 , m_enmEmbedding(enmEmbedding)
Note:
See TracChangeset
for help on using the changeset viewer.