Profiler-IsEnabled (#1503)

Avoid use of Hungarian naming convention for cross-platform API code.

I'm taking my cue here from the "ONNX Runtime coding conventions and standard" document which say we use the "Google C++ style guide", and that says "Do not use Hungarian notation"
https://github.com/microsoft/onnxruntime/blob/master/docs/Coding_Conventions_and_Standards.md
https://google.github.io/styleguide/cppguide.html#Windows_Code

X-ref: internal PR 4824
This commit is contained in:
Jorgen Thelin 2019-07-30 13:32:01 -07:00 committed by jywu-msft
parent a86486ab7f
commit fb7bdd177b
5 changed files with 29 additions and 16 deletions

View file

@ -72,6 +72,11 @@ std::string Profiler::EndProfiling() {
profile_with_logger_ = false;
return std::string();
}
if (session_logger_) {
LOGS(*session_logger_, INFO) << "Writing profiler data to file " << profile_stream_file_;
}
std::lock_guard<OrtMutex> lock(mutex_);
profile_stream_ << "[\n";

View file

@ -44,7 +44,10 @@ class Profiler {
*/
TimePoint StartTime() const;
bool FEnabled() const {
/*
Whether data collection and output from this profiler is enabled.
*/
bool IsEnabled() const {
return enabled_;
}

View file

@ -35,8 +35,8 @@ Status ParallelExecutor::Execute(const SessionState& session_state, const std::v
const std::unordered_map<size_t, CustomAllocator>& fetch_allocators,
const logging::Logger& logger) {
TimePoint tp;
bool f_profiler_enabled = session_state.Profiler().FEnabled();
if (f_profiler_enabled) {
const bool is_profiler_enabled = session_state.Profiler().IsEnabled();
if (is_profiler_enabled) {
tp = session_state.Profiler().StartTime();
}
@ -102,7 +102,7 @@ Status ParallelExecutor::Execute(const SessionState& session_state, const std::v
}
}
if (f_profiler_enabled) {
if (is_profiler_enabled) {
session_state.Profiler().EndTimeAndRecordEvent(profiling::SESSION_EVENT, "ParallelExecutor::Execute", tp);
}
@ -121,7 +121,7 @@ Status ParallelExecutor::RunNodeAsync(size_t p_node_index,
auto graph_viewer = session_state.GetGraphViewer();
TimePoint sync_time_begin;
TimePoint kernel_begin_time;
bool f_profiler_enabled = session_state.Profiler().FEnabled();
const bool f_profiler_enabled = session_state.Profiler().IsEnabled();
// Avoid context switching if possible.
while (keep_running) {

View file

@ -27,12 +27,12 @@ Status SequentialExecutor::Execute(const SessionState& session_state, const std:
std::vector<OrtValue>& fetches,
const std::unordered_map<size_t, CustomAllocator>& fetch_allocators,
const logging::Logger& logger) {
bool f_profiler_enabled = session_state.Profiler().FEnabled();
const bool is_profiler_enabled = session_state.Profiler().IsEnabled();
TimePoint tp;
TimePoint sync_time_begin;
TimePoint kernel_begin_time;
if (f_profiler_enabled) {
if (is_profiler_enabled) {
tp = session_state.Profiler().StartTime();
}
@ -65,7 +65,7 @@ Status SequentialExecutor::Execute(const SessionState& session_state, const std:
OpKernelContextInternal op_kernel_context(session_state, frame, *p_op_kernel, logger,
p_op_kernel->Node().ImplicitInputDefs(), terminate_flag_);
// TODO: log kernel outputs?
if (f_profiler_enabled) {
if (is_profiler_enabled) {
sync_time_begin = session_state.Profiler().StartTime();
}
@ -104,7 +104,7 @@ Status SequentialExecutor::Execute(const SessionState& session_state, const std:
utils::DumpNodeInputs(op_kernel_context, p_op_kernel->Node());
#endif
if (f_profiler_enabled) {
if (is_profiler_enabled) {
session_state.Profiler().EndTimeAndRecordEvent(profiling::NODE_EVENT,
p_op_kernel->Node().Name() + "_fence_before",
sync_time_begin,
@ -128,7 +128,7 @@ Status SequentialExecutor::Execute(const SessionState& session_state, const std:
return Status(compute_status.Category(), compute_status.Code(), msg_string);
}
if (f_profiler_enabled) {
if (is_profiler_enabled) {
session_state.Profiler().EndTimeAndRecordEvent(profiling::NODE_EVENT,
p_op_kernel->Node().Name() + "_kernel_time",
kernel_begin_time,
@ -159,7 +159,7 @@ Status SequentialExecutor::Execute(const SessionState& session_state, const std:
}
}
if (f_profiler_enabled) {
if (is_profiler_enabled) {
session_state.Profiler().EndTimeAndRecordEvent(profiling::NODE_EVENT,
p_op_kernel->Node().Name() + "_fence_after",
sync_time_begin,
@ -199,7 +199,7 @@ Status SequentialExecutor::Execute(const SessionState& session_state, const std:
}
}
if (f_profiler_enabled) {
if (is_profiler_enabled) {
session_state.Profiler().EndTimeAndRecordEvent(profiling::SESSION_EVENT, "SequentialExecutor::Execute", tp);
}

View file

@ -220,7 +220,7 @@ common::Status InferenceSession::Load(std::function<common::Status(std::shared_p
status = Status(common::ONNXRUNTIME, common::RUNTIME_EXCEPTION, "Encountered unknown exception in Load()");
}
if (session_profiler_.FEnabled()) {
if (session_profiler_.IsEnabled()) {
session_profiler_.EndTimeAndRecordEvent(profiling::SESSION_EVENT, event_name, tp);
}
@ -550,7 +550,7 @@ common::Status InferenceSession::Initialize() {
LOGS(*session_logger_, ERROR) << status.ErrorMessage();
}
if (session_profiler_.FEnabled()) {
if (session_profiler_.IsEnabled()) {
session_profiler_.EndTimeAndRecordEvent(profiling::SESSION_EVENT, "session_initialization", tp);
}
return status;
@ -742,7 +742,7 @@ Status InferenceSession::Run(const RunOptions& run_options, const std::vector<st
}
--current_num_runs_;
if (session_profiler_.FEnabled()) {
if (session_profiler_.IsEnabled()) {
session_profiler_.EndTimeAndRecordEvent(profiling::SESSION_EVENT, "model_run", tp);
}
@ -859,7 +859,12 @@ void InferenceSession::StartProfiling(const logging::Logger* logger_ptr) {
std::string InferenceSession::EndProfiling() {
if (is_model_loaded_) {
return session_profiler_.EndProfiling();
if (session_profiler_.IsEnabled()) {
return session_profiler_.EndProfiling();
} else {
LOGS(*session_logger_, VERBOSE) << "Profiler is disabled.";
return std::string();
}
}
LOGS(*session_logger_, ERROR) << "Could not write a profile because no model was loaded.";
return std::string();