/* * Copyright 2004 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.
*/
// Returns the contents of the internal log stream. // Note that parts of the stream won't (as is) be available until *after* the // dtor of the parent class has run. So, as is, this only represents a // partially built stream.
std::string GetPrintStream() {
RTC_DCHECK(!is_finished_);
is_finished_ = true;
FinishPrintStream(); return print_stream_.Release();
}
private: bool is_finished_ = false;
};
// Test basic logging operation. We should get the INFO log but not the VERBOSE. // We should restore the correct global state at the end.
TEST(LogTest, SingleStream) { int sev = LogMessage::GetLogToStream(nullptr);
// Test using multiple log streams. The INFO stream should get the INFO message, // the VERBOSE stream should get the INFO and the VERBOSE. // We should restore the correct global state at the end.
TEST(LogTest, MultipleStreams) { int sev = LogMessage::GetLogToStream(nullptr);
// Ensure we don't crash when adding/removing streams while threads are going. // We should restore the correct global state at the end.
TEST(LogTest, MultipleThreads) { int sev = LogMessage::GetLogToStream(nullptr);
TEST(LogTest, WallClockStartTime) {
uint32_t time = LogMessage::WallClockStartTime(); // Expect the time to be in a sensible range, e.g. > 2012-01-01.
EXPECT_GT(time, 1325376000u);
}
// Test the time required to write 1000 80-character logs to a string.
TEST(LogTest, Perf) {
std::string str;
LogSinkImpl stream(&str);
LogMessage::AddLogToStream(&stream, LS_VERBOSE);
// We now know how many bytes the logging framework will tag onto every msg. const size_t logging_overhead = str.size(); // Reset the stream to 0 size.
str.clear();
str.reserve(120000); staticconstint kRepetitions = 1000;
int64_t start = TimeMillis(), finish; for (int i = 0; i < kRepetitions; ++i) {
LogMessageForTesting(__FILE__, __LINE__, LS_VERBOSE).stream() << message;
}
finish = TimeMillis();
TEST(LogTest, NoopSeverityDoesNotRunStringFormatting) { if (!LogMessage::IsNoop(LS_VERBOSE)) {
RTC_LOG(LS_WARNING) << "Skipping test since verbose logging is turned on."; return;
} bool was_called = false; auto cb = [&was_called]() {
was_called = true; return"This could be an expensive callback.";
};
RTC_LOG(LS_VERBOSE) << "This should not be logged: " << cb();
EXPECT_FALSE(was_called);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.