Changeset 45051 in vbox
- Timestamp:
- Mar 15, 2013 3:34:54 PM (12 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/Performance.h
r44551 r45051 389 389 virtual int getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total); 390 390 391 /** Returns the list of disksused by the specified file system. */392 virtual int getDiskListByFs(const char *name, DiskList& list );391 /** Returns the lists of disks (aggregate and physical) used by the specified file system. */ 392 virtual int getDiskListByFs(const char *name, DiskList& listUsage, DiskList& listLoad); 393 393 }; 394 394 -
trunk/src/VBox/Main/src-server/HostImpl.cpp
r44179 r45051 2978 2978 2979 2979 /* For now we are concerned with the root file system only. */ 2980 pm::DiskList disks ;2981 int rc = hal->getDiskListByFs("/", disks );2982 if (RT_FAILURE(rc) || disks.empty())2980 pm::DiskList disksUsage, disksLoad; 2981 int rc = hal->getDiskListByFs("/", disksUsage, disksLoad); 2982 if (RT_FAILURE(rc)) 2983 2983 return; 2984 2984 pm::DiskList::iterator it; 2985 for (it = disks .begin(); it != disks.end(); ++it)2985 for (it = disksLoad.begin(); it != disksLoad.end(); ++it) 2986 2986 { 2987 2987 Utf8StrFmt strName("Disk/%s", it->c_str()); 2988 2988 pm::SubMetric *fsLoadUtil = new pm::SubMetric(strName + "/Load/Util", 2989 2989 "Percentage of time disk was busy serving I/O requests."); 2990 pm::SubMetric *fsUsageTotal = new pm::SubMetric(strName + "/Usage/Total",2991 "Disk size.");2992 2990 pm::BaseMetric *fsLoad = new pm::HostDiskLoadRaw(hal, this, strName + "/Load", 2993 2991 *it, fsLoadUtil); 2994 2992 aCollector->registerBaseMetric (fsLoad); 2995 pm::BaseMetric *fsUsage = new pm::HostDiskUsage(hal, this, strName + "/Usage",2996 *it, fsUsageTotal);2997 aCollector->registerBaseMetric (fsUsage);2998 2993 2999 2994 aCollector->registerMetric(new pm::Metric(fsLoad, fsLoadUtil, 0)); … … 3004 2999 aCollector->registerMetric(new pm::Metric(fsLoad, fsLoadUtil, 3005 3000 new pm::AggregateMax())); 3001 } 3002 for (it = disksUsage.begin(); it != disksUsage.end(); ++it) 3003 { 3004 Utf8StrFmt strName("Disk/%s", it->c_str()); 3005 pm::SubMetric *fsUsageTotal = new pm::SubMetric(strName + "/Usage/Total", 3006 "Disk size."); 3007 pm::BaseMetric *fsUsage = new pm::HostDiskUsage(hal, this, strName + "/Usage", 3008 *it, fsUsageTotal); 3009 aCollector->registerBaseMetric (fsUsage); 3006 3010 3007 3011 aCollector->registerMetric(new pm::Metric(fsUsage, fsUsageTotal, 0)); -
trunk/src/VBox/Main/src-server/Performance.cpp
r44742 r45051 98 98 } 99 99 100 int CollectorHAL::getDiskListByFs(const char * /* name */, DiskList& /* list */)100 int CollectorHAL::getDiskListByFs(const char * /* name */, DiskList& /* listUsage */, DiskList& /* listLoad */) 101 101 { 102 102 return E_NOTIMPL; -
trunk/src/VBox/Main/src-server/freebsd/PerformanceFreeBSD.cpp
r44528 r45051 110 110 } 111 111 112 int getDiskListByFs(const char *name, DiskList& list)113 {114 return VERR_NOT_IMPLEMENTED;115 }116 117 112 } /* namespace pm */ 118 113 -
trunk/src/VBox/Main/src-server/linux/PerformanceLinux.cpp
r44528 r45051 57 57 virtual int getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total); 58 58 59 virtual int getDiskListByFs(const char *name, DiskList& list );59 virtual int getDiskListByFs(const char *name, DiskList& listUsage, DiskList& listLoad); 60 60 private: 61 61 virtual int _getRawHostCpuLoad(); … … 63 63 char *getDiskName(char *pszDiskName, size_t cbDiskName, const char *pszDevName, bool fTrimDigits); 64 64 void addVolumeDependencies(const char *pcszVolume, DiskList& listDisks); 65 void addRaidDisks(const char *pcszDevice, DiskList& listDisks); 65 66 char *trimTrailingDigits(char *pszName); 67 char *trimNewline(char *pszName); 66 68 67 69 struct VMProcessStats … … 425 427 } 426 428 429 char *CollectorLinux::trimNewline(char *pszName) 430 { 431 unsigned cbName = strlen(pszName); 432 if (cbName == 0) 433 return pszName; 434 435 char *pszEnd = pszName + cbName - 1; 436 while (pszEnd > pszName && *pszEnd == '\n') 437 pszEnd--; 438 pszEnd[1] = '\0'; 439 440 return pszName; 441 } 442 427 443 char *CollectorLinux::trimTrailingDigits(char *pszName) 428 444 { … … 456 472 } 457 473 474 void CollectorLinux::addRaidDisks(const char *pcszDevice, DiskList& listDisks) 475 { 476 FILE *f = fopen("/proc/mdstat", "r"); 477 if (f) 478 { 479 char szBuf[128]; 480 while (fgets(szBuf, sizeof(szBuf), f)) 481 { 482 char *pszBufName = szBuf; 483 484 char *pszBufData = strchr(pszBufName, ' '); 485 if (!pszBufData) 486 { 487 LogRel(("CollectorLinux::addRaidDisks() failed to parse disk stats: %s\n", szBuf)); 488 continue; 489 } 490 *pszBufData++ = '\0'; 491 if (!strcmp(pcszDevice, pszBufName)) 492 { 493 while (*pszBufData == ':') ++pszBufData; /* Skip delimiter */ 494 while (*pszBufData == ' ') ++pszBufData; /* Skip spaces */ 495 while (RT_C_IS_ALNUM(*pszBufData)) ++pszBufData; /* Skip status */ 496 while (*pszBufData == ' ') ++pszBufData; /* Skip spaces */ 497 while (RT_C_IS_ALNUM(*pszBufData)) ++pszBufData; /* Skip type */ 498 499 while (*pszBufData != '\0') 500 { 501 while (*pszBufData == ' ') ++pszBufData; /* Skip spaces */ 502 char *pszDisk = pszBufData; 503 while (RT_C_IS_ALPHA(*pszBufData)) 504 ++pszBufData; 505 if (*pszBufData) 506 { 507 *pszBufData++ = '\0'; 508 listDisks.push_back(RTCString(pszDisk)); 509 while (*pszBufData != '\0' && *pszBufData != ' ') 510 ++pszBufData; 511 } 512 else 513 listDisks.push_back(RTCString(pszDisk)); 514 } 515 break; 516 } 517 } 518 fclose(f); 519 } 520 } 521 458 522 void CollectorLinux::addVolumeDependencies(const char *pcszVolume, DiskList& listDisks) 459 523 { … … 474 538 475 539 while (fgets(szBuf, sizeof(szBuf), fp)) 476 listDisks.push_back(RTCString(trimTrailingDigits(szBuf))); 540 if (strncmp(szBuf, "dm-", 3)) 541 listDisks.push_back(RTCString(trimTrailingDigits(szBuf))); 542 else 543 listDisks.push_back(RTCString(trimNewline(szBuf))); 477 544 478 545 pclose(fp); … … 482 549 } 483 550 484 int CollectorLinux::getDiskListByFs(const char *pszPath, DiskList& list Disks)551 int CollectorLinux::getDiskListByFs(const char *pszPath, DiskList& listUsage, DiskList& listLoad) 485 552 { 486 553 FILE *mtab = setmntent("/etc/mtab", "r"); … … 490 557 while ((mntent = getmntent(mtab))) 491 558 { 559 /* Skip rootfs entry, there must be another root mount. */ 560 if (strcmp(mntent->mnt_fsname, "rootfs") == 0) 561 continue; 492 562 if (strcmp(pszPath, mntent->mnt_dir) == 0) 493 563 { 494 564 char szDevName[128]; 495 if (strncmp(mntent->mnt_fsname, "/dev/mapper", 11)) 496 { 565 char szFsName[1024]; 566 /* Try to resolve symbolic link if necessary */ 567 ssize_t cbFsName = readlink(mntent->mnt_fsname, szFsName, sizeof(szFsName) - 1); 568 if (cbFsName != -1) 569 szFsName[cbFsName] = '\0'; 570 else 571 strcpy(szFsName, mntent->mnt_fsname); 572 if (!strncmp(szFsName, "/dev/mapper", 11)) 573 { 574 /* LVM */ 575 getDiskName(szDevName, sizeof(szDevName), szFsName, false); 576 addVolumeDependencies(szDevName, listUsage); 577 listLoad = listUsage; 578 } 579 else if (!strncmp(szFsName, "/dev/md", 7)) 580 { 581 /* Software RAID */ 582 getDiskName(szDevName, sizeof(szDevName), szFsName, false); 583 listUsage.push_back(RTCString(szDevName)); 584 addRaidDisks(szDevName, listLoad); 585 } 586 else 587 { 588 /* Plain disk partition */ 497 589 getDiskName(szDevName, sizeof(szDevName), mntent->mnt_fsname, true); 498 list Disks.push_back(RTCString(szDevName));499 }500 else501 {502 getDiskName(szDevName, sizeof(szDevName), mntent->mnt_fsname, false);503 addVolumeDependencies(szDevName, listDisks);590 listUsage.push_back(RTCString(szDevName)); 591 listLoad.push_back(RTCString(szDevName)); 592 } 593 if (listUsage.empty() || listLoad.empty()) 594 { 595 LogRel(("Failed to retrive disk info: getDiskName(%s) --> %s\n", mntent->mnt_fsname, szDevName)); 504 596 } 505 597 break; -
trunk/src/VBox/Main/src-server/solaris/PerformanceSolaris.cpp
r44529 r45051 74 74 virtual int getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total); 75 75 76 virtual int getDiskListByFs(const char *name, DiskList& list );76 virtual int getDiskListByFs(const char *name, DiskList& listUsage, DiskList& listLoad); 77 77 private: 78 78 static uint32_t getInstance(const char *pszIfaceName, char *pszDevName); … … 665 665 } 666 666 667 int CollectorSolaris::getDiskListByFs(const char *name, DiskList& list )667 int CollectorSolaris::getDiskListByFs(const char *name, DiskList& listUsage, DiskList& listLoad) 668 668 { 669 669 FsMap::iterator it = mFsMap.find(name); … … 708 708 pszStart += 8; // Skip "/devices" 709 709 *pszEnd = '\0'; // Trim partition 710 list .push_back(physToInstName(pszStart));710 listUsage.push_back(physToInstName(pszStart)); 711 711 } 712 712 } … … 719 719 } 720 720 else 721 list.push_back(pathToInstName(it->second.c_str())); 721 listUsage.push_back(pathToInstName(it->second.c_str())); 722 listLoad = listUsage; 722 723 return VINF_SUCCESS; 723 724 } -
trunk/src/VBox/Main/testcase/tstCollector.cpp
r45012 r45051 224 224 uint64_t diskMsStop, totalMsStop; 225 225 226 pm::DiskList disks ;227 int rc = collector->getDiskListByFs(FSNAME, disks );226 pm::DiskList disksUsage, disksLoad; 227 int rc = collector->getDiskListByFs(FSNAME, disksUsage, disksLoad); 228 228 if (RT_FAILURE(rc)) 229 229 { … … 231 231 return 1; 232 232 } 233 if (disks.empty()) 234 { 235 RTPrintf("tstCollector: getDiskListByFs(%s) returned empty list\n", FSNAME); 233 if (disksUsage.empty()) 234 { 235 RTPrintf("tstCollector: getDiskListByFs(%s) returned empty usage list\n", FSNAME); 236 return 1; 237 } 238 if (disksLoad.empty()) 239 { 240 RTPrintf("tstCollector: getDiskListByFs(%s) returned empty usage list\n", FSNAME); 236 241 return 1; 237 242 } 238 243 239 244 pm::DiskList::iterator it; 240 for (it = disks .begin(); it != disks.end(); ++it)245 for (it = disksUsage.begin(); it != disksUsage.end(); ++it) 241 246 { 242 247 uint64_t diskSize = 0; 243 rc = collector->getHostDiskSize( disks.front().c_str(), &diskSize);244 RTPrintf("tstCollector: TESTING - Disk size (%s) = %llu\n", disks.front().c_str(), diskSize);248 rc = collector->getHostDiskSize(it->c_str(), &diskSize); 249 RTPrintf("tstCollector: TESTING - Disk size (%s) = %llu\n", it->c_str(), diskSize); 245 250 if (RT_FAILURE(rc)) 246 251 { … … 248 253 return 1; 249 254 } 250 251 RTPrintf("tstCollector: TESTING - Disk utilization (%s), sleeping for 5 sec...\n", disks.front().c_str()); 255 } 256 257 for (it = disksLoad.begin(); it != disksLoad.end(); ++it) 258 { 259 RTPrintf("tstCollector: TESTING - Disk utilization (%s), sleeping for 5 sec...\n", it->c_str()); 252 260 253 261 hints.collectHostCpuLoad(); … … 258 266 return 1; 259 267 } 260 rc = collector->getRawHostDiskLoad( disks.front().c_str(), &diskMsStart, &totalMsStart);268 rc = collector->getRawHostDiskLoad(it->c_str(), &diskMsStart, &totalMsStart); 261 269 if (RT_FAILURE(rc)) 262 270 { … … 273 281 return 1; 274 282 } 275 rc = collector->getRawHostDiskLoad( disks.front().c_str(), &diskMsStop, &totalMsStop);283 rc = collector->getRawHostDiskLoad(it->c_str(), &diskMsStop, &totalMsStop); 276 284 if (RT_FAILURE(rc)) 277 285 {
Note:
See TracChangeset
for help on using the changeset viewer.