31 #include <string_view>
32 #include <unordered_map>
34 #include "boost/log/common.hpp"
37 using SeverityLogger = boost::log::sources::severity_logger_mt<Severity>;
41 namespace query_state {
47 , started(
Clock::now().time_since_epoch())
48 , stopped(
Clock::duration::zero()) {}
51 CHECK(
stopped.exchange(Clock::now().time_since_epoch()) == Clock::duration::zero())
52 <<
"stop() called more than once.";
56 std::shared_ptr<Catalog_Namespace::SessionInfo const>
const& session_info)
57 : session_info(session_info)
58 , db_name(session_info->getCatalog().getCurrentDB().dbName)
59 , user_name(session_info->get_currentUser().userLoggable())
60 , public_session_id(session_info->get_public_session_id()) {}
63 std::shared_ptr<Catalog_Namespace::SessionInfo const>
const& session_info,
64 std::string query_str)
65 : session_data_(session_info ? boost::make_optional<
SessionData>(session_info)
67 , query_str_(std::move(query_str))
69 , submitted_(::
toString(std::chrono::system_clock::now())) {}
87 throw std::runtime_error(
"session_info_ was not set for this QueryState.");
93 throw std::runtime_error(
"session_info requested but has expired.");
108 unsigned const depth,
109 Events::iterator parent) {
110 auto it = parent ==
events_.end() ?
events_.begin() : std::next(parent);
111 for (; it !=
events_.end(); ++it) {
112 if (it->parent == parent) {
113 auto duration = it->duration();
115 << std::setw(depth << 1) <<
' ' << it->name <<
' ' << it->thread_id
116 <<
" - total time " << (duration ? *duration : -1) <<
" ms";
133 Timer::Timer(std::shared_ptr<QueryState>&& query_state, Events::iterator event)
134 : query_state_(std::move(query_state)), event_(event) {
164 if (quote_formatter.
str.find_first_of(
" \"") == std::string::npos) {
165 return os << quote_formatter.
str;
167 return os << std::quoted(quote_formatter.
str,
'"',
'"');
192 static std::unordered_map<std::string_view, logger::Severity>
const map{
213 auto const itr = map.find(func);
214 return itr == map.cend() ? defaultSeverity : itr->second;
219 std::stringstream ss;
222 <<
' ' << label <<
' ' <<
func_ <<
' ' <<
match_ <<
' '
223 << duration<std::chrono::milliseconds>() <<
' ';
236 std::stringstream values;
237 unsigned nvalues = 0;
239 ss << (nvalues ?
',' :
'{') << std::quoted(
"query_str",
'"',
'"');
240 values << (nvalues++ ?
',' :
'{')
245 for (
auto itr = nv.cbegin(); itr != nv.cend(); ++itr) {
246 ss << (nvalues ?
',' :
'{') << std::quoted(*itr,
'"',
'"');
247 values << (nvalues++ ?
',' :
'{') << std::quoted(*++itr,
'"',
'"');
249 ss <<
"} " << values.rdbuf() <<
'}';
251 BOOST_LOG_SEV(logger::gSeverityLogger::get(), severity) << ss.rdbuf();
257 std::stringstream ss;
260 <<
' ' << label <<
' ' <<
func_ <<
' ' <<
match_ <<
" total time "
261 << duration<std::chrono::milliseconds>() <<
" ms";
263 BOOST_LOG_SEV(logger::gSeverityLogger::get(), severity) << ss.rdbuf();
283 std::shared_ptr<Catalog_Namespace::SessionInfo> session_info) {
boost::optional< SessionData > session_data_
std::shared_ptr< QueryState > query_state_
void logCallStack(std::stringstream &, unsigned const depth, Events::iterator parent)
QueryStateProxy createQueryStateProxy()
std::string const & get_public_session_id() const
Events::iterator const parent_
void setQuerySubmittedTime(const std::string &t)
void setSessionInfo(std::shared_ptr< Catalog_Namespace::SessionInfo >)
Timer createTimer(char const *event_name)
std::ostream & operator<<(std::ostream &os, QuoteFormatter const "e_formatter)
QueryState(std::shared_ptr< Catalog_Namespace::SessionInfo const > const &, std::string query_str)
void omnisci_range_push(Category c, const char *name, const char *file)
This file contains the class specification and related data structures for Catalog.
std::atomic< Clock::duration > stopped
std::list< std::string > name_value_pairs_
bool fast_logging_check(Channel)
QueryStateProxy createQueryStateProxy()
const DBMetadata & getCurrentDB() const
static logger::Severity stdlogBeginSeverity(char const *func)
void setQueryState(std::shared_ptr< QueryState >)
void logCallStack(logger::Severity, char const *label)
std::shared_ptr< Catalog_Namespace::SessionInfo > getSessionInfo() const
boost::log::sources::severity_logger_mt< Severity > SeverityLogger
std::string toString(const Executor::ExtModuleKinds &kind)
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Event(char const *const name, Events::iterator parent)
Timer(std::shared_ptr< QueryState > &&, Events::iterator event)
static std::atomic< int64_t > s_match
Catalog & getCatalog() const
QueryState & query_state_
std::shared_ptr< QueryState > query_state_
bool g_enable_watchdog false
std::string public_session_id
void log(logger::Severity, char const *label)
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Timer createTimer(char const *event_name, Events::iterator parent)
const UserMetadata & get_currentUser() const
ThreadLocalIds thread_local_ids()
std::chrono::steady_clock Clock
const std::string getQuerySubmittedTime() const