diff options
author | hongbo.min@intel.com <hongbo.min@intel.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-08 09:53:01 +0000 |
---|---|---|
committer | hongbo.min@intel.com <hongbo.min@intel.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-08 09:53:01 +0000 |
commit | d5df0c8c043a25aa7b7d43f7f6f29198bcf74348 (patch) | |
tree | d937d7dc6866099dfc624cbc624020449f792559 /base | |
parent | 4c35f73337302284aaa503dc2d6b2172623687b5 (diff) | |
download | chromium_src-d5df0c8c043a25aa7b7d43f7f6f29198bcf74348.zip chromium_src-d5df0c8c043a25aa7b7d43f7f6f29198bcf74348.tar.gz chromium_src-d5df0c8c043a25aa7b7d43f7f6f29198bcf74348.tar.bz2 |
Refine systemInfo.cpu API and provide systemInfo.cpu.get impl for Windows and Linux.
BUG=136519
TEST=browser_test --gtest_filter=SystemInfoCpuApiTest.*
Review URL: https://chromiumcodereview.appspot.com/10914060
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@155575 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/sys_info.h | 4 | ||||
-rw-r--r-- | base/sys_info_ios.mm | 11 | ||||
-rw-r--r-- | base/sys_info_linux.cc | 19 | ||||
-rw-r--r-- | base/sys_info_mac.cc | 11 | ||||
-rw-r--r-- | base/sys_info_win.cc | 5 | ||||
-rw-r--r-- | base/win/windows_version.cc | 14 | ||||
-rw-r--r-- | base/win/windows_version.h | 4 |
7 files changed, 68 insertions, 0 deletions
diff --git a/base/sys_info.h b/base/sys_info.h index af9f017..e5917f1 100644 --- a/base/sys_info.h +++ b/base/sys_info.h @@ -55,6 +55,10 @@ class BASE_EXPORT SysInfo { // across platforms. static std::string CPUArchitecture(); + // Returns the CPU model name of the system. If it can not be figured out, + // an empty string is returned. + static std::string CPUModelName(); + // Return the smallest amount of memory (in bytes) which the VM system will // allocate. static size_t VMAllocationGranularity(); diff --git a/base/sys_info_ios.mm b/base/sys_info_ios.mm index 48c7bd9..8b1ffd4 100644 --- a/base/sys_info_ios.mm +++ b/base/sys_info_ios.mm @@ -6,6 +6,8 @@ #import <UIKit/UIKit.h> #include <mach/mach.h> +#include <sys/sysctl.h> +#include <sys/types.h> #include "base/logging.h" #include "base/mac/scoped_nsautorelease_pool.h" @@ -65,4 +67,13 @@ int64 SysInfo::AmountOfPhysicalMemory() { return static_cast<int64>(hostinfo.max_mem); } +// static +std::string SysInfo::CPUModelName() { + char name[256]; + size_t len = arraysize(name); + if (sysctlbyname("machdep.cpu.brand_string", &name, &len, NULL, 0) == 0) + return name; + return std::string(); +} + } // namespace base diff --git a/base/sys_info_linux.cc b/base/sys_info_linux.cc index 03fdac2..59dfee0 100644 --- a/base/sys_info_linux.cc +++ b/base/sys_info_linux.cc @@ -46,4 +46,23 @@ size_t SysInfo::MaxSharedMemorySize() { return static_cast<size_t>(limit); } +// static +std::string SysInfo::CPUModelName() { + const char kModelNamePrefix[] = "model name"; + std::string contents; + file_util::ReadFileToString(FilePath("/proc/cpuinfo"), &contents); + DCHECK(!contents.empty()); + if (!contents.empty()) { + std::istringstream iss(contents); + std::string line; + while (std::getline(iss, line)){ + if (line.compare(0, strlen(kModelNamePrefix), kModelNamePrefix) == 0) { + size_t pos = line.find(": "); + return line.substr(pos + 2); + } + } + } + return std::string(); +} + } // namespace base diff --git a/base/sys_info_mac.cc b/base/sys_info_mac.cc index 1a1d23c..3a93689 100644 --- a/base/sys_info_mac.cc +++ b/base/sys_info_mac.cc @@ -8,6 +8,8 @@ #include <CoreServices/CoreServices.h> #include <mach/mach_host.h> #include <mach/mach_init.h> +#include <sys/sysctl.h> +#include <sys/types.h> #include "base/logging.h" #include "base/stringprintf.h" @@ -54,4 +56,13 @@ int64 SysInfo::AmountOfPhysicalMemory() { return static_cast<int64>(hostinfo.max_mem); } +// static +std::string SysInfo::CPUModelName() { + char name[256]; + size_t len = arraysize(name); + if (sysctlbyname("machdep.cpu.brand_string", &name, &len, NULL, 0) == 0) + return name; + return std::string(); +} + } // namespace base diff --git a/base/sys_info_win.cc b/base/sys_info_win.cc index 87ce66d..d8de736 100644 --- a/base/sys_info_win.cc +++ b/base/sys_info_win.cc @@ -80,6 +80,11 @@ std::string SysInfo::CPUArchitecture() { } // static +std::string SysInfo::CPUModelName() { + return win::OSInfo::GetInstance()->processor_model_name(); +} + +// static size_t SysInfo::VMAllocationGranularity() { return win::OSInfo::GetInstance()->allocation_granularity(); } diff --git a/base/win/windows_version.cc b/base/win/windows_version.cc index f0c94e2..c130e0e 100644 --- a/base/win/windows_version.cc +++ b/base/win/windows_version.cc @@ -7,6 +7,8 @@ #include <windows.h> #include "base/logging.h" +#include "base/utf_string_conversions.h" +#include "base/win/registry.h" namespace base { namespace win { @@ -76,6 +78,18 @@ OSInfo::OSInfo() OSInfo::~OSInfo() { } +std::string OSInfo::processor_model_name() { + if (processor_model_name_.empty()) { + const wchar_t kProcessorNameString[] = + L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"; + base::win::RegKey key(HKEY_LOCAL_MACHINE, kProcessorNameString, KEY_READ); + string16 value; + key.ReadValue(L"ProcessorNameString", &value); + processor_model_name_ = UTF16ToUTF8(value); + } + return processor_model_name_; +} + // static OSInfo::WOW64Status OSInfo::GetWOW64StatusForProcess(HANDLE process_handle) { typedef BOOL (WINAPI* IsWow64ProcessFunc)(HANDLE, PBOOL); diff --git a/base/win/windows_version.h b/base/win/windows_version.h index 0e4a75e..d466dad 100644 --- a/base/win/windows_version.h +++ b/base/win/windows_version.h @@ -5,6 +5,8 @@ #ifndef BASE_WIN_WINDOWS_VERSION_H_ #define BASE_WIN_WINDOWS_VERSION_H_ +#include <string> + #include "base/base_export.h" #include "base/basictypes.h" @@ -76,6 +78,7 @@ class BASE_EXPORT OSInfo { int processors() const { return processors_; } size_t allocation_granularity() const { return allocation_granularity_; } WOW64Status wow64_status() const { return wow64_status_; } + std::string processor_model_name(); // Like wow64_status(), but for the supplied handle instead of the current // process. This doesn't touch member state, so you can bypass the singleton. @@ -92,6 +95,7 @@ class BASE_EXPORT OSInfo { int processors_; size_t allocation_granularity_; WOW64Status wow64_status_; + std::string processor_model_name_; DISALLOW_COPY_AND_ASSIGN(OSInfo); }; |