Changeset 10753 in vbox
- Timestamp:
- Jul 18, 2008 7:22:21 PM (16 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 3 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/HostImpl.cpp
r10713 r10753 2711 2711 aCollector->registerBaseMetric (cpuLoad); 2712 2712 pm::BaseMetric *ramUsage = 2713 metricFactory->createHost CpuLoad(objptr, ramUsageTotal, ramUsageUsed,2714 ramUsageFree);2713 metricFactory->createHostRamUsage (objptr, ramUsageTotal, ramUsageUsed, 2714 ramUsageFree); 2715 2715 aCollector->registerBaseMetric (ramUsage); 2716 2716 -
trunk/src/VBox/Main/Makefile.kmk
r10744 r10753 268 268 PerformanceImpl.cpp \ 269 269 Performance.cpp 270 VBoxSVC_SOURCES.darwin += darwin/PerformanceDarwin.cpp 271 VBoxSVC_SOURCES.linux += linux/PerformanceLinux.cpp 272 VBoxSVC_SOURCES.os2 += os2/PerformanceOs2.cpp 273 VBoxSVC_SOURCES.solaris += solaris/PerformanceSolaris.cpp 274 VBoxSVC_SOURCES.win += win/PerformanceWin.cpp 275 VBoxSVC_LDFLAGS.win += PDH.LIB 270 276 endif 271 277 -
trunk/src/VBox/Main/Performance.cpp
r10725 r10753 61 61 } 62 62 63 // Linux factory64 65 MetricFactoryLinux::MetricFactoryLinux()66 {67 mHAL = new CollectorLinux();68 Assert(mHAL);69 }70 71 BaseMetric *MetricFactoryLinux::createHostCpuLoad(ComPtr<IUnknown> object, SubMetric *user, SubMetric *kernel, SubMetric *idle)72 {73 Assert(mHAL);74 return new HostCpuLoadRaw(mHAL, object, user, kernel, idle);75 }76 77 BaseMetric *MetricFactoryLinux::createMachineCpuLoad(ComPtr<IUnknown> object, RTPROCESS process, SubMetric *user, SubMetric *kernel)78 {79 Assert(mHAL);80 return new MachineCpuLoadRaw(mHAL, object, process, user, kernel);81 }82 83 84 63 // Stubs for non-pure virtual methods 85 64 … … 100 79 101 80 int CollectorHAL::getRawProcessCpuLoad(RTPROCESS process, unsigned long *user, unsigned long *kernel) 102 {103 return E_NOTIMPL;104 }105 106 // Collector HAL for Linux107 #include <stdio.h>108 109 int CollectorLinux::getRawHostCpuLoad(unsigned long *user, unsigned long *kernel, unsigned long *idle)110 {111 #ifdef RT_OS_LINUX112 int rc = VINF_SUCCESS;113 unsigned long nice;114 FILE *f = fopen("/proc/stat", "r");115 116 if (f)117 {118 if (fscanf(f, "cpu %lu %lu %lu %lu", user, &nice, kernel, idle) == 4)119 *user += nice;120 else121 rc = VERR_FILE_IO_ERROR;122 fclose(f);123 }124 else125 rc = VERR_ACCESS_DENIED;126 127 return rc;128 #else129 return E_NOTIMPL;130 #endif131 }132 133 int CollectorLinux::getRawProcessCpuLoad(RTPROCESS process, unsigned long *user, unsigned long *kernel)134 {135 #ifdef RT_OS_LINUX136 int rc = VINF_SUCCESS;137 char *pszName;138 pid_t pid2;139 char c;140 int iTmp;141 unsigned uTmp;142 unsigned long ulTmp;143 char buf[80]; /* @todo: this should be tied to max allowed proc name. */144 145 RTStrAPrintf(&pszName, "/proc/%d/stat", process);146 //printf("Opening %s...\n", pszName);147 FILE *f = fopen(pszName, "r");148 RTMemFree(pszName);149 150 if (f)151 {152 if (fscanf(f, "%d %s %c %d %d %d %d %d %u %lu %lu %lu %lu %lu %lu",153 &pid2, buf, &c, &iTmp, &iTmp, &iTmp, &iTmp, &iTmp, &uTmp,154 &ulTmp, &ulTmp, &ulTmp, &ulTmp, user, kernel) == 15)155 {156 Assert((pid_t)process == pid2);157 }158 else159 rc = VERR_FILE_IO_ERROR;160 fclose(f);161 }162 else163 rc = VERR_ACCESS_DENIED;164 165 return rc;166 #else167 return E_NOTIMPL;168 #endif169 }170 171 int CollectorLinux::getHostCpuMHz(unsigned long *mhz)172 {173 return E_NOTIMPL;174 }175 176 int CollectorLinux::getHostMemoryUsage(unsigned long *total, unsigned long *used, unsigned long *available)177 {178 #ifdef RT_OS_LINUX179 int rc = VINF_SUCCESS;180 unsigned long buffers, cached;181 FILE *f = fopen("/proc/meminfo", "r");182 183 if (f)184 {185 int processed = fscanf(f, "MemTotal: %lu kB", total);186 processed += fscanf(f, "MemFree: %lu kB", available);187 processed += fscanf(f, "Buffers: %lu kB", &buffers);188 processed += fscanf(f, "Cached: %lu kB", &cached);189 if (processed == 4)190 *available += buffers + cached;191 else192 rc = VERR_FILE_IO_ERROR;193 fclose(f);194 }195 else196 rc = VERR_ACCESS_DENIED;197 198 return rc;199 #else200 return E_NOTIMPL;201 #endif202 }203 int CollectorLinux::getProcessMemoryUsage(RTPROCESS process, unsigned long *used)204 81 { 205 82 return E_NOTIMPL; … … 230 107 { 231 108 unsigned long user, kernel, idle; 232 mHAL->getHostCpuLoad(&user, &kernel, &idle); 233 mUser->put(user); 234 mKernel->put(kernel); 235 mIdle->put(idle); 109 int rc = mHAL->getHostCpuLoad(&user, &kernel, &idle); 110 if (RT_SUCCESS(rc)) 111 { 112 mUser->put(user); 113 mKernel->put(kernel); 114 mIdle->put(idle); 115 } 236 116 } 237 117 … … 242 122 243 123 int rc = mHAL->getRawHostCpuLoad(&user, &kernel, &idle); 244 AssertRC(rc);245 124 if (RT_SUCCESS(rc)) 246 125 { … … 271 150 unsigned long mhz; 272 151 int rc = mHAL->getHostCpuMHz(&mhz); 273 AssertRC(rc);274 152 if (RT_SUCCESS(rc)) 275 153 mMHz->put(mhz); … … 289 167 unsigned long total, used, available; 290 168 int rc = mHAL->getHostMemoryUsage(&total, &used, &available); 291 AssertRC(rc);292 169 if (RT_SUCCESS(rc)) 293 170 { … … 312 189 unsigned long user, kernel; 313 190 int rc = mHAL->getProcessCpuLoad(mProcess, &user, &kernel); 314 AssertRC(rc);315 191 if (RT_SUCCESS(rc)) 316 192 { … … 326 202 327 203 int rc = mHAL->getRawHostCpuLoad(&hostUser, &hostKernel, &hostIdle); 328 AssertRC(rc);329 204 if (RT_SUCCESS(rc)) 330 205 { … … 356 231 unsigned long used; 357 232 int rc = mHAL->getProcessMemoryUsage(mProcess, &used); 358 AssertRC(rc);359 233 if (RT_SUCCESS(rc)) 360 234 mUsed->put(used); … … 442 316 for (unsigned long i = 0; i < length; ++i) 443 317 tmp += data[i]; 444 return tmp / length;318 return (unsigned long)(tmp / length); 445 319 } 446 320 -
trunk/src/VBox/Main/PerformanceImpl.cpp
r10725 r10753 102 102 103 103 /* @todo Obviously other platforms must be added as well. */ 104 #ifdef RT_OS_SOLARIS 105 m.mFactory = new pm::MetricFactorySolaris(); 106 #endif 107 #ifdef RT_OS_LINUX 104 108 m.mFactory = new pm::MetricFactoryLinux(); 109 #endif 110 #ifdef RT_OS_WINDOWS 111 m.mFactory = new pm::MetricFactoryWin(); 112 #endif 113 #ifdef RT_OS_OS2 114 m.mFactory = new pm::MetricFactoryOS2(); 115 #endif 116 #ifdef RT_OS_DARWIN 117 m.mFactory = new pm::MetricFactoryDarwin(); 118 #endif 105 119 106 120 /* Let the sampler know it gets a valid collector. */ … … 196 210 pm::Filter filter(ComSafeArrayInArg(metricNames), ComSafeArrayInArg(objects)); 197 211 212 AutoReadLock alock (this); 213 198 214 MetricList filteredMetrics; 199 215 MetricList::iterator it; … … 204 220 com::SafeIfaceArray<IPerformanceMetric> retMetrics(filteredMetrics.size()); 205 221 int i = 0; 206 for (it = m.mMetrics.begin(); it != m.mMetrics.end(); ++it)222 for (it = filteredMetrics.begin(); it != filteredMetrics.end(); ++it) 207 223 { 208 224 ComObjPtr<PerformanceMetric> metric; … … 211 227 rc = metric->init (*it); 212 228 ComAssertComRCThrowRC (rc); 229 LogFlow(("PerformanceCollector::GetMetrics() store a metric at retMetrics[%d]...\n", i)); 213 230 metric.queryInterfaceTo(&retMetrics[i++]); 214 231 } … … 225 242 226 243 pm::Filter filter(ComSafeArrayInArg(metricNames), ComSafeArrayInArg(objects)); 244 245 AutoWriteLock alock (this); 227 246 228 247 BaseMetricList::iterator it; … … 245 264 pm::Filter filter(ComSafeArrayInArg(metricNames), ComSafeArrayInArg(objects)); 246 265 266 AutoReadLock alock (this); /* Need a read lock to access mBaseMetrics */ 267 247 268 BaseMetricList::iterator it; 248 269 for (it = m.mBaseMetrics.begin(); it != m.mBaseMetrics.end(); ++it) … … 260 281 261 282 pm::Filter filter(ComSafeArrayInArg(metricNames), ComSafeArrayInArg(objects)); 283 284 AutoReadLock alock (this); 262 285 263 286 BaseMetricList::iterator it; … … 280 303 CheckComRCReturnRC (autoCaller.rc()); 281 304 282 /// @todo r=dmik don't we need to lock this for reading?305 AutoReadLock alock (this); 283 306 284 307 int i; … … 328 351 void PerformanceCollector::registerBaseMetric (pm::BaseMetric *baseMetric) 329 352 { 353 AutoWriteLock alock (this); 330 354 m.mBaseMetrics.push_back (baseMetric); 331 355 } … … 333 357 void PerformanceCollector::registerMetric (pm::Metric *metric) 334 358 { 359 AutoWriteLock alock (this); 335 360 m.mMetrics.push_back (metric); 336 361 } … … 338 363 void PerformanceCollector::unregisterBaseMetricsFor (const ComPtr <IUnknown> &aObject) 339 364 { 365 AutoWriteLock alock (this); 340 366 std::remove_if (m.mBaseMetrics.begin(), m.mBaseMetrics.end(), 341 367 std::bind2nd (std::mem_fun (&pm::BaseMetric::associatedWith), … … 345 371 void PerformanceCollector::unregisterMetricsFor (const ComPtr <IUnknown> &aObject) 346 372 { 373 AutoWriteLock alock (this); 347 374 std::remove_if (m.mMetrics.begin(), m.mMetrics.end(), 348 375 std::bind2nd (std::mem_fun (&pm::Metric::associatedWith), … … 368 395 void PerformanceCollector::samplerCallback() 369 396 { 397 AutoWriteLock alock (this); 398 370 399 uint64_t timestamp = RTTimeMilliTS(); 371 400 std::for_each(m.mBaseMetrics.begin(), m.mBaseMetrics.end(), … … 380 409 //////////////////////////////////////////////////////////////////////////////// 381 410 382 PerformanceMetric::PerformanceMetric() 383 { 384 mMetric = 0; 411 PerformanceMetric::PerformanceMetric() : mMetric(0) 412 { 385 413 } 386 414 -
trunk/src/VBox/Main/include/Performance.h
r10726 r10753 25 25 #include <iprt/types.h> 26 26 #include <VBox/com/defs.h> 27 #include <VBox/com/ptr.h> 27 28 #include <list> 28 29 #include <string> 29 30 30 31 namespace pm { 31 const uint64_t PM_CPU_LOAD_MULTIPLIER = UINT64_C(100000000); 32 /* CPU load is measured in 1/1000 of per cent. */ 33 const uint64_t PM_CPU_LOAD_MULTIPLIER = UINT64_C(100000); 32 34 33 35 /* Sub Metrics **********************************************************/ … … 68 70 virtual int getProcessCpuLoad(RTPROCESS process, unsigned long *user, unsigned long *kernel); 69 71 virtual int getProcessMemoryUsage(RTPROCESS process, unsigned long *used) = 0; 70 71 virtual int getRawHostCpuLoad(unsigned long *user, unsigned long *kernel, unsigned long *idle);72 virtual int getRawProcessCpuLoad(RTPROCESS process, unsigned long *user, unsigned long *kernel);73 };74 75 class CollectorLinux : public CollectorHAL76 {77 public:78 virtual int getHostCpuMHz(unsigned long *mhz);79 virtual int getHostMemoryUsage(unsigned long *total, unsigned long *used, unsigned long *available);80 virtual int getProcessMemoryUsage(RTPROCESS process, unsigned long *used);81 72 82 73 virtual int getRawHostCpuLoad(unsigned long *user, unsigned long *kernel, unsigned long *idle); … … 309 300 }; 310 301 311 // @todo Move implementation to linux/PerformanceLinux.cpp 302 class MetricFactorySolaris : public MetricFactory 303 { 304 public: 305 MetricFactorySolaris(); 306 virtual BaseMetric *createHostCpuLoad(ComPtr<IUnknown> object, SubMetric *user, SubMetric *kernel, SubMetric *idle); 307 virtual BaseMetric *createMachineCpuLoad(ComPtr<IUnknown> object, RTPROCESS process, SubMetric *user, SubMetric *kernel); 308 }; 309 312 310 class MetricFactoryLinux : public MetricFactory 313 311 { … … 318 316 }; 319 317 318 class MetricFactoryWin : public MetricFactory 319 { 320 public: 321 MetricFactoryWin(); 322 // Nothing else to do here (yet) 323 }; 324 325 class MetricFactoryOS2 : public MetricFactory 326 { 327 public: 328 MetricFactoryOS2(); 329 // Nothing else to do here (yet) 330 }; 331 332 class MetricFactoryDarwin : public MetricFactory 333 { 334 public: 335 MetricFactoryDarwin(); 336 // Nothing else to do here (yet) 337 }; 338 320 339 class Filter 321 340 { -
trunk/src/VBox/Main/testcase/tstAPI.cpp
r10727 r10753 1056 1056 for (unsigned j = 0; j < retLengths[i]; j++) 1057 1057 { 1058 printf(", %d % s", retData[retIndices[i] + j], metricUnit.raw());1058 printf(", %d %ls", retData[retIndices[i] + j] / (strcmp((const char *)metricUnit.raw(), "%")?1:1000), metricUnit.raw()); 1059 1059 } 1060 1060 printf("\n");
Note:
See TracChangeset
for help on using the changeset viewer.