Unverified Commit 906716e5 authored by Scott Cyphers's avatar Scott Cyphers Committed by GitHub

Move chrome trace to proper namespace (#4400)

Co-authored-by: 's avatarScott Cyphers <diyessi@users.noreply.github.com>
parent 263d5197
...@@ -33,10 +33,10 @@ static bool read_tracing_env_var() ...@@ -33,10 +33,10 @@ static bool read_tracing_env_var()
return is_enabled; return is_enabled;
} }
mutex runtime::event::Manager::s_file_mutex; mutex event::Manager::s_file_mutex;
bool runtime::event::Manager::s_tracing_enabled = read_tracing_env_var(); bool event::Manager::s_tracing_enabled = read_tracing_env_var();
runtime::event::Duration::Duration(const string& name, const string& category, const string& args) event::Duration::Duration(const string& name, const string& category, const string& args)
{ {
if (Manager::is_tracing_enabled()) if (Manager::is_tracing_enabled())
{ {
...@@ -48,7 +48,7 @@ runtime::event::Duration::Duration(const string& name, const string& category, c ...@@ -48,7 +48,7 @@ runtime::event::Duration::Duration(const string& name, const string& category, c
} }
} }
void runtime::event::Duration::stop() void event::Duration::stop()
{ {
if (Manager::is_tracing_enabled()) if (Manager::is_tracing_enabled())
{ {
...@@ -56,7 +56,7 @@ void runtime::event::Duration::stop() ...@@ -56,7 +56,7 @@ void runtime::event::Duration::stop()
} }
} }
void runtime::event::Duration::write() void event::Duration::write()
{ {
if (Manager::is_tracing_enabled()) if (Manager::is_tracing_enabled())
{ {
...@@ -64,11 +64,11 @@ void runtime::event::Duration::write() ...@@ -64,11 +64,11 @@ void runtime::event::Duration::write()
lock_guard<mutex> lock(Manager::get_mutex()); lock_guard<mutex> lock(Manager::get_mutex());
ofstream& out = runtime::event::Manager::get_output_stream(); ofstream& out = event::Manager::get_output_stream();
string str; string str;
if (out.is_open() == false) if (out.is_open() == false)
{ {
runtime::event::Manager::open(); event::Manager::open();
} }
else else
{ {
...@@ -88,7 +88,7 @@ void runtime::event::Duration::write() ...@@ -88,7 +88,7 @@ void runtime::event::Duration::write()
} }
} }
runtime::event::Object::Object(const string& name, const string& args) event::Object::Object(const string& name, const string& args)
: m_name{name} : m_name{name}
, m_id{static_cast<size_t>(chrono::high_resolution_clock::now().time_since_epoch().count())} , m_id{static_cast<size_t>(chrono::high_resolution_clock::now().time_since_epoch().count())}
{ {
...@@ -96,11 +96,11 @@ runtime::event::Object::Object(const string& name, const string& args) ...@@ -96,11 +96,11 @@ runtime::event::Object::Object(const string& name, const string& args)
{ {
lock_guard<mutex> lock(Manager::get_mutex()); lock_guard<mutex> lock(Manager::get_mutex());
ofstream& out = runtime::event::Manager::get_output_stream(); ofstream& out = event::Manager::get_output_stream();
string str; string str;
if (out.is_open() == false) if (out.is_open() == false)
{ {
runtime::event::Manager::open(); event::Manager::open();
} }
else else
{ {
...@@ -119,16 +119,16 @@ runtime::event::Object::Object(const string& name, const string& args) ...@@ -119,16 +119,16 @@ runtime::event::Object::Object(const string& name, const string& args)
} }
} }
void runtime::event::Object::snapshot(const string& args) void event::Object::snapshot(const string& args)
{ {
if (Manager::is_tracing_enabled()) if (Manager::is_tracing_enabled())
{ {
lock_guard<mutex> lock(Manager::get_mutex()); lock_guard<mutex> lock(Manager::get_mutex());
ofstream& out = runtime::event::Manager::get_output_stream(); ofstream& out = event::Manager::get_output_stream();
if (out.is_open() == false) if (out.is_open() == false)
{ {
runtime::event::Manager::open(); event::Manager::open();
} }
else else
{ {
...@@ -138,7 +138,7 @@ void runtime::event::Object::snapshot(const string& args) ...@@ -138,7 +138,7 @@ void runtime::event::Object::snapshot(const string& args)
} }
} }
void runtime::event::Object::write_snapshot(ostream& out, const string& args) void event::Object::write_snapshot(ostream& out, const string& args)
{ {
string str = R"({"name":")" + m_name + R"(","ph":"O","id":")" + to_string(m_id) + string str = R"({"name":")" + m_name + R"(","ph":"O","id":")" + to_string(m_id) +
R"(","ts":)" + to_string(Manager::get_current_microseconds()) + R"(","ts":)" + to_string(Manager::get_current_microseconds()) +
...@@ -151,16 +151,16 @@ void runtime::event::Object::write_snapshot(ostream& out, const string& args) ...@@ -151,16 +151,16 @@ void runtime::event::Object::write_snapshot(ostream& out, const string& args)
out << str; out << str;
} }
void runtime::event::Object::destroy() void event::Object::destroy()
{ {
if (Manager::is_tracing_enabled()) if (Manager::is_tracing_enabled())
{ {
lock_guard<mutex> lock(Manager::get_mutex()); lock_guard<mutex> lock(Manager::get_mutex());
ofstream& out = runtime::event::Manager::get_output_stream(); ofstream& out = event::Manager::get_output_stream();
if (out.is_open() == false) if (out.is_open() == false)
{ {
runtime::event::Manager::open(); event::Manager::open();
} }
else else
{ {
...@@ -173,7 +173,7 @@ void runtime::event::Object::destroy() ...@@ -173,7 +173,7 @@ void runtime::event::Object::destroy()
} }
} }
void runtime::event::Manager::open(const string& path) void event::Manager::open(const string& path)
{ {
ofstream& out = get_output_stream(); ofstream& out = get_output_stream();
if (out.is_open() == false) if (out.is_open() == false)
...@@ -183,7 +183,7 @@ void runtime::event::Manager::open(const string& path) ...@@ -183,7 +183,7 @@ void runtime::event::Manager::open(const string& path)
} }
} }
void runtime::event::Manager::close() void event::Manager::close()
{ {
ofstream& out = get_output_stream(); ofstream& out = get_output_stream();
if (out.is_open()) if (out.is_open())
...@@ -193,34 +193,34 @@ void runtime::event::Manager::close() ...@@ -193,34 +193,34 @@ void runtime::event::Manager::close()
} }
} }
ofstream& runtime::event::Manager::get_output_stream() ofstream& event::Manager::get_output_stream()
{ {
static ofstream s_event_log; static ofstream s_event_log;
return s_event_log; return s_event_log;
} }
const string& runtime::event::Manager::get_process_id() const string& event::Manager::get_process_id()
{ {
static const string s_pid = to_string(getpid()); static const string s_pid = to_string(getpid());
return s_pid; return s_pid;
} }
void runtime::event::Manager::enable_event_tracing() void event::Manager::enable_event_tracing()
{ {
s_tracing_enabled = true; s_tracing_enabled = true;
} }
void runtime::event::Manager::disable_event_tracing() void event::Manager::disable_event_tracing()
{ {
s_tracing_enabled = false; s_tracing_enabled = false;
} }
bool runtime::event::Manager::is_event_tracing_enabled() bool event::Manager::is_event_tracing_enabled()
{ {
return s_tracing_enabled; return s_tracing_enabled;
} }
string runtime::event::Manager::get_thread_id() string event::Manager::get_thread_id()
{ {
thread::id tid = this_thread::get_id(); thread::id tid = this_thread::get_id();
static map<thread::id, string> tid_map; static map<thread::id, string> tid_map;
......
...@@ -33,14 +33,11 @@ ...@@ -33,14 +33,11 @@
namespace ngraph namespace ngraph
{ {
namespace runtime namespace event
{ {
namespace event class Duration;
{ class Object;
class Duration; class Manager;
class Object;
class Manager;
}
} }
} }
...@@ -75,7 +72,7 @@ namespace ngraph ...@@ -75,7 +72,7 @@ namespace ngraph
// More information about this is at: // More information about this is at:
// http://dev.chromium.org/developers/how-tos/trace-event-profiling-tool // http://dev.chromium.org/developers/how-tos/trace-event-profiling-tool
class ngraph::runtime::event::Manager class ngraph::event::Manager
{ {
friend class Duration; friend class Duration;
friend class Object; friend class Object;
...@@ -102,7 +99,7 @@ private: ...@@ -102,7 +99,7 @@ private:
static bool s_tracing_enabled; static bool s_tracing_enabled;
}; };
class ngraph::runtime::event::Duration class ngraph::event::Duration
{ {
public: public:
explicit Duration(const std::string& name, explicit Duration(const std::string& name,
...@@ -130,7 +127,7 @@ private: ...@@ -130,7 +127,7 @@ private:
std::string m_args; std::string m_args;
}; };
class ngraph::runtime::event::Object class ngraph::event::Object
{ {
public: public:
Object(const std::string& name, const std::string& args); Object(const std::string& name, const std::string& args);
......
...@@ -97,7 +97,7 @@ const char* runtime::HostTensor::get_data_ptr() const ...@@ -97,7 +97,7 @@ const char* runtime::HostTensor::get_data_ptr() const
void runtime::HostTensor::write(const void* source, size_t n) void runtime::HostTensor::write(const void* source, size_t n)
{ {
runtime::event::Duration d1("write", "HostTensor"); event::Duration d1("write", "HostTensor");
if (n != m_buffer_size) if (n != m_buffer_size)
{ {
...@@ -109,7 +109,7 @@ void runtime::HostTensor::write(const void* source, size_t n) ...@@ -109,7 +109,7 @@ void runtime::HostTensor::write(const void* source, size_t n)
void runtime::HostTensor::read(void* target, size_t n) const void runtime::HostTensor::read(void* target, size_t n) const
{ {
runtime::event::Duration d1("read", "HostTensor"); event::Duration d1("read", "HostTensor");
if (n != m_buffer_size) if (n != m_buffer_size)
{ {
throw out_of_range("partial tensor read access not supported"); throw out_of_range("partial tensor read access not supported");
......
...@@ -101,7 +101,7 @@ runtime::interpreter::INTExecutable::INTExecutable(const std::string& model_stri ...@@ -101,7 +101,7 @@ runtime::interpreter::INTExecutable::INTExecutable(const std::string& model_stri
bool runtime::interpreter::INTExecutable::call(const vector<shared_ptr<runtime::Tensor>>& outputs, bool runtime::interpreter::INTExecutable::call(const vector<shared_ptr<runtime::Tensor>>& outputs,
const vector<shared_ptr<runtime::Tensor>>& inputs) const vector<shared_ptr<runtime::Tensor>>& inputs)
{ {
runtime::event::Duration d1("call", "Interpreter"); event::Duration d1("call", "Interpreter");
// convert inputs to HostTensor // convert inputs to HostTensor
vector<shared_ptr<HostTensor>> func_inputs; vector<shared_ptr<HostTensor>> func_inputs;
...@@ -150,7 +150,7 @@ bool runtime::interpreter::INTExecutable::call(const vector<shared_ptr<runtime:: ...@@ -150,7 +150,7 @@ bool runtime::interpreter::INTExecutable::call(const vector<shared_ptr<runtime::
// for each ordered op in the graph // for each ordered op in the graph
for (auto op : m_nodes) for (auto op : m_nodes)
{ {
runtime::event::Duration d2(op->description(), "Interpreter"); event::Duration d2(op->description(), "Interpreter");
if (op->is_parameter()) if (op->is_parameter())
{ {
continue; continue;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment