OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "base/sys_info.h" | 5 #include "base/sys_info.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <string.h> | 8 #include <string.h> |
9 #include <sys/param.h> | 9 #include <sys/param.h> |
| 10 #include <sys/resource.h> |
10 #include <sys/utsname.h> | 11 #include <sys/utsname.h> |
11 #include <unistd.h> | 12 #include <unistd.h> |
12 | 13 |
13 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
14 #include "base/file_util.h" | 15 #include "base/file_util.h" |
15 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
16 #include "base/logging.h" | 17 #include "base/logging.h" |
17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
18 #include "base/sys_info_internal.h" | 19 #include "base/sys_info_internal.h" |
19 #include "base/threading/thread_restrictions.h" | 20 #include "base/threading/thread_restrictions.h" |
(...skipping 18 matching lines...) Expand all Loading... |
38 } | 39 } |
39 | 40 |
40 return static_cast<int>(res); | 41 return static_cast<int>(res); |
41 } | 42 } |
42 | 43 |
43 base::LazyInstance< | 44 base::LazyInstance< |
44 base::internal::LazySysInfoValue<int, NumberOfProcessors> >::Leaky | 45 base::internal::LazySysInfoValue<int, NumberOfProcessors> >::Leaky |
45 g_lazy_number_of_processors = LAZY_INSTANCE_INITIALIZER; | 46 g_lazy_number_of_processors = LAZY_INSTANCE_INITIALIZER; |
46 #endif | 47 #endif |
47 | 48 |
| 49 int64 AmountOfVirtualMemory() { |
| 50 struct rlimit limit; |
| 51 int result = getrlimit(RLIMIT_DATA, &limit); |
| 52 if (result != 0) { |
| 53 NOTREACHED(); |
| 54 return 0; |
| 55 } |
| 56 return limit.rlim_cur == RLIM_INFINITY ? 0 : limit.rlim_cur; |
| 57 } |
| 58 |
| 59 base::LazyInstance< |
| 60 base::internal::LazySysInfoValue<int64, AmountOfVirtualMemory> >::Leaky |
| 61 g_lazy_virtual_memory = LAZY_INSTANCE_INITIALIZER; |
| 62 |
48 } // namespace | 63 } // namespace |
49 | 64 |
50 namespace base { | 65 namespace base { |
51 | 66 |
52 #if !defined(OS_OPENBSD) | 67 #if !defined(OS_OPENBSD) |
53 int SysInfo::NumberOfProcessors() { | 68 int SysInfo::NumberOfProcessors() { |
54 return g_lazy_number_of_processors.Get().value(); | 69 return g_lazy_number_of_processors.Get().value(); |
55 } | 70 } |
56 #endif | 71 #endif |
57 | 72 |
58 // static | 73 // static |
| 74 int64 SysInfo::AmountOfVirtualMemory() { |
| 75 return g_lazy_virtual_memory.Get().value(); |
| 76 } |
| 77 |
| 78 // static |
59 int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) { | 79 int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) { |
60 base::ThreadRestrictions::AssertIOAllowed(); | 80 base::ThreadRestrictions::AssertIOAllowed(); |
61 | 81 |
62 struct statvfs stats; | 82 struct statvfs stats; |
63 if (HANDLE_EINTR(statvfs(path.value().c_str(), &stats)) != 0) | 83 if (HANDLE_EINTR(statvfs(path.value().c_str(), &stats)) != 0) |
64 return -1; | 84 return -1; |
65 return static_cast<int64>(stats.f_bavail) * stats.f_frsize; | 85 return static_cast<int64>(stats.f_bavail) * stats.f_frsize; |
66 } | 86 } |
67 | 87 |
68 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 88 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 } | 124 } |
105 return arch; | 125 return arch; |
106 } | 126 } |
107 | 127 |
108 // static | 128 // static |
109 size_t SysInfo::VMAllocationGranularity() { | 129 size_t SysInfo::VMAllocationGranularity() { |
110 return getpagesize(); | 130 return getpagesize(); |
111 } | 131 } |
112 | 132 |
113 } // namespace base | 133 } // namespace base |
OLD | NEW |