D:/WorkDir/SugoiProjects/SugoiTracer/include/SugoiTracer/appli.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_APPLI_H
00022 #define _SG_TRC_APPLI_H
00023 
00024 #include "SugoiTracer\config.h"
00025 
00026 #ifdef __cplusplus
00027         #include "SugoiTracer\timer.h"
00028         #include "SugoiTracer\base.h"
00029         #include "SugoiTracer\function.h"
00030         #include "SugoiTracer\class.h"
00031         #include <SugoiTools\cl_xml_mngr.h>
00032         #include <iostream>
00033         #include <map>          //to create map for C wrapping
00034 
00035 namespace SG_TRC{
00036 
00046 //EXPIMP_TEMPLATE template class DECLSPECIFIER std::vector<TTCL_FCT_TRACER *>;//see http://support.microsoft.com/kb/168958/en-us
00047 
00048 template <typename TracerType=SG_TRC_Default_Trc_Type>
00049         class  TTCL_APPLI_TRACER: 
00050                 public SGE::CL_XML_OBJ
00051 {
00052 public:
00053         typedef typename CL_FUNCT_TRC<TracerType>                       *       TplFctHdle;
00054         typedef typename CL_FUNCT_TRC<TracerType>                               TplFctObj;
00055         typedef typename CL_CLASS_TRACER<TracerType>            *       TplClassHdle;   
00056         typedef typename CL_CLASS_TRACER<TracerType>                    TplClassObj;
00057 
00058                 
00059 protected:
00060         bool TracingEnable;
00061         
00062 
00063 public:
00064         SGE::CL_XML_MNGR<TplClassObj,   std::string >   * ClassManager;         
00065         SGE::CL_XML_MNGR<TplFctObj,             std::string >   * FunctionsManager;     
00066         //used for wrapping with C      ===========================
00067         std::map<int, CL_TEMP_TRACER<TracerType> *>             *MapTempTracer;
00068         std::map<int, TplFctHdle>                                               *MapFunction;
00069         int             MapFunctionLastID;
00070         int             MapTracerLastID;
00071         //===================================================
00072 
00073         TTCL_APPLI_TRACER():
00074                 CL_XML_OBJ("benchmark"),
00075                 TracingEnable(true)
00076                 {
00077                         ClassManager            = new CL_XML_MNGR<TplClassObj   ,std::string>   (NULL,"ClassManager",           "class",        "name");
00078                         FunctionsManager        = new CL_XML_MNGR<TplFctObj             ,std::string>   (NULL,"FunctionManager",        "function", "name");
00079 
00080                         if(!MainAppliTracer)
00081                                 MainAppliTracer = this;
00082 
00083                 //used to enable wrappping with C library and programs
00084                         MapTempTracer   = new std::map<int, CL_TEMP_TRACER<TracerType> *>       ();
00085                         MapFunction             = new std::map<int, TplFctHdle>         ();
00086                         MapFunctionLastID       = 0;
00087                         MapTracerLastID         = 0;
00088                         //====================================================
00089                 }
00090 
00091 
00092         ~TTCL_APPLI_TRACER(void)
00093         {
00094                 delete (ClassManager);
00095                 delete(FunctionsManager);
00096 
00097                 //used to enable wrappping with C library and programs
00098                 //???delete all temptracer recorded before...????
00099                 //      delete(MapTempTracer);
00100                 //      delete(MapFunction);
00101                 //====================================================
00102         }
00103 
00104         void 
00105                 Process()
00106         {
00107                 cout << "Process() class\n";
00108                 CL_XML_MNGR<TplClassObj >::iterator iClass;
00109                 /*if (ClassManager->GetCount())
00110                         for (iClass = ClassManager->GetFirstIter(); iClass != ClassManager->GetLastIter(); iClass++)
00111                                 (*iClass).second->Process();
00112 */
00113                 cout <<"Process() function(s)\n";
00114                 CL_XML_MNGR<TplFctObj>::iterator iFunct;
00115 /*              if (FunctionsManager->GetCount())       
00116                         for (iFunct = FunctionsManager->GetFirstIter(); iFunct != FunctionsManager->GetLastIter(); iFunct++)
00117                                 (*iFunct).second->Process();
00118 */
00119         }
00120 
00121         void 
00122                 ClearAll()
00123         {       
00124                 //clear all class
00125                 CL_XML_MNGR<CL_CLASS_TRACER<TracerType> >::iterator iClass;
00126                 for (iClass = ClassManager->GetFirstIter(); iClass != ClassManager->GetLastIter(); iClass++)
00127                         (*iClass).second->Clear();
00128 
00129                 //clear all function
00130                 CL_XML_MNGR<CL_FUNCT_TRC<TracerType> >::iterator iFunct;
00131                 for (iFunct = FunctionsManager->GetFirstIter(); iFunct != FunctionsManager->GetLastIter(); iFunct++)
00132                         (*iFunct).second->Clear();
00133         }
00134 
00135 
00136         TplFctHdle
00137                 AddFunct(std::string _FunctName)
00138         {
00139                 return (TplFctHdle) (FunctionsManager->Add(_FunctName));
00140         }
00141 
00142 
00143         TplFctHdle
00144                 AddFunct(std::string _FunctName, TplFctHdle _NewFct)
00145         {
00146                 TplFctHdle TempFunct = (TplFctHdle)FunctionsManager->Get(_FunctName);
00147 
00148                 if (TempFunct)
00149                         return TempFunct;
00150 
00151                 //else we add it
00152                 FunctionsManager->AddObj(_NewFct);
00153                 return _NewFct;
00154         }
00155 
00156         static TTCL_APPLI_TRACER<TracerType> * MainAppliTracer;
00157 
00158 public:
00159 #if _SG_TLS_XML
00160         _SG_TLS_INLINE 
00161                 TiXmlElement* 
00162                 XMLLoad(TiXmlElement* _XML_ROOT)
00163         {
00164                 SG_Assert(_XML_ROOT, "No XML root");
00165 
00166                 ClearAll();//we clear all previous records
00167                 //Get Date
00168                 //_XML_ROOT->SetAttribute("date",       "today");
00169                 
00170                 //Get Application version
00171                 //_XML_ROOT->SetAttribute("app_version", "V0.001");     //save name
00172                 
00173         #ifdef GPUCV_USE
00174                 //load system, GPU/CPU and os version
00175                 //_XML_ROOT
00176         #endif
00177 
00178 
00179                 //list of class benched
00180                 ClassManager->XMLLoad(_XML_ROOT);
00181                 SG_NOTICE_LOG_C("\nClass loaded : %d\n");//,ClassManager->GetCount());
00182 
00183                 //list of function benched
00184                 FunctionsManager->XMLLoad(_XML_ROOT);
00185                 SG_NOTICE_LOG_C("Function loaded : %d\n");//,FunctionsManager->GetCount());
00186 
00187                 return _XML_ROOT;
00188         }
00189 
00190         _SG_TLS_INLINE 
00191                 TiXmlElement* 
00192                         XMLSave(TiXmlElement* _XML_ROOT)
00193         {
00194                 SG_Assert(_XML_ROOT, "No XML root");
00195                 
00196                 SG_NOTICE_LOG("XMLSave()...Start saving XML values to file\n");
00197 
00198 
00199                 Process();
00200                 //set Applitracer Attribute
00201                 //date
00202                 XMLWriteVal(_XML_ROOT, "date",  __DATE__);
00203                 XMLWriteVal(_XML_ROOT, "time", __TIME__);
00204                 
00205                 //application version
00206                 XMLWriteVal(_XML_ROOT, "app_version", "V0.001");        //save name
00207                 
00208         #ifdef GPUCV_USE
00209                 //system, save GPU/CPU and os version
00210         #endif
00211                 
00212                 //list of class benched
00213                 SG_NOTICE_LOG_C("\nClass to save : %d\n");//,ClassManager->GetCount());
00214                 if (ClassManager->GetCount())
00215                         ClassManager->XMLSave(_XML_ROOT);
00216                 else
00217                         SG_NOTICE_LOG("\nNo Class record to save.");
00218 
00219                 //list of function benched
00220                 SG_NOTICE_LOG_C("Function to save : %d\n");//,FunctionsManager->GetCount());
00221                 if (FunctionsManager->GetCount())
00222                         FunctionsManager->XMLSave(_XML_ROOT);
00223                 else
00224                         SG_NOTICE_LOG("\nNo Function record to save.");
00225 
00226                 return _XML_ROOT;
00227         }
00228 
00229 #endif
00230 
00231 
00232 int GenerateSvgFiles()
00233 {
00234 #if _SG_TRC_SVG
00235                 SG_NOTICE_LOG("\nGenerating SVG files...");
00236        
00237                 //clear all class
00238                 CL_XML_MNGR<CL_CLASS_TRACER<TracerType> >::iterator iClass;
00239                 //for (iClass = ClassManager->GetFirstIter(); iClass != ClassManager->GetLastIter(); iClass++)
00240                 //      (*iClass).second->SaveToSVGFile();
00241 
00242                 //clear all function
00243                 CL_XML_MNGR<CL_FUNCT_TRC<TracerType> >::iterator iFunct;
00244                 for (iFunct = FunctionsManager->GetFirstIter(); iFunct != FunctionsManager->GetLastIter(); iFunct++)
00245                         (*iFunct).second->SaveToSVGFile();
00246         
00247                 printf("Done!");
00248 
00249         #ifdef _CVG_SVG_CONVERT_TO_PNG
00250                 printf("\nGenerating PNG files...");
00251                 //"/k java.exe -jar D:\\batik-1.6\\batik-rasterizer.jar -m image/png SVG\\*.svg "
00252                 string Command = "/k java.exe -jar ";
00253                 Command += _CVG_SVG_BATIK_RASTERIZER_PATH;
00254                 Command += " -m image/png ";
00255                 Command += _CVG_SVG_EXPORT_PATH;
00256                 Command += "\\*.svg";
00257                 ShellExecute(0,0,"cmd.exe",Command.data(),0,SW_HIDE);  
00258                 printf("Done!");
00259         #endif
00260         return 1;
00261 #else
00262                 printf("\n_CVG_SVG_CREATE_FILES flag is not defined in definitions.h, SVG files not created...");
00263                 return 0;
00264 #endif
00265 }
00266 
00267 
00268 };
00269 
00270 
00271 template <typename TracerType> 
00272         TTCL_APPLI_TRACER<TracerType>* 
00273                 TTCL_APPLI_TRACER<TracerType>::MainAppliTracer = NULL;
00274 
00275 
00276 template <typename TracerType>
00277 TTCL_APPLI_TRACER<TracerType> * CreateMainTracer()
00278 {       
00279         if (!TTCL_APPLI_TRACER<TracerType>::MainAppliTracer)
00280                 TTCL_APPLI_TRACER<TracerType>::MainAppliTracer  = new TTCL_APPLI_TRACER<TracerType>();
00281         return TTCL_APPLI_TRACER<TracerType>::MainAppliTracer;
00282 }
00283 
00284 //================================================================
00285 
00286 _SG_TRC_DLL_EXPORT int StartRecording(int _FctNumber, CL_TRACE_BASE_PARAMS * _Params);//used for C wrapping
00287 
00288 
00289 #ifdef __cplusplus
00290 extern "C"
00291 {
00292 #endif //__cplusplus
00293 
00294 //===============================================================
00295 //here is definition of C function we could use for tracking....
00296 //see http://jeg.developpez.com/cours/cpp_to_c/
00297 //and http://www.cprogramming.com/tutorial/stl/stlmap.html
00298 //===============================================================
00299 //static SG_TRC_FUNCT_BY_TIME = TTCL_APPLI_TRACER<CL_TimerVal>::MainAppliTracer->AddFunct("arDetectMarker");
00300 //      SG_TRC_TEMP_TRACER_BY_TIME (ThisFct, TParams);
00301 
00302 //todo
00303 //TParams->AddInt("C", marker_num);
00304 //CL_TRACE_BASE_PARAMS * TParams = new CL_TRACE_BASE_PARAMS("ART",std::string("_2.71"));
00305 _SG_TRC_DLL_EXPORT bool XMLSaveBench(const char *Filename);
00306 _SG_TRC_DLL_EXPORT bool XMLLoadBench(const char *Filename);
00307 _SG_TRC_DLL_EXPORT int StartRecordingInt(const int _FctNumber, const char * ParamsName, const int * _intArray, const int _nbr);
00308 _SG_TRC_DLL_EXPORT int StartRecordingChar(const int _FctNumber, const char * ParamsName, const char *_Value);
00309 _SG_TRC_DLL_EXPORT int CreateFunction(const char * _fctName);
00310 _SG_TRC_DLL_EXPORT int StartRecording(const int _FctNumber);
00311 _SG_TRC_DLL_EXPORT void StopRecording(const int _TracerNumber);
00312 _SG_TRC_DLL_EXPORT bool AddParamInt(const int _TracerNumber, const char * _Name, const int  _Value);
00313 _SG_TRC_DLL_EXPORT bool AddParamChar(const int _TracerNumber, const char * _Name, const char * _Value);
00314 //C functions---------------------------------------------------
00315 #ifdef __cplusplus
00316 }//to export this few functions to 'C'
00317 #endif
00318 
00319 //================================================================
00320 //================================================================
00321 
00322 };//namespace SG_TRC
00323 #endif
00324 #endif //_SG_TRC_APPLI_H

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