28a0802000-08-14Martin Stjernholm // -*- pike -*- // // Some stuff to do logging of a request through the server. //
84aee52015-10-23Henrik Grubbström (Grubba) // $Id$
f2180f2002-03-12Martin Stjernholm  #ifndef REQUEST_TRACE_H #define REQUEST_TRACE_H #include <roxen.h> #include <module.h>
28a0802000-08-14Martin Stjernholm 
b4642f2008-09-03Jonas Wallden // Note that TRACE_ENTER (and TRACE_LEAVE) takes message strings // in plain text. Messages are preferably a single line, and they
1b87102002-10-25Martin Stjernholm // should not end with period and/or newline.
b4642f2008-09-03Jonas Wallden // // // Roxen 5.0 compatibility notice: //
40ba452008-09-26Martin Stjernholm // Pre-5.0 TRACE_ENTER and TRACE_LEAVE allowed html markup to pass // through unquoted into the Resolve Path wizard page, but since the // ultimate destination may not be a web page at all this capability // has been removed. The Resolve Path wizard will now quote all // strings instead.
76c8c12002-03-19Martin Stjernholm 
35d1552008-11-06Martin Stjernholm #if efun (gethrvtime) #define HRTIME() gethrvtime() #elif efun (gethrtime) #define HRTIME() gethrtime() #else #define HRTIME() 0 #endif
28a0802000-08-14Martin Stjernholm  #ifdef REQUEST_TRACE
35d1552008-11-06Martin Stjernholm # define ID_TRACE_ENTER(ID, MSG, OBJ) do{ \ int _ts_ = HRTIME(); \ if (object _id_ = (ID)) { \ Roxen->trace_enter ((ID), (MSG), (OBJ), _ts_); \ _id_->misc->trace_overhead += HRTIME() - _ts_; \ } \ }while(0) # define ID_TRACE_LEAVE(ID, MSG) do{ \ int _ts_ = HRTIME(); \ if (object _id_ = (ID)) { \ Roxen->trace_leave ((ID), (MSG), _ts_); \ _id_->misc->trace_overhead += HRTIME() - _ts_; \ } \ }while(0)
28a0802000-08-14Martin Stjernholm  #else
35d1552008-11-06Martin Stjernholm # define ID_TRACE_ENTER(ID, MSG, OBJ) do{ \ if (object _id_ = (ID)) { \ mapping _id_misc_ = _id_->misc; \ if (function(string,mixed,int:void) _trace_enter = \
18b9c52009-04-21Martin Stjernholm  ([function(string,mixed,int:void)] _id_misc_->trace_enter)) { \ int _ts_ = HRTIME(); \ _trace_enter ((MSG), (OBJ), _ts_); \ _id_->misc->trace_overhead += HRTIME() - _ts_; \ } \
35d1552008-11-06Martin Stjernholm  } \
fa4f792000-03-13Martin Nilsson  }while(0)
35d1552008-11-06Martin Stjernholm # define ID_TRACE_LEAVE(ID, MSG) do{ \ if (object _id_ = (ID)) { \ mapping _id_misc_ = _id_->misc; \ if (function(string,int:void) _trace_leave = \
18b9c52009-04-21Martin Stjernholm  ([function(string,int:void)] _id_misc_->trace_leave)) { \ int _ts_ = HRTIME(); \ _trace_leave ((MSG), _ts_); \ _id_->misc->trace_overhead += HRTIME() - _ts_; \ } \
35d1552008-11-06Martin Stjernholm  } \
fa4f792000-03-13Martin Nilsson  }while(0)
28a0802000-08-14Martin Stjernholm 
fa4f792000-03-13Martin Nilsson #endif
4717052001-05-07Per Hedbor 
35d1552008-11-06Martin Stjernholm #define TRACE_ENTER(MSG,OBJ) ID_TRACE_ENTER (id, (MSG), (OBJ)) #define TRACE_LEAVE(MSG) ID_TRACE_LEAVE (id, (MSG))
6e28de2008-11-05Martin Stjernholm 
76c8c12002-03-19Martin Stjernholm // SIMPLE_TRACE_ENTER and SIMPLE_TRACE_LEAVE are simpler variants of
52ff1e2008-09-26Martin Stjernholm // the above macros since they handle sprintf style format lists. Note // the reversed argument order in SIMPLE_TRACE_ENTER compared to // TRACE_ENTER.
76c8c12002-03-19Martin Stjernholm 
6e28de2008-11-05Martin Stjernholm #define SIMPLE_ID_TRACE_ENTER(ID, OBJ, MSG...) do { \
76c8c12002-03-19Martin Stjernholm  array _msg_arr_; \
6e28de2008-11-05Martin Stjernholm  ID_TRACE_ENTER ((ID), \ (_msg_arr_ = ({MSG}), \
1b87102002-10-25Martin Stjernholm  sizeof (_msg_arr_) > 1 ? sprintf (@_msg_arr_) : \
b4642f2008-09-03Jonas Wallden  (sizeof (_msg_arr_) ? _msg_arr_[0] : "")), \
76c8c12002-03-19Martin Stjernholm  (OBJ)); \ } while (0)
6e28de2008-11-05Martin Stjernholm #define SIMPLE_ID_TRACE_LEAVE(ID, MSG...) do { \
76c8c12002-03-19Martin Stjernholm  array _msg_arr_; \
6e28de2008-11-05Martin Stjernholm  ID_TRACE_LEAVE ((ID), \ (_msg_arr_ = ({MSG}), \
879c702004-05-14Martin Stjernholm  sizeof (_msg_arr_) > 1 ? sprintf (@_msg_arr_) : \
b4642f2008-09-03Jonas Wallden  (sizeof (_msg_arr_) ? _msg_arr_[0] : ""))); \
76c8c12002-03-19Martin Stjernholm  } while (0)
6e28de2008-11-05Martin Stjernholm #define SIMPLE_TRACE_ENTER(OBJ, MSG...) SIMPLE_ID_TRACE_ENTER (id, OBJ, MSG) #define SIMPLE_TRACE_LEAVE(MSG...) SIMPLE_ID_TRACE_LEAVE (id, MSG)
f2180f2002-03-12Martin Stjernholm // The following variant should be used inside RXML.Frame callbacks // such as do_enter. In addition to the request trace, it does rxml // debug logging which is activated with the DEBUG define in // combination with the magic _debug_ tag argument or the RXML_VERBOSE // or RXML_REQUEST_VERBOSE defines. #define TAG_TRACE_ENTER(MSG...) do { \ array _msg_arr_; \ string _msg_; \
35d1552008-11-06Martin Stjernholm  TRACE_ENTER ("tag <" + (tag && tag->name) + "> " + \
1b87102002-10-25Martin Stjernholm  (_msg_arr_ = ({MSG}), \ _msg_ = sizeof (_msg_arr_) > 1 ? sprintf (@_msg_arr_) : \
b4642f2008-09-03Jonas Wallden  (sizeof (_msg_arr_) ? _msg_arr_[0] : "")), \
f2180f2002-03-12Martin Stjernholm  tag); \ DO_IF_DEBUG ( \ if (TAG_DEBUG_TEST (flags & RXML.FLAG_DEBUG)) \ tag_debug ("%O: %s\n", this_object(), \
76c8c12002-03-19Martin Stjernholm  _msg_ || \ (_msg_arr_ = ({MSG}), \ sizeof (_msg_arr_) > 1 ? sprintf (@_msg_arr_) : \ (sizeof (_msg_arr_) ? _msg_arr_[0] : ""))); \
1b87102002-10-25Martin Stjernholm  ); \
f2180f2002-03-12Martin Stjernholm  } while (0) #define TAG_TRACE_LEAVE(MSG...) do { \ array _msg_arr_; \ string _msg_; \
bc34bf2002-10-25Martin Stjernholm  TRACE_LEAVE ((_msg_arr_ = ({MSG}), \ _msg_ = sizeof (_msg_arr_) > 1 ? sprintf (@_msg_arr_) : \ (sizeof (_msg_arr_) ? _msg_arr_[0] : ""))); \
f2180f2002-03-12Martin Stjernholm  DO_IF_DEBUG ( \ if (TAG_DEBUG_TEST (flags & RXML.FLAG_DEBUG)) { \ if (!_msg_) { \ _msg_arr_ = ({MSG}); \
76c8c12002-03-19Martin Stjernholm  _msg_ = \ sizeof (_msg_arr_) > 1 ? sprintf (@_msg_arr_) : \ (sizeof (_msg_arr_) ? _msg_arr_[0] : ""); \
f2180f2002-03-12Martin Stjernholm  } \ if (sizeof (_msg_)) tag_debug ("%O: %s\n", this_object(), _msg_); \ } \ ); \ } while (0)
4717052001-05-07Per Hedbor  #ifdef AVERAGE_PROFILING #define PROF_ENTER(X,Y) id->conf->avg_prof_enter( X, Y, id ) #define PROF_LEAVE(X,Y) id->conf->avg_prof_leave( X, Y, id ) #define COND_PROF_ENTER(X,Y,Z) if(X)PROF_ENTER(Y,Z) #define COND_PROF_LEAVE(X,Y,Z) if(X)PROF_LEAVE(Y,Z) #else #define PROF_ENTER(X,Y) #define PROF_LEAVE(X,Y) #define COND_PROF_ENTER(X,Y,Z) #define COND_PROF_LEAVE(X,Y,Z) #endif
f2180f2002-03-12Martin Stjernholm  #endif // !REQUEST_TRACE_H