Commit 185d70cb authored by Robert Kimball's avatar Robert Kimball

add tracing to interpreter

parent 3e3e0a66
...@@ -463,6 +463,8 @@ set (SRC ...@@ -463,6 +463,8 @@ set (SRC
runtime/backend.hpp runtime/backend.hpp
runtime/backend_manager.cpp runtime/backend_manager.cpp
runtime/backend_manager.hpp runtime/backend_manager.hpp
runtime/chrome_trace.cpp
runtime/chrome_trace.hpp
runtime/executable.cpp runtime/executable.cpp
runtime/executable.hpp runtime/executable.hpp
runtime/host_tensor.cpp runtime/host_tensor.cpp
......
...@@ -32,12 +32,10 @@ static bool read_tracing_env_var() ...@@ -32,12 +32,10 @@ static bool read_tracing_env_var()
return is_enabled; return is_enabled;
} }
mutex runtime::interpreter::event::Manager::s_file_mutex; mutex runtime::event::Manager::s_file_mutex;
bool runtime::interpreter::event::Manager::s_tracing_enabled = read_tracing_env_var(); bool runtime::event::Manager::s_tracing_enabled = read_tracing_env_var();
runtime::interpreter::event::Duration::Duration(const string& name, runtime::event::Duration::Duration(const string& name, const string& category, const string& args)
const string& category,
const string& args)
{ {
if (Manager::is_tracing_enabled()) if (Manager::is_tracing_enabled())
{ {
...@@ -49,7 +47,7 @@ runtime::interpreter::event::Duration::Duration(const string& name, ...@@ -49,7 +47,7 @@ runtime::interpreter::event::Duration::Duration(const string& name,
} }
} }
void runtime::interpreter::event::Duration::stop() void runtime::event::Duration::stop()
{ {
if (Manager::is_tracing_enabled()) if (Manager::is_tracing_enabled())
{ {
...@@ -57,7 +55,7 @@ void runtime::interpreter::event::Duration::stop() ...@@ -57,7 +55,7 @@ void runtime::interpreter::event::Duration::stop()
} }
} }
void runtime::interpreter::event::Duration::write() void runtime::event::Duration::write()
{ {
if (Manager::is_tracing_enabled()) if (Manager::is_tracing_enabled())
{ {
...@@ -65,10 +63,10 @@ void runtime::interpreter::event::Duration::write() ...@@ -65,10 +63,10 @@ void runtime::interpreter::event::Duration::write()
lock_guard<mutex> lock(Manager::get_mutex()); lock_guard<mutex> lock(Manager::get_mutex());
ofstream& out = runtime::interpreter::event::Manager::get_output_stream(); ofstream& out = runtime::event::Manager::get_output_stream();
if (out.is_open() == false) if (out.is_open() == false)
{ {
runtime::interpreter::event::Manager::open(); runtime::event::Manager::open();
} }
else else
{ {
...@@ -89,7 +87,7 @@ void runtime::interpreter::event::Duration::write() ...@@ -89,7 +87,7 @@ void runtime::interpreter::event::Duration::write()
} }
} }
runtime::interpreter::event::Object::Object(const string& name, const string& args) runtime::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())}
{ {
...@@ -97,10 +95,10 @@ runtime::interpreter::event::Object::Object(const string& name, const string& ar ...@@ -97,10 +95,10 @@ runtime::interpreter::event::Object::Object(const string& name, const string& ar
{ {
lock_guard<mutex> lock(Manager::get_mutex()); lock_guard<mutex> lock(Manager::get_mutex());
ofstream& out = runtime::interpreter::event::Manager::get_output_stream(); ofstream& out = runtime::event::Manager::get_output_stream();
if (out.is_open() == false) if (out.is_open() == false)
{ {
runtime::interpreter::event::Manager::open(); runtime::event::Manager::open();
} }
else else
{ {
...@@ -120,16 +118,16 @@ runtime::interpreter::event::Object::Object(const string& name, const string& ar ...@@ -120,16 +118,16 @@ runtime::interpreter::event::Object::Object(const string& name, const string& ar
} }
} }
void runtime::interpreter::event::Object::snapshot(const string& args) void runtime::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::interpreter::event::Manager::get_output_stream(); ofstream& out = runtime::event::Manager::get_output_stream();
if (out.is_open() == false) if (out.is_open() == false)
{ {
runtime::interpreter::event::Manager::open(); runtime::event::Manager::open();
} }
else else
{ {
...@@ -139,7 +137,7 @@ void runtime::interpreter::event::Object::snapshot(const string& args) ...@@ -139,7 +137,7 @@ void runtime::interpreter::event::Object::snapshot(const string& args)
} }
} }
void runtime::interpreter::event::Object::write_snapshot(ostream& out, const string& args) void runtime::event::Object::write_snapshot(ostream& out, const string& args)
{ {
out << R"({"name":")" << m_name << R"(","ph":"O","id":")" << m_id << out << R"({"name":")" << m_name << R"(","ph":"O","id":")" << m_id <<
R"(","ts":)" << Manager::get_current_microseconds() << R"(","ts":)" << Manager::get_current_microseconds() <<
...@@ -152,16 +150,16 @@ void runtime::interpreter::event::Object::write_snapshot(ostream& out, const str ...@@ -152,16 +150,16 @@ void runtime::interpreter::event::Object::write_snapshot(ostream& out, const str
out << "}"; out << "}";
} }
void runtime::interpreter::event::Object::destroy() void runtime::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::interpreter::event::Manager::get_output_stream(); ofstream& out = runtime::event::Manager::get_output_stream();
if (out.is_open() == false) if (out.is_open() == false)
{ {
runtime::interpreter::event::Manager::open(); runtime::event::Manager::open();
} }
else else
{ {
...@@ -174,17 +172,18 @@ void runtime::interpreter::event::Object::destroy() ...@@ -174,17 +172,18 @@ void runtime::interpreter::event::Object::destroy()
} }
} }
void runtime::interpreter::event::Manager::open(const string& path) void runtime::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)
{ {
NGRAPH_INFO << path;
out.open(path, ios_base::trunc); out.open(path, ios_base::trunc);
out << "[\n"; out << "[\n";
} }
} }
void runtime::interpreter::event::Manager::close() void runtime::event::Manager::close()
{ {
ofstream& out = get_output_stream(); ofstream& out = get_output_stream();
if (out.is_open()) if (out.is_open())
...@@ -194,34 +193,34 @@ void runtime::interpreter::event::Manager::close() ...@@ -194,34 +193,34 @@ void runtime::interpreter::event::Manager::close()
} }
} }
ofstream& runtime::interpreter::event::Manager::get_output_stream() ofstream& runtime::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::interpreter::event::Manager::get_process_id() const string& runtime::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::interpreter::event::Manager::enable_event_tracing() void runtime::event::Manager::enable_event_tracing()
{ {
s_tracing_enabled = true; s_tracing_enabled = true;
} }
void runtime::interpreter::event::Manager::disable_event_tracing() void runtime::event::Manager::disable_event_tracing()
{ {
s_tracing_enabled = false; s_tracing_enabled = false;
} }
bool runtime::interpreter::event::Manager::is_event_tracing_enabled() bool runtime::event::Manager::is_event_tracing_enabled()
{ {
return s_tracing_enabled; return s_tracing_enabled;
} }
string runtime::interpreter::event::Manager::get_thread_id() string runtime::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;
......
...@@ -35,14 +35,11 @@ namespace ngraph ...@@ -35,14 +35,11 @@ namespace ngraph
{ {
namespace runtime namespace runtime
{ {
namespace interpreter namespace event
{ {
namespace event class Duration;
{ class Object;
class Duration; class Manager;
class Object;
class Manager;
}
} }
} }
} }
...@@ -78,13 +75,13 @@ namespace ngraph ...@@ -78,13 +75,13 @@ 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::interpreter::event::Manager class ngraph::runtime::event::Manager
{ {
friend class Duration; friend class Duration;
friend class Object; friend class Object;
public: public:
static void open(const std::string& path = "interpreter_event_trace.json"); static void open(const std::string& path = "runtime_event_trace.json");
static void close(); static void close();
static bool is_tracing_enabled() { return s_tracing_enabled; } static bool is_tracing_enabled() { return s_tracing_enabled; }
static void enable_event_tracing(); static void enable_event_tracing();
...@@ -105,7 +102,7 @@ private: ...@@ -105,7 +102,7 @@ private:
static bool s_tracing_enabled; static bool s_tracing_enabled;
}; };
class ngraph::runtime::interpreter::event::Duration class ngraph::runtime::event::Duration
{ {
public: public:
explicit Duration(const std::string& name, explicit Duration(const std::string& name,
...@@ -133,7 +130,7 @@ private: ...@@ -133,7 +130,7 @@ private:
std::string m_args; std::string m_args;
}; };
class ngraph::runtime::interpreter::event::Object class ngraph::runtime::event::Object
{ {
public: public:
Object(const std::string& name, const std::string& args); Object(const std::string& name, const std::string& args);
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <memory> #include <memory>
#include "ngraph/descriptor/layout/dense_tensor_layout.hpp" #include "ngraph/descriptor/layout/dense_tensor_layout.hpp"
#include "ngraph/runtime/chrome_trace.hpp"
#include "ngraph/runtime/host_tensor.hpp" #include "ngraph/runtime/host_tensor.hpp"
#include "ngraph/util.hpp" #include "ngraph/util.hpp"
...@@ -96,6 +97,8 @@ const char* runtime::HostTensor::get_data_ptr() const ...@@ -96,6 +97,8 @@ 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("HostTensor", "write");
if (n > m_buffer_size) if (n > m_buffer_size)
{ {
throw out_of_range("write access past end of tensor"); throw out_of_range("write access past end of tensor");
...@@ -106,6 +109,7 @@ void runtime::HostTensor::write(const void* source, size_t n) ...@@ -106,6 +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("HostTensor", "read");
if (n > m_buffer_size) if (n > m_buffer_size)
{ {
throw out_of_range("read access past end of tensor"); throw out_of_range("read access past end of tensor");
......
...@@ -15,8 +15,7 @@ ...@@ -15,8 +15,7 @@
# ****************************************************************************** # ******************************************************************************
if (NGRAPH_INTERPRETER_ENABLE) if (NGRAPH_INTERPRETER_ENABLE)
add_library(interpreter_backend SHARED int_backend.cpp node_wrapper.cpp int_executable.cpp add_library(interpreter_backend SHARED int_backend.cpp node_wrapper.cpp int_executable.cpp)
chrome_trace.cpp)
if(NGRAPH_LIB_VERSIONING_ENABLE) if(NGRAPH_LIB_VERSIONING_ENABLE)
set_target_properties(interpreter_backend PROPERTIES set_target_properties(interpreter_backend PROPERTIES
VERSION ${NGRAPH_VERSION} VERSION ${NGRAPH_VERSION}
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "ngraph/pass/manager.hpp" #include "ngraph/pass/manager.hpp"
#include "ngraph/pass/memory_layout.hpp" #include "ngraph/pass/memory_layout.hpp"
#include "ngraph/runtime/backend_manager.hpp" #include "ngraph/runtime/backend_manager.hpp"
#include "ngraph/runtime/chrome_trace.hpp"
#include "ngraph/serializer.hpp" #include "ngraph/serializer.hpp"
#include "ngraph/util.hpp" #include "ngraph/util.hpp"
...@@ -76,6 +77,8 @@ runtime::interpreter::INTExecutable::INTExecutable(const std::string& model_stri ...@@ -76,6 +77,8 @@ 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("Interpreter", "call");
// convert inputs to HostTensor // convert inputs to HostTensor
vector<shared_ptr<HostTensor>> func_inputs; vector<shared_ptr<HostTensor>> func_inputs;
for (auto tensor : inputs) for (auto tensor : inputs)
......
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