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) return 0; | |
Mark Mentovai
2014/04/08 18:49:57
It’s a little weird to use 0 for both the failure
jochen (gone - plz use gerrit)
2014/04/08 19:26:31
this call should never fail. I can add NOTREACHED(
| |
53 return limit.rlim_cur == RLIM_INFINITY ? 0 : limit.rlim_cur; | |
54 } | |
55 | |
56 base::LazyInstance< | |
57 base::internal::LazySysInfoValue<int64, AmountOfVirtualMemory> >::Leaky | |
58 g_lazy_virtual_memory = LAZY_INSTANCE_INITIALIZER; | |
59 | |
48 } // namespace | 60 } // namespace |
49 | 61 |
50 namespace base { | 62 namespace base { |
51 | 63 |
52 #if !defined(OS_OPENBSD) | 64 #if !defined(OS_OPENBSD) |
53 int SysInfo::NumberOfProcessors() { | 65 int SysInfo::NumberOfProcessors() { |
54 return g_lazy_number_of_processors.Get().value(); | 66 return g_lazy_number_of_processors.Get().value(); |
55 } | 67 } |
56 #endif | 68 #endif |
57 | 69 |
58 // static | 70 // static |
71 int64 SysInfo::AmountOfVirtualMemory() { | |
72 return g_lazy_virtual_memory.Get().value(); | |
73 } | |
74 | |
75 // static | |
59 int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) { | 76 int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) { |
60 base::ThreadRestrictions::AssertIOAllowed(); | 77 base::ThreadRestrictions::AssertIOAllowed(); |
61 | 78 |
62 struct statvfs stats; | 79 struct statvfs stats; |
63 if (HANDLE_EINTR(statvfs(path.value().c_str(), &stats)) != 0) | 80 if (HANDLE_EINTR(statvfs(path.value().c_str(), &stats)) != 0) |
64 return -1; | 81 return -1; |
65 return static_cast<int64>(stats.f_bavail) * stats.f_frsize; | 82 return static_cast<int64>(stats.f_bavail) * stats.f_frsize; |
66 } | 83 } |
67 | 84 |
68 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 85 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 } | 121 } |
105 return arch; | 122 return arch; |
106 } | 123 } |
107 | 124 |
108 // static | 125 // static |
109 size_t SysInfo::VMAllocationGranularity() { | 126 size_t SysInfo::VMAllocationGranularity() { |
110 return getpagesize(); | 127 return getpagesize(); |
111 } | 128 } |
112 | 129 |
113 } // namespace base | 130 } // namespace base |
OLD | NEW |