00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _SG_TRC_CLASS_H
00022 #define _SG_TRC_CLASS_H
00023
00024 #include "SugoiTracer\config.h"
00025
00026 #ifdef __cplusplus
00027 #include "SugoiTracer\timer.h"
00028 #include "SugoiTracer\function.h"
00029 #include "SugoiTracer\appli.h"
00030 #include <Time.h>
00031 #include <sys/timeb.h>
00032 #include <SugoiTools\cl_base_obj.h>
00033 #include <SugoiTools\cl_template_manager.h>
00034
00035
00036 namespace SG_TRC{
00037
00038
00039
00040 template <typename TracerType= SG_TRC_Default_Trc_Type>
00041 class CL_CLASS_TRACER:
00042 public SGE::CL_XML_BASE_OBJ<std::string>
00043 {
00044 public:
00045 #if _SG_TLS_SMARTPTR
00046 typedef typename CL_CLASS_TRACER<TracerType>* TplSmartP;
00047 #else
00048 typedef typename CL_CLASS_TRACER<TracerType> * TplSmartP;
00049 #endif
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 typedef TplSmartP TplHdle;
00060
00061
00062 SGE::CL_XML_MNGR<CL_FUNCT_TRC<TracerType> > * FunctionsManager;
00063
00064 CL_CLASS_TRACER(std::string _Name, TTCL_APPLI_TRACER<TracerType> * _ParentAppliTracer = NULL);
00065 ~CL_CLASS_TRACER();
00066
00067 void Clear();
00068
00069 bool TracingEnable;
00070
00071 void SetParrentAppliTracer(TTCL_APPLI_TRACER<TracerType> * _ParentAppliTracer);
00072 CL_FUNCT_TRC<TracerType> * AddFunct(std::string _FunctName);
00073 int GetAllRecordNumbers();
00074
00075 int Process();
00076 TracerType *TotalTime;
00077
00078 private:
00079 TTCL_APPLI_TRACER<TracerType> * ParentAppliTracer;
00080
00081 #if _SG_TLS_XML
00082 public:
00083 _SG_TLS_INLINE TiXmlElement* XMLLoad(TiXmlElement* _XML_ROOT);
00084 _SG_TLS_INLINE TiXmlElement* XMLSave(TiXmlElement* _XML_ROOT);
00085 #endif
00086 };
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 template <typename TracerType>
00101 CL_CLASS_TRACER<TracerType>::CL_CLASS_TRACER(std::string _Name, TTCL_APPLI_TRACER<TracerType> * _ParentAppliTracer)
00102 :CL_XML_BASE_OBJ<std::string>(_Name, "Class")
00103 {
00104 TracingEnable = true;
00105 SetParrentAppliTracer(_ParentAppliTracer);
00106 FunctionsManager = new CL_XML_MNGR<CL_FUNCT_TRC<TracerType> > (NULL, "FunctionManager", "function", "name");
00107 TotalTime = new TracerType();
00108 }
00109
00110 template <typename TracerType> CL_CLASS_TRACER<TracerType>::~CL_CLASS_TRACER()
00111 {
00112 delete (FunctionsManager);
00113 delete (TotalTime);
00114 }
00115
00116 template <typename TracerType> void CL_CLASS_TRACER<TracerType>::Clear()
00117 {
00118 TotalTime->Clear();
00119
00120 CL_XML_MNGR<CL_FUNCT_TRC<TracerType> >::iterator iFunct;
00121 for (iFunct = FunctionsManager->GetFirstIter(); iFunct != FunctionsManager->GetLastIter(); iFunct++)
00122 (*iFunct).second->Clear();
00123
00124 }
00125
00126
00127 template <typename TracerType> void CL_CLASS_TRACER<TracerType>::SetParrentAppliTracer(TTCL_APPLI_TRACER<TracerType> * _ParentAppliTracer)
00128 {
00129 ParentAppliTracer = _ParentAppliTracer;
00130 }
00131
00132 template <typename TracerType> CL_FUNCT_TRC<TracerType> * CL_CLASS_TRACER<TracerType>::AddFunct(std::string _FunctName)
00133 {
00134 CL_FUNCT_TRC<TracerType> * TempFunct = FunctionsManager->Get(_FunctName);
00135
00136 if (TempFunct)
00137 return TempFunct;
00138
00139
00140 FunctionsManager->Add(_FunctName);
00141 TempFunct = FunctionsManager->GetLastAdded();
00142 SG_Assert(TempFunct, "CL_CLASS_TRACER<TracerType>::AddFunct() : Error Adding new function." );
00143
00144 TempFunct->SetParrentClass(this);
00145
00146 return TempFunct;
00147 }
00148
00149 template <typename TracerType> int CL_CLASS_TRACER<TracerType>::Process(void)
00150 {
00151 int i =0;
00152 CL_XML_MNGR<CL_FUNCT_TRC<TracerType> >::iterator iFct;
00153 for ( iFct = FunctionsManager->GetFirstIter() ; iFct != FunctionsManager->GetLastIter( ) ; iFct++ )
00154 {
00155 if ((*iFct).second->IsModified())
00156 {
00157 (*iFct).second->Process();
00158 i++;
00159 }
00160 }
00161 return i;
00162 }
00163
00164
00165 template <typename TracerType> int CL_CLASS_TRACER<TracerType>::GetAllRecordNumbers()
00166 {
00167 int i =0;
00168 CL_XML_MNGR<CL_FUNCT_TRC<TracerType>>::iterator iFct;
00169 for ( iFct = FunctionsManager->GetFirstIter.begin() ; iFct != FunctionsManager->GetLastIter.end( ) ; iFct++ )
00170 {
00171 i+= (*iFct).second->GetAllRecordNumbers();
00172 }
00173 return i;
00174 }
00175
00176
00177 #if _SG_TLS_XML
00178 template <typename TracerType> TiXmlElement* CL_CLASS_TRACER<TracerType>::XMLLoad(TiXmlElement* _XML_ROOT)
00179 {
00180 SG_Assert(_XML_ROOT, "No XML root");
00181
00182
00183
00184
00185 FunctionsManager->XMLLoad(_XML_ROOT);
00186
00187
00188
00189 TotalTime->XMLLoad(_XML_ROOT, "TotalTime");
00190
00191 return _XML_ROOT;
00192 }
00193
00194 template <typename TracerType>
00195 TiXmlElement*
00196 CL_CLASS_TRACER<TracerType>::XMLSave(TiXmlElement* _XML_ROOT)
00197 {
00198 SG_Assert(_XML_ROOT, "No XML root");
00199
00200
00201 FunctionsManager->XMLSave( _XML_ROOT);
00202
00203
00204 TotalTime->XMLSave(_XML_ROOT, "TotalTime");
00205
00206 return _XML_ROOT;
00207 }
00208 #endif
00209
00210
00211
00212
00213
00214
00215 };
00216
00217 #endif //__cplusplus
00218
00219 #endif//_SG_TRC_CLASS_H