michael@0: // Copyright (c) 2008 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #ifndef BASE_SYS_INFO_H_ michael@0: #define BASE_SYS_INFO_H_ michael@0: michael@0: #include "base/basictypes.h" michael@0: michael@0: #include michael@0: michael@0: namespace base { michael@0: michael@0: class SysInfo { michael@0: public: michael@0: // Return the number of logical processors/cores on the current machine. michael@0: // WARNING: On POSIX, this method uses static variables and is not threadsafe michael@0: // until it's been initialized by being called once without a race. michael@0: static int NumberOfProcessors(); michael@0: michael@0: // Return the number of bytes of physical memory on the current machine. michael@0: static int64_t AmountOfPhysicalMemory(); michael@0: michael@0: // Return the number of megabytes of physical memory on the current machine. michael@0: static int AmountOfPhysicalMemoryMB() { michael@0: return static_cast(AmountOfPhysicalMemory() / 1024 / 1024); michael@0: } michael@0: michael@0: // Return the available disk space in bytes on the volume containing |path|, michael@0: // or -1 on failure. michael@0: static int64_t AmountOfFreeDiskSpace(const std::wstring& path); michael@0: michael@0: // Return true if the given environment variable is defined. michael@0: // TODO: find a better place for HasEnvVar. michael@0: static bool HasEnvVar(const wchar_t* var); michael@0: michael@0: // Return the value of the given environment variable michael@0: // or an empty string if not defined. michael@0: // TODO: find a better place for GetEnvVar. michael@0: static std::wstring GetEnvVar(const wchar_t* var); michael@0: michael@0: // Returns the name of the host operating system. michael@0: static std::string OperatingSystemName(); michael@0: michael@0: // Returns the version of the host operating system. michael@0: static std::string OperatingSystemVersion(); michael@0: michael@0: // Retrieves detailed numeric values for the OS version. michael@0: // WARNING: On OS X, this method uses static variables and is not threadsafe michael@0: // until it's been initialized by being called once without a race. michael@0: // TODO(port): Implement a Linux version of this method and enable the michael@0: // corresponding unit test. michael@0: static void OperatingSystemVersionNumbers(int32_t *major_version, michael@0: int32_t *minor_version, michael@0: int32_t *bugfix_version); michael@0: michael@0: // Returns the CPU architecture of the system. Exact return value may differ michael@0: // across platforms. michael@0: static std::string CPUArchitecture(); michael@0: michael@0: // Returns the pixel dimensions of the primary display via the michael@0: // width and height parameters. michael@0: static void GetPrimaryDisplayDimensions(int* width, int* height); michael@0: michael@0: // Return the number of displays. michael@0: static int DisplayCount(); michael@0: michael@0: // Return the smallest amount of memory (in bytes) which the VM system will michael@0: // allocate. michael@0: static size_t VMAllocationGranularity(); michael@0: michael@0: #if defined(OS_MACOSX) michael@0: // Under the OS X Sandbox, our access to the system is limited, this call michael@0: // caches the system info on startup before we turn the Sandbox on. michael@0: // The above functions are all wired up to return the cached value so the rest michael@0: // of the code can call them in the Sandbox without worrying. michael@0: static void CacheSysInfo(); michael@0: #endif michael@0: }; michael@0: michael@0: } // namespace base michael@0: michael@0: #endif // BASE_SYS_INFO_H_