Commit 92e5a8ee authored by Robert Kimball's avatar Robert Kimball Committed by Scott Cyphers

move log from nervana to ngraph namespace (#496)

parent 9348da6d
...@@ -26,45 +26,45 @@ ...@@ -26,45 +26,45 @@
using namespace std; using namespace std;
namespace nervana namespace ngraph
{ {
class thread_starter; class thread_starter;
} }
string nervana::logger::log_path; string ngraph::logger::log_path;
deque<string> nervana::logger::queue; deque<string> ngraph::logger::queue;
static mutex queue_mutex; static mutex queue_mutex;
static condition_variable queue_condition; static condition_variable queue_condition;
static unique_ptr<thread> queue_thread; static unique_ptr<thread> queue_thread;
static bool active = false; static bool active = false;
std::ostream& nervana::get_nil_stream() std::ostream& ngraph::get_nil_stream()
{ {
static std::stringstream nil; static std::stringstream nil;
return nil; return nil;
} }
class nervana::thread_starter class ngraph::thread_starter
{ {
public: public:
thread_starter() { nervana::logger::start(); } thread_starter() { ngraph::logger::start(); }
virtual ~thread_starter() { nervana::logger::stop(); } virtual ~thread_starter() { ngraph::logger::stop(); }
}; };
static nervana::thread_starter _starter; static ngraph::thread_starter _starter;
void nervana::logger::set_log_path(const string& path) void ngraph::logger::set_log_path(const string& path)
{ {
log_path = path; log_path = path;
} }
void nervana::logger::start() void ngraph::logger::start()
{ {
active = true; active = true;
queue_thread = unique_ptr<thread>(new thread(&thread_entry, nullptr)); queue_thread = unique_ptr<thread>(new thread(&thread_entry, nullptr));
} }
void nervana::logger::stop() void ngraph::logger::stop()
{ {
{ {
unique_lock<std::mutex> lk(queue_mutex); unique_lock<std::mutex> lk(queue_mutex);
...@@ -74,12 +74,12 @@ void nervana::logger::stop() ...@@ -74,12 +74,12 @@ void nervana::logger::stop()
queue_thread->join(); queue_thread->join();
} }
void nervana::logger::process_event(const string& s) void ngraph::logger::process_event(const string& s)
{ {
cout << s << "\n"; cout << s << "\n";
} }
void nervana::logger::thread_entry(void* param) void ngraph::logger::thread_entry(void* param)
{ {
unique_lock<std::mutex> lk(queue_mutex); unique_lock<std::mutex> lk(queue_mutex);
while (active) while (active)
...@@ -93,14 +93,14 @@ void nervana::logger::thread_entry(void* param) ...@@ -93,14 +93,14 @@ void nervana::logger::thread_entry(void* param)
} }
} }
void nervana::logger::log_item(const string& s) void ngraph::logger::log_item(const string& s)
{ {
unique_lock<std::mutex> lk(queue_mutex); unique_lock<std::mutex> lk(queue_mutex);
queue.push_back(s); queue.push_back(s);
queue_condition.notify_one(); queue_condition.notify_one();
} }
nervana::log_helper::log_helper(LOG_TYPE type, const char* file, int line, const char* func) ngraph::log_helper::log_helper(LOG_TYPE type, const char* file, int line, const char* func)
{ {
switch (type) switch (type)
{ {
...@@ -124,7 +124,7 @@ nervana::log_helper::log_helper(LOG_TYPE type, const char* file, int line, const ...@@ -124,7 +124,7 @@ nervana::log_helper::log_helper(LOG_TYPE type, const char* file, int line, const
_stream << "\t"; _stream << "\t";
} }
nervana::log_helper::~log_helper() ngraph::log_helper::~log_helper()
{ {
cout << _stream.str() << endl; cout << _stream.str() << endl;
// logger::log_item(_stream.str()); // logger::log_item(_stream.str());
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include <sstream> #include <sstream>
#include <stdexcept> #include <stdexcept>
namespace nervana namespace ngraph
{ {
class conststring class conststring
{ {
...@@ -93,30 +93,30 @@ namespace nervana ...@@ -93,30 +93,30 @@ namespace nervana
extern std::ostream& get_nil_stream(); extern std::ostream& get_nil_stream();
#define NGRAPH_ERR \ #define NGRAPH_ERR \
nervana::log_helper(nervana::LOG_TYPE::_LOG_TYPE_ERROR, \ ngraph::log_helper(ngraph::LOG_TYPE::_LOG_TYPE_ERROR, \
nervana::get_file_name(__FILE__), \ ngraph::get_file_name(__FILE__), \
__LINE__, \ __LINE__, \
__PRETTY_FUNCTION__) \ __PRETTY_FUNCTION__) \
.stream() .stream()
#define NGRAPH_WARN \ #define NGRAPH_WARN \
nervana::log_helper(nervana::LOG_TYPE::_LOG_TYPE_WARNING, \ ngraph::log_helper(ngraph::LOG_TYPE::_LOG_TYPE_WARNING, \
nervana::get_file_name(__FILE__), \ ngraph::get_file_name(__FILE__), \
__LINE__, \ __LINE__, \
__PRETTY_FUNCTION__) \ __PRETTY_FUNCTION__) \
.stream() .stream()
#define NGRAPH_INFO \ #define NGRAPH_INFO \
nervana::log_helper(nervana::LOG_TYPE::_LOG_TYPE_INFO, \ ngraph::log_helper(ngraph::LOG_TYPE::_LOG_TYPE_INFO, \
nervana::get_file_name(__FILE__), \ ngraph::get_file_name(__FILE__), \
__LINE__, \ __LINE__, \
__PRETTY_FUNCTION__) \ __PRETTY_FUNCTION__) \
.stream() .stream()
// #define NGRAPH_DEBUG \ // #define NGRAPH_DEBUG \
// nervana::log_helper(nervana::LOG_TYPE::_LOG_TYPE_DEBUG, \ // ngraph::log_helper(ngraph::LOG_TYPE::_LOG_TYPE_DEBUG, \
// nervana::get_file_name(__FILE__), \ // ngraph::get_file_name(__FILE__), \
// __LINE__, \ // __LINE__, \
// __PRETTY_FUNCTION__) \ // __PRETTY_FUNCTION__) \
// .stream() // .stream()
#define NGRAPH_DEBUG nervana::get_nil_stream() #define NGRAPH_DEBUG ngraph::get_nil_stream()
} }
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