This source file includes following definitions.
- AmountOfMemory
- NumberOfProcessors
- AmountOfPhysicalMemory
- AmountOfAvailablePhysicalMemory
- AmountOfFreeDiskSpace
- OperatingSystemName
- OperatingSystemVersion
- OperatingSystemArchitecture
- CPUModelName
- VMAllocationGranularity
- OperatingSystemVersionNumbers
#include "base/sys_info.h"
#include <windows.h>
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/stringprintf.h"
#include "base/threading/thread_restrictions.h"
#include "base/win/windows_version.h"
namespace {
int64 AmountOfMemory(DWORDLONG MEMORYSTATUSEX::* memory_field) {
MEMORYSTATUSEX memory_info;
memory_info.dwLength = sizeof(memory_info);
if (!GlobalMemoryStatusEx(&memory_info)) {
NOTREACHED();
return 0;
}
int64 rv = static_cast<int64>(memory_info.*memory_field);
if (rv < 0)
rv = kint64max;
return rv;
}
}
namespace base {
int SysInfo::NumberOfProcessors() {
return win::OSInfo::GetInstance()->processors();
}
int64 SysInfo::AmountOfPhysicalMemory() {
return AmountOfMemory(&MEMORYSTATUSEX::ullTotalPhys);
}
int64 SysInfo::AmountOfAvailablePhysicalMemory() {
return AmountOfMemory(&MEMORYSTATUSEX::ullAvailPhys);
}
int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) {
base::ThreadRestrictions::AssertIOAllowed();
ULARGE_INTEGER available, total, free;
if (!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free)) {
return -1;
}
int64 rv = static_cast<int64>(available.QuadPart);
if (rv < 0)
rv = kint64max;
return rv;
}
std::string SysInfo::OperatingSystemName() {
return "Windows NT";
}
std::string SysInfo::OperatingSystemVersion() {
win::OSInfo* os_info = win::OSInfo::GetInstance();
win::OSInfo::VersionNumber version_number = os_info->version_number();
std::string version(StringPrintf("%d.%d", version_number.major,
version_number.minor));
win::OSInfo::ServicePack service_pack = os_info->service_pack();
if (service_pack.major != 0) {
version += StringPrintf(" SP%d", service_pack.major);
if (service_pack.minor != 0)
version += StringPrintf(".%d", service_pack.minor);
}
return version;
}
std::string SysInfo::OperatingSystemArchitecture() {
win::OSInfo::WindowsArchitecture arch =
win::OSInfo::GetInstance()->architecture();
switch (arch) {
case win::OSInfo::X86_ARCHITECTURE:
return "x86";
case win::OSInfo::X64_ARCHITECTURE:
return "x86_64";
case win::OSInfo::IA64_ARCHITECTURE:
return "ia64";
default:
return "";
}
}
std::string SysInfo::CPUModelName() {
return win::OSInfo::GetInstance()->processor_model_name();
}
size_t SysInfo::VMAllocationGranularity() {
return win::OSInfo::GetInstance()->allocation_granularity();
}
void SysInfo::OperatingSystemVersionNumbers(int32* major_version,
int32* minor_version,
int32* bugfix_version) {
win::OSInfo* os_info = win::OSInfo::GetInstance();
*major_version = os_info->version_number().major;
*minor_version = os_info->version_number().minor;
*bugfix_version = 0;
}
}