Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(302)

Side by Side Diff: base/sys_info.h

Issue 2558043007: Fix free memory calculation. (Closed)
Patch Set: Fix various things again. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_SYS_INFO_H_ 5 #ifndef BASE_SYS_INFO_H_
6 #define BASE_SYS_INFO_H_ 6 #define BASE_SYS_INFO_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <map> 11 #include <map>
12 #include <string> 12 #include <string>
13 13
14 #include "base/base_export.h" 14 #include "base/base_export.h"
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/gtest_prod_util.h"
16 #include "base/time/time.h" 17 #include "base/time/time.h"
17 #include "build/build_config.h" 18 #include "build/build_config.h"
18 19
20 FORWARD_DECLARE_TEST(SysInfoTest, AmountOfAvailablePhysicalMemory);
danakj 2017/03/13 16:01:21 I think you don't need these if the tests are in t
Michael K. (Yandex Team) 2017/03/14 03:49:09 Done.
21
19 namespace base { 22 namespace base {
20 23
24 namespace debug {
25 FORWARD_DECLARE_TEST(SystemMetricsTest, ParseMeminfo);
26 }
27
28 struct SystemMemoryInfoKB;
29
21 class BASE_EXPORT SysInfo { 30 class BASE_EXPORT SysInfo {
22 public: 31 public:
23 // Return the number of logical processors/cores on the current machine. 32 // Return the number of logical processors/cores on the current machine.
24 static int NumberOfProcessors(); 33 static int NumberOfProcessors();
25 34
26 // Return the number of bytes of physical memory on the current machine. 35 // Return the number of bytes of physical memory on the current machine.
27 static int64_t AmountOfPhysicalMemory(); 36 static int64_t AmountOfPhysicalMemory();
28 37
29 // Return the number of bytes of current available physical memory on the 38 // Return the number of bytes of current available physical memory on the
30 // machine. 39 // machine.
40 // (The amount of memory that can be allocated without any significant
41 // impact on the system. It can lead to freeing inactive file-backed
42 // and/or speculative file-backed memory).
31 static int64_t AmountOfAvailablePhysicalMemory(); 43 static int64_t AmountOfAvailablePhysicalMemory();
32 44
33 // Return the number of bytes of virtual memory of this process. A return 45 // 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 46 // value of zero means that there is no limit on the available virtual
35 // memory. 47 // memory.
36 static int64_t AmountOfVirtualMemory(); 48 static int64_t AmountOfVirtualMemory();
37 49
38 // Return the number of megabytes of physical memory on the current machine. 50 // Return the number of megabytes of physical memory on the current machine.
39 static int AmountOfPhysicalMemoryMB() { 51 static int AmountOfPhysicalMemoryMB() {
40 return static_cast<int>(AmountOfPhysicalMemory() / 1024 / 1024); 52 return static_cast<int>(AmountOfPhysicalMemory() / 1024 / 1024);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 static std::string GetAndroidBuildID(); 152 static std::string GetAndroidBuildID();
141 153
142 static int DalvikHeapSizeMB(); 154 static int DalvikHeapSizeMB();
143 static int DalvikHeapGrowthLimitMB(); 155 static int DalvikHeapGrowthLimitMB();
144 #endif // defined(OS_ANDROID) 156 #endif // defined(OS_ANDROID)
145 157
146 // Returns true if this is a low-end device. 158 // Returns true if this is a low-end device.
147 // Low-end device refers to devices having less than 512M memory in the 159 // Low-end device refers to devices having less than 512M memory in the
148 // current implementation. 160 // current implementation.
149 static bool IsLowEndDevice(); 161 static bool IsLowEndDevice();
162
163 private:
164 FRIEND_TEST_ALL_PREFIXES(::SysInfoTest, AmountOfAvailablePhysicalMemory);
165 FRIEND_TEST_ALL_PREFIXES(::base::debug::SystemMetricsTest, ParseMeminfo);
166
167 #if defined(OS_LINUX) || defined(OS_ANDROID)
168 static int64_t AmountOfAvailablePhysicalMemory(
169 const SystemMemoryInfoKB& meminfo);
170 #endif
150 }; 171 };
151 172
152 } // namespace base 173 } // namespace base
153 174
154 #endif // BASE_SYS_INFO_H_ 175 #endif // BASE_SYS_INFO_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698