1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BASE_SYS_INFO_H_
6 #define BASE_SYS_INFO_H_
11 #include "base/base_export.h"
12 #include "base/basictypes.h"
13 #include "base/files/file_path.h"
14 #include "base/time/time.h"
15 #include "build/build_config.h"
19 class BASE_EXPORT SysInfo
{
21 // Return the number of logical processors/cores on the current machine.
22 static int NumberOfProcessors();
24 // Return the number of bytes of physical memory on the current machine.
25 static int64
AmountOfPhysicalMemory();
27 // Return the number of bytes of current available physical memory on the
29 static int64
AmountOfAvailablePhysicalMemory();
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
34 static int64
AmountOfVirtualMemory();
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);
41 // Return the number of megabytes of available virtual memory, or zero if it
43 static int AmountOfVirtualMemoryMB() {
44 return static_cast<int>(AmountOfVirtualMemory() / 1024 / 1024);
47 // Return the available disk space in bytes on the volume containing |path|,
49 static int64
AmountOfFreeDiskSpace(const FilePath
& path
);
51 // Determine whether the device that services |path| has a seek penalty.
52 // Returns false if it couldn't be determined (e.g., |path| doesn't exist).
53 static bool HasSeekPenalty(const FilePath
& path
, bool* has_seek_penalty
);
55 // Returns system uptime in milliseconds.
56 static int64
Uptime();
58 // Returns a descriptive string for the current machine model or an empty
59 // string if machime model is unknown or an error occured.
60 // e.g. MacPro1,1 on Mac.
61 // Only implemented on OS X, will return an empty string on other platforms.
62 static std::string
HardwareModelName();
64 // Returns the name of the host operating system.
65 static std::string
OperatingSystemName();
67 // Returns the version of the host operating system.
68 static std::string
OperatingSystemVersion();
70 // Retrieves detailed numeric values for the OS version.
71 // TODO(port): Implement a Linux version of this method and enable the
72 // corresponding unit test.
73 // DON'T USE THIS ON THE MAC OR WINDOWS to determine the current OS release
74 // for OS version-specific feature checks and workarounds. If you must use
75 // an OS version check instead of a feature check, use the base::mac::IsOS*
76 // family from base/mac/mac_util.h, or base::win::GetVersion from
77 // base/win/windows_version.h.
78 static void OperatingSystemVersionNumbers(int32
* major_version
,
80 int32
* bugfix_version
);
82 // Returns the architecture of the running operating system.
83 // Exact return value may differ across platforms.
84 // e.g. a 32-bit x86 kernel on a 64-bit capable CPU will return "x86",
85 // whereas a x86-64 kernel on the same CPU will return "x86_64"
86 static std::string
OperatingSystemArchitecture();
88 // Avoid using this. Use base/cpu.h to get information about the CPU instead.
89 // http://crbug.com/148884
90 // Returns the CPU model name of the system. If it can not be figured out,
91 // an empty string is returned.
92 static std::string
CPUModelName();
94 // Return the smallest amount of memory (in bytes) which the VM system will
96 static size_t VMAllocationGranularity();
98 #if defined(OS_POSIX) && !defined(OS_MACOSX)
99 // Returns the maximum SysV shared memory segment size, or zero if there is no
101 static size_t MaxSharedMemorySize();
102 #endif // defined(OS_POSIX) && !defined(OS_MACOSX)
104 #if defined(OS_CHROMEOS)
105 typedef std::map
<std::string
, std::string
> LsbReleaseMap
;
107 // Returns the contents of /etc/lsb-release as a map.
108 static const LsbReleaseMap
& GetLsbReleaseMap();
110 // If |key| is present in the LsbReleaseMap, sets |value| and returns true.
111 static bool GetLsbReleaseValue(const std::string
& key
, std::string
* value
);
113 // Convenience function for GetLsbReleaseValue("CHROMEOS_RELEASE_BOARD",...).
114 // Returns "unknown" if CHROMEOS_RELEASE_BOARD is not set.
115 static std::string
GetLsbReleaseBoard();
117 // Returns the creation time of /etc/lsb-release. (Used to get the date and
118 // time of the Chrome OS build).
119 static Time
GetLsbReleaseTime();
121 // Returns true when actually running in a Chrome OS environment.
122 static bool IsRunningOnChromeOS();
124 // Test method to force re-parsing of lsb-release.
125 static void SetChromeOSVersionInfoForTest(const std::string
& lsb_release
,
126 const Time
& lsb_release_time
);
127 #endif // defined(OS_CHROMEOS)
129 #if defined(OS_ANDROID)
130 // Returns the Android build's codename.
131 static std::string
GetAndroidBuildCodename();
133 // Returns the Android build ID.
134 static std::string
GetAndroidBuildID();
136 // Returns the device's name.
137 static std::string
GetDeviceName();
139 static int DalvikHeapSizeMB();
140 static int DalvikHeapGrowthLimitMB();
141 #endif // defined(OS_ANDROID)
143 // Returns true if this is a low-end device.
144 // Low-end device refers to devices having less than 512M memory in the
145 // current implementation.
146 static bool IsLowEndDevice();
151 #endif // BASE_SYS_INFO_H_