summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authordeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-17 10:09:39 +0000
committerdeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-17 10:09:39 +0000
commit2a758d61d9ee5c8ae43bf5a6d974d27cc6779ef2 (patch)
tree7cb3e04c299f96ab01d0848c47fbb0d0aedf7e97 /base
parentc1444fef13763a4f19215bdffb148f4d1a6c6098 (diff)
downloadchromium_src-2a758d61d9ee5c8ae43bf5a6d974d27cc6779ef2.zip
chromium_src-2a758d61d9ee5c8ae43bf5a6d974d27cc6779ef2.tar.gz
chromium_src-2a758d61d9ee5c8ae43bf5a6d974d27cc6779ef2.tar.bz2
Add a class for extracting system-specific information, like the number of processors.
Review URL: http://codereview.chromium.org/3084 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2302 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/SConscript3
-rw-r--r--base/base.xcodeproj/project.pbxproj16
-rw-r--r--base/build/base.vcproj8
-rw-r--r--base/build/base_unittests.vcproj4
-rw-r--r--base/sys_info.h18
-rw-r--r--base/sys_info_posix.cc28
-rw-r--r--base/sys_info_unittest.cc11
-rw-r--r--base/sys_info_win.cc18
8 files changed, 102 insertions, 4 deletions
diff --git a/base/SConscript b/base/SConscript
index 5705702..05da9ae 100644
--- a/base/SConscript
+++ b/base/SConscript
@@ -115,6 +115,7 @@ if env['PLATFORM'] == 'win32':
'process_util_win.cc',
'registry.cc',
'shared_memory_win.cc',
+ 'sys_info_win.cc',
'sys_string_conversions_win.cc',
'thread_local_storage_win.cc',
'thread_local_win.cc',
@@ -135,6 +136,7 @@ if env['PLATFORM'] in ('darwin', 'posix'):
'process_util_posix.cc',
'shared_memory_posix.cc',
'string16.cc',
+ 'sys_info_posix.cc',
'thread_local_storage_posix.cc',
'thread_local_posix.cc',
'time_posix.cc',
@@ -260,6 +262,7 @@ test_files = [
'string_piece_unittest.cc',
'string_tokenizer_unittest.cc',
'string_util_unittest.cc',
+ 'sys_info_unittest.cc',
'thread_local_unittest.cc',
'thread_local_storage_unittest.cc',
'thread_unittest.cc',
diff --git a/base/base.xcodeproj/project.pbxproj b/base/base.xcodeproj/project.pbxproj
index 0763b44..db625de 100644
--- a/base/base.xcodeproj/project.pbxproj
+++ b/base/base.xcodeproj/project.pbxproj
@@ -37,6 +37,8 @@
/* Begin PBXBuildFile section */
7B4C5F4A0E4B6BF900679E8F /* sys_string_conversions_mac.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7B4C5F480E4B6BF900679E8F /* sys_string_conversions_mac.cc */; };
7B4DF5350E5B6A66004D7619 /* libskia.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7B4DF5320E5B6A4B004D7619 /* libskia.a */; };
+ 7B6AF6340E80211C00F9F9CF /* sys_info_posix.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7B6AF6320E80211700F9F9CF /* sys_info_posix.cc */; };
+ 7B6AF6350E80211E00F9F9CF /* sys_info_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7B6AF6330E80211700F9F9CF /* sys_info_unittest.cc */; };
7B78CE120E53131800609465 /* debug_util_posix.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7B78CE100E53131800609465 /* debug_util_posix.cc */; };
7B78CE250E5314A000609465 /* debug_util.cc in Sources */ = {isa = PBXBuildFile; fileRef = 825402F20D92D1AC0006B936 /* debug_util.cc */; };
7B78D38C0E54FDEC00609465 /* libbase.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 825402BB0D92D0FA0006B936 /* libbase.a */; };
@@ -343,6 +345,9 @@
7B4C5F470E4B6BF900679E8F /* sys_string_conversions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sys_string_conversions.h; sourceTree = "<group>"; };
7B4C5F480E4B6BF900679E8F /* sys_string_conversions_mac.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sys_string_conversions_mac.cc; sourceTree = "<group>"; };
7B5AD60D0D9DD8050012BCF1 /* scoped_cftyperef.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scoped_cftyperef.h; sourceTree = "<group>"; };
+ 7B6AF6310E80211700F9F9CF /* sys_info.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sys_info.h; sourceTree = "<group>"; };
+ 7B6AF6320E80211700F9F9CF /* sys_info_posix.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sys_info_posix.cc; sourceTree = "<group>"; };
+ 7B6AF6330E80211700F9F9CF /* sys_info_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sys_info_unittest.cc; sourceTree = "<group>"; };
7B78CE100E53131800609465 /* debug_util_posix.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = debug_util_posix.cc; sourceTree = "<group>"; };
7B78D40D0E54FE8000609465 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = "<group>"; };
7B836C040E55BBB800F6AD31 /* ref_counted.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ref_counted.cc; sourceTree = "<group>"; };
@@ -361,7 +366,6 @@
7BAE30E40E6D939800C3F750 /* simple_thread_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = simple_thread_unittest.cc; sourceTree = "<group>"; };
7BAE38A80E6EFD9900C3F750 /* thread_local.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = thread_local.h; sourceTree = "<group>"; };
7BAE38A90E6EFD9900C3F750 /* thread_local_posix.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = thread_local_posix.cc; sourceTree = "<group>"; };
- 7BAE38AA0E6EFD9900C3F750 /* thread_local_storage_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = thread_local_storage_unittest.cc; sourceTree = "<group>"; };
7BAE38AB0E6EFD9900C3F750 /* thread_local_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = thread_local_unittest.cc; sourceTree = "<group>"; };
7BAE39220E6F4EEC00C3F750 /* hmac_mac.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = hmac_mac.cc; sourceTree = "<group>"; };
7BAE39240E6F4EEC00C3F750 /* hmac_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = hmac_unittest.cc; sourceTree = "<group>"; };
@@ -740,7 +744,6 @@
825402B60D92D0E20006B936 /* base */ = {
isa = PBXGroup;
children = (
- BA0F69860E79D7980079A8A1 /* thread_local_storage_unittest.cc */,
825403B40D92D2EC0006B936 /* gfx */,
E49115EC0E47B461001EE8C3 /* at_exit.cc */,
E49115EB0E47B461001EE8C3 /* at_exit.h */,
@@ -915,6 +918,9 @@
820EB4F90E3A6178009668FC /* string_util_icu.cc */,
7BAF50A90E50BACB00CA8A07 /* string_util_posix.h */,
7BAF50B10E50BAE700CA8A07 /* string_util_unittest.cc */,
+ 7B6AF6310E80211700F9F9CF /* sys_info.h */,
+ 7B6AF6320E80211700F9F9CF /* sys_info_posix.cc */,
+ 7B6AF6330E80211700F9F9CF /* sys_info_unittest.cc */,
7B4C5F470E4B6BF900679E8F /* sys_string_conversions.h */,
7B4C5F480E4B6BF900679E8F /* sys_string_conversions_mac.cc */,
8254037E0D92D2CF0006B936 /* task.h */,
@@ -924,7 +930,7 @@
7BAE38A90E6EFD9900C3F750 /* thread_local_posix.cc */,
825403820D92D2CF0006B936 /* thread_local_storage.h */,
829E36720DC0FBAD00819EBF /* thread_local_storage_posix.cc */,
- 7BAE38AA0E6EFD9900C3F750 /* thread_local_storage_unittest.cc */,
+ BA0F69860E79D7980079A8A1 /* thread_local_storage_unittest.cc */,
7BAE38AB0E6EFD9900C3F750 /* thread_local_unittest.cc */,
93E7031A0E5D64390046259B /* thread_unittest.cc */,
824654900DC25A8C007C2BAA /* time.cc */,
@@ -1286,6 +1292,7 @@
820EB4F70E3A613F009668FC /* string_piece.cc in Sources */,
829E36460DC0F6AC00819EBF /* string_util.cc in Sources */,
820EB4FA0E3A6178009668FC /* string_util_icu.cc in Sources */,
+ 7B6AF6340E80211C00F9F9CF /* sys_info_posix.cc in Sources */,
7B4C5F4A0E4B6BF900679E8F /* sys_string_conversions_mac.cc in Sources */,
93E703240E5D64F00046259B /* thread.cc in Sources */,
7BAE38AC0E6EFDBA00C3F750 /* thread_local_posix.cc in Sources */,
@@ -1360,8 +1367,9 @@
7B78D39F0E54FE0100609465 /* string_piece_unittest.cc in Sources */,
7B78D3A00E54FE0100609465 /* string_tokenizer_unittest.cc in Sources */,
7B78D3A10E54FE0100609465 /* string_util_unittest.cc in Sources */,
- 7BAE38AF0E6EFDC300C3F750 /* thread_local_unittest.cc in Sources */,
+ 7B6AF6350E80211E00F9F9CF /* sys_info_unittest.cc in Sources */,
BA0F69870E79D7980079A8A1 /* thread_local_storage_unittest.cc in Sources */,
+ 7BAE38AF0E6EFDC300C3F750 /* thread_local_unittest.cc in Sources */,
93E7031B0E5D64390046259B /* thread_unittest.cc in Sources */,
7B78D3A20E54FE0100609465 /* time_unittest.cc in Sources */,
BA739A030E5E3242009842A7 /* timer_unittest.cc in Sources */,
diff --git a/base/build/base.vcproj b/base/build/base.vcproj
index 2dd71a1..4eed57ea 100644
--- a/base/build/base.vcproj
+++ b/base/build/base.vcproj
@@ -694,6 +694,14 @@
>
</File>
<File
+ RelativePath="..\sys_info.h"
+ >
+ </File>
+ <File
+ RelativePath="..\sys_info_win.cc"
+ >
+ </File>
+ <File
RelativePath="..\sys_string_conversions.h"
>
</File>
diff --git a/base/build/base_unittests.vcproj b/base/build/base_unittests.vcproj
index c8db389..1fa32c9 100644
--- a/base/build/base_unittests.vcproj
+++ b/base/build/base_unittests.vcproj
@@ -308,6 +308,10 @@
>
</File>
<File
+ RelativePath="..\sys_info_unittest.cc"
+ >
+ </File>
+ <File
RelativePath="..\sys_string_conversions_win_unittest.cc"
>
</File>
diff --git a/base/sys_info.h b/base/sys_info.h
new file mode 100644
index 0000000..65949a0
--- /dev/null
+++ b/base/sys_info.h
@@ -0,0 +1,18 @@
+// Copyright (c) 2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_SYS_INFO_H_
+#define BASE_SYS_INFO_H_
+
+namespace base {
+
+class SysInfo {
+ public:
+ // Return the number of logical processors/cores on the current machine.
+ static int NumberOfProcessors();
+};
+
+} // namespace base
+
+#endif // BASE_SYS_INFO_H_
diff --git a/base/sys_info_posix.cc b/base/sys_info_posix.cc
new file mode 100644
index 0000000..093e607
--- /dev/null
+++ b/base/sys_info_posix.cc
@@ -0,0 +1,28 @@
+// Copyright (c) 2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/sys_info.h"
+
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "base/basictypes.h"
+#include "base/logging.h"
+
+namespace base {
+
+int SysInfo::NumberOfProcessors() {
+ // It seems that sysconf returns the number of "logical" processors on both
+ // mac and linux. So we get the number of "online logical" processors.
+ long res = sysconf(_SC_NPROCESSORS_ONLN);
+ if (res == -1) {
+ NOTREACHED();
+ return 1;
+ }
+
+ return static_cast<int>(res);
+}
+
+} // namespace base
diff --git a/base/sys_info_unittest.cc b/base/sys_info_unittest.cc
new file mode 100644
index 0000000..4ed2834
--- /dev/null
+++ b/base/sys_info_unittest.cc
@@ -0,0 +1,11 @@
+// Copyright (c) 2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/sys_info.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+TEST(SysInfoTest, NumProcs) {
+ // We aren't actually testing that it's correct, just that it's sane.
+ EXPECT_GE(base::SysInfo::NumberOfProcessors(), 1);
+}
diff --git a/base/sys_info_win.cc b/base/sys_info_win.cc
new file mode 100644
index 0000000..4d32489
--- /dev/null
+++ b/base/sys_info_win.cc
@@ -0,0 +1,18 @@
+// Copyright (c) 2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/sys_info.h"
+
+#include <windows.h>
+
+namespace base {
+
+// static
+int SysInfo::NumberOfProcessors() {
+ SYSTEM_INFO info;
+ GetSystemInfo(&info);
+ return static_cast<int>(info.dwNumberOfProcessors);
+}
+
+} // namespace base