00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef _CProfiler_
00028 #define _CProfiler_
00029
00030 #include "Setup.h"
00031
00032
00033 #if defined(_DEBUG) || defined(PROFILE_RELEASE)
00035 #define ProfileStart(name) _instProfile._ProfileStart(name,__FILE__)
00037 #define ProfileStop(name) _instProfile._ProfileStop(name,__FILE__)
00039 #define ProfileScope(name) CAutoProfileHelper _auto_scope_profiler(name); ProfileStart(name)
00040 #else
00041 #define ProfileStart(name)
00042 #define ProfileStop(name)
00043 #define ProfileScope(name)
00044 #endif
00045
00046
00047
00048 #if defined(_DEBUG) || defined(PROFILE_RELEASE)
00049
00050 #include <string>
00051 #include <list>
00052 #include "Locks.h"
00053 #include "Types.h"
00054 #include "Timer.h"
00055
00056
00057 class CProfiler
00058 {
00059 public:
00060 CProfiler();
00061 virtual ~CProfiler();
00062
00063 void _ProfileStart(const std::string &pName, const std::string &fName);
00064 void _ProfileStop(const std::string &pName, const std::string &fName);
00065
00066 private:
00067 struct SProfile
00068 {
00069 std::string name;
00070 std::string file;
00071
00072 double timeTotal;
00073 double timeMax;
00074 double timeMin;
00075
00076 MPMA::Timer timeStart;
00077
00078 int samples;
00079
00080 bool started;
00081
00082 inline bool operator <(const SProfile &o) { return timeTotal>o.timeTotal; }
00083 };
00084
00085 std::list<SProfile> llProf;
00086
00087 MPMA::Timer timeStart;
00088
00089
00090
00091 void Write(FILE* f, double val);
00092 void Write(FILE* f, const char* str);
00093 void Write(FILE* f, int num);
00094
00095 SProfile* FindProfile(const std::string &name);
00096
00097 void WriteProfilesToFile(FILE *f, double finalTime);
00098 void DeallocProfiles();
00099
00100 void Error(const char *lpzMsg);
00101
00102
00103 MPMA::MutexLock crit;
00104 };
00105
00106 #endif
00107
00108
00109 #if defined(_DEBUG) || defined(PROFILE_RELEASE)
00110 extern CProfiler _instProfile;
00111 #endif
00112
00113
00114 #if defined(_DEBUG) || defined(PROFILE_RELEASE)
00115 class CAutoProfileHelper
00116 {
00117 public:
00118 inline CAutoProfileHelper(const std::string &profileName) { name=profileName; }
00119 inline ~CAutoProfileHelper() { ProfileStop(name); }
00120
00121 private:
00122 std::string name;
00123 };
00124 #endif
00125
00126 #endif //#ifdef _CProfiler_