D:/WorkDir/SugoiProjects/SugoiTracer/include/SugoiTracer/class.h

Go to the documentation of this file.
00001 /* LICENSE_BEGIN
00002 SutoiTracer library supply support profiling functions, class, or evet simple 
00003 piece of code. It is part of the SugoiEngine project.
00004 Copyright (C) 2006 Allusse Yannick (yannick dot allusse at laposte dot net)
00005 
00006 This program is free software; you can redistribute it and/or
00007 modify it under the terms of the GNU General Public License
00008 as published by the Free Software Foundation; either version 2
00009 of the License, or (at your option) any later version.
00010 
00011 This program is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU General Public License for more details.
00015 
00016 You should have received a copy of the GNU General Public License
00017 along with this program; if not, write to the Free Software
00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00019 LICENSE_END
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 //template <typename TracerType> class CL_FUNCT_TRC;
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 #if _SG_TLS_SMARTPTR
00052         typedef typename SGE::CSmartPtr<CL_FUNCT_TRC<TracerType> >                      TplFctP;
00053         typedef typename SGE::CSmartPtr<CL_CLASS_TRC<TracerType> >                      TplClassP;
00054         
00055 #else
00056         typedef CL_FUNCT_TRC<TracerType> *                      TplSmartP;
00057         typedef CL_CLASS_TRC<TracerType> *                      TplClassP;
00058 #endif*/
00059         typedef TplSmartP                                                       TplHdle;
00060 
00061         //Class Name
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 //===========                    CODE           ==============================
00090 //================================================================
00091 /*
00092 template <typename TracerType> CL_CLASS_TRACER<TracerType>::CL_CLASS_TRACER(std::string _Name):CL_BASE_OBJ(_Name)
00093 {
00094         TracingEnable = true;
00095         SetParrentAppliTracer(NULL);
00096         FunctionsManager = new CL_TEMPLATE_OBJECT_MANAGER <CL_FUNCT_TRC<TracerType>> (NULL);
00097         TotalTime = new TracerType();
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         //we clear all function, but we don't delete them cause some of them are statics...
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         //else we add it
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         //name already read.
00183 
00184         //load functions list
00185         FunctionsManager->XMLLoad(_XML_ROOT);
00186 
00187         //affect the function pointer to all members of the list...
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         //list of class benched
00201         FunctionsManager->XMLSave( _XML_ROOT);
00202 
00203         //TotalTime
00204         TotalTime->XMLSave(_XML_ROOT, "TotalTime");
00205 
00206         return _XML_ROOT;
00207 }
00208 #endif
00209 //================================================================
00210 //================================================================
00211 //================================================================
00212 
00213 
00214 
00215 };//namespace SG_TRC
00216 
00217 #endif //__cplusplus
00218 
00219 #endif//_SG_TRC_CLASS_H

Generated on Mon Mar 19 23:16:20 2007 for SugoiTracer by  doxygen 1.4.6-NO