Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages
profile.h
00001 /* 00002 Copyright (C) 2005 by Jorrit Tyberghein 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 #ifndef __CS_UTIL_PROFILE_H__ 00020 #define __CS_UTIL_PROFILE_H__ 00021 00022 #include "csextern.h" 00023 #include "csutil/csstring.h" 00024 #include "csutil/array.h" 00025 00026 #ifdef CS_DO_PROFILING 00027 00028 #include <sys/time.h> 00029 00030 SCF_VERSION (iProfiler, 0, 0, 1); 00031 00032 struct iProfiler : public iBase 00033 { 00034 virtual void RegisterProfilePoint (const char* token, 00035 const char* file, int line, 00036 uint32* ptr_count, uint32* ptr_time, 00037 uint32* ptr_timemin, uint32* ptr_timemax) = 0; 00038 virtual void Dump () = 0; 00039 virtual void Reset () = 0; 00040 }; 00041 00042 struct csProfileInfo 00043 { 00044 const char* token; 00045 const char* file; 00046 int line; 00047 uint32* ptr_count; 00048 uint32* ptr_time; 00049 uint32* ptr_timemin; 00050 uint32* ptr_timemax; 00051 }; 00052 00053 class csProfiler : public iProfiler 00054 { 00055 public: 00056 csArray<csProfileInfo> profile_info; 00057 00058 public: 00059 csProfiler (); 00060 virtual ~csProfiler (); 00061 00062 SCF_DECLARE_IBASE; 00063 virtual void RegisterProfilePoint (const char* token, 00064 const char* file, int line, 00065 uint32* ptr_count, uint32* ptr_time, 00066 uint32* ptr_timemin, uint32* ptr_timemax); 00067 virtual void Dump (); 00068 virtual void Reset (); 00069 }; 00070 00071 #if 1 00072 #define CS_PROFTIME(v) \ 00073 v = csGetTicks() 00074 #else 00075 #define CS_PROFTIME(v) \ 00076 {\ 00077 struct timeval tv;\ 00078 gettimeofday(&tv, 0);\ 00079 v = tv.tv_sec + tv.tv_usec*1000000;\ 00080 } 00081 #endif 00082 00083 #define CS_PROFRESET(obj_reg) \ 00084 { \ 00085 csRef<iProfiler> profiler = CS_QUERY_REGISTRY (obj_reg, iProfiler); \ 00086 if (profiler) profiler->Reset (); \ 00087 } 00088 00089 #define CS_PROFDUMP(obj_reg) \ 00090 { \ 00091 csRef<iProfiler> profiler = CS_QUERY_REGISTRY (obj_reg, iProfiler); \ 00092 if (profiler) profiler->Dump (); \ 00093 } 00094 00095 #define CS_PROFSTART(tok,obj_reg) \ 00096 static bool tok##__prof__init = false; \ 00097 static uint32 tok##__prof__cnt = 0; \ 00098 static uint32 tok##__prof__time = 0; \ 00099 static uint32 tok##__prof__timemin = 1000000000; \ 00100 static uint32 tok##__prof__timemax = 0; \ 00101 if (!tok##__prof__init) \ 00102 { \ 00103 tok##__prof__init = true; \ 00104 csRef<iProfiler> profiler = CS_QUERY_REGISTRY (obj_reg, iProfiler); \ 00105 if (!profiler) \ 00106 { \ 00107 profiler.AttachNew (new csProfiler ()); \ 00108 obj_reg->Register (profiler, "iProfiler"); \ 00109 } \ 00110 if (profiler) \ 00111 profiler->RegisterProfilePoint (#tok,__FILE__, __LINE__, &tok##__prof__cnt, &tok##__prof__time, &tok##__prof__timemin, &tok##__prof__timemax); \ 00112 } \ 00113 uint32 tok##__prof__starttime; \ 00114 CS_PROFTIME(tok##__prof__starttime) 00115 00116 #define CS_PROFSTOP(tok) \ 00117 { \ 00118 uint32 prof__endtime; \ 00119 CS_PROFTIME(prof__endtime); \ 00120 uint32 prof__dt = prof__endtime - tok##__prof__starttime; \ 00121 if (prof__dt < tok##__prof__timemin) tok##__prof__timemin = prof__dt; \ 00122 if (prof__dt > tok##__prof__timemax) tok##__prof__timemax = prof__dt; \ 00123 tok##__prof__time += prof__dt; \ 00124 } \ 00125 tok##__prof__cnt++ 00126 00127 #else 00128 00129 #define CS_PROFRESET(obj_reg) 00130 #define CS_PROFDUMP(obj_reg) 00131 #define CS_PROFSTART(tok,obj_reg) 00132 #define CS_PROFSTOP(tok) 00133 00134 #endif 00135 00136 #endif //__CS_UTIL_PROFILE_H__ 00137
Generated for Crystal Space by doxygen 1.3.9.1