diff --git a/onnxruntime/core/common/profiler.cc b/onnxruntime/core/common/profiler.cc index 6a99e6daf3..4ba358ab68 100644 --- a/onnxruntime/core/common/profiler.cc +++ b/onnxruntime/core/common/profiler.cc @@ -18,6 +18,7 @@ profiling::Profiler::~Profiler() {} #endif ::onnxruntime::TimePoint profiling::Profiler::StartTime() const { + ORT_ENFORCE(enabled_); return std::chrono::high_resolution_clock::now(); } diff --git a/onnxruntime/core/session/inference_session.cc b/onnxruntime/core/session/inference_session.cc index 686f36358d..ac8810d835 100644 --- a/onnxruntime/core/session/inference_session.cc +++ b/onnxruntime/core/session/inference_session.cc @@ -215,7 +215,10 @@ common::Status InferenceSession::RegisterCustomRegistry(std::shared_ptr&)> loader, const std::string& event_name) { Status status = Status::OK(); - auto tp = session_profiler_.StartTime(); + TimePoint tp; + if (session_profiler_.IsEnabled()) { + tp = session_profiler_.StartTime(); + } try { std::lock_guard l(session_mutex_); if (is_model_loaded_) { // already loaded @@ -539,7 +542,10 @@ common::Status InferenceSession::InitializeSubgraphSessions(Graph& graph, Sessio common::Status InferenceSession::Initialize() { Status status = Status::OK(); - auto tp = session_profiler_.StartTime(); + TimePoint tp; + if (session_profiler_.IsEnabled()) { + tp = session_profiler_.StartTime(); + } try { LOGS(*session_logger_, INFO) << "Initializing session."; @@ -775,7 +781,10 @@ common::Status InferenceSession::ValidateOutputs(const std::vector& Status InferenceSession::Run(const RunOptions& run_options, const std::vector& feed_names, const std::vector& feeds, const std::vector& output_names, std::vector* p_fetches) { - auto tp = session_profiler_.StartTime(); + TimePoint tp; + if (session_profiler_.IsEnabled()) { + tp = session_profiler_.StartTime(); + } Status retval = Status::OK(); try {