1 #ifndef CORELIB___PERF_LOG__HPP
2 #define CORELIB___PERF_LOG__HPP
149 static bool IsON(
void);
152 static void SetON(
bool enable =
true);
169 double GetElapsedTime(
void)
const;
172 bool x_CheckValidity(
const CTempString& err_msg)
const;
213 #define PERF_POST(perf_logger, status, resource, args) \
214 do { if ( CPerfLogger::IsON() ) \
215 perf_logger.Post(CRequestStatus::status, resource) args; \
232 #define PERF_POST_DB(perf_logger, status, resource, server, args) \
233 do { if ( CPerfLogger::IsON() ) \
234 perf_logger.Post(CRequestStatus::status, resource) \
235 .Print("dbserver", server) args; \
318 void Post(
int status,
440 return Post((
int)status, resource, status_msg);
488 "CPerfLogger is already discarded");
501 : m_Logger(
state), m_Resource(resource)
503 if ( resource.
empty() ) {
505 "CPerfLogGuard:: resource name is not specified");
517 if ( resource.
empty() ) {
519 "CPerfLogGuard:: resource name is not specified");
528 : m_Logger(stopwatch,
state), m_Resource(resource)
530 if ( resource.
empty() ) {
532 "CPerfLogGuard:: resource name is not specified");
569 "CPerfLogGuard is already discarded");
581 return Post((
int)status, status_msg);
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
bool x_CheckValidity(const CTempString &err_msg) const
void Post(CRequestStatus::ECode status, CTempString status_msg=CTempString())
Write the collected resource info and timing to the log.
#define ERR_POST_ONCE(message)
Error posting only once during program execution.
EStart
If to start the timing immediately.
CDiagContext_Extra Post(CRequestStatus::ECode status, CTempString resource, CTempString status_msg=CTempString())
Log the timing; stop and deactivate the timer.
~CPerfLogger()
If the timer is still active, then post an error (once).
double GetElapsedTime(void) const
Get total elapsed time (including any adjustments) in seconds.
CPerfLogGuard(CTempString resource, CPerfLogger::EStart state=CPerfLogger::eStart)
Constructor.
void Discard(void)
Discard the results.
CPerfLogger & GetLogger(void)
Access logger directly.
void Discard(void)
Discard the timing results; stop and deactivate the timer.
SDiagMessage::TExtraArgs m_Parameters
list< TExtraArg > TExtraArgs
const CTime & GetLoggerStartTime(void) const
Get the logger's start time.
CPerfLogger(EStart state=eStart)
Constructor. Starts the timer by default.
void Adjust(CTimeSpan timespan)
Adjust the printed elapsed time.
pair< string, string > TExtraArg
static bool IsON(void)
Is performance logging on, globally? Controlled by CParam(section="Log", entry="PerfLogging",...
~CPerfLogGuard()
If Post() or Discard() have not been called, then log the collected info with status 500.
CStopWatch::EStart m_TimerState
void Suspend(void)
Suspend the timer.
CPerfLogGuard & AddParameter(CTempString name, CTempString value)
Add info to the resource's description.
void Suspend(void)
Suspend the timer.
void Start(void)
Activate and start (or, restart after Suspend()) the timer.
void Start(void)
Activate and start (or, restart after Suspend()) the timer.
@ eStart
Call Start() immediately after creating.
@ e500_InternalServerError
void Error(CExceptionArgs_Base &args)
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
bool empty(void) const
Return true if the represented string is empty (i.e., the length is zero)
double Elapsed(void) const
Return time elapsed since first Start() or last Restart() call (in seconds).
void Stop(void)
Suspend the timer.
double GetAsDouble(void) const
Return time span as number of seconds.
bool IsEmpty(void) const
Is time object empty (date and time)?
EStart
Defines how to create new timer.
CTimeSpan DiffTimeSpan(const CTime &t) const
Difference in nanoseconds from specified time.
void Start(void)
Start the timer.
CTime GetFastLocalTime(void)
Quick and dirty getter of local time.
@ eStart
Start timer immediately after creating.
@ eStop
Do not start timer, just create it.
#define NCBI_XNCBI_EXPORT
const GenericPointer< typename T::ValueType > T2 value
Defines NCBI C++ diagnostic APIs, classes, and macros.
Defines: CTimeFormat - storage class for time format.
Defines CRequestStatus class for NCBI C++ diagnostic API.