Home | History | Annotate | Download | only in base
      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.
      4 
      5 #ifndef BASE_SYS_INFO_H_
      6 #define BASE_SYS_INFO_H_
      7 
      8 #include <stddef.h>
      9 #include <stdint.h>
     10 
     11 #include <map>
     12 #include <string>
     13 
     14 #include "base/base_export.h"
     15 #include "base/files/file_path.h"
     16 #include "base/time/time.h"
     17 #include "build/build_config.h"
     18 
     19 namespace base {
     20 
     21 class BASE_EXPORT SysInfo {
     22  public:
     23   // Return the number of logical processors/cores on the current machine.
     24   static int NumberOfProcessors();
     25 
     26   // Return the number of bytes of physical memory on the current machine.
     27   static int64_t AmountOfPhysicalMemory();
     28 
     29   // Return the number of bytes of current available physical memory on the
     30   // machine.
     31   static int64_t AmountOfAvailablePhysicalMemory();
     32 
     33   // Return the number of bytes of virtual memory of this process. A return
     34   // value of zero means that there is no limit on the available virtual
     35   // memory.
     36   static int64_t AmountOfVirtualMemory();
     37 
     38   // Return the number of megabytes of physical memory on the current machine.
     39   static int AmountOfPhysicalMemoryMB() {
     40     return static_cast<int>(AmountOfPhysicalMemory() / 1024 / 1024);
     41   }
     42 
     43   // Return the number of megabytes of available virtual memory, or zero if it
     44   // is unlimited.
     45   static int AmountOfVirtualMemoryMB() {
     46     return static_cast<int>(AmountOfVirtualMemory() / 1024 / 1024);
     47   }
     48 
     49   // Return the available disk space in bytes on the volume containing |path|,
     50   // or -1 on failure.
     51   static int64_t AmountOfFreeDiskSpace(const FilePath& path);
     52 
     53   // Return the total disk space in bytes on the volume containing |path|, or -1
     54   // on failure.
     55   static int64_t AmountOfTotalDiskSpace(const FilePath& path);
     56 
     57   // Returns system uptime.
     58   static TimeDelta Uptime();
     59 
     60   // Returns a descriptive string for the current machine model or an empty
     61   // string if the machine model is unknown or an error occured.
     62   // e.g. "MacPro1,1" on Mac, or "Nexus 5" on Android. Only implemented on OS X,
     63   // Android, and Chrome OS. This returns an empty string on other platforms.
     64   static std::string HardwareModelName();
     65 
     66   // Returns the name of the host operating system.
     67   static std::string OperatingSystemName();
     68 
     69   // Returns the version of the host operating system.
     70   static std::string OperatingSystemVersion();
     71 
     72   // Retrieves detailed numeric values for the OS version.
     73   // TODO(port): Implement a Linux version of this method and enable the
     74   // corresponding unit test.
     75   // DON'T USE THIS ON THE MAC OR WINDOWS to determine the current OS release
     76   // for OS version-specific feature checks and workarounds. If you must use
     77   // an OS version check instead of a feature check, use the base::mac::IsOS*
     78   // family from base/mac/mac_util.h, or base::win::GetVersion from
     79   // base/win/windows_version.h.
     80   static void OperatingSystemVersionNumbers(int32_t* major_version,
     81                                             int32_t* minor_version,
     82                                             int32_t* bugfix_version);
     83 
     84   // Returns the architecture of the running operating system.
     85   // Exact return value may differ across platforms.
     86   // e.g. a 32-bit x86 kernel on a 64-bit capable CPU will return "x86",
     87   //      whereas a x86-64 kernel on the same CPU will return "x86_64"
     88   static std::string OperatingSystemArchitecture();
     89 
     90   // Avoid using this. Use base/cpu.h to get information about the CPU instead.
     91   // http://crbug.com/148884
     92   // Returns the CPU model name of the system. If it can not be figured out,
     93   // an empty string is returned.
     94   static std::string CPUModelName();
     95 
     96   // Return the smallest amount of memory (in bytes) which the VM system will
     97   // allocate.
     98   static size_t VMAllocationGranularity();
     99 
    100 #if defined(OS_CHROMEOS)
    101   typedef std::map<std::string, std::string> LsbReleaseMap;
    102 
    103   // Returns the contents of /etc/lsb-release as a map.
    104   static const LsbReleaseMap& GetLsbReleaseMap();
    105 
    106   // If |key| is present in the LsbReleaseMap, sets |value| and returns true.
    107   static bool GetLsbReleaseValue(const std::string& key, std::string* value);
    108 
    109   // Convenience function for GetLsbReleaseValue("CHROMEOS_RELEASE_BOARD",...).
    110   // Returns "unknown" if CHROMEOS_RELEASE_BOARD is not set.
    111   static std::string GetLsbReleaseBoard();
    112 
    113   // Returns the creation time of /etc/lsb-release. (Used to get the date and
    114   // time of the Chrome OS build).
    115   static Time GetLsbReleaseTime();
    116 
    117   // Returns true when actually running in a Chrome OS environment.
    118   static bool IsRunningOnChromeOS();
    119 
    120   // Test method to force re-parsing of lsb-release.
    121   static void SetChromeOSVersionInfoForTest(const std::string& lsb_release,
    122                                             const Time& lsb_release_time);
    123 #endif  // defined(OS_CHROMEOS)
    124 
    125 #if defined(OS_ANDROID)
    126   // Returns the Android build's codename.
    127   static std::string GetAndroidBuildCodename();
    128 
    129   // Returns the Android build ID.
    130   static std::string GetAndroidBuildID();
    131 
    132   static int DalvikHeapSizeMB();
    133   static int DalvikHeapGrowthLimitMB();
    134 #endif  // defined(OS_ANDROID)
    135 
    136   // Returns true if this is a low-end device.
    137   // Low-end device refers to devices having less than 512M memory in the
    138   // current implementation.
    139   static bool IsLowEndDevice();
    140 };
    141 
    142 }  // namespace base
    143 
    144 #endif  // BASE_SYS_INFO_H_
    145