- Timestamp:
- Sep 23, 2008 12:35:28 PM (16 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp
r12607 r12668 661 661 " [-period <seconds>]\n" 662 662 " [-samples <count>]\n" 663 " [-list]\n" 663 664 " [*|host|<vmname> [<metric_list>]]\n\n" 664 665 "VBoxManage metrics query [*|host|<vmname> [<metric_list>]]\n\n" … … 7807 7808 } 7808 7809 7810 static void listAffectedMetrics(ComPtr<IVirtualBox> aVirtualBox, 7811 ComSafeArrayIn(IPerformanceMetric*, aMetrics)) 7812 { 7813 HRESULT rc; 7814 com::SafeIfaceArray<IPerformanceMetric> metrics(ComSafeArrayInArg(aMetrics)); 7815 if (metrics.size()) 7816 { 7817 ComPtr<IUnknown> object; 7818 Bstr metricName; 7819 RTPrintf("The following metrics were modified:\n\n" 7820 "Object Metric\n" 7821 "---------- --------------------\n"); 7822 for (size_t i = 0; i < metrics.size(); i++) 7823 { 7824 CHECK_ERROR(metrics[i], COMGETTER(Object)(object.asOutParam())); 7825 CHECK_ERROR(metrics[i], COMGETTER(MetricName)(metricName.asOutParam())); 7826 RTPrintf("%-10ls %-20ls\n", 7827 getObjectName(aVirtualBox, object).raw(), metricName.raw()); 7828 } 7829 RTPrintf("\n"); 7830 } 7831 else 7832 { 7833 RTPrintf("No metrics match the specified filter!\n"); 7834 } 7835 } 7836 7809 7837 /** 7810 7838 * list * … … 7870 7898 com::SafeIfaceArray<IUnknown> objects; 7871 7899 ULONG period = 1, samples = 1; 7872 /*bool listMatches = false;*/7900 bool listMatches = false; 7873 7901 int i; 7874 7902 … … 7893 7921 return errorArgument("Invalid value for 'samples' parameter: '%s'", argv[i]); 7894 7922 } 7923 else if (strcmp(argv[i], "-list") == 0) 7924 listMatches = true; 7895 7925 else 7896 7926 break; /* The rest of params should define the filter */ 7897 /*else if (strcmp(argv[i], "-list") == 0)7898 listMatches = true;*/7899 7927 } 7900 7928 … … 7906 7934 return 1; 7907 7935 7908 /* if (countMatchingMetrics(aVirtualBox, performanceCollector, 7909 ComSafeArrayAsInParam(metrics), 7910 ComSafeArrayAsInParam(objects), 7911 listMatches) == 0) 7912 return 1;*/ 7913 7914 CHECK_ERROR(performanceCollector, 7915 SetupMetrics(ComSafeArrayAsInParam(metrics), 7916 ComSafeArrayAsInParam(objects), period, samples)); 7917 7936 if (listMatches) 7937 { 7938 com::SafeIfaceArray<IPerformanceMetric> affectedMetrics; 7939 CHECK_ERROR(performanceCollector, 7940 SetupMetricsEx(ComSafeArrayAsInParam(metrics), 7941 ComSafeArrayAsInParam(objects), period, samples, 7942 ComSafeArrayAsOutParam(affectedMetrics))); 7943 listAffectedMetrics(aVirtualBox, 7944 ComSafeArrayAsInParam(affectedMetrics)); 7945 } 7946 else 7947 { 7948 CHECK_ERROR(performanceCollector, 7949 SetupMetrics(ComSafeArrayAsInParam(metrics), 7950 ComSafeArrayAsInParam(objects), period, samples)); 7951 } 7952 7918 7953 return 0; 7919 7954 } … … 7980 8015 RTPrintf("%s%d %ls", separator, retData[retIndices[i] + j], metricUnit.raw()); 7981 8016 else 7982 RTPrintf("%s%d.%02d%%", separator, retData[retIndices[i] + j] / 1000, retData[retIndices[i] + j]% 100);8017 RTPrintf("%s%d.%02d%%", separator, retData[retIndices[i] + j] / 1000, (retData[retIndices[i] + j] / 10) % 100); 7983 8018 separator = ", "; 7984 8019 } -
trunk/src/VBox/Main/PerformanceImpl.cpp
r12461 r12668 192 192 //////////////////////////////////////////////////////////////////////////////// 193 193 194 HRESULT PerformanceCollector::toIPerformanceMetric(pm::Metric *src, IPerformanceMetric **dst) 195 { 196 ComObjPtr <PerformanceMetric> metric; 197 HRESULT rc = metric.createObject(); 198 if (SUCCEEDED (rc)) 199 rc = metric->init (src); 200 AssertComRCReturnRC (rc); 201 metric.queryInterfaceTo (dst); 202 return rc; 203 } 204 205 HRESULT PerformanceCollector::toIPerformanceMetric(pm::BaseMetric *src, IPerformanceMetric **dst) 206 { 207 ComObjPtr <PerformanceMetric> metric; 208 HRESULT rc = metric.createObject(); 209 if (SUCCEEDED (rc)) 210 rc = metric->init (src); 211 AssertComRCReturnRC (rc); 212 metric.queryInterfaceTo (dst); 213 return rc; 214 } 215 194 216 STDMETHODIMP 195 217 PerformanceCollector::GetMetrics (ComSafeArrayIn (INPTR BSTR, metricNames), … … 239 261 ULONG aPeriod, ULONG aCount) 240 262 { 263 LogFlowThisFuncEnter(); 264 com::SafeIfaceArray <IPerformanceMetric> tmp; 265 return SetupMetricsInt(ComSafeArrayInArg(metricNames), 266 ComSafeArrayInArg(objects), 267 aPeriod, aCount, 268 false, ComSafeArrayAsOutParam(tmp)); 269 } 270 271 STDMETHODIMP 272 PerformanceCollector::SetupMetricsEx (ComSafeArrayIn (INPTR BSTR, metricNames), 273 ComSafeArrayIn (IUnknown *, objects), 274 ULONG aPeriod, ULONG aCount, 275 ComSafeArrayOut (IPerformanceMetric *, 276 outMetrics)) 277 { 278 LogFlowThisFuncEnter(); 279 return SetupMetricsInt(ComSafeArrayInArg(metricNames), 280 ComSafeArrayInArg(objects), 281 aPeriod, aCount, 282 true, ComSafeArrayOutArg(outMetrics)); 283 } 284 285 HRESULT 286 PerformanceCollector::SetupMetricsInt (ComSafeArrayIn (INPTR BSTR, metricNames), 287 ComSafeArrayIn (IUnknown *, objects), 288 ULONG aPeriod, ULONG aCount, 289 bool reportAffected, 290 ComSafeArrayOut (IPerformanceMetric *, 291 outMetrics)) 292 { 241 293 AutoCaller autoCaller (this); 242 294 CheckComRCReturnRC (autoCaller.rc()); … … 247 299 AutoWriteLock alock (this); 248 300 301 HRESULT rc = S_OK; 302 BaseMetricList filteredMetrics; 249 303 BaseMetricList::iterator it; 250 304 for (it = m.baseMetrics.begin(); it != m.baseMetrics.end(); ++it) … … 266 320 (*it)->enable(); 267 321 } 322 if (reportAffected) 323 filteredMetrics.push_back(*it); 268 324 } 269 270 return S_OK; 325 326 if (reportAffected) 327 { 328 com::SafeIfaceArray<IPerformanceMetric> retMetrics (filteredMetrics.size()); 329 int i = 0; 330 for (it = filteredMetrics.begin(); 331 it != filteredMetrics.end() && SUCCEEDED (rc); ++it) 332 rc = toIPerformanceMetric(*it, &retMetrics [i++]); 333 retMetrics.detachTo (ComSafeArrayOutArg(outMetrics)); 334 } 335 LogFlowThisFuncLeave(); 336 return rc; 271 337 } 272 338 … … 274 340 PerformanceCollector::EnableMetrics (ComSafeArrayIn (INPTR BSTR, metricNames), 275 341 ComSafeArrayIn (IUnknown *, objects)) 342 { 343 LogFlowThisFuncEnter(); 344 com::SafeIfaceArray <IPerformanceMetric> tmp; 345 return EnableMetricsInt (ComSafeArrayInArg(metricNames), 346 ComSafeArrayInArg(objects), 347 false, ComSafeArrayAsOutParam(tmp)); 348 } 349 350 STDMETHODIMP 351 PerformanceCollector::EnableMetricsEx (ComSafeArrayIn (INPTR BSTR, metricNames), 352 ComSafeArrayIn (IUnknown *, objects), 353 ComSafeArrayOut (IPerformanceMetric *, 354 outMetrics)) 355 { 356 LogFlowThisFuncEnter(); 357 return EnableMetricsInt (ComSafeArrayInArg(metricNames), 358 ComSafeArrayInArg(objects), 359 true, ComSafeArrayOutArg(outMetrics)); 360 } 361 362 HRESULT 363 PerformanceCollector::EnableMetricsInt (ComSafeArrayIn (INPTR BSTR, metricNames), 364 ComSafeArrayIn (IUnknown *, objects), 365 bool reportAffected, 366 ComSafeArrayOut (IPerformanceMetric *, 367 outMetrics)) 276 368 { 277 369 AutoCaller autoCaller (this); … … 285 377 /* care for those who come next :-). */ 286 378 379 HRESULT rc = S_OK; 380 BaseMetricList filteredMetrics; 287 381 BaseMetricList::iterator it; 288 382 for (it = m.baseMetrics.begin(); it != m.baseMetrics.end(); ++it) 289 383 if (filter.match((*it)->getObject(), (*it)->getName())) 384 { 290 385 (*it)->enable(); 291 292 return S_OK; 386 if (reportAffected) 387 filteredMetrics.push_back(*it); 388 } 389 390 if (reportAffected) 391 { 392 com::SafeIfaceArray<IPerformanceMetric> retMetrics (filteredMetrics.size()); 393 int i = 0; 394 for (it = filteredMetrics.begin(); 395 it != filteredMetrics.end() && SUCCEEDED (rc); ++it) 396 rc = toIPerformanceMetric(*it, &retMetrics [i++]); 397 retMetrics.detachTo (ComSafeArrayOutArg(outMetrics)); 398 } 399 LogFlowThisFuncLeave(); 400 return rc; 293 401 } 294 402 … … 296 404 PerformanceCollector::DisableMetrics (ComSafeArrayIn (INPTR BSTR, metricNames), 297 405 ComSafeArrayIn (IUnknown *, objects)) 406 { 407 LogFlowThisFuncEnter(); 408 com::SafeIfaceArray <IPerformanceMetric> tmp; 409 return DisableMetricsInt (ComSafeArrayInArg(metricNames), 410 ComSafeArrayInArg(objects), 411 false, ComSafeArrayAsOutParam(tmp)); 412 } 413 414 STDMETHODIMP 415 PerformanceCollector::DisableMetricsEx (ComSafeArrayIn (INPTR BSTR, metricNames), 416 ComSafeArrayIn (IUnknown *, objects), 417 ComSafeArrayOut (IPerformanceMetric *, 418 outMetrics)) 419 { 420 LogFlowThisFuncEnter(); 421 return DisableMetricsInt (ComSafeArrayInArg(metricNames), 422 ComSafeArrayInArg(objects), 423 true, ComSafeArrayOutArg(outMetrics)); 424 } 425 426 HRESULT 427 PerformanceCollector::DisableMetricsInt (ComSafeArrayIn (INPTR BSTR, metricNames), 428 ComSafeArrayIn (IUnknown *, objects), 429 bool reportAffected, 430 ComSafeArrayOut (IPerformanceMetric *, 431 outMetrics)) 298 432 { 299 433 AutoCaller autoCaller (this); … … 307 441 /* care for those who come next :-). */ 308 442 443 HRESULT rc = S_OK; 444 BaseMetricList filteredMetrics; 309 445 BaseMetricList::iterator it; 310 446 for (it = m.baseMetrics.begin(); it != m.baseMetrics.end(); ++it) 311 447 if (filter.match((*it)->getObject(), (*it)->getName())) 448 { 312 449 (*it)->disable(); 313 314 return S_OK; 450 if (reportAffected) 451 filteredMetrics.push_back(*it); 452 } 453 454 if (reportAffected) 455 { 456 com::SafeIfaceArray<IPerformanceMetric> retMetrics (filteredMetrics.size()); 457 int i = 0; 458 for (it = filteredMetrics.begin(); 459 it != filteredMetrics.end() && SUCCEEDED (rc); ++it) 460 rc = toIPerformanceMetric(*it, &retMetrics [i++]); 461 retMetrics.detachTo (ComSafeArrayOutArg(outMetrics)); 462 } 463 LogFlowThisFuncLeave(); 464 return rc; 315 465 } 316 466 … … 526 676 } 527 677 678 HRESULT PerformanceMetric::init (pm::BaseMetric *aMetric) 679 { 680 m.name = aMetric->getName(); 681 m.object = aMetric->getObject(); 682 m.description = ""; 683 m.period = aMetric->getPeriod(); 684 m.count = aMetric->getLength(); 685 m.unit = aMetric->getUnit(); 686 m.min = aMetric->getMinValue(); 687 m.max = aMetric->getMaxValue(); 688 return S_OK; 689 } 690 528 691 void PerformanceMetric::uninit() 529 692 { -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r12449 r12668 10402 10402 <interface 10403 10403 name="IPerformanceCollector" extends="$unknown" 10404 uuid=" dcd37e5a-3964-43d1-be30-0f3c7234e347"10404 uuid="840f887a-18b4-4af9-9608-d6a1813fe6ac" 10405 10405 wsmap="managed" 10406 10406 > … … 10415 10415 Metric data are collected at the specified intervals and are retained 10416 10416 internally. The interval and the number of samples retained can be set 10417 with <link to="IPerformanceCollector::set Metrics" />.10417 with <link to="IPerformanceCollector::setupMetrics" />. 10418 10418 10419 10419 Metrics are organized hierarchically, each level separated by slash (/). … … 10595 10595 </method> 10596 10596 10597 <method name="setupMetricsEx"> 10598 <desc> 10599 Sets parameters of specified base metrics for a set of objects. 10600 Indentical to <link to="IPerformanceCollector::setupMetrics" /> except 10601 that it returns an array of <link to="IPerformanceMetric" /> describing 10602 the metrics have been affected. 10603 <note> 10604 @c Null metrics array means all metrics. @c Null object array means 10605 all existing objects. 10606 </note> 10607 </desc> 10608 <param name="metricNames" type="wstring" dir="in" safearray="yes"> 10609 <desc> 10610 Metric name filter. Currently, only a comma-separated list of metrics 10611 is supported. 10612 </desc> 10613 </param> 10614 <param name="objects" type="$unknown" dir="in" safearray="yes"> 10615 <desc> 10616 Set of objects to setup metric parameters for. 10617 </desc> 10618 </param> 10619 <param name="period" type="unsigned long" dir="in"> 10620 <desc> 10621 Time interval in seconds between two consecutive samples of performace 10622 data. 10623 </desc> 10624 </param> 10625 <param name="count" type="unsigned long" dir="in"> 10626 <desc> 10627 Number of samples to retain in performance data history. Older samples 10628 get discarded. 10629 </desc> 10630 </param> 10631 <param name="affectedMetrics" type="IPerformanceMetric" dir="return" safearray="yes"> 10632 <desc> 10633 Array of metrics that have been modified by the call to this method. 10634 </desc> 10635 </param> 10636 </method> 10637 10638 <method name="enableMetricsEx"> 10639 <desc> 10640 Turns on collecting specified base metrics. 10641 Indentical to <link to="IPerformanceCollector::enableMetrics" /> except 10642 that it returns an array of <link to="IPerformanceMetric" /> describing 10643 the metrics have been affected. 10644 <note> 10645 @c Null metrics array means all metrics. @c Null object array means 10646 all existing objects. 10647 </note> 10648 </desc> 10649 <param name="metricNames" type="wstring" dir="in" safearray="yes"> 10650 <desc> 10651 Metric name filter. Currently, only a comma-separated list of metrics 10652 is supported. 10653 </desc> 10654 </param> 10655 <param name="objects" type="$unknown" dir="in" safearray="yes"> 10656 <desc> 10657 Set of objects to enable metrics for. 10658 </desc> 10659 </param> 10660 <param name="affectedMetrics" type="IPerformanceMetric" dir="return" safearray="yes"> 10661 <desc> 10662 Array of metrics that have been modified by the call to this method. 10663 </desc> 10664 </param> 10665 </method> 10666 10667 <method name="disableMetricsEx"> 10668 <desc> 10669 Turns off collecting specified base metrics. 10670 Indentical to <link to="IPerformanceCollector::disableMetrics" /> except 10671 that it returns an array of <link to="IPerformanceMetric" /> describing 10672 the metrics have been affected. 10673 <note> 10674 @c Null metrics array means all metrics. @c Null object array means 10675 all existing objects. 10676 </note> 10677 </desc> 10678 <param name="metricNames" type="wstring" dir="in" safearray="yes"> 10679 <desc> 10680 Metric name filter. Currently, only a comma-separated list of metrics 10681 is supported. 10682 </desc> 10683 </param> 10684 <param name="objects" type="$unknown" dir="in" safearray="yes"> 10685 <desc> 10686 Set of objects to disable metrics for. 10687 </desc> 10688 </param> 10689 <param name="affectedMetrics" type="IPerformanceMetric" dir="return" safearray="yes"> 10690 <desc> 10691 Array of metrics that have been modified by the call to this method. 10692 </desc> 10693 </param> 10694 </method> 10695 10597 10696 <method name="queryMetricsData"> 10598 10697 <desc> -
trunk/src/VBox/Main/include/PerformanceImpl.h
r12400 r12668 68 68 // public initializer/uninitializer for internal purposes only 69 69 HRESULT init (pm::Metric *aMetric); 70 HRESULT init (pm::BaseMetric *aMetric); 70 71 void uninit(); 71 72 … … 152 153 STDMETHOD(DisableMetrics) (ComSafeArrayIn (INPTR BSTR, metricNames), 153 154 ComSafeArrayIn (IUnknown *, objects)); 155 STDMETHOD(SetupMetricsEx) (ComSafeArrayIn (INPTR BSTR, metricNames), 156 ComSafeArrayIn (IUnknown *, objects), 157 ULONG aPeriod, ULONG aCount, 158 ComSafeArrayOut (IPerformanceMetric *, 159 outMetrics)); 160 STDMETHOD(EnableMetricsEx) (ComSafeArrayIn (INPTR BSTR, metricNames), 161 ComSafeArrayIn (IUnknown *, objects), 162 ComSafeArrayOut (IPerformanceMetric *, 163 outMetrics)); 164 STDMETHOD(DisableMetricsEx) (ComSafeArrayIn (INPTR BSTR, metricNames), 165 ComSafeArrayIn (IUnknown *, objects), 166 ComSafeArrayOut (IPerformanceMetric *, 167 outMetrics)); 154 168 STDMETHOD(QueryMetricsData) (ComSafeArrayIn (INPTR BSTR, metricNames), 155 169 ComSafeArrayIn (IUnknown *, objects), … … 176 190 177 191 private: 178 192 HRESULT toIPerformanceMetric(pm::Metric *src, IPerformanceMetric **dst); 193 HRESULT toIPerformanceMetric(pm::BaseMetric *src, IPerformanceMetric **dst); 194 HRESULT SetupMetricsInt(ComSafeArrayIn (INPTR BSTR, metricNames), 195 ComSafeArrayIn (IUnknown *, objects), 196 ULONG aPeriod, ULONG aCount, bool reportAffected, 197 ComSafeArrayOut (IPerformanceMetric *, outMetrics)); 198 HRESULT EnableMetricsInt (ComSafeArrayIn (INPTR BSTR, metricNames), 199 ComSafeArrayIn (IUnknown *, objects), 200 bool reportAffected, 201 ComSafeArrayOut (IPerformanceMetric *, 202 outMetrics)); 203 HRESULT DisableMetricsInt (ComSafeArrayIn (INPTR BSTR, metricNames), 204 ComSafeArrayIn (IUnknown *, objects), 205 bool reportAffected, 206 ComSafeArrayOut (IPerformanceMetric *, 207 outMetrics)); 208 179 209 static void staticSamplerCallback (RTTIMERLR hTimerLR, void *pvUser, uint64_t iTick); 180 210 void samplerCallback(); -
trunk/src/VBox/Main/testcase/tstAPI.cpp
r12455 r12668 48 48 /////////////////////////////////////////////////////////////////////////////// 49 49 50 void queryMetrics (ComPtr <IPerformanceCollector> collector, 51 ComSafeArrayIn (IUnknown *, objects)); 50 static Bstr getObjectName(ComPtr<IVirtualBox> aVirtualBox, 51 ComPtr<IUnknown> aObject); 52 static void queryMetrics (ComPtr<IVirtualBox> aVirtualBox, 53 ComPtr <IPerformanceCollector> collector, 54 ComSafeArrayIn (IUnknown *, objects)); 55 static void listAffectedMetrics(ComPtr<IVirtualBox> aVirtualBox, 56 ComSafeArrayIn(IPerformanceMetric*, aMetrics)); 52 57 53 58 // funcs … … 946 951 ComPtr <IMachine> machine; 947 952 Bstr name = argc > 1 ? argv [1] : "dsl"; 953 Bstr sessionType = argc > 2 ? argv [2] : "vrdp"; 948 954 printf ("Getting a machine object named '%ls'...\n", name.raw()); 949 955 CHECK_RC_BREAK (virtualBox->FindMachine (name, machine.asOutParam())); … … 954 960 printf ("Opening a remote session for this machine...\n"); 955 961 ComPtr <IProgress> progress; 956 CHECK_RC_BREAK (virtualBox->OpenRemoteSession (session, guid, Bstr("vrdp"),962 CHECK_RC_BREAK (virtualBox->OpenRemoteSession (session, guid, sessionType, 957 963 NULL, progress.asOutParam())); 958 964 printf ("Waiting for the session to open...\n"); … … 977 983 RTThreadSleep(5000); // Sleep for 5 seconds 978 984 979 printf(" Metrics collected with DSL machinerunning: --------------------\n");980 queryMetrics( collector, ComSafeArrayAsInParam(objects));985 printf("\nMetrics collected with VM running: --------------------\n"); 986 queryMetrics(virtualBox, collector, ComSafeArrayAsInParam(objects)); 981 987 982 988 // Pause … … 987 993 RTThreadSleep(5000); // Sleep for 5 seconds 988 994 989 printf("Metrics collected with DSL machine paused: ---------------------\n"); 990 queryMetrics(collector, ComSafeArrayAsInParam(objects)); 995 printf("\nMetrics collected with VM paused: ---------------------\n"); 996 queryMetrics(virtualBox, collector, ComSafeArrayAsInParam(objects)); 997 998 com::SafeIfaceArray<IPerformanceMetric> affectedMetrics; 999 printf("\nDrop collected metrics: ----------------------------------------\n"); 1000 CHECK_ERROR_BREAK (collector, 1001 SetupMetricsEx(ComSafeArrayAsInParam(baseMetrics), 1002 ComSafeArrayAsInParam(objects), 1003 1u, 5u, ComSafeArrayAsOutParam(affectedMetrics)) ); 1004 listAffectedMetrics(virtualBox, 1005 ComSafeArrayAsInParam(affectedMetrics)); 1006 affectedMetrics.setNull(); 1007 queryMetrics(virtualBox, collector, ComSafeArrayAsInParam(objects)); 1008 1009 com::SafeIfaceArray<IUnknown> vmObject(1); 1010 machine.queryInterfaceTo(&vmObject[0]); 1011 1012 printf("\nDisable collection of VM metrics: ------------------------------\n"); 1013 CHECK_ERROR_BREAK (collector, 1014 DisableMetricsEx(ComSafeArrayAsInParam(baseMetrics), 1015 ComSafeArrayAsInParam(vmObject), 1016 ComSafeArrayAsOutParam(affectedMetrics)) ); 1017 listAffectedMetrics(virtualBox, 1018 ComSafeArrayAsInParam(affectedMetrics)); 1019 affectedMetrics.setNull(); 1020 RTThreadSleep(5000); // Sleep for 5 seconds 1021 queryMetrics(virtualBox, collector, ComSafeArrayAsInParam(objects)); 1022 1023 printf("\nRe-enable collection of all metrics: ---------------------------\n"); 1024 CHECK_ERROR_BREAK (collector, 1025 EnableMetricsEx(ComSafeArrayAsInParam(baseMetrics), 1026 ComSafeArrayAsInParam(objects), 1027 ComSafeArrayAsOutParam(affectedMetrics)) ); 1028 listAffectedMetrics(virtualBox, 1029 ComSafeArrayAsInParam(affectedMetrics)); 1030 affectedMetrics.setNull(); 1031 RTThreadSleep(5000); // Sleep for 5 seconds 1032 queryMetrics(virtualBox, collector, ComSafeArrayAsInParam(objects)); 991 1033 992 1034 // Power off … … 1019 1061 1020 1062 #ifdef VBOX_WITH_RESOURCE_USAGE_API 1021 void queryMetrics (ComPtr <IPerformanceCollector> collector, 1022 ComSafeArrayIn (IUnknown *, objects)) 1063 static void queryMetrics (ComPtr<IVirtualBox> aVirtualBox, 1064 ComPtr <IPerformanceCollector> collector, 1065 ComSafeArrayIn (IUnknown *, objects)) 1023 1066 { 1024 1067 HRESULT rc; … … 1040 1083 ComSafeArrayAsOutParam(retLengths), 1041 1084 ComSafeArrayAsOutParam(retData)) ); 1085 RTPrintf("Object Metric Values\n" 1086 "---------- -------------------- --------------------------------------------\n"); 1042 1087 for (unsigned i = 0; i < retNames.size(); i++) 1043 1088 { … … 1060 1105 CHECK_RC_BREAK (metricInfo[0]->COMGETTER(MinimumValue) (&minVal)); 1061 1106 CHECK_RC_BREAK (metricInfo[0]->COMGETTER(MaximumValue) (&maxVal)); 1062 printf("obj(%p) %ls (min=%lu max=%lu)", anObject[0], metricName.raw(), minVal, maxVal); 1107 RTPrintf("%-10ls %-20ls ", getObjectName(aVirtualBox, anObject[0]).raw(), metricName.raw()); 1108 const char *separator = ""; 1063 1109 for (unsigned j = 0; j < retLengths[i]; j++) 1064 1110 { 1065 printf(", %d %ls", retData[retIndices[i] + j] / (strcmp((const char *)metricUnit.raw(), "%")?1:1000), metricUnit.raw()); 1066 } 1067 printf("\n"); 1111 if (strcmp((const char *)metricUnit.raw(), "%")) 1112 RTPrintf("%s%d %ls", separator, retData[retIndices[i] + j], metricUnit.raw()); 1113 else 1114 RTPrintf("%s%d.%02d%%", separator, retData[retIndices[i] + j] / 1000, (retData[retIndices[i] + j] / 10) % 100); 1115 separator = ", "; 1116 } 1117 RTPrintf("\n"); 1068 1118 } 1069 1119 } 1120 1121 static Bstr getObjectName(ComPtr<IVirtualBox> aVirtualBox, 1122 ComPtr<IUnknown> aObject) 1123 { 1124 HRESULT rc; 1125 1126 ComPtr<IHost> host = aObject; 1127 if (!host.isNull()) 1128 return Bstr("host"); 1129 1130 ComPtr<IMachine> machine = aObject; 1131 if (!machine.isNull()) 1132 { 1133 Bstr name; 1134 CHECK_ERROR(machine, COMGETTER(Name)(name.asOutParam())); 1135 if (SUCCEEDED(rc)) 1136 return name; 1137 } 1138 return Bstr("unknown"); 1139 } 1140 1141 static void listAffectedMetrics(ComPtr<IVirtualBox> aVirtualBox, 1142 ComSafeArrayIn(IPerformanceMetric*, aMetrics)) 1143 { 1144 HRESULT rc; 1145 com::SafeIfaceArray<IPerformanceMetric> metrics(ComSafeArrayInArg(aMetrics)); 1146 if (metrics.size()) 1147 { 1148 ComPtr<IUnknown> object; 1149 Bstr metricName; 1150 RTPrintf("The following metrics were modified:\n\n" 1151 "Object Metric\n" 1152 "---------- --------------------\n"); 1153 for (size_t i = 0; i < metrics.size(); i++) 1154 { 1155 CHECK_ERROR(metrics[i], COMGETTER(Object)(object.asOutParam())); 1156 CHECK_ERROR(metrics[i], COMGETTER(MetricName)(metricName.asOutParam())); 1157 RTPrintf("%-10ls %-20ls\n", 1158 getObjectName(aVirtualBox, object).raw(), metricName.raw()); 1159 } 1160 RTPrintf("\n"); 1161 } 1162 else 1163 { 1164 RTPrintf("No metrics match the specified filter!\n"); 1165 } 1166 } 1167 1070 1168 #endif /* VBOX_WITH_RESOURCE_USAGE_API */
Note:
See TracChangeset
for help on using the changeset viewer.