khorimoto@chromium.org | c7e4e00 | 2012-04-25 10:59:44 +0900 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
deanm@chromium.org | 42a34eb | 2008-09-17 19:09:39 +0900 | [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 | |
stevenjb@chromium.org | 2f4de04 | 2013-09-27 06:51:23 +0900 | [diff] [blame] | 8 | #include <map> |
thestig@chromium.org | c913724 | 2012-09-26 11:49:42 +0900 | [diff] [blame] | 9 | #include <string> |
| 10 | |
darin@chromium.org | e585bed | 2011-08-06 00:34:00 +0900 | [diff] [blame] | 11 | #include "base/base_export.h" |
deanm@chromium.org | 319f044 | 2008-09-17 22:10:45 +0900 | [diff] [blame] | 12 | #include "base/basictypes.h" |
brettw@chromium.org | 59eef1f | 2013-02-24 14:40:52 +0900 | [diff] [blame] | 13 | #include "base/files/file_path.h" |
stevenjb@chromium.org | 2f4de04 | 2013-09-27 06:51:23 +0900 | [diff] [blame] | 14 | #include "base/time/time.h" |
thestig@chromium.org | c913724 | 2012-09-26 11:49:42 +0900 | [diff] [blame] | 15 | #include "build/build_config.h" |
tony@chromium.org | 1e25e00 | 2009-10-14 09:41:56 +0900 | [diff] [blame] | 16 | |
deanm@chromium.org | 42a34eb | 2008-09-17 19:09:39 +0900 | [diff] [blame] | 17 | namespace base { |
| 18 | |
darin@chromium.org | e585bed | 2011-08-06 00:34:00 +0900 | [diff] [blame] | 19 | class BASE_EXPORT SysInfo { |
deanm@chromium.org | 42a34eb | 2008-09-17 19:09:39 +0900 | [diff] [blame] | 20 | public: |
| 21 | // Return the number of logical processors/cores on the current machine. |
| 22 | static int NumberOfProcessors(); |
jeremy@chromium.org | 0da11fa | 2009-02-11 11:01:51 +0900 | [diff] [blame] | 23 | |
deanm@chromium.org | 319f044 | 2008-09-17 22:10:45 +0900 | [diff] [blame] | 24 | // Return the number of bytes of physical memory on the current machine. |
| 25 | static int64 AmountOfPhysicalMemory(); |
deanm@chromium.org | 530ddd9 | 2008-09-18 21:18:14 +0900 | [diff] [blame] | 26 | |
hongbo.min@intel.com | f6312b1 | 2012-10-27 15:10:37 +0900 | [diff] [blame] | 27 | // Return the number of bytes of current available physical memory on the |
| 28 | // machine. |
| 29 | static int64 AmountOfAvailablePhysicalMemory(); |
| 30 | |
jochen@chromium.org | 5ac0b17 | 2014-04-09 08:19:16 +0900 | [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 | |
deanm@chromium.org | 530ddd9 | 2008-09-18 21:18:14 +0900 | [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 | } |
deanm@chromium.org | ee45e8f | 2008-09-18 21:34:24 +0900 | [diff] [blame] | 40 | |
jochen@chromium.org | 5ac0b17 | 2014-04-09 08:19:16 +0900 | [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 | |
rvargas@google.com | af00029 | 2008-09-20 10:16:23 +0900 | [diff] [blame] | 47 | // Return the available disk space in bytes on the volume containing |path|, |
| 48 | // or -1 on failure. |
tony@chromium.org | 1e25e00 | 2009-10-14 09:41:56 +0900 | [diff] [blame] | 49 | static int64 AmountOfFreeDiskSpace(const FilePath& path); |
deanm@chromium.org | ee45e8f | 2008-09-18 21:34:24 +0900 | [diff] [blame] | 50 | |
jeremy@chromium.org | de658ed | 2012-10-29 10:04:09 +0900 | [diff] [blame] | 51 | // Returns system uptime in milliseconds. |
| 52 | static int64 Uptime(); |
| 53 | |
mark@chromium.org | b93c054 | 2008-09-30 07:18:01 +0900 | [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 | |
jeremy@chromium.org | 7730edb | 2009-02-25 01:37:13 +0900 | [diff] [blame] | 60 | // Retrieves detailed numeric values for the OS version. |
jeremy@chromium.org | 7730edb | 2009-02-25 01:37:13 +0900 | [diff] [blame] | 61 | // TODO(port): Implement a Linux version of this method and enable the |
| 62 | // corresponding unit test. |
mark@chromium.org | 71cce47 | 2011-06-15 03:18:38 +0900 | [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. |
pkasting@chromium.org | 271d9db | 2011-04-08 07:15:34 +0900 | [diff] [blame] | 68 | static void OperatingSystemVersionNumbers(int32* major_version, |
| 69 | int32* minor_version, |
| 70 | int32* bugfix_version); |
jeremy@chromium.org | 7730edb | 2009-02-25 01:37:13 +0900 | [diff] [blame] | 71 | |
thestig@chromium.org | c913724 | 2012-09-26 11:49:42 +0900 | [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" |
thestig@chromium.org | e170665 | 2012-10-16 10:58:21 +0900 | [diff] [blame] | 76 | static std::string OperatingSystemArchitecture(); |
mark@chromium.org | b93c054 | 2008-09-30 07:18:01 +0900 | [diff] [blame] | 77 | |
thestig@chromium.org | c913724 | 2012-09-26 11:49:42 +0900 | [diff] [blame] | 78 | // Avoid using this. Use base/cpu.h to get information about the CPU instead. |
| 79 | // http://crbug.com/148884 |
hongbo.min@intel.com | 893f7d6 | 2012-09-08 18:53:01 +0900 | [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 | |
agl@chromium.org | 3d71fda | 2009-01-22 10:42:15 +0900 | [diff] [blame] | 84 | // Return the smallest amount of memory (in bytes) which the VM system will |
| 85 | // allocate. |
| 86 | static size_t VMAllocationGranularity(); |
evan@chromium.org | 54b7210 | 2009-07-22 09:35:18 +0900 | [diff] [blame] | 87 | |
evan@chromium.org | 875bb6e | 2009-12-29 09:32:52 +0900 | [diff] [blame] | 88 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
rmcilroy@chromium.org | e6d3510 | 2013-11-05 05:50:14 +0900 | [diff] [blame] | 89 | // Returns the maximum SysV shared memory segment size, or zero if there is no |
| 90 | // limit. |
agl@chromium.org | 3319f0a | 2009-08-05 02:52:04 +0900 | [diff] [blame] | 91 | static size_t MaxSharedMemorySize(); |
thestig@chromium.org | c913724 | 2012-09-26 11:49:42 +0900 | [diff] [blame] | 92 | #endif // defined(OS_POSIX) && !defined(OS_MACOSX) |
agl@chromium.org | 3319f0a | 2009-08-05 02:52:04 +0900 | [diff] [blame] | 93 | |
evan@chromium.org | 54b7210 | 2009-07-22 09:35:18 +0900 | [diff] [blame] | 94 | #if defined(OS_CHROMEOS) |
stevenjb@chromium.org | 2f4de04 | 2013-09-27 06:51:23 +0900 | [diff] [blame] | 95 | typedef std::map<std::string, std::string> LsbReleaseMap; |
evan@chromium.org | 54b7210 | 2009-07-22 09:35:18 +0900 | [diff] [blame] | 96 | |
stevenjb@chromium.org | 2f4de04 | 2013-09-27 06:51:23 +0900 | [diff] [blame] | 97 | // Returns the contents of /etc/lsb-release as a map. |
| 98 | static const LsbReleaseMap& GetLsbReleaseMap(); |
khorimoto@chromium.org | c7e4e00 | 2012-04-25 10:59:44 +0900 | [diff] [blame] | 99 | |
stevenjb@chromium.org | 2f4de04 | 2013-09-27 06:51:23 +0900 | [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 | |
stevenjb@chromium.org | 861313b | 2013-09-28 04:28:24 +0900 | [diff] [blame] | 111 | // Returns true when actually running in a Chrome OS environment. |
| 112 | static bool IsRunningOnChromeOS(); |
| 113 | |
stevenjb@chromium.org | 2f4de04 | 2013-09-27 06:51:23 +0900 | [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); |
thestig@chromium.org | c913724 | 2012-09-26 11:49:42 +0900 | [diff] [blame] | 117 | #endif // defined(OS_CHROMEOS) |
ulan@chromium.org | 8ac7ea0 | 2012-05-26 00:31:37 +0900 | [diff] [blame] | 118 | |
| 119 | #if defined(OS_ANDROID) |
dfalcantara@chromium.org | 774888d | 2012-08-22 08:55:52 +0900 | [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 | |
ulan@chromium.org | 8ac7ea0 | 2012-05-26 00:31:37 +0900 | [diff] [blame] | 129 | static int DalvikHeapSizeMB(); |
epenner@chromium.org | 066b81b | 2013-02-17 03:15:50 +0900 | [diff] [blame] | 130 | static int DalvikHeapGrowthLimitMB(); |
thestig@chromium.org | c913724 | 2012-09-26 11:49:42 +0900 | [diff] [blame] | 131 | #endif // defined(OS_ANDROID) |
c.shu@samsung.com | da21aff | 2014-06-27 01:55:27 +0900 | [diff] [blame] | 132 | |
| 133 | // Returns true if this is a low-end device. |
| 134 | // Low-end device refers to devices having less than 512M memory in the |
| 135 | // current implementation. |
| 136 | static bool IsLowEndDevice(); |
deanm@chromium.org | 42a34eb | 2008-09-17 19:09:39 +0900 | [diff] [blame] | 137 | }; |
| 138 | |
| 139 | } // namespace base |
| 140 | |
| 141 | #endif // BASE_SYS_INFO_H_ |