Skip to content

Commit 53f2842

Browse files
huningxinshiyi9801
authored andcommitted
Allow to configure ORT logging level (#220)
Add a switch to configure the logging severity level of ONNX Runtime. Example usage: ``` --no-sandbox --enable-logging --webnn-ort-logging-level=VERBOSE ``` Other severity levels could be "INFO", "WARNING" (default), "ERROR" and "FATAL".
1 parent 1de4e08 commit 53f2842

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

content/browser/gpu/gpu_process_host.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ static const char* const kSwitchNames[] = {
332332
switches::kWebNNOrtDumpModel,
333333
switches::kWebNNOrtOVGpuPrecision,
334334
switches::kWebNNOrtUseOVModelCache,
335+
switches::kWebNNOrtLoggingLevel,
335336
#endif
336337
};
337338

services/webnn/webnn_context_provider_impl.cc

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,32 @@ void WebNNContextProviderImpl::CreateWebNNContext(
253253
return;
254254
}
255255

256+
OrtLoggingLevel ort_logging_level = ORT_LOGGING_LEVEL_WARNING;
257+
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
258+
switches::kWebNNOrtLoggingLevel)) {
259+
std::string user_logging_level =
260+
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
261+
switches::kWebNNOrtLoggingLevel);
262+
if (user_logging_level == "VERBOSE") {
263+
ort_logging_level = ORT_LOGGING_LEVEL_VERBOSE;
264+
} else if (user_logging_level == "INFO") {
265+
ort_logging_level = ORT_LOGGING_LEVEL_INFO;
266+
} else if (user_logging_level == "WARNING") {
267+
ort_logging_level = ORT_LOGGING_LEVEL_WARNING;
268+
} else if (user_logging_level == "ERROR") {
269+
ort_logging_level = ORT_LOGGING_LEVEL_ERROR;
270+
} else if (user_logging_level == "FATAL") {
271+
ort_logging_level = ORT_LOGGING_LEVEL_FATAL;
272+
}
273+
}
274+
256275
// `OrtEnv` is reference counted. The first `CreateEnv()` will create the
257276
// `OrtEnv` instance. The following invocations return the reference of the
258277
// same instance. It is released upon the last reference is removed via
259278
// `ReleaseEnv()`.
260279
ort::ScopedOrtEnv env;
261280
if (ORT_CALL_FAILED(ort::GetOrtApi()->CreateEnv(
262-
ORT_LOGGING_LEVEL_WARNING, "WebNN",
281+
ort_logging_level, "WebNN",
263282
ort::ScopedOrtEnv::Receiver(env).get()))) {
264283
std::move(callback).Run(ToError<mojom::CreateContextResult>(
265284
mojom::Error::Code::kNotSupportedError,

services/webnn/webnn_switches.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ inline constexpr char kWebNNOrtOVGpuPrecision[] = "webnn-ort-ov-gpu-precision";
5656
// This switch doesn't work if --webnn-ort-dump-model is enabled.
5757
inline constexpr char kWebNNOrtUseOVModelCache[] =
5858
"webnn-ort-use-ov-model-cache";
59+
60+
// Configure the logging severity level of ONNX Runtime.
61+
// Usage: --no-sandbox --enable-logging --webnn-ort-logging-level=VERBOSE
62+
// Other severity levels could be "INFO", "WARNING" (default), "ERROR" and
63+
// "FATAL".
64+
// Please note if "--use-redist-ort" switch is used, this logging level
65+
// setting will be ignored, because an OrtEnv will be created before with
66+
// WARNING logging level.
67+
inline constexpr char kWebNNOrtLoggingLevel[] = "webnn-ort-logging-level";
5968
#endif // BUILDFLAG(WEBNN_USE_ORT)
6069

6170
} // namespace switches

0 commit comments

Comments
 (0)