
I mistakenly ommitted the checks when logging.h was ported from libjingle to webrtc. This caused a significant CPU cost for logs which were later filtered out anyway. Verified with LS_VERBOSE logging in neteq4, running: $ out/Release/modules_unittests \ --gtest_filter=NetEqDecodingTest.TestBitExactness \ --gtest_repeat=50 > time.txt $ grep "case ran" time.txt | grep "[0-9]* ms" -o | sort Results on a MacBook Retina, averaged over 5 runs: Verbose logs disabled: 666 ms Exisiting implementation, verbose logs enabled: 944 ms (1.42x) New implementation, verbose logs enabled: 673 ms (1.01x) BUG=2314 R=henrik.lundin@webrtc.org, henrike@webrtc.org, kjellander@webrtc.org, turaj@webrtc.org Review URL: https://webrtc-codereview.appspot.com/2160005 git-svn-id: http://webrtc.googlecode.com/svn/trunk@4682 4adac7df-926f-26a2-2b94-8c16560cd09d
83 lines
2.0 KiB
C++
83 lines
2.0 KiB
C++
/*
|
|
* 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.
|
|
*/
|
|
|
|
#ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_UNITTEST_UTILITIES_H_
|
|
#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_UNITTEST_UTILITIES_H_
|
|
|
|
// This file contains utilities that make it simpler to write unittests
|
|
// that are appropriate for the system_wrappers classes.
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include "webrtc/system_wrappers/interface/trace.h"
|
|
|
|
namespace webrtc {
|
|
|
|
class TestTraceCallback : public TraceCallback {
|
|
public:
|
|
virtual void Print(TraceLevel level, const char* msg, int length) {
|
|
if (msg) {
|
|
char* cmd_print = new char[length+1];
|
|
memcpy(cmd_print, msg, length);
|
|
cmd_print[length] = '\0';
|
|
printf("%s\n", cmd_print);
|
|
fflush(stdout);
|
|
delete[] cmd_print;
|
|
}
|
|
}
|
|
};
|
|
|
|
// A class that turns on tracing to stdout at the beginning of the test,
|
|
// and turns it off once the test is finished.
|
|
// Intended usage:
|
|
// class SomeTest : public ::testing::Test {
|
|
// protected:
|
|
// SomeTest()
|
|
// : trace_(false) {} // Change to true to turn on tracing.
|
|
// private:
|
|
// ScopedTracing trace_;
|
|
// }
|
|
class ScopedTracing {
|
|
public:
|
|
explicit ScopedTracing(bool logOn) {
|
|
logging_ = logOn;
|
|
StartTrace();
|
|
}
|
|
|
|
~ScopedTracing() {
|
|
StopTrace();
|
|
}
|
|
|
|
private:
|
|
void StartTrace() {
|
|
if (logging_) {
|
|
Trace::CreateTrace();
|
|
Trace::set_level_filter(webrtc::kTraceAll);
|
|
Trace::SetTraceCallback(&trace_);
|
|
}
|
|
}
|
|
|
|
void StopTrace() {
|
|
if (logging_) {
|
|
Trace::SetTraceCallback(NULL);
|
|
Trace::ReturnTrace();
|
|
}
|
|
}
|
|
|
|
private:
|
|
bool logging_;
|
|
TestTraceCallback trace_;
|
|
};
|
|
|
|
} // namespace webrtc
|
|
|
|
#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_UNITTEST_UTILITIES_H_
|