- Timestamp:
- Aug 6, 2019 6:50:03 PM (5 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/runtime/information
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIPerformanceMonitor.cpp
r80158 r80162 145 145 { 146 146 Q_UNUSED(pEvent); 147 148 147 QPainter painter(this); 149 148 … … 163 162 painter.drawLine(m_iMargin + i * fChartWidth / (float)iXParts, m_iMargin, m_iMargin + i * fChartWidth / (float)iXParts, height() - m_iMargin); 164 163 165 painter.setRenderHint(QPainter::Antialiasing); // | QPainter::TextAntialiasing);164 painter.setRenderHint(QPainter::Antialiasing); 166 165 if (!m_pSubMetric) 167 166 return; … … 170 169 if (data.isEmpty() || iMaximumQueueSize == 0) 171 170 return; 172 float fBarWidth = fChartWidth / (float) iMaximumQueueSize;173 171 174 172 float fMaximum = m_pSubMetric->maximum(); 175 173 if (m_pSubMetric->isPercentage()) 176 174 fMaximum = 100.f; 177 178 float fH = 0; 179 if (fMaximum != 0) 180 fH = fChartHeight / fMaximum; 181 182 QLinearGradient gradient(0, 0, 0, fChartHeight); 183 gradient.setColorAt(1.0, Qt::green); 184 gradient.setColorAt(0.0, Qt::red); 185 painter.setPen(QPen(gradient, 2.5)); 186 187 for (int i = 0; i < data.size() - 1; ++i) 188 { 189 int j = i + 1; 190 191 float fHeight = fH * data[i]; 192 float fX = width() - ((data.size() -i) * fBarWidth); 193 194 float fHeight2 = fH * data[j]; 195 float fX2 = width() - ((data.size() -j) * fBarWidth); 196 197 198 QLineF bar(fX, height() - (fHeight + m_iMargin), fX2, height() - (fHeight2 + m_iMargin)); 199 painter.drawLine(bar); 200 } 201 175 if (fMaximum == 0) 176 return; 177 178 if (isEnabled()) 179 { 180 float fBarWidth = fChartWidth / (float) iMaximumQueueSize; 181 182 float fH = fChartHeight / fMaximum; 183 184 QLinearGradient gradient(0, 0, 0, fChartHeight); 185 gradient.setColorAt(1.0, Qt::green); 186 gradient.setColorAt(0.0, Qt::red); 187 painter.setPen(QPen(gradient, 2.5)); 188 189 for (int i = 0; i < data.size() - 1; ++i) 190 { 191 int j = i + 1; 192 193 float fHeight = fH * data[i]; 194 float fX = width() - ((data.size() -i) * fBarWidth); 195 196 float fHeight2 = fH * data[j]; 197 float fX2 = width() - ((data.size() -j) * fBarWidth); 198 199 200 QLineF bar(fX, height() - (fHeight + m_iMargin), fX2, height() - (fHeight2 + m_iMargin)); 201 painter.drawLine(bar); 202 } 203 } 202 204 203 205 /* Draw a whole non-filled circle: */ … … 207 209 QPointF center(m_pieChartRect.center()); 208 210 QPainterPath fillPath; 209 QPainterPath dataPath;210 dataPath.moveTo(center);211 211 fillPath.moveTo(center); 212 float fAngle = 360.f * data.back() / fMaximum; 213 dataPath.arcTo(m_pieChartRect, 90/*startAngle*/, 214 -1 * fAngle /*sweepLength*/); 212 215 213 fillPath.arcTo(m_pieChartRect, 90/*startAngle*/, 216 214 -1 * 360 /*sweepLength*/); … … 226 224 painter.setBrush(Qt::white); 227 225 painter.drawPath(fillPath); 228 painter.setBrush(pieGradient); 229 painter.drawPath(dataPath); 226 227 if (isEnabled()) 228 { 229 QPainterPath dataPath; 230 dataPath.moveTo(center); 231 float fAngle = 360.f * data.back() / fMaximum; 232 dataPath.arcTo(m_pieChartRect, 90/*startAngle*/, 233 -1 * fAngle /*sweepLength*/); 234 painter.setBrush(pieGradient); 235 painter.drawPath(dataPath); 236 } 237 else 238 { 239 painter.setPen(Qt::NoPen); 240 painter.setBrush(QColor(60, 60, 60, 50)); 241 painter.drawRect(QRect(0, 0, width(), height())); 242 } 230 243 } 231 244 … … 238 251 , m_strUnit(strUnit) 239 252 , m_iMaximumQueueSize(iMaximumQueueSize) 253 , m_fRequiresGuestAdditions(false) 240 254 { 241 255 if (isPercentage()) … … 310 324 } 311 325 326 bool UISubMetric::requiresGuestAdditions() const 327 { 328 return m_fRequiresGuestAdditions; 329 } 330 331 void UISubMetric::setRequiresGuestAdditions(bool fRequiresGAs) 332 { 333 m_fRequiresGuestAdditions = fRequiresGAs; 334 } 312 335 313 336 /********************************************************************************************************************************* … … 315 338 *********************************************************************************************************************************/ 316 339 317 UIPerformanceMonitor::UIPerformanceMonitor(QWidget *pParent, const CMachine &machine, const CConsole &console )340 UIPerformanceMonitor::UIPerformanceMonitor(QWidget *pParent, const CMachine &machine, const CConsole &console, const UISession *pSession) 318 341 : QWidget(pParent) 319 342 , m_fGuestAdditionsAvailable(false) … … 325 348 , m_strRAMMetricName("RAM Usage") 326 349 { 327 // bool fGuestAdditionsStatus = comGuest.GetAdditionsStatus(comGuest.GetAdditionsRunLevel()); 328 // if (fGuestAdditionsStatus) 329 // { 330 // QStringList versionStrings = comGuest.GetAdditionsVersion().split('.', QString::SkipEmptyParts); 331 // if (!versionStrings.isEmpty()) 332 // { 333 // bool fConvert = false; 334 // int iMajorVersion = versionStrings[0].toInt(&fConvert); 335 // if (fConvert && iMajorVersion >= 6) 336 // m_fGuestAdditionsAvailable = true; 337 // } 338 // } 339 // printf("m_fGuestAdditionsAvailable %d\n", m_fGuestAdditionsAvailable); 340 350 if (!m_console.isNull()) 351 m_comGuest = m_console.GetGuest(); 352 m_fGuestAdditionsAvailable = guestAdditionsAvailable(6 /* minimum major version */); 353 354 connect(pSession, &UISession::sigAdditionsStateChange, this, &UIPerformanceMonitor::sltGuestAdditionsStateChange); 341 355 preparePerformaceCollector(); 342 356 prepareObjects(); 357 enableDisableGuestAdditionDependedWidgets(m_fGuestAdditionsAvailable); 343 358 } 344 359 … … 463 478 CPUMetric.addData(aPctExecuting); 464 479 QList<UIChart*> charts = m_charts.values(m_strCPUMetricName); 465 QString strInfo = QString("%1\n%2%3").arg("CPU Load").arg(QString::number(aPctExecuting)).arg("%"); 466 if (m_infoLabels.contains(m_strCPUMetricName)) 467 m_infoLabels[m_strCPUMetricName]->setText(strInfo); 480 481 if (m_infoLabels.contains(m_strCPUMetricName) && m_infoLabels[m_strCPUMetricName]) 482 { 483 if (m_infoLabels[m_strCPUMetricName]->isEnabled()) 484 { 485 QString strInfo = QString("%1\n%2%3").arg("CPU Load").arg(QString::number(aPctExecuting)).arg("%"); 486 m_infoLabels[m_strCPUMetricName]->setText(strInfo); 487 } 488 else 489 { 490 QString strInfo = QString("%1\n%2%3").arg("CPU Load").arg("--").arg("%"); 491 m_infoLabels[m_strCPUMetricName]->setText(strInfo); 492 } 493 } 468 494 if (m_charts.contains(m_strCPUMetricName)) 469 495 m_charts[m_strCPUMetricName]->update(); … … 475 501 RAMMetric.setMaximum(iTotalRAM); 476 502 RAMMetric.addData(iTotalRAM - iFreeRAM); 477 QString strInfo = QString("%1\n%2: %3\n%4: %5\n%6: %7").arg("RAM Usage").arg("Total").arg(uiCommon().formatSize(_1K * iTotalRAM)).arg("Free:").arg(uiCommon().formatSize(_1K * (iFreeRAM))).arg("Used:").arg(uiCommon().formatSize(_1K * (iTotalRAM - iFreeRAM))); 478 if (m_infoLabels.contains(m_strRAMMetricName)) 479 m_infoLabels[m_strRAMMetricName]->setText(strInfo); 480 503 504 if (m_infoLabels.contains(m_strRAMMetricName) && m_infoLabels[m_strRAMMetricName]) 505 { 506 if (m_infoLabels[m_strRAMMetricName]->isEnabled()) 507 { 508 QString strInfo = QString("%1\n%2: %3\n%4: %5\n%6: %7").arg("RAM Usage").arg("Total").arg(uiCommon().formatSize(_1K * iTotalRAM)).arg("Free:").arg(uiCommon().formatSize(_1K * (iFreeRAM))).arg("Used:").arg(uiCommon().formatSize(_1K * (iTotalRAM - iFreeRAM))); 509 m_infoLabels[m_strRAMMetricName]->setText(strInfo); 510 } 511 else 512 { 513 QString strInfo = QString("%1\n%2: %3\n%4: %5\n%6: %7").arg("RAM Usage").arg("Total").arg("---").arg("Free").arg("---").arg("Used").arg("---"); 514 m_infoLabels[m_strRAMMetricName]->setText(strInfo); 515 } 516 } 481 517 if (m_charts.contains(m_strRAMMetricName)) 482 518 { … … 484 520 } 485 521 } 486 487 /* Try to compute a global font size so that all texts fit to widgets: */ 488 // int iMinimumFontSize = 24; 489 // foreach (UIChart *pChart, m_charts) 490 // { 491 // if (!qobject_cast<UIPieChart*>(pChart)) 492 // continue; 493 // iMinimumFontSize = qMin(pChart->fontSize(), iMinimumFontSize); 494 // } 495 496 // foreach (UIChart *pChart, m_charts) 497 // { 498 // if (!pChart) 499 // continue; 500 // pChart->setFontSize(iMinimumFontSize); 501 // pChart->update(); 502 // } 503 504 505 // int iMaxLineNumber = 0; 506 // int iMaxLineLength = 0; 507 // foreach (UIChart *pChart, m_charts) 508 // { 509 // if (!pChart) 510 // continue; 511 // const QStringList &list = pChart->textList(); 512 // iMaxLineNumber = qMax(iMaxLineNumber, list.size()); 513 // foreach (const QString &strLine, list) 514 // iMaxLineLength = qMax(iMaxLineLength, strLine.length()); 515 // } 516 517 // foreach (UIChart *pChart, m_charts) 518 // { 519 // /* Currently we only care about the pie charts since they are the smallest of charts: */ 520 // if (qobject_cast<UIPieChart*>(pChart)) 521 // continue; 522 523 // } 522 } 523 524 void UIPerformanceMonitor::sltGuestAdditionsStateChange() 525 { 526 bool fGuestAdditionsAvailable = guestAdditionsAvailable(6 /* minimum major version */); 527 if (m_fGuestAdditionsAvailable == fGuestAdditionsAvailable) 528 return; 529 m_fGuestAdditionsAvailable = fGuestAdditionsAvailable; 530 enableDisableGuestAdditionDependedWidgets(m_fGuestAdditionsAvailable); 524 531 } 525 532 … … 549 556 { 550 557 QString strRAMMetricName(m_strRAMMetricName); 551 m_subMetrics.insert(strRAMMetricName, UISubMetric(strRAMMetricName, metrics[i].GetUnit(), iMaximumQueueSize)); 558 UISubMetric newMetric(strRAMMetricName, metrics[i].GetUnit(), iMaximumQueueSize); 559 newMetric.setRequiresGuestAdditions(true); 560 m_subMetrics.insert(strRAMMetricName, newMetric); 552 561 } 553 562 } … … 557 566 } 558 567 568 bool UIPerformanceMonitor::guestAdditionsAvailable(int iMinimumMajorVersion) 569 { 570 if (m_comGuest.isNull()) 571 return false; 572 bool fGuestAdditionsStatus = m_comGuest.GetAdditionsStatus(m_comGuest.GetAdditionsRunLevel()); 573 if (fGuestAdditionsStatus) 574 { 575 QStringList versionStrings = m_comGuest.GetAdditionsVersion().split('.', QString::SkipEmptyParts); 576 if (!versionStrings.isEmpty()) 577 { 578 bool fConvert = false; 579 int iMajorVersion = versionStrings[0].toInt(&fConvert); 580 if (fConvert && iMajorVersion >= iMinimumMajorVersion) 581 return true; 582 } 583 } 584 return false; 585 } 586 587 void UIPerformanceMonitor::enableDisableGuestAdditionDependedWidgets(bool fEnable) 588 { 589 for (QMap<QString, UISubMetric>::const_iterator iterator = m_subMetrics.begin(); 590 iterator != m_subMetrics.end(); ++iterator) 591 { 592 if (!iterator.value().requiresGuestAdditions()) 593 continue; 594 if (m_charts.contains(iterator.key()) && m_charts[iterator.key()]) 595 { 596 m_charts[iterator.key()]->setEnabled(fEnable); 597 m_charts[iterator.key()]->update(); 598 } 599 if (m_infoLabels.contains(iterator.key()) && m_infoLabels[iterator.key()]) 600 { 601 m_infoLabels[iterator.key()]->setEnabled(fEnable); 602 m_infoLabels[iterator.key()]->update(); 603 } 604 } 605 } 559 606 #include "UIPerformanceMonitor.moc" -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIPerformanceMonitor.h
r80158 r80162 44 44 class QLabel; 45 45 class UIChart; 46 class UISession; 46 47 47 48 class UISubMetric … … 70 71 bool isPercentage() const; 71 72 73 bool requiresGuestAdditions() const; 74 void setRequiresGuestAdditions(bool fRequiresGAs); 75 72 76 private: 73 77 … … 79 83 QQueue<ULONG> m_data; 80 84 int m_iMaximumQueueSize; 85 bool m_fRequiresGuestAdditions; 81 86 }; 82 87 … … 90 95 * @param machine is machine reference. 91 96 * @param console is machine console reference. */ 92 UIPerformanceMonitor(QWidget *pParent, const CMachine &machine, const CConsole &console );97 UIPerformanceMonitor(QWidget *pParent, const CMachine &machine, const CConsole &console, const UISession *pSession); 93 98 ~UIPerformanceMonitor(); 94 99 … … 96 101 97 102 void sltTimeout(); 103 void sltGuestAdditionsStateChange(); 98 104 99 105 private: … … 102 108 void prepareObjects(); 103 109 void preparePerformaceCollector(); 110 bool guestAdditionsAvailable(int iMinimumMajorVersion); 111 void enableDisableGuestAdditionDependedWidgets(bool fEnable); 104 112 bool m_fGuestAdditionsAvailable; 105 113 /** Holds the machine instance. */ -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIVMInformationDialog.cpp
r80132 r80162 263 263 264 264 UIPerformanceMonitor *pPerformanceMonitor = 265 new UIPerformanceMonitor(this, m_pMachineWindow->machine(), m_pMachineWindow->console() );265 new UIPerformanceMonitor(this, m_pMachineWindow->machine(), m_pMachineWindow->console(), m_pMachineWindow->uisession()); 266 266 if (pPerformanceMonitor) 267 267 {
Note:
See TracChangeset
for help on using the changeset viewer.