From 3280697ca03aef79e9edd957ce96ef9a64268824 Mon Sep 17 00:00:00 2001 From: Mika Fischer Date: Tue, 26 Mar 2019 19:13:32 +0100 Subject: [PATCH 1/2] Fix profiling with C API Currently, when using OrtEnableProfiling to enable profiling using the C API, the profile output file is created but is always empty. The reason is that InferenceSession::EndProfiling() needs to be called to write the profiling data to the output file. However there's currently no way to call this function via the C API. This adds a call to EndProfiling() to the descructor of the session if profiling is enabled in the session options. --- onnxruntime/core/session/inference_session.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/onnxruntime/core/session/inference_session.cc b/onnxruntime/core/session/inference_session.cc index 45609d7d6411b..3111d65af3cc9 100644 --- a/onnxruntime/core/session/inference_session.cc +++ b/onnxruntime/core/session/inference_session.cc @@ -191,7 +191,11 @@ InferenceSession::InferenceSession(const SessionOptions& session_options, loggin } } -InferenceSession::~InferenceSession() = default; +InferenceSession::~InferenceSession() { + if (session_options_.enable_profiling) { + EndProfiling(); + } +} common::Status InferenceSession::RegisterExecutionProvider(std::unique_ptr p_exec_provider) { if (p_exec_provider == nullptr) { From 31035e0563f1eaec5c12b3522e0573a8064dc107 Mon Sep 17 00:00:00 2001 From: Mika Fischer Date: Wed, 3 Apr 2019 16:24:02 +0200 Subject: [PATCH 2/2] Handle exceptions when calling EndProfiling during Session destruction --- onnxruntime/core/session/inference_session.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/onnxruntime/core/session/inference_session.cc b/onnxruntime/core/session/inference_session.cc index 3111d65af3cc9..4d989c171794b 100644 --- a/onnxruntime/core/session/inference_session.cc +++ b/onnxruntime/core/session/inference_session.cc @@ -193,7 +193,18 @@ InferenceSession::InferenceSession(const SessionOptions& session_options, loggin InferenceSession::~InferenceSession() { if (session_options_.enable_profiling) { - EndProfiling(); + try { + EndProfiling(); + } catch (std::exception& e) { + // TODO: Currently we have no way to transport this error to the API user + // Maybe this should be refactored, so that profiling must be explicitly + // started and stopped via C-API functions. + // And not like now a session option and therefore profiling must be started + // and stopped implicitly. + LOGS(*session_logger_, ERROR) << "Error during EndProfiling(): " << e.what(); + } catch (...) { + LOGS(*session_logger_, ERROR) << "Unknown error during EndProfiling()"; + } } }