NCBI C++ ToolKit
rtprofile.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 // add-hock class to make CStopWatch instancess available as global object
2 #ifndef UTIL_PROFILE___RTPROFILE_HPP
3 #define UTIL_PROFILE___RTPROFILE_HPP
4 
5 #include <sys/types.h>
6 #include <corelib/ncbiobj.hpp>
7 #include <corelib/ncbitime.hpp>
8 #include <corelib/ncbimtx.hpp>
9 
10 #include <string>
11 #include <vector>
12 #include <map>
13 #include <list>
14 #include <utility>
15 
17 
18 #define BLAST_PROF_REPORT CRtProfiler::getInstance()->DoReport()
19 #define BLAST_PROF_START(sw_name) CRtProfiler::getInstance()->Start( std::string( #sw_name ) )
20 #define BLAST_PROF_START2(sw_name) CRtProfiler::getInstance()->Start( sw_name )
21 #define BLAST_PROF_STOP(sw_name) CRtProfiler::getInstance()->Stop( std::string( #sw_name ) )
22 #define BLAST_PROF_ADD(key_name,key_val) CRtProfiler::getInstance()->AddUserKVMT(std::string( #key_name ), key_val )
23 #define BLAST_PROF_ADD2(key_name,key_val) CRtProfiler::getInstance()->AddUserKVMT( std::string( #key_name ), std::string( #key_val ) )
24 
25 #define BLAST_PROF_MARK(marker_name) CRtProfiler::getInstance()->AddMarkerMT( std::string( #marker_name ) )
26 #define BLAST_PROF_MARK2(marker_val) CRtProfiler::getInstance()->AddMarkerMT( marker_val )
28 {
29  private:
31 
32  CRtProfiler( size_t stop_watch_sz=0);
33 
34 
35  public:
36  static CRtProfiler* getInstance();
37  // methods to access stop watches. int index => m_sw_vec, string => m_sw_map;
38  // https://www.ncbi.nlm.nih.gov/IEB/ToolBox/CPP_DOC/doxyhtml/classCStopWatch.html
39  // Start, Stop, AsString
40  //
41  void Allocate( size_t sw_ndx);
42  void Allocate(std::string sw_name);
43  //...
44  void Start( size_t sw_ndx);
45  void Start(std::string sw_name);
46  void StartMT( size_t sw_ndx);
47  void StartMT(std::string sw_name);
48  //..
49  void Stop(size_t sw_ndx);
50  void Stop(std::string sw_name);
51  void StopMT(size_t sw_ndx);
52  void StopMT(std::string sw_name);
53  //...
54  void AddMarkerMT(std::string new_marker );
55  //...
56  void AddUserKV(const std::string &key_name, bool bool_val );
57  void AddUserKVMT(const std::string &key_name, bool bool_val );
58  void AddUserKV(const std::string &key_name, int int_val );
59  void AddUserKVMT(const std::string &key_name, int int_val );
60  void AddUserKV(const std::string &key_name, const std::string &key_val );
61  void AddUserKVMT(const std::string &key_name, const std::string &key_val );
62  //...
63  std::string AsString (size_t sw_ndx, const CTimeFormat &fmt=kEmptyStr) ;
64  std::string AsString (std::string sw_name, const CTimeFormat &fmt=kEmptyStr) ;
65  std::string AsStringMT (size_t sw_ndx, const CTimeFormat &fmt=kEmptyStr) ;
67  //....
68  bool CheckDoReport( std::string &report_name );
69  bool DoReport(const CTimeFormat &fmt=kEmptyStr) ;
70 
71  private:
73  std::vector< CStopWatch > m_sw_vec; // OBSOLETE.
74  std::map< std::string,CStopWatch > m_sw_map;
75  CFastMutex m_sw_vec_mx; // OBSOLETE
77  //...
78  std::list< std::pair <std::string, std::string> > m_markers;
80  //...
82  std::list <std::pair< std::string, std::string > > m_user_data;
84 };
85 
86 
88 #endif
89 
CFastMutex –.
Definition: ncbimtx.hpp:667
CTimeFormat m_ctfmt
Definition: rtprofile.hpp:81
void AddUserKV(const std::string &key_name, bool bool_val)
Definition: rtprofile.cpp:81
std::list< std::pair< std::string, std::string > > m_user_data
Definition: rtprofile.hpp:82
static CRtProfiler * instance
Definition: rtprofile.hpp:30
void StopMT(size_t sw_ndx)
Definition: rtprofile.cpp:71
bool CheckDoReport(std::string &report_name)
Definition: rtprofile.cpp:151
void AddUserKVMT(const std::string &key_name, bool bool_val)
Definition: rtprofile.cpp:85
std::list< std::pair< std::string, std::string > > m_markers
Definition: rtprofile.hpp:78
CRtProfiler(size_t stop_watch_sz=0)
Definition: rtprofile.cpp:21
void AddMarkerMT(std::string new_marker)
Definition: rtprofile.cpp:134
CFastMutex m_sw_map_mx
Definition: rtprofile.hpp:76
void Start(size_t sw_ndx)
Definition: rtprofile.cpp:43
std::string AsStringMT(size_t sw_ndx, const CTimeFormat &fmt=kEmptyStr)
Definition: rtprofile.cpp:119
CFastMutex m_user_data_mx
Definition: rtprofile.hpp:83
std::map< std::string, CStopWatch > m_sw_map
Definition: rtprofile.hpp:74
bool DoReport(const CTimeFormat &fmt=kEmptyStr)
Definition: rtprofile.cpp:162
std::string AsString(size_t sw_ndx, const CTimeFormat &fmt=kEmptyStr)
Definition: rtprofile.cpp:109
CStopWatch m_w0
Definition: rtprofile.hpp:72
void StartMT(size_t sw_ndx)
Definition: rtprofile.cpp:52
void Stop(size_t sw_ndx)
Definition: rtprofile.cpp:62
static CRtProfiler * getInstance()
Definition: rtprofile.cpp:12
std::vector< CStopWatch > m_sw_vec
Definition: rtprofile.hpp:73
CFastMutex m_markers_mx
Definition: rtprofile.hpp:79
CFastMutex m_sw_vec_mx
Definition: rtprofile.hpp:75
void Allocate(size_t sw_ndx)
Definition: rtprofile.cpp:30
CStopWatch –.
Definition: ncbitime.hpp:1938
CTimeFormat –.
Definition: ncbitime.hpp:131
string
Definition: cgiapp.hpp:687
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define kEmptyStr
Definition: ncbistr.hpp:123
Multi-threading – mutexes; rw-locks; semaphore.
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
Defines: CTimeFormat - storage class for time format.
Modified on Mon Feb 26 03:58:47 2024 by modify_doxy.py rev. 669887