- Timestamp:
- Jul 17, 2008 1:27:48 PM (16 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/Performance.cpp
r10713 r10725 483 483 com::SafeIfaceArray <IUnknown> objectArray(ComSafeArrayInArg(objects)); 484 484 com::SafeArray <INPTR BSTR> nameArray(ComSafeArrayInArg(metricNames)); 485 for (size_t i = 0; i < objectArray.size(); ++i) 486 processMetricList(std::string(com::Utf8Str(nameArray[i])), objectArray[i]); 485 if (objectArray.isNull()) 486 { 487 if (nameArray.size()) 488 { 489 for (size_t i = 0; i < nameArray.size(); ++i) 490 processMetricList(std::string(com::Utf8Str(nameArray[i])), ComPtr<IUnknown>()); 491 } 492 else 493 processMetricList(std::string("*"), ComPtr<IUnknown>()); 494 } 495 else 496 { 497 for (size_t i = 0; i < objectArray.size(); ++i) 498 switch (nameArray.size()) 499 { 500 case 0: 501 processMetricList(std::string("*"), objectArray[i]); 502 break; 503 case 1: 504 processMetricList(std::string(com::Utf8Str(nameArray[0])), objectArray[i]); 505 break; 506 default: 507 processMetricList(std::string(com::Utf8Str(nameArray[i])), objectArray[i]); 508 break; 509 } 510 } 487 511 } 488 512 … … 503 527 bool Filter::match(const ComPtr<IUnknown> object, const std::string &name) const 504 528 { 505 return true; 506 } 529 ElementList::const_iterator it; 530 531 printf("Filter::match(%p, %s)\n", static_cast<const IUnknown*> (object), name.c_str()); 532 for (it = mElements.begin(); it != mElements.end(); it++) 533 { 534 printf("...matching against(%p, %s)\n", static_cast<const IUnknown*> ((*it).first), (*it).second.c_str()); 535 if ((*it).first.isNull() || (*it).first == object) 536 { 537 // Objects match, compare names 538 if ((*it).second == "*" || (*it).second == name) 539 { 540 printf("...found!\n"); 541 return true; 542 } 543 } 544 } 545 printf("...no matches!\n"); 546 return false; 547 } -
trunk/src/VBox/Main/PerformanceImpl.cpp
r10713 r10725 183 183 //////////////////////////////////////////////////////////////////////////////// 184 184 185 STDMETHODIMP PerformanceCollector::GetMetrics(ComSafeArrayIn( constBSTR, metricNames),185 STDMETHODIMP PerformanceCollector::GetMetrics(ComSafeArrayIn(INPTR BSTR, metricNames), 186 186 ComSafeArrayIn(IUnknown *, objects), 187 ComSafeArrayOut(IPerformanceMetric *, metrics))187 ComSafeArrayOut(IPerformanceMetric *, outMetrics)) 188 188 { 189 189 //LogFlowThisFunc (("mState=%d, mType=%d\n", mState, mType)); 190 190 191 AutoCaller autoCaller (this); 192 CheckComRCReturnRC (autoCaller.rc()); 193 194 return E_NOTIMPL; 191 HRESULT rc = S_OK; 192 193 AutoCaller autoCaller (this); 194 CheckComRCReturnRC (autoCaller.rc()); 195 196 pm::Filter filter(ComSafeArrayInArg(metricNames), ComSafeArrayInArg(objects)); 197 198 MetricList filteredMetrics; 199 MetricList::iterator it; 200 for (it = m.mMetrics.begin(); it != m.mMetrics.end(); ++it) 201 if (filter.match((*it)->getObject(), (*it)->getName())) 202 filteredMetrics.push_back(*it); 203 204 com::SafeIfaceArray<IPerformanceMetric> retMetrics(filteredMetrics.size()); 205 int i = 0; 206 for (it = m.mMetrics.begin(); it != m.mMetrics.end(); ++it) 207 { 208 ComObjPtr<PerformanceMetric> metric; 209 rc = metric.createObject(); 210 if (SUCCEEDED (rc)) 211 rc = metric->init (*it); 212 ComAssertComRCThrowRC (rc); 213 metric.queryInterfaceTo(&retMetrics[i++]); 214 } 215 retMetrics.detachTo(ComSafeArrayOutArg(outMetrics)); 216 return rc; 195 217 } 196 218 … … 199 221 ULONG aPeriod, ULONG aCount) 200 222 { 223 AutoCaller autoCaller (this); 224 CheckComRCReturnRC (autoCaller.rc()); 225 201 226 pm::Filter filter(ComSafeArrayInArg(metricNames), ComSafeArrayInArg(objects)); 202 227 … … 212 237 } 213 238 214 STDMETHODIMP PerformanceCollector::EnableMetrics (ComSafeArrayIn( constBSTR, metricNames),239 STDMETHODIMP PerformanceCollector::EnableMetrics (ComSafeArrayIn(INPTR BSTR, metricNames), 215 240 ComSafeArrayIn(IUnknown *, objects)) 216 241 { 242 AutoCaller autoCaller (this); 243 CheckComRCReturnRC (autoCaller.rc()); 244 217 245 pm::Filter filter(ComSafeArrayInArg(metricNames), ComSafeArrayInArg(objects)); 218 246 … … 225 253 } 226 254 227 STDMETHODIMP PerformanceCollector::DisableMetrics (ComSafeArrayIn( constBSTR, metricNames),255 STDMETHODIMP PerformanceCollector::DisableMetrics (ComSafeArrayIn(INPTR BSTR, metricNames), 228 256 ComSafeArrayIn(IUnknown *, objects)) 229 257 { 258 AutoCaller autoCaller (this); 259 CheckComRCReturnRC (autoCaller.rc()); 260 230 261 pm::Filter filter(ComSafeArrayInArg(metricNames), ComSafeArrayInArg(objects)); 231 262 … … 238 269 } 239 270 240 STDMETHODIMP PerformanceCollector::QueryMetricsData (ComSafeArrayIn( constBSTR, metricNames),271 STDMETHODIMP PerformanceCollector::QueryMetricsData (ComSafeArrayIn(INPTR BSTR, metricNames), 241 272 ComSafeArrayIn(IUnknown *, objects), 242 273 ComSafeArrayOut(BSTR, outMetricNames), … … 398 429 } 399 430 400 STDMETHODIMP PerformanceMetric::COMGETTER(Period) ( unsigned long*aPeriod)431 STDMETHODIMP PerformanceMetric::COMGETTER(Period) (ULONG *aPeriod) 401 432 { 402 433 *aPeriod = mMetric->getPeriod(); … … 404 435 } 405 436 406 STDMETHODIMP PerformanceMetric::COMGETTER(Count) ( unsigned long*aCount)437 STDMETHODIMP PerformanceMetric::COMGETTER(Count) (ULONG *aCount) 407 438 { 408 439 *aCount = mMetric->getLength(); … … 417 448 } 418 449 419 STDMETHODIMP PerformanceMetric::COMGETTER(Min Value) (long*aMinValue)450 STDMETHODIMP PerformanceMetric::COMGETTER(MinimumValue) (LONG *aMinValue) 420 451 { 421 452 *aMinValue = mMetric->getMinValue(); … … 423 454 } 424 455 425 STDMETHODIMP PerformanceMetric::COMGETTER(Max Value) (long*aMaxValue)456 STDMETHODIMP PerformanceMetric::COMGETTER(MaximumValue) (LONG *aMaxValue) 426 457 { 427 458 *aMaxValue = mMetric->getMaxValue(); -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r10713 r10725 10158 10158 <desc> 10159 10159 The IPerformanceCollector interface represents a service that collects and 10160 stores performa ce metrics data.10160 stores performance metrics data. 10161 10161 10162 10162 Performance metrics are associated with objects like IHost and IMachine. -
trunk/src/VBox/Main/include/Performance.h
r10713 r10725 326 326 private: 327 327 typedef std::pair<const ComPtr<IUnknown>, const std::string> FilterElement; 328 std::list<FilterElement> mElements; 328 typedef std::list<FilterElement> ElementList; 329 330 ElementList mElements; 329 331 330 332 void processMetricList(const std::string &name, const ComPtr<IUnknown> object); -
trunk/src/VBox/Main/include/PerformanceImpl.h
r10713 r10725 87 87 STDMETHOD(COMGETTER(MetricName)) (BSTR *aMetricName); 88 88 STDMETHOD(COMGETTER(Object)) (IUnknown **anObject); 89 STDMETHOD(COMGETTER(Period)) ( unsigned long*aPeriod);90 STDMETHOD(COMGETTER(Count)) ( unsigned long*aCount);89 STDMETHOD(COMGETTER(Period)) (ULONG *aPeriod); 90 STDMETHOD(COMGETTER(Count)) (ULONG *aCount); 91 91 STDMETHOD(COMGETTER(Unit)) (BSTR *aUnit); 92 STDMETHOD(COMGETTER(Min Value)) (long*aMinValue);93 STDMETHOD(COMGETTER(Max Value)) (long*aMaxValue);92 STDMETHOD(COMGETTER(MinimumValue)) (LONG *aMinValue); 93 STDMETHOD(COMGETTER(MaximumValue)) (LONG *aMaxValue); 94 94 95 95 // IPerformanceMetric methods … … 202 202 203 203 // IPerformanceCollector methods 204 STDMETHOD(GetMetrics) (ComSafeArrayIn ( constBSTR, metricNames),204 STDMETHOD(GetMetrics) (ComSafeArrayIn (INPTR BSTR, metricNames), 205 205 ComSafeArrayIn (IUnknown *, objects), 206 ComSafeArrayOut (IPerformanceMetric *, metrics));206 ComSafeArrayOut (IPerformanceMetric *, outMetrics)); 207 207 STDMETHOD(SetupMetrics) (ComSafeArrayIn (INPTR BSTR, metricNames), 208 208 ComSafeArrayIn (IUnknown *, objects), 209 209 ULONG aPeriod, ULONG aCount); 210 STDMETHOD(EnableMetrics) (ComSafeArrayIn ( constBSTR, metricNames),210 STDMETHOD(EnableMetrics) (ComSafeArrayIn (INPTR BSTR, metricNames), 211 211 ComSafeArrayIn (IUnknown *, objects)); 212 STDMETHOD(DisableMetrics) (ComSafeArrayIn ( constBSTR, metricNames),212 STDMETHOD(DisableMetrics) (ComSafeArrayIn (INPTR BSTR, metricNames), 213 213 ComSafeArrayIn (IUnknown *, objects)); 214 STDMETHOD(QueryMetricsData) (ComSafeArrayIn ( constBSTR, metricNames),214 STDMETHOD(QueryMetricsData) (ComSafeArrayIn (INPTR BSTR, metricNames), 215 215 ComSafeArrayIn (IUnknown *, objects), 216 216 ComSafeArrayOut (BSTR, outMetricNames), -
trunk/src/VBox/Main/testcase/tstAPI.cpp
r10713 r10725 43 43 44 44 #define printf RTPrintf 45 46 47 // forward declarations 48 /////////////////////////////////////////////////////////////////////////////// 49 50 void queryMetrics (ComPtr <IPerformanceCollector> collector, 51 ComSafeArrayIn (IUnknown *, objects)); 45 52 46 53 // funcs … … 921 928 #if 1 922 929 do { 930 // Get collector 931 ComPtr <IPerformanceCollector> collector; 932 CHECK_ERROR_BREAK (virtualBox, 933 COMGETTER(PerformanceCollector) (collector.asOutParam())); 934 935 936 // Fill base metrics array 923 937 Bstr baseMetricNames[] = { L"CPU/Load,RAM/Usage" }; 924 938 com::SafeArray<BSTR> baseMetrics (1); 925 939 baseMetricNames[0].cloneTo (&baseMetrics [0]); 926 940 941 // Get host 927 942 ComPtr <IHost> host; 928 943 CHECK_ERROR_BREAK (virtualBox, COMGETTER(Host) (host.asOutParam())); 929 ComPtr <IPerformanceCollector> collector; 930 CHECK_ERROR_BREAK (virtualBox, 931 COMGETTER(PerformanceCollector) (collector.asOutParam())); 932 933 com::SafeIfaceArray<IUnknown> objects(1); 934 host.queryInterfaceTo(&objects[0]); 935 CHECK_ERROR_BREAK (collector, SetupMetrics(ComSafeArrayAsInParam(baseMetrics), 936 ComSafeArrayAsInParam(objects), 1u, 10u) ); 937 RTThreadSleep(3000); /* Sleep 10 seconds. */ 938 939 Bstr metricNames[] = { L"CPU/Load/User:avg,CPU/Load/System:avg,CPU/Load/Idle:avg,RAM/Usage/Total.RAM/Usage/Used:avg" }; 940 com::SafeArray<BSTR> metrics (1); 941 metricNames[0].cloneTo (&metrics [0]); 942 com::SafeArray<BSTR> retNames; 943 com::SafeIfaceArray<IUnknown> retObjects; 944 com::SafeArray<ULONG> retIndices; 945 com::SafeArray<ULONG> retLengths; 946 com::SafeArray<LONG> retData; 947 CHECK_ERROR_BREAK (collector, QueryMetricsData(ComSafeArrayAsInParam(metrics), 948 ComSafeArrayAsInParam(objects), 949 ComSafeArrayAsOutParam(retNames), 950 ComSafeArrayAsOutParam(retObjects), 951 ComSafeArrayAsOutParam(retIndices), 952 ComSafeArrayAsOutParam(retLengths), 953 ComSafeArrayAsOutParam(retData)) ); 954 for (unsigned i = 0; i < retNames.size(); i++) 955 { 956 Bstr metricName(retNames[i]); 957 printf("%ls", metricName.raw()); 958 for (unsigned j = 0; j < retLengths[i]; j++) 959 { 960 printf(" %d", retData[retIndices[i] + j]); 961 } 962 printf("\n"); 963 } 964 } while (0); 965 #endif 966 #if 0 967 for (int i = 0; i < 10; i++) 968 { 969 ULONG user, system, idle; 970 host->GetProcessorUsage(&user, &system, &idle); 971 printf("user=%u system=%u idle=%u\n", user/10000000, system/10000000, idle/10000000); 972 } 973 #endif 974 975 #if 0 976 { 944 945 // Get machine 977 946 ComPtr <IMachine> machine; 978 947 Bstr name = argc > 1 ? argv [1] : "dsl"; 979 948 printf ("Getting a machine object named '%ls'...\n", name.raw()); 980 949 CHECK_RC_BREAK (virtualBox->FindMachine (name, machine.asOutParam())); 950 951 // Setup base metrics 952 com::SafeIfaceArray<IUnknown> objects(2); 953 host.queryInterfaceTo(&objects[0]); 954 machine.queryInterfaceTo(&objects[1]); 955 CHECK_ERROR_BREAK (collector, SetupMetrics(ComSafeArrayAsInParam(baseMetrics), 956 ComSafeArrayAsInParam(objects), 1u, 10u) ); 957 958 // Open session 981 959 Guid guid; 982 960 CHECK_RC_BREAK (machine->COMGETTER(Id) (guid.asOutParam())); … … 990 968 printf ("Getting sessioned machine object...\n"); 991 969 CHECK_RC_BREAK (session->COMGETTER(Machine) (sessionMachine.asOutParam())); 970 971 // Get console 992 972 ComPtr <IConsole> console; 993 973 printf ("Getting console object...\n"); 994 974 CHECK_RC_BREAK (session->COMGETTER(Console) (console.asOutParam())); 995 for (int i = 0; i < 10; i++) 996 { 997 ComPtr <IHost> host; 998 CHECK_RC_BREAK (virtualBox->COMGETTER(Host) (host.asOutParam())); 999 ULONG user, system; 1000 sessionMachine->GetProcessorUsage(&user, &system); 1001 printf("VM: user=%u system=%u\n", user/10000000, system/10000000); 1002 RTThreadSleep(1000); 1003 } 975 976 RTThreadSleep(3000); // Sleep for 10 seconds 977 978 printf("Metrics collected with DSL machine running: --------------------\n"); 979 queryMetrics(collector, ComSafeArrayAsInParam(objects)); 980 981 // Pause 1004 982 printf ("Press enter to pause the VM execution in the remote session..."); 1005 983 getchar(); 1006 984 CHECK_RC (console->Pause()); 1007 for (int i = 0; i < 10; i++) 1008 { 1009 ComPtr <IHost> host; 1010 CHECK_RC_BREAK (virtualBox->COMGETTER(Host) (host.asOutParam())); 1011 ULONG user, system; 1012 sessionMachine->GetProcessorUsage(&user, &system); 1013 printf("VM: user=%u system=%u\n", user/10000000, system/10000000); 1014 RTThreadSleep(1000); 1015 } 985 986 RTThreadSleep(3000); // Sleep for 10 seconds 987 988 printf("Metrics collected with DSL machine paused: ---------------------\n"); 989 queryMetrics(collector, ComSafeArrayAsInParam(objects)); 990 991 // Power off 1016 992 printf ("Press enter to power off VM..."); 1017 993 getchar(); … … 1020 996 getchar(); 1021 997 session->Close(); 1022 } 998 } while (false); 1023 999 #endif 1024 1000 … … 1040 1016 return rc; 1041 1017 } 1018 1019 void queryMetrics (ComPtr <IPerformanceCollector> collector, 1020 ComSafeArrayIn (IUnknown *, objects)) 1021 { 1022 HRESULT rc; 1023 1024 Bstr metricNames[] = { L"CPU/Load/User:avg,CPU/Load/System:avg,CPU/Load/Idle:avg,RAM/Usage/Total,RAM/Usage/Used:avg" }; 1025 com::SafeArray<BSTR> metrics (1); 1026 metricNames[0].cloneTo (&metrics [0]); 1027 com::SafeArray<BSTR> retNames; 1028 com::SafeIfaceArray<IUnknown> retObjects; 1029 com::SafeArray<ULONG> retIndices; 1030 com::SafeArray<ULONG> retLengths; 1031 com::SafeArray<LONG> retData; 1032 CHECK_ERROR (collector, QueryMetricsData(ComSafeArrayAsInParam(metrics), 1033 ComSafeArrayInArg(objects), 1034 ComSafeArrayAsOutParam(retNames), 1035 ComSafeArrayAsOutParam(retObjects), 1036 ComSafeArrayAsOutParam(retIndices), 1037 ComSafeArrayAsOutParam(retLengths), 1038 ComSafeArrayAsOutParam(retData)) ); 1039 for (unsigned i = 0; i < retNames.size(); i++) 1040 { 1041 // Get info for the metric 1042 com::SafeArray<BSTR> nameOfMetric(1); 1043 Bstr (retNames[i]).cloneTo (&nameOfMetric[0]); 1044 com::SafeIfaceArray<IUnknown> anObject(1); 1045 ComPtr<IUnknown>(retObjects[i]).queryInterfaceTo(&anObject[0]); 1046 com::SafeIfaceArray <IPerformanceMetric> metricInfo; 1047 CHECK_RC_BREAK (collector->GetMetrics( ComSafeArrayAsInParam(nameOfMetric), 1048 ComSafeArrayAsInParam(anObject), 1049 ComSafeArrayAsOutParam(metricInfo) )); 1050 BSTR metricUnitBSTR; 1051 CHECK_RC_BREAK (metricInfo[0]->COMGETTER(Unit) (&metricUnitBSTR)); 1052 Bstr metricUnit(metricUnitBSTR); 1053 Bstr metricName(retNames[i]); 1054 printf("%ls", metricName.raw()); 1055 for (unsigned j = 0; j < retLengths[i]; j++) 1056 { 1057 printf(", %d %s", retData[retIndices[i] + j], metricUnit.raw()); 1058 } 1059 printf("\n"); 1060 } 1061 }
Note:
See TracChangeset
for help on using the changeset viewer.