Commit ae8d96a3 authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

If DCHECK_IS_ON(), don't truncate long logs on Android

Android truncates long logs in __android_log_write. This is useful
to avoid too verbose logs and save cpu/memory, but we do need some
complete verbose logs for debugging.

Now if DCHECK_IS_ON(), split long logs by new lines and call
__android_log_write for each line to avoid the truncation.

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Ib19c718a8f1d2fe1f2e155c38e1106174b38ae02
Reviewed-on: https://chromium-review.googlesource.com/c/1281883
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: default avatardanakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600111}
parent 836c6008
...@@ -95,6 +95,7 @@ typedef pthread_mutex_t* MutexHandle; ...@@ -95,6 +95,7 @@ typedef pthread_mutex_t* MutexHandle;
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/posix/eintr_wrapper.h" #include "base/posix/eintr_wrapper.h"
#include "base/strings/string_piece.h" #include "base/strings/string_piece.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
...@@ -770,8 +771,17 @@ LogMessage::~LogMessage() { ...@@ -770,8 +771,17 @@ LogMessage::~LogMessage() {
priority = ANDROID_LOG_FATAL; priority = ANDROID_LOG_FATAL;
break; break;
} }
#if DCHECK_IS_ON()
// Split the output by new lines to prevent the Android system from
// truncating the log.
for (const auto& line : base::SplitString(
str_newline, "\n", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL))
__android_log_write(priority, "chromium", line.c_str());
#else
// The Android system may truncate the string if it's too long.
__android_log_write(priority, "chromium", str_newline.c_str()); __android_log_write(priority, "chromium", str_newline.c_str());
#endif #endif
#endif // OS_ANDROID
ignore_result(fwrite(str_newline.data(), str_newline.size(), 1, stderr)); ignore_result(fwrite(str_newline.data(), str_newline.size(), 1, stderr));
fflush(stderr); fflush(stderr);
} else if (severity_ >= kAlwaysPrintErrorLevel) { } else if (severity_ >= kAlwaysPrintErrorLevel) {
......
...@@ -376,22 +376,14 @@ void LayerTreeHost::FinishCommitOnImplThread( ...@@ -376,22 +376,14 @@ void LayerTreeHost::FinishCommitOnImplThread(
// Dump property trees and layers if run with: // Dump property trees and layers if run with:
// --vmodule=layer_tree_host=3 // --vmodule=layer_tree_host=3
if (VLOG_IS_ON(3)) { if (VLOG_IS_ON(3)) {
VLOG(3) << "After finishing commit on impl, the sync tree:";
// Because the property tree and layer list output can be verbose, the VLOG
// output is split by line to avoid line buffer limits on android.
VLOG(3) << "property trees:";
std::string property_trees; std::string property_trees;
base::JSONWriter::WriteWithOptions( base::JSONWriter::WriteWithOptions(
*sync_tree->property_trees()->AsTracedValue()->ToBaseValue(), *sync_tree->property_trees()->AsTracedValue()->ToBaseValue(),
base::JSONWriter::OPTIONS_PRETTY_PRINT, &property_trees); base::JSONWriter::OPTIONS_PRETTY_PRINT, &property_trees);
std::stringstream property_trees_stream(property_trees); VLOG(3) << "After finishing commit on impl, the sync tree:"
for (std::string line; std::getline(property_trees_stream, line);) << "\nproperty_trees:\n"
VLOG(3) << line; << property_trees << "\nlayers:\n"
<< host_impl->LayerListAsJson();
VLOG(3) << "layers:";
std::stringstream layers_stream(host_impl->LayerListAsJson());
for (std::string line; std::getline(layers_stream, line);)
VLOG(3) << line;
} }
} }
...@@ -813,33 +805,27 @@ bool LayerTreeHost::DoUpdateLayers(Layer* root_layer) { ...@@ -813,33 +805,27 @@ bool LayerTreeHost::DoUpdateLayers(Layer* root_layer) {
// --vmodule=layer_tree_host=3 // --vmodule=layer_tree_host=3
// This only prints output for the renderer. // This only prints output for the renderer.
if (VLOG_IS_ON(3) && GetClientNameForMetrics() == std::string("Renderer")) { if (VLOG_IS_ON(3) && GetClientNameForMetrics() == std::string("Renderer")) {
VLOG(3) << "After updating layers on the main thread:";
// Because the property tree and layer list output can be verbose, the VLOG
// output is split by line to avoid line buffer limits on android.
VLOG(3) << "property trees:";
std::string property_trees; std::string property_trees;
base::JSONWriter::WriteWithOptions( base::JSONWriter::WriteWithOptions(
*property_trees_.AsTracedValue()->ToBaseValue(), *property_trees_.AsTracedValue()->ToBaseValue(),
base::JSONWriter::OPTIONS_PRETTY_PRINT, &property_trees); base::JSONWriter::OPTIONS_PRETTY_PRINT, &property_trees);
std::stringstream property_trees_stream(property_trees); std::ostringstream layers;
for (std::string line; std::getline(property_trees_stream, line);)
VLOG(3) << line;
VLOG(3) << "layers:";
for (auto* layer : *this) { for (auto* layer : *this) {
VLOG(3) << " layer id " << layer->id(); layers << "\n layer id " << layer->id();
VLOG(3) << " element_id: " << layer->element_id(); layers << "\n element_id: " << layer->element_id();
VLOG(3) << " bounds: " << layer->bounds().ToString(); layers << "\n bounds: " << layer->bounds().ToString();
VLOG(3) << " opacity: " << layer->opacity(); layers << "\n opacity: " << layer->opacity();
VLOG(3) << " position: " << layer->position().ToString(); layers << "\n position: " << layer->position().ToString();
VLOG(3) << " draws_content: " << layer->DrawsContent(); layers << "\n draws_content: " << layer->DrawsContent();
VLOG(3) << " scrollable: " << layer->scrollable(); layers << "\n scrollable: " << layer->scrollable();
VLOG(3) << " contents_opaque: " << layer->contents_opaque(); layers << "\n contents_opaque: " << layer->contents_opaque();
VLOG(3) << " transform_tree_index: " << layer->transform_tree_index(); layers << "\n transform_tree_index: " << layer->transform_tree_index();
VLOG(3) << " clip_tree_index: " << layer->clip_tree_index(); layers << "\n clip_tree_index: " << layer->clip_tree_index();
VLOG(3) << " effect_tree_index: " << layer->effect_tree_index(); layers << "\n effect_tree_index: " << layer->effect_tree_index();
VLOG(3) << " scroll_tree_index: " << layer->scroll_tree_index(); layers << "\n scroll_tree_index: " << layer->scroll_tree_index();
} }
VLOG(3) << "After updating layers on the main thread:\nproperty trees:\n"
<< property_trees << "\nlayers:" << layers.str();
} }
bool painted_content_has_slow_paths = false; bool painted_content_has_slow_paths = false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment