NCBI C++ ToolKit
Public Types | Public Member Functions | Static Public Member Functions | Static Protected Member Functions | Private Attributes
CStopWatch Class Reference

Search Toolkit Book for CStopWatch

CStopWatch --. More...

#include <ncbitime.hpp>

+ Inheritance diagram for CStopWatch:

List of all members.

Public Types

enum  EStart { eStart, eStop }
 Defines how to create new timer. More...

Public Member Functions

 CStopWatch (EStart state=eStop)
 Constructor.
 NCBI_DEPRECATED_CTOR (CStopWatch(bool start))
 Constructor.
void Start (void)
 Start the timer.
double Elapsed (void) const
 Return time elapsed since first Start() or last Restart() call (in seconds).
void Stop (void)
 Suspend the timer.
double Restart (void)
 Return time elapsed since first Start() or last Restart() call (in seconds).
void Reset (void)
 Stop (if running) and reset the timer.
bool IsRunning (void)
 Check state of stopwatch.
string AsString (const CTimeFormat &format=kEmptyStr) const
 Transform stopwatch time to string.
 operator string (void) const
 Return stopwatch time as string using the format returned by GetFormat().
string AsSmartString (CTimeSpan::ESmartStringPrecision precision=CTimeSpan::eSSP_Nanosecond, ERound rounding=eTrunc, CTimeSpan::ESmartStringZeroMode zero_mode=CTimeSpan::eSSZ_Default) const
 Transform elapsed time to "smart" string.

Static Public Member Functions

static void SetFormat (const CTimeFormat &format)
 Set the current stopwatch time format.
static CTimeFormat GetFormat (void)
 Get the current stopwatch time format.

Static Protected Member Functions

static double GetTimeMark ()
 Get current time mark.

Private Attributes

double m_Start
 Start time value.
double m_Total
 Accumulated elapsed time.
EStart m_State
 Stopwatch state (started/stopped)

Detailed Description

CStopWatch --.

Define a stop watch class to measure elasped time.

Definition at line 1672 of file ncbitime.hpp.


Member Enumeration Documentation

Defines how to create new timer.

Enumerator:
eStart 

Start timer immediately after creating.

eStop 

Do not start timer, just create it.

Definition at line 1676 of file ncbitime.hpp.


Constructor & Destructor Documentation

CStopWatch::CStopWatch ( EStart  state = eStop) [inline]

Constructor.

NB. By default ctor doesn't start timer, it merely creates it.

Definition at line 2467 of file ncbitime.hpp.


Member Function Documentation

string CStopWatch::AsSmartString ( CTimeSpan::ESmartStringPrecision  precision = CTimeSpan::eSSP_Nanosecond,
ERound  rounding = eTrunc,
CTimeSpan::ESmartStringZeroMode  zero_mode = CTimeSpan::eSSZ_Default 
) const [inline]

Transform elapsed time to "smart" string.

For more details see CTimeSpan::AsSmartString().

Parameters:
precisionEnum value describing how many parts of time span should be returned.
roundingRounding mode.
zero_modeMode to print or skip zero parts of time span.
Returns:
A string representation of elapsed time span.
See also:
CTimeSpan::AsSmartString, AsString, Elapsed

Definition at line 2560 of file ncbitime.hpp.

References CTimeSpan::AsSmartString().

Referenced by CBlastDbBioseqSource::CBlastDbBioseqSource(), BlastdbCopyApplication::Run(), and COpenViewlDlgTask::x_Run().

string CStopWatch::AsString ( const CTimeFormat format = kEmptyStr) const

Transform stopwatch time to string.

According to used OS, the double representation can provide much finer grained time control. The string representation is limited by nanoseconds.

Parameters:
formatIf "format" is not defined, then GetFormat() will be used. Format specifier used to convert value returned by Elapsed() to string.
See also:
CTimeSpan::AsString, CTimeFormat, Elapsed, GetFormat, SetFormat

Definition at line 3072 of file ncbitime.cpp.

References CTimeSpan::AsString(), Elapsed(), GetFormat(), and CTimeFormat::IsEmpty().

Referenced by CDiagContext::GetProperty(), operator<<(), CSequenceInputStats::PrintReport(), and CDiagContext::x_PrintMessage().

double CStopWatch::Elapsed ( void  ) const [inline]

Return time elapsed since first Start() or last Restart() call (in seconds).

Result is 0.0 if Start() or Restart() wasn't previously called.

Definition at line 2486 of file ncbitime.hpp.

References GetTimeMark().

Referenced by CBuildDatabase::AddSequences(), CThreadPool_Impl::AddTask(), CNcbiTestApplication::AdjustTestTimeout(), AsString(), CBuildDatabase::Build(), ConvertToPairwise(), CBDB_Cache::EvaluateTimeLine(), CExecute::Exec(), CSeqEntryPresenter::Finalize(), GetBlobReader(), CProcess::Kill(), CBDB_SplitTest::LoadSplitStore(), CBDB_SplitTest::LoadTestSet(), CReadDispatcher::LogStat(), CProjectTreePanel::OnDragOver(), CThreadPool_Controller_PID::OnEvent(), CGenBankUIDataSource::Open(), CSQLITE3_Cache::Open(), CNetBLASTUIDataSource::Open(), CQueryExecEvalFunc::operator()(), CPerfLogger::Post(), CFileHandleDiagHandler::Post(), CFileDiagHandler::Post(), CSeqEntryPresenter::Process(), CTruncateRequest::Process(), CGlCgiImageApplication::ProcessRequest(), CAsnvalApp::ReadClassMember(), CFileHandleDiagHandler::Reopen(), CFileDiagHandler::Reopen(), CSubImageApp::Run(), CConvImageApp::Run(), CSampleNetScheduleClient::Run(), CObjConvProfile::Run(), CMytestApplication::Run(), CProjBulderApp::Run(), CAnnotMetaDataJob::Run(), CDbapiTestSpeedApp::RunSample(), CPhyloTreePS::Update(), CLDS_Object::UpdateBinaryASNObject(), CBuildDatabase::x_AddRemoteSequences(), CRequestRateControl::x_Approve(), CForceJob::x_Calculate(), CAlnMultiDSBuilder::x_CreateSparseDataSource(), CComponentSearchJob::x_DoSearch(), CBuildDatabase::x_DupLocal(), CNetBLASTUIDataSource::x_GetDBTree(), CWorkerNodeIdleThread::x_GetInterval(), CRemoteBlast::x_GetRequestInfoFromRID(), CRemoteBlast::x_GetSubjects(), CWorkerNodeIdleThread::x_IsAutoShutdownTime(), CSyncQueue< Type, Container >::x_LockAndWait(), CNetScheduleHandler::x_ProcessMsgBatchSubmit(), CId2FetchApp::x_ProcessRequest(), IPhyloTreeRenderer::x_RenderNode(), CRemoteBlast::x_SendRequest(), CThreadPool_Impl::x_WaitForPredicate(), CTimedReporter::~CTimedReporter(), and SW::~SW().

CTimeFormat CStopWatch::GetFormat ( void  ) [static]

Get the current stopwatch time format.

The default format is: "-S.n".

Returns:
An object describing the time format. The letters having the same means that for CTimeSpan.
See also:
CTimeFormat, CTimeSpan::GetFormat, AsString

Definition at line 3059 of file ncbitime.cpp.

References format, CStaticTls< TValue >::GetValue(), kDefaultFormatStopWatch, and CTimeFormat::SetFormat().

Referenced by AsString().

double CStopWatch::GetTimeMark ( ) [static, protected]

Get current time mark.

Definition at line 3017 of file ncbitime.cpp.

bool CStopWatch::IsRunning ( void  ) [inline]

Check state of stopwatch.

Returns:
TRUE if stopwatch is "running", FALSE otherwise.
See also:
Start, Stop

Definition at line 2546 of file ncbitime.hpp.

Referenced by CFileHandleDiagHandler::Post(), CFileDiagHandler::Post(), CSeqEntryPresenter::Process(), CFileHandleDiagHandler::Reopen(), and CFileDiagHandler::Reopen().

CStopWatch::NCBI_DEPRECATED_CTOR ( CStopWatch(bool start)  )

Constructor.

Start timer if argument is true.

CStopWatch::operator string ( void  ) const [inline]

Return stopwatch time as string using the format returned by GetFormat().

Definition at line 2553 of file ncbitime.hpp.

void CStopWatch::Reset ( void  ) [inline]

Stop (if running) and reset the timer.

Definition at line 2518 of file ncbitime.hpp.

Referenced by CRequestContext::Reset().

double CStopWatch::Restart ( void  ) [inline]
void CStopWatch::SetFormat ( const CTimeFormat format) [static]

Set the current stopwatch time format.

The default format is: "-S.n".

Parameters:
formatFormat specifier used to convert time span to string. If "format" is not defined, then GetFormat() will be used. Uses the same time format as CTimeSpan class.
See also:
CTimeFormat, CTimeSpan::SetFormat, AsString

Definition at line 3050 of file ncbitime.cpp.

References s_TlsFormatCleanup(), and CStaticTls< TValue >::SetValue().

void CStopWatch::Start ( void  ) [inline]
void CStopWatch::Stop ( void  ) [inline]

Member Data Documentation

double CStopWatch::m_Start [private]

Start time value.

Definition at line 1780 of file ncbitime.hpp.

Stopwatch state (started/stopped)

Definition at line 1782 of file ncbitime.hpp.

double CStopWatch::m_Total [private]

Accumulated elapsed time.

Definition at line 1781 of file ncbitime.hpp.


The documentation for this class was generated from the following files:
Modified on Wed Feb 08 09:07:58 2012 by modify_doxy.py rev. 337098