Changeset 80491 in vbox
- Timestamp:
- Aug 29, 2019 9:00:29 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIInformationRuntime.cpp
r80451 r80491 38 38 #include "UISession.h" 39 39 40 /* COM includes: */ 40 41 #include "CGuest.h" 41 42 #include "CPerformanceCollector.h" … … 43 44 #include "CVRDEServerInfo.h" 44 45 46 /* External includes: */ 47 # include <math.h> 45 48 46 49 const ULONG iPeriod = 1; … … 65 68 }; 66 69 70 71 QString formatNumber(qulonglong number) 72 { 73 if (number <= 0) 74 return QString(); 75 char suffices[] = {'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'}; 76 int zeroCount = (int)log10(number); 77 if (zeroCount < 3) 78 return QString::number(number); 79 int h = 3 * (zeroCount / 3); 80 char result[128]; 81 sprintf(result, "%.2f", number / (float)pow(10, h)); 82 return QString("%1 %2").arg(result).arg(suffices[h / 3 - 1]); 83 } 67 84 68 85 /********************************************************************************************************************************* … … 165 182 * @{ */ 166 183 void drawXAxisLabels(QPainter &painter, int iXSubAxisCount); 167 void drawPieCharts(QPainter &painter, qulonglong iMaximum); 184 void drawPieChart(QPainter &painter, qulonglong iMaximum, int iDataIndex, const QRectF &chartRect, int iAlpha); 185 void drawCombinedPieCharts(QPainter &painter, qulonglong iMaximum); 186 void drawDoughnutChart(QPainter &painter, qulonglong iMaximum, int iDataIndex, 187 const QRectF &chartRect, const QRectF &innerRect, int iAlpha); 188 168 189 /** Drawing an overlay rectangle over the charts to indicate that they are disabled. */ 169 190 void drawDisabledChartRectangle(QPainter &painter); … … 431 452 m_iMarginBottom = 2 * qApp->QApplication::style()->pixelMetric(QStyle::PM_LayoutTopMargin); 432 453 433 m_iPieChartRadius = 1.2f * qApp->style()->pixelMetric(QStyle::PM_LargeIconSize); 434 m_iPieChartSpacing = 0.3 * qApp->QApplication::style()->pixelMetric(QStyle::PM_LayoutTopMargin); 435 m_size = QSize(10 * m_iPieChartRadius, 3 * m_iPieChartRadius); 454 float fAppIconSize = qApp->style()->pixelMetric(QStyle::PM_LargeIconSize); 455 m_size = QSize(14 * fAppIconSize, 4 * fAppIconSize); 456 m_iPieChartSpacing = 2; 457 m_iPieChartRadius = m_size.height() - (m_iMarginTop + m_iMarginBottom + 2 * m_iPieChartSpacing); 458 436 459 retranslateUi(); 437 460 } … … 647 670 strValue = uiCommon().formatSize(iValue, iDecimalCount); 648 671 else if (m_pMetric->unit().compare("times", Qt::CaseInsensitive) == 0) 649 strValue = QString::number(iValue);672 strValue = formatNumber(iValue); 650 673 651 674 painter.drawText(width() - 0.9 * m_iMarginRight, iTextY, strValue); … … 653 676 654 677 if (m_fWithPieChart) 655 draw PieCharts(painter, iMaximum);678 drawCombinedPieCharts(painter, iMaximum); 656 679 } 657 680 … … 677 700 } 678 701 679 void UIChart::drawPieCharts(QPainter &painter, qulonglong iMaximum) 680 { 702 void UIChart::drawPieChart(QPainter &painter, qulonglong iMaximum, int iDataIndex, const QRectF &chartRect, int iAlpha) 703 { 704 if (!m_pMetric) 705 return; 706 /* First draw a doughnut shaped chart for the 1st data series */ 707 const QQueue<qulonglong> *data = m_pMetric->data(iDataIndex); 708 if (!data || data->isEmpty()) 709 return; 710 711 /* Draw a whole non-filled circle: */ 712 painter.setPen(QPen(QColor(100, 100, 100, iAlpha), 1)); 713 painter.drawArc(chartRect, 0, 3600 * 16); 714 painter.setPen(Qt::NoPen); 715 /* Prepare the gradient for the pie chart: */ 716 QConicalGradient pieGradient; 717 pieGradient.setCenter(chartRect.center()); 718 pieGradient.setAngle(90); 719 pieGradient.setColorAt(0, QColor(0, 0, 0, iAlpha)); 720 QColor pieColor(m_dataSeriesColor[iDataIndex]); 721 pieColor.setAlpha(iAlpha); 722 pieGradient.setColorAt(1, pieColor); 723 724 float fAngle = 360.f * data->back() / (float)iMaximum; 725 726 QPainterPath dataPath; 727 dataPath.moveTo(chartRect.center()); 728 dataPath.arcTo(chartRect, 90.f/*startAngle*/, 729 -1.f * fAngle /*sweepLength*/); 730 painter.setBrush(pieGradient); 731 painter.drawPath(dataPath); 732 } 733 734 void UIChart::drawDoughnutChart(QPainter &painter, qulonglong iMaximum, int iDataIndex, 735 const QRectF &chartRect, const QRectF &innerRect, int iAlpha) 736 { 737 const QQueue<qulonglong> *data = m_pMetric->data(iDataIndex); 738 if (!data || data->isEmpty()) 739 return; 740 741 /* Draw a whole non-filled circle: */ 742 painter.setPen(QPen(QColor(100, 100, 100, iAlpha), 1)); 743 painter.drawArc(chartRect, 0, 3600 * 16); 744 painter.setPen(Qt::NoPen); 745 746 /* First draw a white filled circle and that the arc for data: */ 747 QPointF center(chartRect.center()); 748 QPainterPath fillPath; 749 fillPath.moveTo(center); 750 fillPath.arcTo(chartRect, 90/*startAngle*/, 751 -1 * 360 /*sweepLength*/); 752 painter.setPen(Qt::NoPen); 753 painter.setBrush(QColor(255, 255, 255, iAlpha)); 754 painter.drawPath(fillPath); 755 756 /* Prepare the gradient for the pie chart: */ 757 QConicalGradient pieGradient; 758 pieGradient.setCenter(chartRect.center()); 759 pieGradient.setAngle(90); 760 pieGradient.setColorAt(0, QColor(0, 0, 0, iAlpha)); 761 QColor pieColor(m_dataSeriesColor[iDataIndex]); 762 pieColor.setAlpha(iAlpha); 763 pieGradient.setColorAt(1, pieColor); 764 765 766 float fAngle = 360.f * data->back() / (float)iMaximum; 767 768 QPainterPath subPath1; 769 subPath1.moveTo(chartRect.center()); 770 subPath1.arcTo(chartRect, 90.f/*startAngle*/, 771 -1.f * fAngle /*sweepLength*/); 772 subPath1.closeSubpath(); 773 774 QPainterPath subPath2; 775 subPath2.moveTo(innerRect.center()); 776 subPath2.arcTo(innerRect, 90.f/*startAngle*/, 777 -1.f * fAngle /*sweepLength*/); 778 subPath2.closeSubpath(); 779 780 QPainterPath dataPath = subPath1.subtracted(subPath2); 781 782 painter.setBrush(pieGradient); 783 painter.drawPath(dataPath); 784 785 } 786 787 void UIChart::drawCombinedPieCharts(QPainter &painter, qulonglong iMaximum) 788 { 789 if (!m_pMetric) 790 return; 791 792 QRectF chartRect(QPointF(m_iPieChartSpacing + m_iMarginLeft, m_iPieChartSpacing + m_iMarginTop), 793 QSizeF(m_iPieChartRadius, m_iPieChartRadius)); 794 681 795 int iAlpha = 80; 682 for (int i = 0; i < DATA_SERIES_SIZE; ++i) 683 { 684 /* Draw the pie chart for the 0th data series only: */ 685 const QQueue<qulonglong> *data = m_pMetric->data(i); 686 if (!data || data->isEmpty()) 687 continue; 688 QRect chartRect(QPoint((i+1) * m_iPieChartSpacing + i * m_iPieChartRadius + m_iMarginLeft, m_iPieChartSpacing + m_iMarginTop), 689 QSize(m_iPieChartRadius, m_iPieChartRadius)); 690 691 /* Draw a whole non-filled circle: */ 692 painter.setPen(QPen(QColor(100, 100, 100, iAlpha), 1)); 693 painter.drawArc(chartRect, 0, 3600 * 16); 694 695 QPointF center(chartRect.center()); 696 QPainterPath fillPath; 697 fillPath.moveTo(center); 698 fillPath.arcTo(chartRect, 90/*startAngle*/, 699 -1 * 360 /*sweepLength*/); 700 701 /* First draw a white filled circle and that the arc for data: */ 702 painter.setPen(Qt::NoPen); 703 painter.setBrush(QColor(255, 255, 255, iAlpha)); 704 painter.drawPath(fillPath); 705 706 /* Prepare the gradient for the pie chart: */ 707 QConicalGradient pieGradient; 708 pieGradient.setCenter(chartRect.center()); 709 pieGradient.setAngle(90); 710 pieGradient.setColorAt(0, QColor(0, 0, 0, iAlpha)); 711 QColor pieColor(m_dataSeriesColor[i]); 712 pieColor.setAlpha(iAlpha); 713 pieGradient.setColorAt(1, pieColor); 714 715 QPainterPath dataPath; 716 dataPath.moveTo(center); 717 float fAngle = 360.f * data->back() / (float)iMaximum; 718 dataPath.arcTo(chartRect, 90/*startAngle*/, 719 -1 * fAngle /*sweepLength*/); 720 painter.setBrush(pieGradient); 721 painter.drawPath(dataPath); 722 } 796 797 /* First draw a doughnut shaped chart for the 1st data series */ 798 // int iDataIndex = 0; 799 // const QQueue<qulonglong> *data = m_pMetric->data(iDataIndex); 800 // if (!data || data->isEmpty()) 801 // return; 802 bool fData0 = m_pMetric->data(0) && !m_pMetric->data(0)->isEmpty(); 803 bool fData1 = m_pMetric->data(0) && !m_pMetric->data(1)->isEmpty(); 804 805 if (fData0 && fData1) 806 { 807 QRectF innerRect(QPointF(chartRect.left() + 0.25 * chartRect.width(), chartRect.top() + 0.25 * chartRect.height()), 808 QSizeF(0.5 * chartRect.width(), 0.5 * chartRect.height())); 809 810 /* Draw a doughnut shaped chart and then pie chart inside it: */ 811 drawDoughnutChart(painter, iMaximum, 0 /* iDataIndex */, chartRect, innerRect, iAlpha); 812 drawPieChart(painter, iMaximum, 1 /* iDataIndex */, innerRect, iAlpha); 813 814 } 815 else if (fData0 && !fData1) 816 drawPieChart(painter, iMaximum, 0 /* iDataIndex */, chartRect, iAlpha); 817 else if (!fData0 && fData1) 818 drawPieChart(painter, iMaximum, 1 /* iDataIndex */, chartRect, iAlpha); 723 819 } 724 820 … … 1061 1157 if (m_charts.contains(m_strCPUMetricName) && m_charts[m_strCPUMetricName]) 1062 1158 m_charts[m_strCPUMetricName]->setWithPieChart(true); 1063 if (m_charts.contains(m_strRAMMetricName) && m_charts[m_strRAMMetricName])1064 m_charts[m_strRAMMetricName]->setWithPieChart(false);1065 1066 1159 1067 1160 UIRuntimeInfoWidget *m_pRuntimeInfoWidget = new UIRuntimeInfoWidget(0, m_machine, m_console); … … 1447 1540 } 1448 1541 1542 1449 1543 void UIInformationRuntime::updateVMExitMetric(qulonglong uTotalVMExits) 1450 1544 { 1545 if (uTotalVMExits <= 0) 1546 return; 1547 1451 1548 UIMetric &VMExitMetric = m_subMetrics[m_strVMExitMetricName]; 1452 1549 … … 1472 1569 strInfo = QString("<b>%1</b></b><br/>%2: %3 %4<br/>%5: %6 %7") 1473 1570 .arg(m_strVMExitInfoLabelTitle) 1474 .arg(m_strVMExitLabelCurrent).arg( QString::number(iRate)).arg(VMExitMetric.unit())1475 .arg(m_strVMExitLabelTotal).arg( QString::number(uTotalVMExits)).arg(VMExitMetric.unit());1571 .arg(m_strVMExitLabelCurrent).arg(formatNumber(iRate)).arg(VMExitMetric.unit()) 1572 .arg(m_strVMExitLabelTotal).arg(formatNumber(uTotalVMExits)).arg(VMExitMetric.unit()); 1476 1573 else 1477 1574 strInfo = QString("<b>%1</b><br/>%2%3").arg(m_strVMExitInfoLabelTitle).arg("--").arg("%");
Note:
See TracChangeset
for help on using the changeset viewer.