Changeset 102151 in vbox
- Timestamp:
- Nov 20, 2023 2:06:57 PM (12 months ago)
- 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
r102147 r102151 932 932 933 933 /* Translate the chart info labels: */ 934 i nt iMaximum = 0;934 iMaximum = 0; 935 935 m_strCPUInfoLabelTitle = QApplication::translate("UIVMInformationDialog", "CPU Load"); 936 936 iMaximum = qMax(iMaximum, m_strCPUInfoLabelTitle.length()); … … 967 967 m_strDiskIOInfoLabelReadTotal = QApplication::translate("UIVMInformationDialog", "Total Read"); 968 968 iMaximum = qMax(iMaximum, m_strDiskIOInfoLabelReadTotal.length()); 969 } 970 971 bool UIVMActivityMonitor::eventFilter(QObject *pObj, QEvent *pEvent) 972 { 973 if (pEvent-> type() == QEvent::Enter || 974 pEvent-> type() == QEvent::Leave) 975 { 976 UIChart *pChart = qobject_cast<UIChart*>(pObj); 977 if (pChart) 978 pChart->setMouseOver(pEvent-> type() == QEvent::Enter); 979 } 980 return false; 981 } 982 983 void UIVMActivityMonitor::prepareWidgets() 984 { 985 m_pMainLayout = new QVBoxLayout(this); 986 if (!m_pMainLayout) 987 return; 988 989 m_pMainLayout->setContentsMargins(0, 0, 0, 0); 990 #ifdef VBOX_WS_MAC 991 m_pMainLayout->setSpacing(10); 992 #else 993 m_pMainLayout->setSpacing(qApp->style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing) / 2); 994 #endif 995 996 m_pTimer = new QTimer(this); 997 if (m_pTimer) 998 connect(m_pTimer, &QTimer::timeout, this, &UIVMActivityMonitor::sltTimeout); 999 1000 QScrollArea *pScrollArea = new QScrollArea(this); 1001 m_pMainLayout->addWidget(pScrollArea); 1002 1003 QWidget *pContainerWidget = new QWidget(pScrollArea); 1004 QGridLayout *pContainerLayout = new QGridLayout(pContainerWidget); 1005 pContainerWidget->setLayout(pContainerLayout); 1006 pContainerLayout->setSpacing(10); 1007 pContainerWidget->show(); 1008 pScrollArea->setWidget(pContainerWidget); 1009 pScrollArea->setWidgetResizable(true); 1010 1011 QStringList chartOrder; 1012 chartOrder << m_strCPUMetricName << m_strRAMMetricName << 1013 m_strDiskMetricName << m_strNetworkMetricName << m_strDiskIOMetricName << m_strVMExitMetricName; 1014 int iRow = 0; 1015 foreach (const QString &strMetricName, chartOrder) 1016 { 1017 if (!m_metrics.contains(strMetricName)) 1018 continue; 1019 1020 QHBoxLayout *pChartLayout = new QHBoxLayout; 1021 pChartLayout->setSpacing(0); 1022 1023 QLabel *pLabel = new QLabel(this); 1024 pLabel->setAlignment(Qt::AlignLeft | Qt::AlignTop); 1025 pChartLayout->addWidget(pLabel); 1026 m_infoLabels.insert(strMetricName, pLabel); 1027 1028 UIChart *pChart = new UIChart(this, &(m_metrics[strMetricName])); 1029 pChart->installEventFilter(this); 1030 connect(pChart, &UIChart::sigExportMetricsToFile, 1031 this, &UIVMActivityMonitor::sltExportMetricsToFile); 1032 m_charts.insert(strMetricName, pChart); 1033 pChart->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); 1034 pChartLayout->addWidget(pChart); 1035 pContainerLayout->addLayout(pChartLayout, iRow, 0, 1, 2); 1036 ++iRow; 1037 } 1038 1039 /* Configure charts: */ 1040 if (m_charts.contains(m_strCPUMetricName) && m_charts[m_strCPUMetricName]) 1041 { 1042 m_charts[m_strCPUMetricName]->setIsPieChartAllowed(true); 1043 m_charts[m_strCPUMetricName]->setIsAreaChartAllowed(true); 1044 } 1045 1046 QWidget *bottomSpacerWidget = new QWidget(this); 1047 bottomSpacerWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); 1048 bottomSpacerWidget->setVisible(true); 1049 pContainerLayout->addWidget(bottomSpacerWidget, iRow, 0, 1, 2); 1050 } 1051 1052 void UIVMActivityMonitor::sltTimeout() 1053 { 1054 obtainDataAndUpdate(); 1055 } 1056 1057 void UIVMActivityMonitor::sltExportMetricsToFile() 1058 { 1059 QString strStartFileName = QString("%1/%2_%3"). 1060 arg(QFileInfo(defaultMachineFolder()).absolutePath()). 1061 arg(machineName()). 1062 arg(QDateTime::currentDateTime().toString("dd-MM-yyyy_hh-mm-ss")); 1063 QString strFileName = QIFileDialog::getSaveFileName(strStartFileName,"",this, 1064 QApplication::translate("UIVMInformationDialog", 1065 "Export activity data of the machine \"%1\"") 1066 .arg(machineName())); 1067 QFile dataFile(strFileName); 1068 if (dataFile.open(QFile::WriteOnly | QFile::Truncate)) 1069 { 1070 QTextStream stream(&dataFile); 1071 for (QMap<QString, UIMetric>::const_iterator iterator = m_metrics.begin(); iterator != m_metrics.end(); ++iterator) 1072 iterator.value().toFile(stream); 1073 dataFile.close(); 1074 } 1075 } 1076 1077 void UIVMActivityMonitor::sltCreateContextMenu(const QPoint &point) 1078 { 1079 QMenu menu; 1080 QAction *pExportAction = 1081 menu.addAction(QApplication::translate("UIVMInformationDialog", "Export")); 1082 pExportAction->setIcon(UIIconPool::iconSet(":/performance_monitor_export_16px.png")); 1083 connect(pExportAction, &QAction::triggered, this, &UIVMActivityMonitor::sltExportMetricsToFile); 1084 menu.exec(mapToGlobal(point)); 1085 } 1086 1087 void UIVMActivityMonitor::prepareActions() 1088 { 1089 } 1090 1091 void UIVMActivityMonitor::resetCPUInfoLabel() 1092 { 1093 if (m_infoLabels.contains(m_strCPUMetricName) && m_infoLabels[m_strCPUMetricName]) 1094 { 1095 QString strInfo =QString("<b>%1</b></b><br/>%2: %3<br/>%4: %5") 1096 .arg(m_strCPUInfoLabelTitle) 1097 .arg(m_strCPUInfoLabelGuest).arg("--") 1098 .arg(m_strCPUInfoLabelVMM).arg("--"); 1099 m_infoLabels[m_strCPUMetricName]->setText(strInfo); 1100 } 1101 } 1102 1103 void UIVMActivityMonitor::resetRAMInfoLabel() 1104 { 1105 if (m_infoLabels.contains(m_strRAMMetricName) && m_infoLabels[m_strRAMMetricName]) 1106 { 1107 QString strInfo = QString("<b>%1</b><br/>%2: %3<br/>%4: %5<br/>%6: %7"). 1108 arg(m_strRAMInfoLabelTitle).arg(m_strRAMInfoLabelTotal).arg("--") 1109 .arg(m_strRAMInfoLabelFree).arg("--") 1110 .arg(m_strRAMInfoLabelUsed).arg("--"); 1111 m_infoLabels[m_strRAMMetricName]->setText(strInfo); 1112 } 1113 } 1114 1115 void UIVMActivityMonitor::resetNetworkInfoLabel() 1116 { 1117 if (m_infoLabels.contains(m_strNetworkMetricName) && m_infoLabels[m_strNetworkMetricName]) 1118 { 1119 QString strInfo = QString("<b>%1</b></b><br/>%2: %3<br/>%4 %5<br/>%6: %7<br/>%8 %9") 1120 .arg(m_strNetworkInfoLabelTitle) 1121 .arg(m_strNetworkInfoLabelReceived).arg("--") 1122 .arg(m_strNetworkInfoLabelReceivedTotal).arg("--") 1123 .arg(m_strNetworkInfoLabelTransmitted).arg("--") 1124 .arg(m_strNetworkInfoLabelTransmittedTotal).arg("--"); 1125 m_infoLabels[m_strNetworkMetricName]->setText(strInfo); 1126 } 1127 } 1128 1129 void UIVMActivityMonitor::resetDiskIOInfoLabel() 1130 { 1131 if (m_infoLabels.contains(m_strDiskIOMetricName) && m_infoLabels[m_strDiskIOMetricName]) 1132 { 1133 QString strInfo = QString("<b>%1</b></b><br/>%2: %3<br/>%4 %5<br/>%6: %7<br/>%8 %9") 1134 .arg(m_strDiskIOInfoLabelTitle) 1135 .arg(m_strDiskIOInfoLabelWritten).arg("--") 1136 .arg(m_strDiskIOInfoLabelWrittenTotal).arg("--") 1137 .arg(m_strDiskIOInfoLabelRead).arg("--") 1138 .arg(m_strDiskIOInfoLabelReadTotal).arg("--"); 1139 m_infoLabels[m_strDiskIOMetricName]->setText(strInfo); 1140 } 1141 } 1142 1143 QString UIVMActivityMonitor::dataColorString(const QString &strChartName, int iDataIndex) 1144 { 1145 if (!m_charts.contains(strChartName)) 1146 return QColor(Qt::black).name(QColor::HexRgb); 1147 UIChart *pChart = m_charts[strChartName]; 1148 if (!pChart) 1149 return QColor(Qt::black).name(QColor::HexRgb); 1150 return pChart->dataSeriesColor(iDataIndex).name(QColor::HexRgb); 1151 } 1152 1153 void UIVMActivityMonitorLocal::start() 1154 { 1155 if (m_comMachine.isNull() || m_comMachine.GetState() != KMachineState_Running) 1156 return; 1157 1158 m_fGuestAdditionsAvailable = guestAdditionsAvailable("6.1"); 1159 enableDisableGuestAdditionDependedWidgets(m_fGuestAdditionsAvailable); 1160 if (m_pTimer) 1161 m_pTimer->start(1000 * g_iPeriod); 1162 } 1163 1164 UIVMActivityMonitorLocal::UIVMActivityMonitorLocal(EmbedTo enmEmbedding, QWidget *pParent, const CMachine &machine) 1165 :UIVMActivityMonitor(enmEmbedding, pParent) 1166 , m_fGuestAdditionsAvailable(false) 1167 { 1168 prepareMetrics(); 1169 prepareWidgets(); 1170 retranslateUi(); 1171 prepareActions(); 1172 connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigMachineStateChange, this, &UIVMActivityMonitorLocal::sltMachineStateChange); 1173 connect(&uiCommon(), &UICommon::sigAskToDetachCOM, this, &UIVMActivityMonitorLocal::sltClearCOMData); 1174 setMachine(machine); 1175 } 1176 1177 UIVMActivityMonitorLocal::~UIVMActivityMonitorLocal() 1178 { 1179 sltClearCOMData(); 1180 } 1181 1182 QUuid UIVMActivityMonitorLocal::machineId() const 1183 { 1184 if (m_comMachine.isNull()) 1185 return QUuid(); 1186 return m_comMachine.GetId(); 1187 } 1188 1189 void UIVMActivityMonitorLocal::retranslateUi() 1190 { 1191 UIVMActivityMonitor::retranslateUi(); 1192 m_strVMExitInfoLabelTitle = QApplication::translate("UIVMInformationDialog", "VM Exits"); 1193 iMaximum = qMax(iMaximum, m_strVMExitInfoLabelTitle.length()); 1194 m_strVMExitLabelCurrent = QApplication::translate("UIVMInformationDialog", "Current"); 1195 iMaximum = qMax(iMaximum, m_strVMExitLabelCurrent.length()); 1196 m_strVMExitLabelTotal = QApplication::translate("UIVMInformationDialog", "Total"); 1197 iMaximum = qMax(iMaximum, m_strVMExitLabelTotal.length()); 969 1198 970 1199 /* Compute the maximum label string length and set it as a fixed width to labels to prevent always changing widths: */ … … 986 1215 } 987 1216 } 988 }989 990 bool UIVMActivityMonitor::eventFilter(QObject *pObj, QEvent *pEvent)991 {992 if (pEvent-> type() == QEvent::Enter ||993 pEvent-> type() == QEvent::Leave)994 {995 UIChart *pChart = qobject_cast<UIChart*>(pObj);996 if (pChart)997 pChart->setMouseOver(pEvent-> type() == QEvent::Enter);998 }999 return false;1000 }1001 1002 void UIVMActivityMonitor::prepareWidgets()1003 {1004 m_pMainLayout = new QVBoxLayout(this);1005 if (!m_pMainLayout)1006 return;1007 1008 m_pMainLayout->setContentsMargins(0, 0, 0, 0);1009 #ifdef VBOX_WS_MAC1010 m_pMainLayout->setSpacing(10);1011 #else1012 m_pMainLayout->setSpacing(qApp->style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing) / 2);1013 #endif1014 1015 m_pTimer = new QTimer(this);1016 if (m_pTimer)1017 connect(m_pTimer, &QTimer::timeout, this, &UIVMActivityMonitor::sltTimeout);1018 1019 QScrollArea *pScrollArea = new QScrollArea(this);1020 m_pMainLayout->addWidget(pScrollArea);1021 1022 QWidget *pContainerWidget = new QWidget(pScrollArea);1023 QGridLayout *pContainerLayout = new QGridLayout(pContainerWidget);1024 pContainerWidget->setLayout(pContainerLayout);1025 pContainerLayout->setSpacing(10);1026 pContainerWidget->show();1027 pScrollArea->setWidget(pContainerWidget);1028 pScrollArea->setWidgetResizable(true);1029 1030 QStringList chartOrder;1031 chartOrder << m_strCPUMetricName << m_strRAMMetricName <<1032 m_strDiskMetricName << m_strNetworkMetricName << m_strDiskIOMetricName << m_strVMExitMetricName;1033 int iRow = 0;1034 foreach (const QString &strMetricName, chartOrder)1035 {1036 if (!m_metrics.contains(strMetricName))1037 continue;1038 1039 QHBoxLayout *pChartLayout = new QHBoxLayout;1040 pChartLayout->setSpacing(0);1041 1042 QLabel *pLabel = new QLabel(this);1043 pLabel->setAlignment(Qt::AlignLeft | Qt::AlignTop);1044 pChartLayout->addWidget(pLabel);1045 m_infoLabels.insert(strMetricName, pLabel);1046 1047 UIChart *pChart = new UIChart(this, &(m_metrics[strMetricName]));1048 pChart->installEventFilter(this);1049 connect(pChart, &UIChart::sigExportMetricsToFile,1050 this, &UIVMActivityMonitor::sltExportMetricsToFile);1051 m_charts.insert(strMetricName, pChart);1052 pChart->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);1053 pChartLayout->addWidget(pChart);1054 pContainerLayout->addLayout(pChartLayout, iRow, 0, 1, 2);1055 ++iRow;1056 }1057 1058 /* Configure charts: */1059 if (m_charts.contains(m_strCPUMetricName) && m_charts[m_strCPUMetricName])1060 {1061 m_charts[m_strCPUMetricName]->setIsPieChartAllowed(true);1062 m_charts[m_strCPUMetricName]->setIsAreaChartAllowed(true);1063 }1064 1065 QWidget *bottomSpacerWidget = new QWidget(this);1066 bottomSpacerWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);1067 bottomSpacerWidget->setVisible(true);1068 pContainerLayout->addWidget(bottomSpacerWidget, iRow, 0, 1, 2);1069 }1070 1071 void UIVMActivityMonitor::sltTimeout()1072 {1073 obtainDataAndUpdate();1074 }1075 1076 void UIVMActivityMonitor::sltExportMetricsToFile()1077 {1078 QString strStartFileName = QString("%1/%2_%3").1079 arg(QFileInfo(defaultMachineFolder()).absolutePath()).1080 arg(machineName()).1081 arg(QDateTime::currentDateTime().toString("dd-MM-yyyy_hh-mm-ss"));1082 QString strFileName = QIFileDialog::getSaveFileName(strStartFileName,"",this,1083 QApplication::translate("UIVMInformationDialog",1084 "Export activity data of the machine \"%1\"")1085 .arg(machineName()));1086 QFile dataFile(strFileName);1087 if (dataFile.open(QFile::WriteOnly | QFile::Truncate))1088 {1089 QTextStream stream(&dataFile);1090 for (QMap<QString, UIMetric>::const_iterator iterator = m_metrics.begin(); iterator != m_metrics.end(); ++iterator)1091 iterator.value().toFile(stream);1092 dataFile.close();1093 }1094 }1095 1096 void UIVMActivityMonitor::sltCreateContextMenu(const QPoint &point)1097 {1098 QMenu menu;1099 QAction *pExportAction =1100 menu.addAction(QApplication::translate("UIVMInformationDialog", "Export"));1101 pExportAction->setIcon(UIIconPool::iconSet(":/performance_monitor_export_16px.png"));1102 connect(pExportAction, &QAction::triggered, this, &UIVMActivityMonitor::sltExportMetricsToFile);1103 menu.exec(mapToGlobal(point));1104 }1105 1106 void UIVMActivityMonitor::prepareActions()1107 {1108 }1109 1110 void UIVMActivityMonitor::resetCPUInfoLabel()1111 {1112 if (m_infoLabels.contains(m_strCPUMetricName) && m_infoLabels[m_strCPUMetricName])1113 {1114 QString strInfo =QString("<b>%1</b></b><br/>%2: %3<br/>%4: %5")1115 .arg(m_strCPUInfoLabelTitle)1116 .arg(m_strCPUInfoLabelGuest).arg("--")1117 .arg(m_strCPUInfoLabelVMM).arg("--");1118 m_infoLabels[m_strCPUMetricName]->setText(strInfo);1119 }1120 }1121 1122 void UIVMActivityMonitor::resetRAMInfoLabel()1123 {1124 if (m_infoLabels.contains(m_strRAMMetricName) && m_infoLabels[m_strRAMMetricName])1125 {1126 QString strInfo = QString("<b>%1</b><br/>%2: %3<br/>%4: %5<br/>%6: %7").1127 arg(m_strRAMInfoLabelTitle).arg(m_strRAMInfoLabelTotal).arg("--")1128 .arg(m_strRAMInfoLabelFree).arg("--")1129 .arg(m_strRAMInfoLabelUsed).arg("--");1130 m_infoLabels[m_strRAMMetricName]->setText(strInfo);1131 }1132 }1133 1134 void UIVMActivityMonitor::resetNetworkInfoLabel()1135 {1136 if (m_infoLabels.contains(m_strNetworkMetricName) && m_infoLabels[m_strNetworkMetricName])1137 {1138 QString strInfo = QString("<b>%1</b></b><br/>%2: %3<br/>%4 %5<br/>%6: %7<br/>%8 %9")1139 .arg(m_strNetworkInfoLabelTitle)1140 .arg(m_strNetworkInfoLabelReceived).arg("--")1141 .arg(m_strNetworkInfoLabelReceivedTotal).arg("--")1142 .arg(m_strNetworkInfoLabelTransmitted).arg("--")1143 .arg(m_strNetworkInfoLabelTransmittedTotal).arg("--");1144 m_infoLabels[m_strNetworkMetricName]->setText(strInfo);1145 }1146 }1147 1148 void UIVMActivityMonitor::resetDiskIOInfoLabel()1149 {1150 if (m_infoLabels.contains(m_strDiskIOMetricName) && m_infoLabels[m_strDiskIOMetricName])1151 {1152 QString strInfo = QString("<b>%1</b></b><br/>%2: %3<br/>%4 %5<br/>%6: %7<br/>%8 %9")1153 .arg(m_strDiskIOInfoLabelTitle)1154 .arg(m_strDiskIOInfoLabelWritten).arg("--")1155 .arg(m_strDiskIOInfoLabelWrittenTotal).arg("--")1156 .arg(m_strDiskIOInfoLabelRead).arg("--")1157 .arg(m_strDiskIOInfoLabelReadTotal).arg("--");1158 m_infoLabels[m_strDiskIOMetricName]->setText(strInfo);1159 }1160 }1161 1162 QString UIVMActivityMonitor::dataColorString(const QString &strChartName, int iDataIndex)1163 {1164 if (!m_charts.contains(strChartName))1165 return QColor(Qt::black).name(QColor::HexRgb);1166 UIChart *pChart = m_charts[strChartName];1167 if (!pChart)1168 return QColor(Qt::black).name(QColor::HexRgb);1169 return pChart->dataSeriesColor(iDataIndex).name(QColor::HexRgb);1170 }1171 1172 void UIVMActivityMonitorLocal::start()1173 {1174 if (m_comMachine.isNull() || m_comMachine.GetState() != KMachineState_Running)1175 return;1176 1177 m_fGuestAdditionsAvailable = guestAdditionsAvailable("6.1");1178 enableDisableGuestAdditionDependedWidgets(m_fGuestAdditionsAvailable);1179 if (m_pTimer)1180 m_pTimer->start(1000 * g_iPeriod);1181 }1182 1183 UIVMActivityMonitorLocal::UIVMActivityMonitorLocal(EmbedTo enmEmbedding, QWidget *pParent, const CMachine &machine)1184 :UIVMActivityMonitor(enmEmbedding, pParent)1185 , m_fGuestAdditionsAvailable(false)1186 {1187 prepareMetrics();1188 prepareWidgets();1189 prepareActions();1190 connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigMachineStateChange, this, &UIVMActivityMonitorLocal::sltMachineStateChange);1191 connect(&uiCommon(), &UICommon::sigAskToDetachCOM, this, &UIVMActivityMonitorLocal::sltClearCOMData);1192 setMachine(machine);1193 }1194 1195 UIVMActivityMonitorLocal::~UIVMActivityMonitorLocal()1196 {1197 sltClearCOMData();1198 }1199 1200 QUuid UIVMActivityMonitorLocal::machineId() const1201 {1202 if (m_comMachine.isNull())1203 return QUuid();1204 return m_comMachine.GetId();1205 }1206 1207 void UIVMActivityMonitorLocal::retranslateUi()1208 {1209 UIVMActivityMonitor::retranslateUi();1210 m_strVMExitInfoLabelTitle = QApplication::translate("UIVMInformationDialog", "VM Exits");1211 //iMaximum = qMax(iMaximum, m_strVMExitInfoLabelTitle.length());1212 m_strVMExitLabelCurrent = QApplication::translate("UIVMInformationDialog", "Current");1213 //iMaximum = qMax(iMaximum, m_strVMExitLabelCurrent.length());1214 m_strVMExitLabelTotal = QApplication::translate("UIVMInformationDialog", "Total");1215 //iMaximum = qMax(iMaximum, m_strVMExitLabelTotal.length());1216 1217 } 1217 1218 -
trunk/src/VBox/Frontends/VirtualBox/src/activity/vmactivity/UIVMActivityMonitor.h
r102148 r102151 220 220 QString m_strDiskIOInfoLabelReadTotal; 221 221 /** @} */ 222 222 int iMaximum = 0; 223 223 224 224 private slots:
Note:
See TracChangeset
for help on using the changeset viewer.