OmniSciDB  6686921089
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
logger Namespace Reference

Namespaces

 anonymous_namespace{Logger.cpp}
 

Classes

class  Duration
 
class  DurationTree
 
struct  GetDepth
 
class  JsonEncoder
 
struct  EraseDurationTrees
 Depth-first search and erase all DurationTrees. Not thread-safe. More...
 
class  LogOptions
 
struct  LogShutdown
 
class  Logger
 
class  DebugTimer
 
class  QidScopeGuard
 

Typedefs

using ClogSync = sinks::synchronous_sink< sinks::text_ostream_backend >
 
using FileSync = sinks::synchronous_sink< sinks::text_file_backend >
 
using Clock = std::chrono::steady_clock
 
using DurationTreeNode = boost::variant< Duration, DurationTree & >
 
using DurationTreeNodes = std::deque< DurationTreeNode >
 
using DurationTreeMap = std::unordered_map< ThreadId, std::unique_ptr< DurationTree >>
 
using Channels = std::set< Channel >
 
using FatalFunc = void(*)() noexcept
 
using ChannelLogger = boost::log::sources::channel_logger_mt< Channel >
 
using SeverityLogger = boost::log::sources::severity_logger_mt< Severity >
 
using QueryId = uint64_t
 
using ThreadId = uint64_t
 

Enumerations

enum  Channel { IR = 0, PTX, ASM, _NCHANNELS }
 
enum  Severity {
  DEBUG4 = 0, DEBUG3, DEBUG2, DEBUG1,
  INFO, WARNING, ERROR, FATAL,
  _NSEVERITIES
}
 

Functions

 BOOST_LOG_GLOBAL_LOGGER_CTOR_ARGS (gChannelLogger_IR, ChannelLogger,(keywords::channel=IR)) BOOST_LOG_GLOBAL_LOGGER_CTOR_ARGS(gChannelLogger_PTX
 
template<typename CONSOLE_SINK >
boost::shared_ptr< CONSOLE_SINK > make_sink (LogOptions const &log_opts)
 
void init (LogOptions const &log_opts)
 
void set_once_fatal_func (FatalFunc fatal_func)
 
void shutdown ()
 
std::istream & operator>> (std::istream &in, Channels &channels)
 
std::ostream & operator<< (std::ostream &out, Channels const &channels)
 
std::istream & operator>> (std::istream &in, Severity &sev)
 
std::ostream & operator<< (std::ostream &out, Severity const &sev)
 
QueryId query_id ()
 
QidScopeGuard set_thread_local_query_id (QueryId const query_id)
 
template<typename... Ts>
DurationnewDuration (Severity severity, Ts &&...args)
 
std::ostream & operator<< (std::ostream &os, Duration const &duration)
 
std::ostream & operator<< (std::ostream &os, DurationTree const &duration_tree)
 
boost::log::record_ostream & operator<< (boost::log::record_ostream &os, DurationTreeMap::const_reference kv_pair)
 
void logAndEraseDurationTree (std::string *json_str)
 
void debug_timer_new_thread (ThreadId parent_thread_id)
 
ThreadId thread_id ()
 
bool fast_logging_check (Channel)
 
bool fast_logging_check (Severity severity)
 
template<typename X , typename Y >
BOOST_NOINLINE std::string * check_failed (X const &x, Y const &y, char const *xstr, char const *ystr, char const *op_str)
 

Variables

std::once_flag g_fatal_func_flag
 
bool g_any_active_channels {false}
 
Severity g_min_active_severity {Severity::FATAL}
 
thread_local std::atomic< QueryIdg_query_id {0}
 
std::mutex g_duration_tree_map_mutex
 
DurationTreeMap g_duration_tree_map
 
std::atomic< ThreadIdg_next_thread_id {0}
 
thread_local ThreadId const g_thread_id = g_next_thread_id++
 
constexpr std::array< char
const *, 3 > 
ChannelNames {"IR", "PTX", "ASM"}
 
constexpr std::array< char, 3 > ChannelSymbols {'R', 'P', 'A'}
 
constexpr std::array< char
const *, 8 > 
SeverityNames
 
constexpr std::array< char, 8 > SeveritySymbols {'4', '3', '2', '1', 'I', 'W', 'E', 'F'}
 

Typedef Documentation

Definition at line 157 of file Logger.h.

using logger::Channels = typedef std::set<Channel>

Definition at line 110 of file Logger.h.

using logger::Clock = typedef std::chrono::steady_clock

Definition at line 480 of file Logger.cpp.

using logger::ClogSync = typedef sinks::synchronous_sink<sinks::text_ostream_backend>

Definition at line 272 of file Logger.cpp.

using logger::DurationTreeMap = typedef std::unordered_map<ThreadId, std::unique_ptr<DurationTree>>

Definition at line 575 of file Logger.cpp.

using logger::DurationTreeNode = typedef boost::variant<Duration, DurationTree&>

Definition at line 518 of file Logger.cpp.

using logger::DurationTreeNodes = typedef std::deque<DurationTreeNode>

Definition at line 519 of file Logger.cpp.

using logger::FatalFunc = typedef void (*)() noexcept

Definition at line 154 of file Logger.h.

using logger::FileSync = typedef sinks::synchronous_sink<sinks::text_file_backend>

Definition at line 273 of file Logger.cpp.

using logger::QueryId = typedef uint64_t

Definition at line 318 of file Logger.h.

using logger::SeverityLogger = typedef boost::log::sources::severity_logger_mt<Severity>

Definition at line 162 of file Logger.h.

using logger::ThreadId = typedef uint64_t

Definition at line 345 of file Logger.h.

Enumeration Type Documentation

Enumerator
IR 
PTX 
ASM 
_NCHANNELS 

Definition at line 68 of file Logger.h.

Enumerator
DEBUG4 
DEBUG3 
DEBUG2 
DEBUG1 
INFO 
WARNING 
ERROR 
FATAL 
_NSEVERITIES 

Definition at line 80 of file Logger.h.

80  {
81  DEBUG4 = 0,
82  DEBUG3,
83  DEBUG2,
84  DEBUG1,
85  INFO,
86  WARNING,
87  ERROR,
88  FATAL,
89  _NSEVERITIES // number of severity levels
90 };

Function Documentation

logger::BOOST_LOG_GLOBAL_LOGGER_CTOR_ARGS ( gChannelLogger_IR  ,
ChannelLogger  ,
(keywords::channel=IR)   
)
template<typename X , typename Y >
BOOST_NOINLINE std::string* logger::check_failed ( X const x,
Y const y,
char const xstr,
char const ystr,
char const op_str 
)

Definition at line 225 of file Logger.h.

229  {
230  std::stringstream ss;
231  ss << "Check failed: " << xstr << op_str << ystr << " (" << x << op_str << y << ") ";
232  return new std::string(ss.str()); // Deleted by CHECK_OP macro.
233 }
void logger::debug_timer_new_thread ( ThreadId  parent_thread_id)

Call this when a new thread is spawned that will have timers that need to be associated with timers on the parent thread.

Definition at line 776 of file Logger.cpp.

References CHECK, g_duration_tree_map, g_duration_tree_map_mutex, and g_thread_id.

776  {
777  std::lock_guard<std::mutex> lock_guard(g_duration_tree_map_mutex);
778  auto parent_itr = g_duration_tree_map.find(parent_thread_id);
779  CHECK(parent_itr != g_duration_tree_map.end());
780  auto const current_depth = parent_itr->second->currentDepth();
781  auto& duration_tree_ptr = g_duration_tree_map[g_thread_id];
782  if (!duration_tree_ptr) {
783  duration_tree_ptr = std::make_unique<DurationTree>(g_thread_id, current_depth + 1);
784  parent_itr->second->pushDurationTree(*duration_tree_ptr);
785  } else {
786  // If this is executed, then this was not really a new thread.
787  // Since some libraries recycle threads, we won't trigger an error here.
788  }
789 }
std::mutex g_duration_tree_map_mutex
Definition: Logger.cpp:577
thread_local ThreadId const g_thread_id
Definition: Logger.cpp:580
#define CHECK(condition)
Definition: Logger.h:209
DurationTreeMap g_duration_tree_map
Definition: Logger.cpp:578
bool logger::fast_logging_check ( Channel  )
inline

Definition at line 183 of file Logger.h.

References g_any_active_channels.

Referenced by query_state::StdLog::log(), and query_state::StdLog::logCallStack().

183  {
184  extern bool g_any_active_channels;
185  return g_any_active_channels;
186 }
bool g_any_active_channels
Definition: Logger.cpp:287

+ Here is the caller graph for this function:

bool logger::fast_logging_check ( Severity  severity)
inline

Definition at line 188 of file Logger.h.

References g_min_active_severity.

188  {
190  return g_min_active_severity <= severity;
191 }
Severity g_min_active_severity
Definition: Logger.cpp:288
Severity
Definition: Logger.h:80
void logger::init ( LogOptions const log_opts)

Definition at line 290 of file Logger.cpp.

References _NSEVERITIES, logger::LogOptions::channels_, logger::LogOptions::full_log_dir(), g_any_active_channels, g_min_active_severity, i, INFO, nvtx_helpers::init(), LOG, logger::LogOptions::max_files_, logger::LogOptions::severity_, and logger::LogOptions::severity_clog_.

Referenced by UdfCompiler::compileFromCommandLine(), UdfCompiler::generateAST(), QueryRunner::QueryRunner::init(), CommandLineOptions::init_logging(), main(), ColumnarResults::mergeResults(), ResultSetManager::reduce(), Executor::reduceMultiDeviceResultSets(), FixedLengthEncoder< T, V >::updateStatsEncoded(), and NoneEncoder< T >::updateStatsEncoded().

290  {
291  boost::shared_ptr<boost::log::core> core = boost::log::core::get();
292  // boost::log::add_common_attributes(); // LineID TimeStamp ProcessID ThreadID
293  core->add_global_attribute("TimeStamp", attr::local_clock());
294  core->add_global_attribute("ProcessID", attr::current_process_id());
295  if (0 < log_opts.max_files_) {
296  boost::filesystem::path const full_log_dir = log_opts.full_log_dir();
297  bool const log_dir_was_created = boost::filesystem::create_directory(full_log_dir);
298  // Don't create separate log sinks for anything less than Severity::INFO.
299  Severity const min_sink_level = std::max(Severity::INFO, log_opts.severity_);
300  for (int i = min_sink_level; i < Severity::_NSEVERITIES; ++i) {
301  Severity const level = static_cast<Severity>(i);
302  core->add_sink(make_sink<FileSync>(log_opts, full_log_dir, level));
303  }
304  g_min_active_severity = std::min(g_min_active_severity, log_opts.severity_);
305  if (log_dir_was_created) {
306  LOG(INFO) << "Log directory(" << full_log_dir.native() << ") created.";
307  }
308  for (auto const channel : log_opts.channels_) {
309  core->add_sink(make_sink<FileSync>(log_opts, full_log_dir, channel));
310  }
311  g_any_active_channels = !log_opts.channels_.empty();
312  }
313  core->add_sink(make_sink<ClogSync>(log_opts));
314  g_min_active_severity = std::min(g_min_active_severity, log_opts.severity_clog_);
316 }
#define LOG(tag)
Definition: Logger.h:203
Severity g_min_active_severity
Definition: Logger.cpp:288
Severity
Definition: Logger.h:80
bool g_any_active_channels
Definition: Logger.cpp:287

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void logger::logAndEraseDurationTree ( std::string *  json_str)

Definition at line 728 of file Logger.cpp.

References CHECK, g_duration_tree_map, g_duration_tree_map_mutex, g_thread_id, and logger::JsonEncoder::str().

Referenced by logger::DebugTimer::stop(), and logger::DebugTimer::stopAndGetJson().

728  {
729  std::lock_guard<std::mutex> lock_guard(g_duration_tree_map_mutex);
730  DurationTreeMap::const_iterator const itr = g_duration_tree_map.find(g_thread_id);
731  CHECK(itr != g_duration_tree_map.cend());
732  auto const& root_duration = itr->second->rootDuration();
733  if (auto log = Logger(root_duration.severity_)) {
734  log.stream(root_duration.file_, root_duration.line_) << *itr;
735  }
736  if (json_str) {
737  JsonEncoder json_encoder;
738  *json_str = json_encoder.str(*itr);
739  }
740  EraseDurationTrees erase_duration_trees;
741  erase_duration_trees(itr);
742 }
std::mutex g_duration_tree_map_mutex
Definition: Logger.cpp:577
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
thread_local ThreadId const g_thread_id
Definition: Logger.cpp:580
#define CHECK(condition)
Definition: Logger.h:209
DurationTreeMap g_duration_tree_map
Definition: Logger.cpp:578

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename CONSOLE_SINK >
boost::shared_ptr<CONSOLE_SINK> logger::make_sink ( LogOptions const log_opts)

Definition at line 276 of file Logger.cpp.

References logger::LogOptions::severity_clog_.

276  {
277  auto sink = boost::make_shared<CONSOLE_SINK>();
278  boost::shared_ptr<std::ostream> clog(&std::clog, boost::null_deleter());
279  sink->locked_backend()->add_stream(clog);
280  sink->set_filter(log_opts.severity_clog_ <= severity);
281  set_formatter<Severity>(sink);
282  return sink;
283 }
template<typename... Ts>
Duration* logger::newDuration ( Severity  severity,
Ts &&...  args 
)

Definition at line 583 of file Logger.cpp.

References run_benchmark_import::args, g_duration_tree_map, g_duration_tree_map_mutex, g_enable_debug_timer, and g_thread_id.

583  {
584  if (g_enable_debug_timer) {
585  std::lock_guard<std::mutex> lock_guard(g_duration_tree_map_mutex);
586  auto& duration_tree_ptr = g_duration_tree_map[g_thread_id];
587  if (!duration_tree_ptr) {
588  duration_tree_ptr = std::make_unique<DurationTree>(g_thread_id, 0);
589  }
590  return duration_tree_ptr->newDuration(severity, std::forward<Ts>(args)...);
591  }
592  return nullptr; // Inactive - don't measure or report timing.
593 }
std::mutex g_duration_tree_map_mutex
Definition: Logger.cpp:577
bool g_enable_debug_timer
Definition: Logger.cpp:17
thread_local ThreadId const g_thread_id
Definition: Logger.cpp:580
DurationTreeMap g_duration_tree_map
Definition: Logger.cpp:578
std::ostream& logger::operator<< ( std::ostream &  out,
Channels const channels 
)

Definition at line 368 of file Logger.cpp.

References ChannelNames, and i.

368  {
369  int i = 0;
370  for (auto const channel : channels) {
371  out << (i++ ? " " : "") << ChannelNames.at(channel);
372  }
373  return out;
374 }
constexpr std::array< char const *, 3 > ChannelNames
Definition: Logger.h:70
std::ostream& logger::operator<< ( std::ostream &  out,
Severity const sev 
)

Definition at line 391 of file Logger.cpp.

References SeverityNames.

391  {
392  return out << SeverityNames.at(sev);
393 }
constexpr std::array< char const *, 8 > SeverityNames
Definition: Logger.h:92
std::ostream& logger::operator<< ( std::ostream &  os,
Duration const duration 
)

Definition at line 595 of file Logger.cpp.

References logger::Duration::depth_, logger::Duration::file_, nvtx_helpers::anonymous_namespace{nvtx_helpers.cpp}::filename(), logger::Duration::line_, logger::Duration::name_, logger::Duration::relative_start_time(), and logger::Duration::value().

595  {
596  return os << std::setw(2 * duration.depth_) << ' ' << duration.value() << "ms start("
597  << duration.relative_start_time() << "ms) " << duration.name_ << ' '
598  << filename(duration.file_) << ':' << duration.line_;
599 }

+ Here is the call graph for this function:

std::ostream& logger::operator<< ( std::ostream &  os,
DurationTree const duration_tree 
)

Definition at line 601 of file Logger.cpp.

References logger::DurationTree::depth_, logger::DurationTree::durations(), and logger::DurationTree::thread_id_.

601  {
602  os << std::setw(2 * duration_tree.depth_) << ' ' << "New thread("
603  << duration_tree.thread_id_ << ')';
604  for (auto const& duration_tree_node : duration_tree.durations()) {
605  os << '\n' << duration_tree_node;
606  }
607  return os << '\n'
608  << std::setw(2 * duration_tree.depth_) << ' ' << "End thread("
609  << duration_tree.thread_id_ << ')';
610 }

+ Here is the call graph for this function:

boost::log::record_ostream& logger::operator<< ( boost::log::record_ostream &  os,
DurationTreeMap::const_reference  kv_pair 
)

Definition at line 613 of file Logger.cpp.

614  {
615  auto itr = kv_pair.second->durations().cbegin();
616  auto const end = kv_pair.second->durations().cend();
617  auto const& root_duration = boost::get<Duration>(*itr);
618  os << "DEBUG_TIMER thread_id(" << kv_pair.first << ")\n"
619  << root_duration.value() << "ms total duration for " << root_duration.name_;
620  for (++itr; itr != end; ++itr) {
621  os << '\n' << *itr;
622  }
623  return os;
624 }
std::istream& logger::operator>> ( std::istream &  in,
Channels &  channels 
)

Definition at line 348 of file Logger.cpp.

References ChannelNames, parse_ast::line, and logger::anonymous_namespace{Logger.cpp}::unquote().

348  {
349  std::string line;
350  std::getline(in, line);
351  unquote(line);
352  std::regex const rex(R"(\w+)");
353  using TokenItr = std::regex_token_iterator<std::string::iterator>;
354  TokenItr const end;
355  for (TokenItr tok(line.begin(), line.end(), rex); tok != end; ++tok) {
356  auto itr = std::find(ChannelNames.cbegin(), ChannelNames.cend(), *tok);
357  if (itr == ChannelNames.cend()) {
358  in.setstate(std::ios_base::failbit);
359  break;
360  } else {
361  channels.emplace(static_cast<Channel>(itr - ChannelNames.cbegin()));
362  }
363  }
364  return in;
365 }
constexpr std::array< char const *, 3 > ChannelNames
Definition: Logger.h:70
tuple line
Definition: parse_ast.py:10
void unquote(std::string &str)
Definition: Logger.cpp:337

+ Here is the call graph for this function:

std::istream& logger::operator>> ( std::istream &  in,
Severity &  sev 
)

Definition at line 377 of file Logger.cpp.

References SeverityNames, and logger::anonymous_namespace{Logger.cpp}::unquote().

377  {
378  std::string token;
379  in >> token;
380  unquote(token);
381  auto itr = std::find(SeverityNames.cbegin(), SeverityNames.cend(), token);
382  if (itr == SeverityNames.cend()) {
383  in.setstate(std::ios_base::failbit);
384  } else {
385  sev = static_cast<Severity>(itr - SeverityNames.cbegin());
386  }
387  return in;
388 }
Severity
Definition: Logger.h:80
constexpr std::array< char const *, 8 > SeverityNames
Definition: Logger.h:92
void unquote(std::string &str)
Definition: Logger.cpp:337

+ Here is the call graph for this function:

QueryId logger::query_id ( )

Definition at line 454 of file Logger.cpp.

References g_query_id.

Referenced by DBHandler::broadcast_serialized_rows(), query_state::StdLog::log(), ResultSet::ResultSetComparator< BUFFER_ITERATOR_TYPE >::materializeApproxQuantileColumn(), ResultSet::ResultSetComparator< BUFFER_ITERATOR_TYPE >::materializeCountDistinctColumn(), ResultSet::parallelRowCount(), ResultSet::parallelTop(), and logger::Logger::stream().

454  {
455  return g_query_id.load();
456 }
thread_local std::atomic< QueryId > g_query_id
Definition: Logger.cpp:452

+ Here is the caller graph for this function:

void logger::set_once_fatal_func ( FatalFunc  fatal_func)

Definition at line 318 of file Logger.cpp.

Referenced by QueryRunner::QueryRunner::QueryRunner().

318  {
319  if (g_fatal_func.exchange(fatal_func)) {
320  throw std::runtime_error(
321  "logger::set_once_fatal_func() should not be called more than once.");
322  }
323 }

+ Here is the caller graph for this function:

QidScopeGuard logger::set_thread_local_query_id ( QueryId const  query_id)

Definition at line 468 of file Logger.cpp.

References g_query_id.

Referenced by ResultSet::ResultSetComparator< BUFFER_ITERATOR_TYPE >::materializeApproxQuantileColumn(), ResultSet::ResultSetComparator< BUFFER_ITERATOR_TYPE >::materializeCountDistinctColumn(), ResultSet::parallelRowCount(), ResultSet::parallelTop(), and query_state::QueryState::setThreadLocalQueryId().

468  {
469  QueryId expected = 0;
470  return g_query_id.compare_exchange_strong(expected, query_id) ? QidScopeGuard(query_id)
471  : QidScopeGuard(0);
472 }
uint64_t QueryId
Definition: Logger.h:318
thread_local std::atomic< QueryId > g_query_id
Definition: Logger.cpp:452
QueryId query_id()
Definition: Logger.cpp:454

+ Here is the caller graph for this function:

void logger::shutdown ( )

Definition at line 325 of file Logger.cpp.

References nvtx_helpers::shutdown().

Referenced by heartbeat(), EmbeddedDatabase::DBEngineImpl::reset(), TestProcessSignalHandler::shutdownSubsystemsAndExit(), startMapdServer(), and logger::LogShutdown::~LogShutdown().

325  {
326  static std::once_flag logger_flag;
327  std::call_once(logger_flag, []() {
328  boost::log::core::get()->remove_all_sinks();
330  });
331 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

constexpr std::array<char const*, 3> logger::ChannelNames {"IR", "PTX", "ASM"}

Definition at line 70 of file Logger.h.

Referenced by operator<<(), and operator>>().

constexpr std::array<char, 3> logger::ChannelSymbols {'R', 'P', 'A'}

Definition at line 72 of file Logger.h.

bool logger::g_any_active_channels {false}

Definition at line 287 of file Logger.cpp.

Referenced by fast_logging_check(), and init().

std::mutex logger::g_duration_tree_map_mutex

Definition at line 577 of file Logger.cpp.

Referenced by debug_timer_new_thread(), logAndEraseDurationTree(), and newDuration().

std::once_flag logger::g_fatal_func_flag

Definition at line 270 of file Logger.cpp.

Referenced by logger::Logger::~Logger().

Severity logger::g_min_active_severity {Severity::FATAL}

Definition at line 288 of file Logger.cpp.

Referenced by fast_logging_check(), and init().

std::atomic<ThreadId> logger::g_next_thread_id {0}

Definition at line 579 of file Logger.cpp.

thread_local std::atomic<QueryId> logger::g_query_id {0}
thread_local ThreadId const logger::g_thread_id = g_next_thread_id++
constexpr std::array<char const*, 8> logger::SeverityNames
Initial value:
{"DEBUG4",
"DEBUG3",
"DEBUG2",
"DEBUG1",
"INFO",
"WARNING",
"ERROR",
"FATAL"}

Definition at line 92 of file Logger.h.

Referenced by operator<<(), and operator>>().

constexpr std::array<char, 8> logger::SeveritySymbols {'4', '3', '2', '1', 'I', 'W', 'E', 'F'}

Definition at line 101 of file Logger.h.