Skip to content

Commit

Permalink
apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
k-ye committed Mar 6, 2021
1 parent 18c5c3e commit fefafa3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
15 changes: 11 additions & 4 deletions taichi/common/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ Logger::Logger() {
TI_LOG_SET_PATTERN("%^[%L %D %X.%e] %v%$");

set_level_default();
// TODO: restore PID printing below.
// TI_TRACE("Taichi core started. Thread ID = {}", PID::get_pid());
}

void Logger::set_level_default() {
Expand Down Expand Up @@ -113,10 +111,19 @@ void Logger::set_print_stacktrace_func(std::function<void()> print_fn) {

// static
Logger &Logger::get_instance() {
// Use the singleton pattern, instead of defining a global variable. This is
// because I've moved the signal handler registration + pybind11's
// py::register_exception_translator to
// taichi/system/hacked_signal_handler.cpp. We instantiate a global
// HackedSIgnalHandler (in the anonymous namespace), whose constructor
// registers the signal handlers.

// This decouples Logger from pybind11. However, it has introduced a problem
// if we continue to keep a global Logger instance: the construction order
// between Logger and HackedSIgnalHandler is unspecified, and it actually
// crashes on my system. So we use the singleton pattern instead.
static Logger *l = new Logger();
return *l;
}

// Logger logger;

} // namespace taichi
5 changes: 3 additions & 2 deletions taichi/python/export_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,9 @@ void export_misc(py::module &m) {
.def(py::init<>())
.def("clear", &Statistics::clear)
.def("get_counters", &Statistics::get_counters);
m.def("get_kernel_stats", []() -> Statistics & { return stat; },
py::return_value_policy::reference);
m.def(
"get_kernel_stats", []() -> Statistics & { return stat; },
py::return_value_policy::reference);
}

TI_NAMESPACE_END
2 changes: 2 additions & 0 deletions taichi/system/hacked_signal_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "taichi/python/export.h"
#include "taichi/common/logging.h"
#include "taichi/system/threading.h"
#include "taichi/system/traceback.h"

namespace taichi {
Expand Down Expand Up @@ -70,6 +71,7 @@ class HackedSignalRegister {
#undef TI_REGISTER_SIGNAL_HANDLER

Logger::get_instance().set_print_stacktrace_func(print_traceback);
TI_TRACE("Taichi core started. Thread ID = {}", PID::get_pid());
}
};

Expand Down

0 comments on commit fefafa3

Please sign in to comment.