blob: 982e71572643e3578b9bd7732f80988331a89aae [file] [log] [blame]
* Copyright (c) 2012 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 "system_wrappers/interface/trace.h"
#include "gtest/gtest.h"
#include "system_wrappers/source/cpu_measurement_harness.h"
#include "testsupport/fileutils.h"
using webrtc::CpuMeasurementHarness;
using webrtc::Trace;
using webrtc::kTraceWarning;
using webrtc::kTraceUtility;
class Logger : public webrtc::CpuTarget {
Logger() {
std::string trace_file = webrtc::test::OutputPath() +
virtual ~Logger() {
virtual bool DoWork() {
// Use input paremeters to WEBRTC_TRACE that are not likely to be removed
// in future code. E.g. warnings will likely be kept and this file is in
// utility so it should use kTraceUtility.
WEBRTC_TRACE(kTraceWarning, kTraceUtility, 0, "Log line");
return true;
// This test is disabled because it measures CPU usage. This is flaky because
// the CPU usage for a machine may spike due to OS or other application.
TEST(TraceTest, DISABLED_CpuUsage) {
Logger logger;
const int periodicity_ms = 1;
const int iterations_per_period = 10;
const int duration_ms = 1000;
CpuMeasurementHarness* cpu_harness =
CpuMeasurementHarness::Create(&logger, periodicity_ms,
iterations_per_period, duration_ms);
const int average_cpu = cpu_harness->AverageCpu();
EXPECT_GE(5, average_cpu);