23 #ifndef OMNISCI_THRIFTHANDLER_QUERYSTATE_H
24 #define OMNISCI_THRIFTHANDLER_QUERYSTATE_H
29 #include <boost/circular_buffer.hpp>
30 #include <boost/filesystem.hpp>
31 #include <boost/noncopyable.hpp>
32 #include <boost/optional.hpp>
33 #include <boost/preprocessor.hpp>
86 namespace Catalog_Namespace {
90 namespace query_state {
92 using Clock = std::chrono::steady_clock;
105 template <
typename Units = std::chrono::milliseconds>
106 boost::optional<typename Units::rep>
duration()
const {
107 auto const stop_time =
stopped.load();
108 return boost::make_optional(
109 stop_time != Clock::duration::zero(),
110 std::chrono::duration_cast<Units>(stop_time -
started).count());
128 SessionData(std::shared_ptr<Catalog_Namespace::SessionInfo const>
const&);
133 class QueryState :
public std::enable_shared_from_this<QueryState> {
140 void logCallStack(std::stringstream&,
unsigned const depth, Events::iterator parent);
143 QueryState(std::shared_ptr<Catalog_Namespace::SessionInfo const>
const&,
144 std::string query_str);
147 template <
typename... ARGS>
153 return std::make_shared<EnableMakeShared>(std::forward<ARGS>(
args)...);
187 using CircleBuffer = boost::circular_buffer<std::shared_ptr<QueryState>>;
193 template <
typename... ARGS>
218 Timer(std::shared_ptr<QueryState>&&, Events::iterator event);
234 #define STDLOG(...) \
235 BOOST_PP_IF(BOOST_PP_IS_EMPTY(__VA_ARGS__), \
236 query_state::StdLog(__FILE__, __LINE__, __func__), \
237 query_state::StdLog(__FILE__, __LINE__, __func__, __VA_ARGS__))
248 template <
typename... Pairs>
256 static_assert(
sizeof...(Pairs) % 2 == 0,
257 "StdLogData() requires an even number of name/value parameters.");
269 template <
typename... Pairs>
273 std::shared_ptr<Catalog_Namespace::SessionInfo> session_info,
275 :
StdLogData(file, line, func, std::forward<Pairs>(pairs)...)
280 template <
typename... Pairs>
284 std::shared_ptr<Catalog_Namespace::SessionInfo> session_info,
285 std::shared_ptr<QueryState> query_state,
287 :
StdLogData(file, line, func, std::forward<Pairs>(pairs)...)
293 template <
typename... Pairs>
297 std::shared_ptr<QueryState> query_state,
299 :
StdLogData(file, line, func, std::forward<Pairs>(pairs)...)
303 template <
typename... Pairs>
304 StdLog(
char const* file,
unsigned line,
char const* func, Pairs&&... pairs)
305 :
StdLogData(file, line, func, std::forward<Pairs>(pairs)...) {
311 template <
typename... Pairs>
313 static_assert(
sizeof...(Pairs) % 2 == 0,
314 "appendNameValuePairs() requires an even number of parameters.");
316 {
to_string(std::forward<Pairs>(pairs))...});
318 template <
typename Units = std::chrono::milliseconds>
320 return std::chrono::duration_cast<Units>(Clock::now() -
start_).count();
323 std::shared_ptr<Catalog_Namespace::SessionInfo>
getSessionInfo()
const;
325 void setSessionInfo(std::shared_ptr<Catalog_Namespace::SessionInfo>);
330 #endif // OMNISCI_THRIFTHANDLER_QUERYSTATE_H
boost::optional< SessionData > session_data_
std::shared_ptr< QueryState > query_state_
void logCallStack(std::stringstream &, unsigned const depth, Events::iterator parent)
QueryStateProxy createQueryStateProxy()
boost::optional< SessionData > const & getSessionData() const
std::string const & getQueryStr() const
Events::iterator const parent_
Clock::duration const started
static std::shared_ptr< QueryState > create(ARGS &&...args)
void setQuerySubmittedTime(const std::string &t)
Timer & operator=(Timer const &)=delete
CircleBuffer::value_type create(ARGS &&...args)
Events::iterator const parent
void setSessionInfo(std::shared_ptr< Catalog_Namespace::SessionInfo >)
Timer createTimer(char const *event_name)
QueryState(std::shared_ptr< Catalog_Namespace::SessionInfo const > const &, std::string query_str)
Units::rep duration() const
std::atomic< Clock::duration > stopped
std::list< std::string > name_value_pairs_
StdLogData(char const *file, unsigned line, char const *func, Pairs &&...pairs)
void setLogged(bool logged)
boost::circular_buffer< std::shared_ptr< QueryState >> CircleBuffer
QueryStateProxy createQueryStateProxy()
std::string const query_str_
static logger::Severity stdlogBeginSeverity(char const *func)
void setQueryState(std::shared_ptr< QueryState >)
StdLog(char const *file, unsigned line, char const *func, std::shared_ptr< Catalog_Namespace::SessionInfo > session_info, Pairs &&...pairs)
void logCallStack(logger::Severity, char const *label)
std::shared_ptr< Catalog_Namespace::SessionInfo > getSessionInfo() const
QueryStateProxy(QueryState &query_state, Events::iterator parent)
std::thread::id const thread_id
StdLog(char const *file, unsigned line, char const *func, std::shared_ptr< QueryState > query_state, Pairs &&...pairs)
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
std::weak_ptr< Catalog_Namespace::SessionInfo const > session_info
std::list< Event > Events
Event(char const *const name, Events::iterator parent)
Timer(std::shared_ptr< QueryState > &&, Events::iterator event)
void appendNameValuePairs(Pairs &&...pairs)
static std::atomic< int64_t > s_match
QueryState & query_state_
boost::optional< typename Units::rep > duration() const
std::shared_ptr< QueryState > query_state_
std::string filename(char const *path)
Clock::time_point const start_
std::function< void(Event const &)> EventFunction
StdLog(char const *file, unsigned line, char const *func, std::shared_ptr< Catalog_Namespace::SessionInfo > session_info, std::shared_ptr< QueryState > query_state, Pairs &&...pairs)
StdLog(char const *file, unsigned line, char const *func, Pairs &&...pairs)
std::string public_session_id
QueryState * operator->() const
void log(logger::Severity, char const *label)
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
CircleBuffer circle_buffer_
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Timer createTimer(char const *event_name, Events::iterator parent)
std::chrono::steady_clock Clock
const std::string getQuerySubmittedTime() const
std::atomic< bool > logged_