-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding VLOG overrides - MediaPipe utilizes VLOG heavily, but it's not…
… straightforward for how to enable this when running an Android app. VLOG overrides allow to relatively quickly enable VLOGs for various modules within MediaPipe. PiperOrigin-RevId: 697671583
- Loading branch information
1 parent
0cebcc0
commit cccc5d2
Showing
4 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "mediapipe/framework/vlog_overrides.h" | ||
|
||
// Template to temporary enable VLOG overrides in code: | ||
// #define MEDIAPIPE_VLOG_VMODULE "calculator_graph*=5,southbound*=5" | ||
// #define MEDIAPIPE_VLOG_V 1 | ||
|
||
#if defined(MEDIAPIPE_VLOG_V) || defined(MEDIAPIPE_VLOG_VMODULE) | ||
|
||
#include <string> | ||
#include <utility> | ||
#include <vector> | ||
|
||
#include "absl/log/absl_check.h" | ||
#include "absl/log/absl_log.h" | ||
#include "absl/log/globals.h" | ||
#include "absl/strings/str_format.h" | ||
#include "absl/strings/str_split.h" | ||
#include "absl/strings/string_view.h" | ||
#include "mediapipe/framework/deps/no_destructor.h" | ||
|
||
#endif // defined(MEDIAPIPE_VLOG_V) || defined(MEDIAPIPE_VLOG_VMODULE) | ||
|
||
namespace mediapipe { | ||
|
||
void SetVLogOverrides() { | ||
#if defined(MEDIAPIPE_VLOG_V) | ||
ABSL_LOG(INFO) << absl::StrFormat("Setting global VLOG level: %d", | ||
MEDIAPIPE_VLOG_V); | ||
absl::SetGlobalVLogLevel(MEDIAPIPE_VLOG_V); | ||
#endif // defined(MEDIAPIPE_VLOG_V) | ||
|
||
#if defined(MEDIAPIPE_VLOG_VMODULE) | ||
static NoDestructor<std::vector<std::pair<std::string, int>>> kVModuleMapping( | ||
[]() { | ||
constexpr absl::string_view kVModule = MEDIAPIPE_VLOG_VMODULE; | ||
std::vector<std::string> parts = | ||
absl::StrSplit(kVModule, absl::ByAnyChar(",=")); | ||
ABSL_CHECK_EQ(parts.size() % 2, 0) | ||
<< "Invalid MEDIAPIPE_VLOG_VMODULE: " << kVModule; | ||
std::vector<std::pair<std::string, int>> result; | ||
for (int i = 0; i < parts.size(); i += 2) { | ||
result.push_back({parts[i], std::stoi(parts[i + 1])}); | ||
} | ||
return result; | ||
}()); | ||
|
||
ABSL_LOG(INFO) << "Setting VLOG levels..."; | ||
for (const auto& [key, value] : *kVModuleMapping) { | ||
ABSL_LOG(INFO) << absl::StrFormat("Setting [%s] to level: %d", key, value); | ||
absl::SetVLogLevel(key, value); | ||
} | ||
#endif // defined(MEDIAPIPE_VLOG_VMODULE) | ||
} | ||
|
||
} // namespace mediapipe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#ifndef MEDIAPIPE_FRAMEWORK_VLOG_OVERRIDES_H_ | ||
#define MEDIAPIPE_FRAMEWORK_VLOG_OVERRIDES_H_ | ||
|
||
namespace mediapipe { | ||
|
||
// If possible, rely on --v / --vmodule to set VLOG level and modules. | ||
// | ||
// However, in cases when --v / --vmodule cannot be used (e.g. running an | ||
// Android app and enabling VLOGs), MediaPipe allows to set VLOG --v / --vmodule | ||
// overrides for debugging purposes which are applied when `CalculatorGraph` is | ||
// created. | ||
// | ||
// Overrides: | ||
// - MEDIAPIPE_VLOG_V (define and provide value you provide for --v) | ||
// - MEDIAPIPE_VLOG_VMODULE (define and provide value you provide for --vmodule) | ||
// | ||
// You can set overrides by adding: | ||
// ``` | ||
// --copt=-DMEDIAPIPE_VLOG_VMODULE=\"*calculator*=5\" | ||
// ``` | ||
// with your desired module patterns and VLOG levels (see more details for | ||
// --vmodule) to your build command. | ||
// | ||
// IMPORTANT: mind that adding the above to your build command will trigger | ||
// rebuild of the whole binary including dependencies. So, considering vlog | ||
// overrides exist for debugging purposes only, it is faster to simply modify | ||
// `vlog_overrides.cc` adding MEDIAPIPE_VLOG_V/VMODULE at the very top. | ||
void SetVLogOverrides(); | ||
|
||
} // namespace mediapipe | ||
|
||
#endif // MEDIAPIPE_FRAMEWORK_VLOG_OVERRIDES_H_ |