[email protected] | af25b47 | 2012-04-25 01:59:44 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 2a758d61 | 2008-09-17 10:09:39 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef BASE_SYS_INFO_H_ |
| 6 | #define BASE_SYS_INFO_H_ |
| 7 | |
[email protected] | a0a1c5a | 2013-09-26 21:51:23 | [diff] [blame] | 8 | #include <map> |
[email protected] | 56d0cef | 2012-09-26 02:49:42 | [diff] [blame] | 9 | #include <string> |
| 10 | |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 11 | #include "base/base_export.h" |
[email protected] | d632798e | 2008-09-17 13:10:45 | [diff] [blame] | 12 | #include "base/basictypes.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 13 | #include "base/files/file_path.h" |
[email protected] | a0a1c5a | 2013-09-26 21:51:23 | [diff] [blame] | 14 | #include "base/time/time.h" |
[email protected] | 56d0cef | 2012-09-26 02:49:42 | [diff] [blame] | 15 | #include "build/build_config.h" |
[email protected] | 13326bb | 2009-10-14 00:41:56 | [diff] [blame] | 16 | |
[email protected] | 2a758d61 | 2008-09-17 10:09:39 | [diff] [blame] | 17 | namespace base { |
| 18 | |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 19 | class BASE_EXPORT SysInfo { |
[email protected] | 2a758d61 | 2008-09-17 10:09:39 | [diff] [blame] | 20 | public: |
| 21 | // Return the number of logical processors/cores on the current machine. |
| 22 | static int NumberOfProcessors(); |
[email protected] | 5965842 | 2009-02-11 02:01:51 | [diff] [blame] | 23 | |
[email protected] | d632798e | 2008-09-17 13:10:45 | [diff] [blame] | 24 | // Return the number of bytes of physical memory on the current machine. |
| 25 | static int64 AmountOfPhysicalMemory(); |
[email protected] | fadf97f | 2008-09-18 12:18:14 | [diff] [blame] | 26 | |
[email protected] | 52bdcda | 2012-10-27 06:10:37 | [diff] [blame] | 27 | // Return the number of bytes of current available physical memory on the |
| 28 | // machine. |
| 29 | static int64 AmountOfAvailablePhysicalMemory(); |
| 30 | |
[email protected] | 275a29de | 2014-04-08 23:19:16 | [diff] [blame^] | 31 | // Return the number of bytes of virtual memory of this process. A return |
| 32 | // value of zero means that there is no limit on the available virtual |
| 33 | // memory. |
| 34 | static int64 AmountOfVirtualMemory(); |
| 35 | |
[email protected] | fadf97f | 2008-09-18 12:18:14 | [diff] [blame] | 36 | // Return the number of megabytes of physical memory on the current machine. |
| 37 | static int AmountOfPhysicalMemoryMB() { |
| 38 | return static_cast<int>(AmountOfPhysicalMemory() / 1024 / 1024); |
| 39 | } |
[email protected] | 0e91dd2 | 2008-09-18 12:34:24 | [diff] [blame] | 40 | |
[email protected] | 275a29de | 2014-04-08 23:19:16 | [diff] [blame^] | 41 | // Return the number of megabytes of available virtual memory, or zero if it |
| 42 | // is unlimited. |
| 43 | static int AmountOfVirtualMemoryMB() { |
| 44 | return static_cast<int>(AmountOfVirtualMemory() / 1024 / 1024); |
| 45 | } |
| 46 | |
[email protected] | 02ee34a | 2008-09-20 01:16:23 | [diff] [blame] | 47 | // Return the available disk space in bytes on the volume containing |path|, |
| 48 | // or -1 on failure. |
[email protected] | 13326bb | 2009-10-14 00:41:56 | [diff] [blame] | 49 | static int64 AmountOfFreeDiskSpace(const FilePath& path); |
[email protected] | 0e91dd2 | 2008-09-18 12:34:24 | [diff] [blame] | 50 | |
[email protected] | 0f24e53e | 2012-10-29 01:04:09 | [diff] [blame] | 51 | // Returns system uptime in milliseconds. |
| 52 | static int64 Uptime(); |
| 53 | |
[email protected] | 05f9b68 | 2008-09-29 22:18:01 | [diff] [blame] | 54 | // Returns the name of the host operating system. |
| 55 | static std::string OperatingSystemName(); |
| 56 | |
| 57 | // Returns the version of the host operating system. |
| 58 | static std::string OperatingSystemVersion(); |
| 59 | |
[email protected] | 71aa16c | 2009-02-24 16:37:13 | [diff] [blame] | 60 | // Retrieves detailed numeric values for the OS version. |
[email protected] | 71aa16c | 2009-02-24 16:37:13 | [diff] [blame] | 61 | // TODO(port): Implement a Linux version of this method and enable the |
| 62 | // corresponding unit test. |
[email protected] | ba64e2b | 2011-06-14 18:18:38 | [diff] [blame] | 63 | // DON'T USE THIS ON THE MAC OR WINDOWS to determine the current OS release |
| 64 | // for OS version-specific feature checks and workarounds. If you must use |
| 65 | // an OS version check instead of a feature check, use the base::mac::IsOS* |
| 66 | // family from base/mac/mac_util.h, or base::win::GetVersion from |
| 67 | // base/win/windows_version.h. |
[email protected] | f48122119 | 2011-04-07 22:15:34 | [diff] [blame] | 68 | static void OperatingSystemVersionNumbers(int32* major_version, |
| 69 | int32* minor_version, |
| 70 | int32* bugfix_version); |
[email protected] | 71aa16c | 2009-02-24 16:37:13 | [diff] [blame] | 71 | |
[email protected] | 56d0cef | 2012-09-26 02:49:42 | [diff] [blame] | 72 | // Returns the architecture of the running operating system. |
| 73 | // Exact return value may differ across platforms. |
| 74 | // e.g. a 32-bit x86 kernel on a 64-bit capable CPU will return "x86", |
| 75 | // whereas a x86-64 kernel on the same CPU will return "x86_64" |
[email protected] | 0b6a4fb | 2012-10-16 01:58:21 | [diff] [blame] | 76 | static std::string OperatingSystemArchitecture(); |
[email protected] | 05f9b68 | 2008-09-29 22:18:01 | [diff] [blame] | 77 | |
[email protected] | 56d0cef | 2012-09-26 02:49:42 | [diff] [blame] | 78 | // Avoid using this. Use base/cpu.h to get information about the CPU instead. |
| 79 | // http://crbug.com/148884 |
[email protected] | d5df0c8c | 2012-09-08 09:53:01 | [diff] [blame] | 80 | // Returns the CPU model name of the system. If it can not be figured out, |
| 81 | // an empty string is returned. |
| 82 | static std::string CPUModelName(); |
| 83 | |
[email protected] | 037fce0 | 2009-01-22 01:42:15 | [diff] [blame] | 84 | // Return the smallest amount of memory (in bytes) which the VM system will |
| 85 | // allocate. |
| 86 | static size_t VMAllocationGranularity(); |
[email protected] | 61b8ad7 | 2009-07-22 00:35:18 | [diff] [blame] | 87 | |
[email protected] | e43eddf1 | 2009-12-29 00:32:52 | [diff] [blame] | 88 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | 849447a | 2013-11-04 20:50:14 | [diff] [blame] | 89 | // Returns the maximum SysV shared memory segment size, or zero if there is no |
| 90 | // limit. |
[email protected] | 80a086c5 | 2009-08-04 17:52:04 | [diff] [blame] | 91 | static size_t MaxSharedMemorySize(); |
[email protected] | 56d0cef | 2012-09-26 02:49:42 | [diff] [blame] | 92 | #endif // defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | 80a086c5 | 2009-08-04 17:52:04 | [diff] [blame] | 93 | |
[email protected] | 61b8ad7 | 2009-07-22 00:35:18 | [diff] [blame] | 94 | #if defined(OS_CHROMEOS) |
[email protected] | a0a1c5a | 2013-09-26 21:51:23 | [diff] [blame] | 95 | typedef std::map<std::string, std::string> LsbReleaseMap; |
[email protected] | 61b8ad7 | 2009-07-22 00:35:18 | [diff] [blame] | 96 | |
[email protected] | a0a1c5a | 2013-09-26 21:51:23 | [diff] [blame] | 97 | // Returns the contents of /etc/lsb-release as a map. |
| 98 | static const LsbReleaseMap& GetLsbReleaseMap(); |
[email protected] | af25b47 | 2012-04-25 01:59:44 | [diff] [blame] | 99 | |
[email protected] | a0a1c5a | 2013-09-26 21:51:23 | [diff] [blame] | 100 | // If |key| is present in the LsbReleaseMap, sets |value| and returns true. |
| 101 | static bool GetLsbReleaseValue(const std::string& key, std::string* value); |
| 102 | |
| 103 | // Convenience function for GetLsbReleaseValue("CHROMEOS_RELEASE_BOARD",...). |
| 104 | // Returns "unknown" if CHROMEOS_RELEASE_BOARD is not set. |
| 105 | static std::string GetLsbReleaseBoard(); |
| 106 | |
| 107 | // Returns the creation time of /etc/lsb-release. (Used to get the date and |
| 108 | // time of the Chrome OS build). |
| 109 | static Time GetLsbReleaseTime(); |
| 110 | |
[email protected] | 49c4cf85 | 2013-09-27 19:28:24 | [diff] [blame] | 111 | // Returns true when actually running in a Chrome OS environment. |
| 112 | static bool IsRunningOnChromeOS(); |
| 113 | |
[email protected] | a0a1c5a | 2013-09-26 21:51:23 | [diff] [blame] | 114 | // Test method to force re-parsing of lsb-release. |
| 115 | static void SetChromeOSVersionInfoForTest(const std::string& lsb_release, |
| 116 | const Time& lsb_release_time); |
[email protected] | 56d0cef | 2012-09-26 02:49:42 | [diff] [blame] | 117 | #endif // defined(OS_CHROMEOS) |
[email protected] | 5702108f | 2012-05-25 15:31:37 | [diff] [blame] | 118 | |
| 119 | #if defined(OS_ANDROID) |
[email protected] | abef4b33 | 2012-08-21 23:55:52 | [diff] [blame] | 120 | // Returns the Android build's codename. |
| 121 | static std::string GetAndroidBuildCodename(); |
| 122 | |
| 123 | // Returns the Android build ID. |
| 124 | static std::string GetAndroidBuildID(); |
| 125 | |
| 126 | // Returns the device's name. |
| 127 | static std::string GetDeviceName(); |
| 128 | |
[email protected] | 5702108f | 2012-05-25 15:31:37 | [diff] [blame] | 129 | static int DalvikHeapSizeMB(); |
[email protected] | 0cea355 | 2013-02-16 18:15:50 | [diff] [blame] | 130 | static int DalvikHeapGrowthLimitMB(); |
[email protected] | 56d0cef | 2012-09-26 02:49:42 | [diff] [blame] | 131 | #endif // defined(OS_ANDROID) |
[email protected] | 2a758d61 | 2008-09-17 10:09:39 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | } // namespace base |
| 135 | |
| 136 | #endif // BASE_SYS_INFO_H_ |