/* $Id$ */
/** @file
*
* VBox Linux-specific Performance Classes implementation.
*/
/*
* Copyright (C) 2008-2012 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <mntent.h>
#include <map>
#include <vector>
#include "Logging.h"
#include "Performance.h"
namespace pm {
{
public:
virtual int getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total);
private:
virtual int _getRawHostCpuLoad();
int getRawProcessStats(RTPROCESS process, uint64_t *cpuUser, uint64_t *cpuKernel, ULONG *memPagesUsed);
char *trimTrailingDigits(char *pszName);
char *trimNewline(char *pszName);
struct VMProcessStats
{
};
};
{
return new CollectorLinux();
}
// Collector HAL for Linux
{
if (hz == -1)
{
LogRel(("CollectorLinux failed to obtain HZ from kernel, assuming 100.\n"));
mHZ = 100;
}
else
if (RT_FAILURE(rc))
totalRAM = 0;
else
}
{
{
/* On failure, do NOT stop. Just skip the entry. Having the stats for
* to not updating many process stats and the host cpu stats. */
if (RT_SUCCESS(rc))
}
{
}
return VINF_SUCCESS;
}
{
if (f)
{
{
{
}
/* Try to get single CPU stats. */
{
{
}
else
{
/* Assume that this is not an SMP system. */
mSingleUser = mUser;
mSingleIdle = mIdle;
}
}
else
}
else
fclose(f);
}
else
return rc;
}
{
return VINF_SUCCESS;
}
int CollectorLinux::getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total)
{
{
return VERR_INTERNAL_ERROR;
}
return VINF_SUCCESS;
}
{
if (RT_SUCCESS(rc))
{
}
return rc;
}
int CollectorLinux::getHostFilesystemUsage(const char *path, ULONG *total, ULONG *used, ULONG *available)
{
{
return VERR_ACCESS_DENIED;
}
return VINF_SUCCESS;
}
{
if (!RTLinuxSysFsExists(pszPath))
else
{
if (cSize < 0)
else
}
return rc;
}
{
{
return VERR_INTERNAL_ERROR;
}
return VINF_SUCCESS;
}
int CollectorLinux::getRawProcessStats(RTPROCESS process, uint64_t *cpuUser, uint64_t *cpuKernel, ULONG *memPagesUsed)
{
char *pszName;
char c;
int iTmp;
long long unsigned int u64Tmp;
unsigned uTmp;
unsigned long ulTmp;
signed long ilTmp;
if (f)
{
if (fscanf(f, "%d %79s %c %d %d %d %d %d %u %lu %lu %lu %lu %u %u "
"%ld %ld %ld %ld %ld %ld %llu %lu %u",
{
}
else
fclose(f);
}
else
return rc;
}
{
if (!RTLinuxSysFsExists(szIfName))
return VERR_FILE_NOT_FOUND;
if (cSize < 0)
return VERR_ACCESS_DENIED;
if (!RTLinuxSysFsExists(szIfName))
return VERR_FILE_NOT_FOUND;
if (cSize < 0)
return VERR_ACCESS_DENIED;
return VINF_SUCCESS;
}
{
#if 0
int rc = VINF_SUCCESS;
if (f)
{
if (fscanf(f, "%llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu",
{
}
else
fclose(f);
}
else
#else
if (f)
{
{
if (!pszBufData)
{
continue;
}
*pszBufData++ = '\0';
{
{
rc = VINF_SUCCESS;
}
else
break;
}
}
fclose(f);
}
#endif
return rc;
}
{
if (cbName == 0)
return pszName;
pszEnd--;
return pszName;
}
{
if (cbName == 0)
return pszName;
pszEnd--;
return pszName;
}
/**
* Use the partition name to get the name of the disk. Any path component is stripped.
* is converted to 'sda'.
*
* @param pszDiskName Where to store the name of the disk.
* @param cbDiskName The size of the buffer pszDiskName points to.
* @param pszDevName The device name used to get the disk name.
*/
void CollectorLinux::getDiskName(char *pszDiskName, size_t cbDiskName, const char *pszDevName, bool fTrimDigits)
{
unsigned cbName = 0;
if (fTrimDigits)
pszEnd--;
{
cbName++;
pszEnd--;
}
}
{
if (f)
{
{
if (!pszBufData)
{
continue;
}
*pszBufData++ = '\0';
{
while (*pszBufData != '\0')
{
while (RT_C_IS_ALPHA(*pszBufData))
++pszBufData;
if (*pszBufData)
{
*pszBufData++ = '\0';
++pszBufData;
}
else
}
break;
}
}
fclose(f);
}
}
{
if (RT_FAILURE(rc))
{
return;
}
if (fp)
{
else
}
else
}
{
if (mtab)
{
{
/* Skip rootfs entry, there must be another root mount. */
continue;
{
/* Try to resolve symbolic link if necessary. Yes, we access the file system here! */
if (RT_FAILURE(rc))
continue; /* something got wrong, just ignore this path */
* often a symlink to something else */
{
/* LVM */
}
{
/* Software RAID */
}
else
{
/* Plain disk partition. Trim the trailing digits to get the drive name */
}
{
LogRel(("Failed to retrive disk info: getDiskName(%s) --> %s\n",
}
break;
}
}
}
return VINF_SUCCESS;
}
}