OLD | NEW |
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 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/statvfs.h> | 9 #include <sys/statvfs.h> |
10 #include <sys/utsname.h> | 10 #include <sys/utsname.h> |
11 #include <unistd.h> | 11 #include <unistd.h> |
12 | 12 |
13 #if !defined(OS_MACOSX) | 13 #if !defined(OS_MACOSX) |
14 #include <gdk/gdk.h> | 14 #include <gdk/gdk.h> |
15 #endif | 15 #endif |
16 | 16 |
17 #if defined(OS_OPENBSD) | 17 #if defined(OS_OPENBSD) |
18 #include <sys/param.h> | 18 #include <sys/param.h> |
19 #include <sys/sysctl.h> | 19 #include <sys/sysctl.h> |
20 #endif | 20 #endif |
21 | 21 |
22 #include "base/basictypes.h" | 22 #include "base/basictypes.h" |
23 #include "base/file_util.h" | 23 #include "base/file_util.h" |
24 #include "base/logging.h" | 24 #include "base/logging.h" |
25 #include "base/utf_string_conversions.h" | 25 #include "base/utf_string_conversions.h" |
26 | 26 |
27 namespace base { | 27 namespace base { |
28 | 28 |
| 29 #if !defined(OS_OPENBSD) |
29 int SysInfo::NumberOfProcessors() { | 30 int SysInfo::NumberOfProcessors() { |
30 #if defined(OS_OPENBSD) | |
31 int mib[] = { CTL_HW, HW_NCPU }; | |
32 int ncpu; | |
33 size_t size = sizeof(ncpu); | |
34 if (sysctl(mib, 2, &ncpu, &size, NULL, 0) == -1) { | |
35 NOTREACHED(); | |
36 return 1; | |
37 } | |
38 return ncpu; | |
39 #else | |
40 // It seems that sysconf returns the number of "logical" processors on both | 31 // It seems that sysconf returns the number of "logical" processors on both |
41 // mac and linux. So we get the number of "online logical" processors. | 32 // Mac and Linux. So we get the number of "online logical" processors. |
42 long res = sysconf(_SC_NPROCESSORS_ONLN); | 33 long res = sysconf(_SC_NPROCESSORS_ONLN); |
43 if (res == -1) { | 34 if (res == -1) { |
44 NOTREACHED(); | 35 NOTREACHED(); |
45 return 1; | 36 return 1; |
46 } | 37 } |
47 | 38 |
48 return static_cast<int>(res); | 39 return static_cast<int>(res); |
49 #endif | |
50 } | |
51 | |
52 #if !defined(OS_MACOSX) | |
53 // static | |
54 int64 SysInfo::AmountOfPhysicalMemory() { | |
55 #if defined(OS_FREEBSD) | |
56 // _SC_PHYS_PAGES is not part of POSIX and not available on OS X or | |
57 // FreeBSD | |
58 // TODO(benl): I have no idea how to get this | |
59 NOTIMPLEMENTED(); | |
60 return 0; | |
61 #else | |
62 long pages = sysconf(_SC_PHYS_PAGES); | |
63 long page_size = sysconf(_SC_PAGE_SIZE); | |
64 if (pages == -1 || page_size == -1) { | |
65 NOTREACHED(); | |
66 return 0; | |
67 } | |
68 | |
69 return static_cast<int64>(pages) * page_size; | |
70 #endif | |
71 } | 40 } |
72 #endif | 41 #endif |
73 | 42 |
74 // static | 43 // static |
75 int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) { | 44 int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) { |
76 struct statvfs stats; | 45 struct statvfs stats; |
77 if (statvfs(path.value().c_str(), &stats) != 0) { | 46 if (statvfs(path.value().c_str(), &stats) != 0) { |
78 return -1; | 47 return -1; |
79 } | 48 } |
80 return static_cast<int64>(stats.f_bavail) * stats.f_frsize; | 49 return static_cast<int64>(stats.f_bavail) * stats.f_frsize; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 GdkScreen* screen = gdk_screen_get_default(); | 118 GdkScreen* screen = gdk_screen_get_default(); |
150 return gdk_screen_get_n_monitors(screen); | 119 return gdk_screen_get_n_monitors(screen); |
151 } | 120 } |
152 #endif | 121 #endif |
153 | 122 |
154 // static | 123 // static |
155 size_t SysInfo::VMAllocationGranularity() { | 124 size_t SysInfo::VMAllocationGranularity() { |
156 return getpagesize(); | 125 return getpagesize(); |
157 } | 126 } |
158 | 127 |
159 #if defined(OS_LINUX) | |
160 // static | |
161 size_t SysInfo::MaxSharedMemorySize() { | |
162 static size_t limit; | |
163 static bool limit_valid = false; | |
164 | |
165 if (!limit_valid) { | |
166 std::string contents; | |
167 file_util::ReadFileToString(FilePath("/proc/sys/kernel/shmmax"), &contents); | |
168 limit = strtoul(contents.c_str(), NULL, 0); | |
169 limit_valid = true; | |
170 } | |
171 | |
172 return limit; | |
173 } | |
174 #endif | |
175 | |
176 } // namespace base | 128 } // namespace base |
OLD | NEW |