Review URL: http://webrtc-codereview.appspot.com/292007

git-svn-id: http://webrtc.googlecode.com/svn/trunk@1053 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
henrike@webrtc.org 2011-11-29 18:21:46 +00:00
parent 5fef05b529
commit 0bf2ca2eed
2 changed files with 16 additions and 10 deletions

View File

@ -32,6 +32,8 @@ public:
// Note that the pointer passed as cpu_usage is redirected to a local member
// of the CPU wrapper.
// numCores is the number of cores in the cpu_usage array.
// The return value is -1 for failure or 0-100, indicating the average
// CPU usage across all cores.
// Note: on some OSs this class is initialized lazy. This means that it
// might not yet be possible to retrieve any CPU metrics. When this happens
// the return value will be zero (indicating that there is not a failure),

View File

@ -13,11 +13,14 @@
#include "gtest/gtest.h"
#include "system_wrappers/interface/cpu_info.h"
#include "system_wrappers/interface/event_wrapper.h"
#include "system_wrappers/interface/scoped_ptr.h"
#include "system_wrappers/interface/trace.h"
#include "testsupport/fileutils.h"
using webrtc::CpuInfo;
using webrtc::CpuWrapper;
using webrtc::EventWrapper;
using webrtc::scoped_ptr;
using webrtc::Trace;
TEST(CpuWrapperTest, Usage) {
@ -27,10 +30,10 @@ TEST(CpuWrapperTest, Usage) {
Trace::SetTraceFile(trace_file.c_str());
Trace::SetLevelFilter(webrtc::kTraceAll);
printf("Number of cores detected:%u\n", CpuInfo::DetectNumberOfCores());
CpuWrapper* cpu = CpuWrapper::CreateCpu();
ASSERT_TRUE(cpu != NULL);
webrtc::EventWrapper* sleep_event = webrtc::EventWrapper::Create();
ASSERT_TRUE(sleep_event != NULL);
scoped_ptr<CpuWrapper> cpu(CpuWrapper::CreateCpu());
ASSERT_TRUE(cpu.get() != NULL);
scoped_ptr<EventWrapper> sleep_event(EventWrapper::Create());
ASSERT_TRUE(sleep_event.get() != NULL);
int num_iterations = 0;
WebRtc_UWord32 num_cores = 0;
@ -49,18 +52,19 @@ TEST(CpuWrapperTest, Usage) {
}
ASSERT_TRUE(cpu_usage_available);
const WebRtc_Word32 total = cpu->CpuUsageMultiCore(num_cores, cores);
const WebRtc_Word32 average = cpu->CpuUsageMultiCore(num_cores, cores);
ASSERT_TRUE(cores != NULL);
EXPECT_GT(num_cores, 0u);
EXPECT_GE(total, 0);
EXPECT_GE(average, 0);
EXPECT_LE(average, 100);
printf("\nNumCores:%d\n", num_cores);
printf("Total cpu:%d\n", total);
printf("\nNumber of cores:%d\n", num_cores);
printf("Average cpu:%d\n", average);
for (WebRtc_UWord32 i = 0; i < num_cores; i++) {
printf("Core:%u CPU:%u \n", i, cores[i]);
EXPECT_LE(cores[i], static_cast<WebRtc_UWord32> (total));
EXPECT_GE(cores[i], 0u);
EXPECT_LE(cores[i], 100u);
}
delete cpu;
Trace::ReturnTrace();
};