Go to the documentation of this file.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 #pragma once
00027 #include "Setup.h"
00028
00029
00030 #ifdef TIMEPROFILE_ENABLED
00031
00032 #define MPMAProfileSetOutputFile(filename) do { if (_instProfile) _instProfile->_SetOutputFile(filename); } while (false)
00033
00034 #define MPMAProfileStart(name) do { if (_instProfile) _instProfile->_ProfileStart(name,__FILE__); } while (false)
00035
00036 #define MPMAProfileStop(name) do { if (_instProfile) _instProfile->_ProfileStop(name,__FILE__); } while (false)
00037
00038 #define MPMAProfileScope(name) MPMA::Internal_AutoProfileHelper _auto_scope_profiler(name); MPMAProfileStart(name)
00039 #else
00040 #define MPMAProfileSetOutputFile(filename)
00041 #define MPMAProfileStart(name)
00042 #define MPMAProfileStop(name)
00043 #define MPMAProfileScope(name)
00044 #endif
00045
00046
00047
00048 #ifdef TIMEPROFILE_ENABLED
00049
00050 #include <string>
00051 #include <list>
00052 #include "Locks.h"
00053 #include "Types.h"
00054 #include "Timer.h"
00055
00056 namespace MPMA
00057 {
00058
00059 class Internal_Profiler
00060 {
00061 public:
00062 ~Internal_Profiler();
00063
00064 void _ProfileStart(const std::string &pName, const std::string &fName);
00065 void _ProfileStop(const std::string &pName, const std::string &fName);
00066 void _SetOutputFile(const std::string &filename);
00067
00068 private:
00069 struct SProfile
00070 {
00071 std::string name;
00072 std::string file;
00073
00074 double timeTotal;
00075 double timeMax;
00076 double timeMin;
00077
00078 MPMA::Timer timeStart;
00079
00080 int samples;
00081
00082 bool started;
00083
00084 inline bool operator <(const SProfile &o) { return timeTotal>o.timeTotal; }
00085 };
00086
00087 std::list<SProfile> llProf;
00088
00089 MPMA::Timer timeStart;
00090
00091
00092
00093 void Write(FILE* f, double val);
00094 void Write(FILE* f, const char* str);
00095 void Write(FILE* f, int num);
00096
00097 SProfile* FindProfile(const std::string &name);
00098
00099 void WriteProfilesToFile(FILE *f, double finalTime);
00100
00101 void Error(const char *lpzMsg);
00102
00103
00104 MPMA::MutexLock crit;
00105 };
00106 }
00107
00108 #endif
00109
00110
00111 #ifdef TIMEPROFILE_ENABLED
00112 extern MPMA::Internal_Profiler *_instProfile;
00113 #endif
00114
00115
00116 #ifdef TIMEPROFILE_ENABLED
00117 namespace MPMA
00118 {
00119 class Internal_AutoProfileHelper
00120 {
00121 public:
00122 inline Internal_AutoProfileHelper(const std::string &profileName) { name=profileName; }
00123 inline ~Internal_AutoProfileHelper() { MPMAProfileStop(name); }
00124
00125 private:
00126 std::string name;
00127 };
00128 }
00129 #endif