From c58ef08da2e33ba6b5dccdd81a88baf7bbac7e34 Mon Sep 17 00:00:00 2001 From: "henrikg@webrtc.org" Date: Tue, 8 Nov 2011 08:44:17 +0000 Subject: [PATCH] Removes system CPU measurement for Chrome build. It does not work on Chrome Windows, and is anyway not needed for Chrome. Review URL: http://webrtc-codereview.appspot.com/243006 git-svn-id: http://webrtc.googlecode.com/svn/trunk@902 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../codecs/test/videoprocessor.cc | 4 +- src/system_wrappers/interface/cpu_info.h | 27 +++++++ src/system_wrappers/interface/cpu_wrapper.h | 6 -- src/system_wrappers/source/cpu.cc | 49 ------------- src/system_wrappers/source/cpu_dummy.cc | 22 ++++++ src/system_wrappers/source/cpu_info.cc | 72 +++++++++++++++++++ .../source/cpu_wrapper_unittest.cc | 8 ++- .../source/system_wrappers.gyp | 12 ++++ .../main/source/vie_shared_data.cc | 4 +- 9 files changed, 142 insertions(+), 62 deletions(-) create mode 100644 src/system_wrappers/interface/cpu_info.h create mode 100644 src/system_wrappers/source/cpu_dummy.cc create mode 100644 src/system_wrappers/source/cpu_info.cc diff --git a/src/modules/video_coding/codecs/test/videoprocessor.cc b/src/modules/video_coding/codecs/test/videoprocessor.cc index 75ccad90b..620fc3763 100644 --- a/src/modules/video_coding/codecs/test/videoprocessor.cc +++ b/src/modules/video_coding/codecs/test/videoprocessor.cc @@ -13,7 +13,7 @@ #include #include -#include "cpu_wrapper.h" +#include "cpu_info.h" #include "util.h" namespace webrtc { @@ -79,7 +79,7 @@ bool VideoProcessorImpl::Init() { // Init the encoder and decoder WebRtc_UWord32 nbr_of_cores = 1; if (!config_.use_single_core) { - nbr_of_cores = CpuWrapper::DetectNumberOfCores(); + nbr_of_cores = CpuInfo::DetectNumberOfCores(); } WebRtc_Word32 init_result = encoder_->InitEncode(&config_.codec_settings, nbr_of_cores, diff --git a/src/system_wrappers/interface/cpu_info.h b/src/system_wrappers/interface/cpu_info.h new file mode 100644 index 000000000..a6da29f3d --- /dev/null +++ b/src/system_wrappers/interface/cpu_info.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_CPU_INFO_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_CPU_INFO_H_ + +#include "typedefs.h" + +namespace webrtc { +class CpuInfo +{ +public: + static WebRtc_UWord32 DetectNumberOfCores(); + +private: + CpuInfo() {} + static WebRtc_UWord32 _numberOfCores; +}; +} // namespace webrtc +#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_CPU_INFO_H_ diff --git a/src/system_wrappers/interface/cpu_wrapper.h b/src/system_wrappers/interface/cpu_wrapper.h index b72c20cd5..bcc6a81b5 100644 --- a/src/system_wrappers/interface/cpu_wrapper.h +++ b/src/system_wrappers/interface/cpu_wrapper.h @@ -17,8 +17,6 @@ namespace webrtc { class CpuWrapper { public: - static WebRtc_UWord32 DetectNumberOfCores(); - static CpuWrapper* CreateCpu(); virtual ~CpuWrapper() {} @@ -42,10 +40,6 @@ public: protected: CpuWrapper() {} - -private: - static WebRtc_UWord32 _numberOfCores; - }; } // namespace webrtc #endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_CPU_WRAPPER_H_ diff --git a/src/system_wrappers/source/cpu.cc b/src/system_wrappers/source/cpu.cc index 56dbfbde2..258390f26 100644 --- a/src/system_wrappers/source/cpu.cc +++ b/src/system_wrappers/source/cpu.cc @@ -11,67 +11,18 @@ #include "cpu_wrapper.h" #if defined(_WIN32) - #include - #include "engine_configurations.h" #include "cpu_windows.h" #elif defined(WEBRTC_MAC) - #include - #include #include "cpu_mac.h" #elif defined(WEBRTC_MAC_INTEL) #include "cpu_mac.h" #elif defined(WEBRTC_ANDROID) // Not implemented yet, might be possible to use Linux implementation #else // defined(WEBRTC_LINUX) - #include #include "cpu_linux.h" #endif -#include "trace.h" - namespace webrtc { -WebRtc_UWord32 CpuWrapper::_numberOfCores = 0; - -WebRtc_UWord32 CpuWrapper::DetectNumberOfCores() -{ - if (!_numberOfCores) - { -#if defined(_WIN32) - SYSTEM_INFO si; - GetSystemInfo(&si); - _numberOfCores = static_cast(si.dwNumberOfProcessors); - WEBRTC_TRACE(kTraceStateInfo, kTraceUtility, -1, - "Available number of cores:%d", _numberOfCores); - -#elif defined(WEBRTC_LINUX) && !defined(WEBRTC_ANDROID) - _numberOfCores = get_nprocs(); - WEBRTC_TRACE(kTraceStateInfo, kTraceUtility, -1, - "Available number of cores:%d", _numberOfCores); - -#elif (defined(WEBRTC_MAC) || defined(WEBRTC_MAC_INTEL)) - int name[] = {CTL_HW, HW_AVAILCPU}; - int ncpu; - size_t size = sizeof(ncpu); - if(0 == sysctl(name, 2, &ncpu, &size, NULL, 0)) - { - _numberOfCores = static_cast(ncpu); - WEBRTC_TRACE(kTraceStateInfo, kTraceUtility, -1, - "Available number of cores:%d", _numberOfCores); - } else - { - WEBRTC_TRACE(kTraceError, kTraceUtility, -1, - "Failed to get number of cores"); - _numberOfCores = 1; - } -#else - WEBRTC_TRACE(kTraceWarning, kTraceUtility, -1, - "No function to get number of cores"); - _numberOfCores = 1; -#endif - } - return _numberOfCores; -} - CpuWrapper* CpuWrapper::CreateCpu() { #if defined(_WIN32) diff --git a/src/system_wrappers/source/cpu_dummy.cc b/src/system_wrappers/source/cpu_dummy.cc new file mode 100644 index 000000000..e42ef9184 --- /dev/null +++ b/src/system_wrappers/source/cpu_dummy.cc @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include + +#include "cpu_wrapper.h" + +namespace webrtc { + +CpuWrapper* CpuWrapper::CreateCpu() +{ + return NULL; +} + +} // namespace webrtc diff --git a/src/system_wrappers/source/cpu_info.cc b/src/system_wrappers/source/cpu_info.cc new file mode 100644 index 000000000..e367abfbd --- /dev/null +++ b/src/system_wrappers/source/cpu_info.cc @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "cpu_info.h" + +#if defined(_WIN32) +#include +#elif defined(WEBRTC_MAC) +#include +#include +#elif defined(WEBRTC_MAC_INTEL) +// Intentionally empty +#elif defined(WEBRTC_ANDROID) +// Not implemented yet, might be possible to use Linux implementation +#else // defined(WEBRTC_LINUX) +#include +#endif + +#include "trace.h" + +namespace webrtc { + +WebRtc_UWord32 CpuInfo::_numberOfCores = 0; + +WebRtc_UWord32 CpuInfo::DetectNumberOfCores() +{ + if (!_numberOfCores) + { +#if defined(_WIN32) + SYSTEM_INFO si; + GetSystemInfo(&si); + _numberOfCores = static_cast(si.dwNumberOfProcessors); + WEBRTC_TRACE(kTraceStateInfo, kTraceUtility, -1, + "Available number of cores:%d", _numberOfCores); + +#elif defined(WEBRTC_LINUX) && !defined(WEBRTC_ANDROID) + _numberOfCores = get_nprocs(); + WEBRTC_TRACE(kTraceStateInfo, kTraceUtility, -1, + "Available number of cores:%d", _numberOfCores); + +#elif (defined(WEBRTC_MAC) || defined(WEBRTC_MAC_INTEL)) + int name[] = {CTL_HW, HW_AVAILCPU}; + int ncpu; + size_t size = sizeof(ncpu); + if(0 == sysctl(name, 2, &ncpu, &size, NULL, 0)) + { + _numberOfCores = static_cast(ncpu); + WEBRTC_TRACE(kTraceStateInfo, kTraceUtility, -1, + "Available number of cores:%d", _numberOfCores); + } else + { + WEBRTC_TRACE(kTraceError, kTraceUtility, -1, + "Failed to get number of cores"); + _numberOfCores = 1; + } +#else + WEBRTC_TRACE(kTraceWarning, kTraceUtility, -1, + "No function to get number of cores"); + _numberOfCores = 1; +#endif + } + return _numberOfCores; +} + +} // namespace webrtc diff --git a/src/system_wrappers/source/cpu_wrapper_unittest.cc b/src/system_wrappers/source/cpu_wrapper_unittest.cc index 16f6fe1b9..e2e8fb0a7 100644 --- a/src/system_wrappers/source/cpu_wrapper_unittest.cc +++ b/src/system_wrappers/source/cpu_wrapper_unittest.cc @@ -11,20 +11,22 @@ #include "system_wrappers/interface/cpu_wrapper.h" #include "gtest/gtest.h" +#include "system_wrappers/interface/cpu_info.h" #include "system_wrappers/interface/trace.h" +using webrtc::CpuInfo; using webrtc::CpuWrapper; using webrtc::Trace; -// Only utilizes some of the cpu_wrapper.h code. Does not very anything except -// that it doesn't crash. +// Only utilizes some of the cpu_info.h and cpu_wrapper.h code. Does not verify +// anything except that it doesn't crash. // TODO(kjellander): Improve this test so it verifies the implementation // executes as expected. TEST(CpuWrapperTest, Usage) { Trace::CreateTrace(); Trace::SetTraceFile("cpu_wrapper_unittest.txt"); Trace::SetLevelFilter(webrtc::kTraceAll); - printf("Number of cores detected:%u\n", CpuWrapper::DetectNumberOfCores()); + printf("Number of cores detected:%u\n", CpuInfo::DetectNumberOfCores()); CpuWrapper* cpu = CpuWrapper::CreateCpu(); WebRtc_UWord32 numCores; WebRtc_UWord32* cores; diff --git a/src/system_wrappers/source/system_wrappers.gyp b/src/system_wrappers/source/system_wrappers.gyp index 3eabc4edf..fd150207e 100644 --- a/src/system_wrappers/source/system_wrappers.gyp +++ b/src/system_wrappers/source/system_wrappers.gyp @@ -29,6 +29,7 @@ '../interface/aligned_malloc.h', '../interface/atomic32_wrapper.h', '../interface/condition_variable_wrapper.h', + '../interface/cpu_info.h', '../interface/cpu_wrapper.h', '../interface/cpu_features_wrapper.h', '../interface/critical_section_wrapper.h', @@ -57,6 +58,8 @@ 'condition_variable_posix.h', 'condition_variable_windows.h', 'cpu.cc', + 'cpu_dummy.cc', + 'cpu_info.cc', 'cpu_linux.h', 'cpu_mac.h', 'cpu_windows.h', @@ -141,6 +144,15 @@ ], }, }], + ['build_with_chromium==1', { + 'sources!': [ + 'cpu.cc', + ], + }, { + 'sources!': [ + 'cpu_dummy.cc', + ], + }] ] # conditions }, ], # targets diff --git a/src/video_engine/main/source/vie_shared_data.cc b/src/video_engine/main/source/vie_shared_data.cc index 4bf2c3cd7..9412772b3 100644 --- a/src/video_engine/main/source/vie_shared_data.cc +++ b/src/video_engine/main/source/vie_shared_data.cc @@ -13,7 +13,7 @@ #include "vie_shared_data.h" #include "vie_defines.h" -#include "cpu_wrapper.h" +#include "cpu_info.h" #include "critical_section_wrapper.h" #include "process_thread.h" #include "trace.h" @@ -30,7 +30,7 @@ ViESharedData::ViESharedData() : _instanceId(++_instanceCounter), _apiCritsect(*CriticalSectionWrapper::CreateCriticalSection()), _isInitialized(false), - _numberOfCores(CpuWrapper::DetectNumberOfCores()), + _numberOfCores(CpuInfo::DetectNumberOfCores()), _viePerformanceMonitor(ViEPerformanceMonitor(_instanceId)), _channelManager(*new ViEChannelManager(_instanceId, _numberOfCores, _viePerformanceMonitor)),