Skip to content

Commit

Permalink
Enable log message output for messages larger than 4096 bytes.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 705879341
  • Loading branch information
MediaPipe Team authored and copybara-github committed Dec 13, 2024
1 parent cc8bfd7 commit 91baa9b
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 11 deletions.
16 changes: 16 additions & 0 deletions mediapipe/framework/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,7 @@ cc_library(
":stream_handler_cc_proto",
":subgraph",
":thread_pool_executor_cc_proto",
":vlog_utils",
"//mediapipe/framework/port:core_proto",
"//mediapipe/framework/port:file_helpers",
"//mediapipe/framework/port:logging",
Expand All @@ -1377,6 +1378,7 @@ cc_library(
"//mediapipe/framework/tool:validate_name",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/log",
"@com_google_absl//absl/log:absl_check",
"@com_google_absl//absl/log:absl_log",
"@com_google_absl//absl/status",
Expand Down Expand Up @@ -1965,3 +1967,17 @@ cc_library(
"@com_google_absl//absl/strings:string_view",
],
)

cc_library(
name = "vlog_utils",
srcs = ["vlog_utils.cc"],
hdrs = ["vlog_utils.h"],
visibility = ["//visibility:public"],
deps = [
"//mediapipe/framework/port:logging",
"@com_google_absl//absl/log",
"@com_google_absl//absl/log:absl_log",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:string_view",
],
)
6 changes: 6 additions & 0 deletions mediapipe/framework/tool/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -987,13 +987,18 @@ cc_library(
":graph_runtime_info_utils",
"//mediapipe/framework:calculator_cc_proto",
"//mediapipe/framework:graph_runtime_info_cc_proto",
"//mediapipe/framework:vlog_utils",
"//mediapipe/framework/port:logging",
"//mediapipe/framework/port:ret_check",
"//mediapipe/framework/port:threadpool",
"@com_google_absl//absl/base:log_severity",
"@com_google_absl//absl/functional:any_invocable",
"@com_google_absl//absl/log",
"@com_google_absl//absl/log:absl_check",
"@com_google_absl//absl/log:absl_log",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings:string_view",
"@com_google_absl//absl/synchronization",
"@com_google_absl//absl/time",
],
Expand Down Expand Up @@ -1021,6 +1026,7 @@ cc_library(
deps = [
"//mediapipe/framework:graph_runtime_info_cc_proto",
"//mediapipe/framework:timestamp",
"//mediapipe/framework:vlog_utils",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
Expand Down
5 changes: 3 additions & 2 deletions mediapipe/framework/tool/graph_runtime_info_logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
#include "mediapipe/framework/calculator.pb.h"
#include "mediapipe/framework/port/ret_check.h"
#include "mediapipe/framework/tool/graph_runtime_info_utils.h"
#include "mediapipe/framework/vlog_utils.h"

namespace mediapipe::tool {

constexpr absl::Duration kDefaultCaptureInterval = absl::Seconds(10);

GraphRuntimeInfoLogger::GraphRuntimeInfoLogger()
: thread_pool_("GraphRuntimeInfoLogger", 1) {}
: thread_pool_("GraphRuntimeInfoLogger", /*num_threads=*/1) {}

GraphRuntimeInfoLogger::~GraphRuntimeInfoLogger() { Stop(); };

Expand Down Expand Up @@ -49,7 +50,7 @@ absl::Status GraphRuntimeInfoLogger::StartInBackground(
<< runtime_info_str.status();
return;
}
ABSL_LOG(INFO) << *runtime_info_str;
VlogLargeMessage(/*verbose_level=*/0, *runtime_info_str);
shutdown_signal_.WaitForNotificationWithTimeout(interval);
}
});
Expand Down
23 changes: 14 additions & 9 deletions mediapipe/framework/validated_graph_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "absl/container/flat_hash_set.h"
#include "absl/log/absl_check.h"
#include "absl/log/absl_log.h"
#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_join.h"
Expand All @@ -46,6 +47,7 @@
#include "mediapipe/framework/tool/status_util.h"
#include "mediapipe/framework/tool/subgraph_expansion.h"
#include "mediapipe/framework/tool/validate_name.h"
#include "mediapipe/framework/vlog_utils.h"

namespace mediapipe {

Expand Down Expand Up @@ -325,11 +327,12 @@ absl::Status ValidatedGraphConfig::Initialize(
const GraphServiceManager* service_manager) {
RET_CHECK(!initialized_)
<< "ValidatedGraphConfig can be initialized only once.";

#if !defined(MEDIAPIPE_MOBILE)
VLOG(1) << "ValidatedGraphConfig::Initialize called with config:\n"
<< input_config.DebugString();
#endif
if (VLOG_IS_ON(1)) {
VlogLargeMessage(
/*verbose_level=*/1,
absl::StrCat("ValidatedGraphConfig::Initialize called with config:\n",
input_config.DebugString()));
}

config_ = std::move(input_config);
MP_RETURN_IF_ERROR(
Expand Down Expand Up @@ -401,10 +404,12 @@ absl::Status ValidatedGraphConfig::Initialize(

MP_RETURN_IF_ERROR(ValidateExecutors());

#if !defined(MEDIAPIPE_MOBILE)
VLOG(1) << "ValidatedGraphConfig produced canonical config:\n"
<< config_.DebugString();
#endif
if (VLOG_IS_ON(1)) {
VlogLargeMessage(
/*verbose_level=*/1,
absl::StrCat("ValidatedGraphConfig produced canonical config:\n",
config_.DebugString()));
}

initialized_ = true;
return absl::OkStatus();
Expand Down
23 changes: 23 additions & 0 deletions mediapipe/framework/vlog_utils.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "mediapipe/framework/vlog_utils.h"

#include "absl/log/absl_log.h"
#include "absl/log/log.h"
#include "absl/strings/str_split.h" // IWYU pragma: keep
#include "absl/strings/string_view.h"
#include "mediapipe/framework/port/logging.h"

namespace mediapipe {

void VlogLargeMessage(int verbose_level, absl::string_view message) {
#if defined(MEDIAPIPE_MOBILE)
if (message.size() > 4096) {
for (const auto& line : absl::StrSplit(message, '\n')) {
VLOG(verbose_level) << line;
}
return;
}
#endif
VLOG(verbose_level) << message;
}

} // namespace mediapipe
22 changes: 22 additions & 0 deletions mediapipe/framework/vlog_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef MEDIAPIPE_FRAMEWORK_VLOG_UTILS_H_
#define MEDIAPIPE_FRAMEWORK_VLOG_UTILS_H_

#include "absl/strings/string_view.h"

namespace mediapipe {

// Helper to log a message with a large number of lines on mobile (Android).
//
// On Android, the logcat will truncate the log if the message is larger than
// 4096 bytes. This function splits the message by new lines and logs each
// line separately. To ensure the log message is only generated when VLOG is
// turned on, use this function in a VLOG_IS_ON() block:
// if (VLOG_IS_ON(1)) {
// VlogLargeMessage(
// /*verbose_level=*/1, GenerateDebugString());
// }
void VlogLargeMessage(int verbose_level, absl::string_view message);

} // namespace mediapipe

#endif // MEDIAPIPE_FRAMEWORK_VLOG_UTILS_H_

0 comments on commit 91baa9b

Please sign in to comment.