00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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>
00034
00035 namespace SG_TRC{
00036
00046
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
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
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
00098
00099
00100
00101
00102 }
00103
00104 void
00105 Process()
00106 {
00107 cout << "Process() class\n";
00108 CL_XML_MNGR<TplClassObj >::iterator iClass;
00109
00110
00111
00112
00113 cout <<"Process() function(s)\n";
00114 CL_XML_MNGR<TplFctObj>::iterator iFunct;
00115
00116
00117
00118
00119 }
00120
00121 void
00122 ClearAll()
00123 {
00124
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
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
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();
00167
00168
00169
00170
00171
00172
00173 #ifdef GPUCV_USE
00174
00175
00176 #endif
00177
00178
00179
00180 ClassManager->XMLLoad(_XML_ROOT);
00181 SG_NOTICE_LOG_C("\nClass loaded : %d\n");
00182
00183
00184 FunctionsManager->XMLLoad(_XML_ROOT);
00185 SG_NOTICE_LOG_C("Function loaded : %d\n");
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
00201
00202 XMLWriteVal(_XML_ROOT, "date", __DATE__);
00203 XMLWriteVal(_XML_ROOT, "time", __TIME__);
00204
00205
00206 XMLWriteVal(_XML_ROOT, "app_version", "V0.001");
00207
00208 #ifdef GPUCV_USE
00209
00210 #endif
00211
00212
00213 SG_NOTICE_LOG_C("\nClass to save : %d\n");
00214 if (ClassManager->GetCount())
00215 ClassManager->XMLSave(_XML_ROOT);
00216 else
00217 SG_NOTICE_LOG("\nNo Class record to save.");
00218
00219
00220 SG_NOTICE_LOG_C("Function to save : %d\n");
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
00238 CL_XML_MNGR<CL_CLASS_TRACER<TracerType> >::iterator iClass;
00239
00240
00241
00242
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
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);
00287
00288
00289 #ifdef __cplusplus
00290 extern "C"
00291 {
00292 #endif //__cplusplus
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
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
00315 #ifdef __cplusplus
00316 }
00317 #endif
00318
00319
00320
00321
00322 };
00323 #endif
00324 #endif //_SG_TRC_APPLI_H