csutil/profile.h
Go to the documentation of this file.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 00026 #include "csextern.h" 00027 #include "csutil/array.h" 00028 #include "csutil/csstring.h" 00029 #include "csutil/scf_implementation.h" 00030 00031 #ifdef CS_DO_PROFILING 00032 00033 #include <sys/time.h> 00034 00035 00036 struct iProfiler : public virtual iBase 00037 { 00038 SCF_INTERFACE(iProfiler, 2,0,0); 00039 virtual void RegisterProfilePoint (const char* token, 00040 const char* file, int line, 00041 uint32* ptr_count, uint32* ptr_time, 00042 uint32* ptr_timemin, uint32* ptr_timemax) = 0; 00043 virtual void Dump () = 0; 00044 virtual void Reset () = 0; 00045 }; 00046 00047 struct csProfileInfo 00048 { 00049 const char* token; 00050 const char* file; 00051 int line; 00052 uint32* ptr_count; 00053 uint32* ptr_time; 00054 uint32* ptr_timemin; 00055 uint32* ptr_timemax; 00056 }; 00057 00058 class csProfiler : public scfImplementation1<csProfiler, iProfiler> 00059 { 00060 public: 00061 csArray<csProfileInfo> profile_info; 00062 00063 public: 00064 csProfiler (); 00065 virtual ~csProfiler (); 00066 00067 virtual void RegisterProfilePoint (const char* token, 00068 const char* file, int line, 00069 uint32* ptr_count, uint32* ptr_time, 00070 uint32* ptr_timemin, uint32* ptr_timemax); 00071 virtual void Dump (); 00072 virtual void Reset (); 00073 }; 00074 00075 #if 1 00076 #define CS_PROFTIME(v) \ 00077 v = csGetTicks() 00078 #else 00079 #define CS_PROFTIME(v) \ 00080 {\ 00081 struct timeval tv;\ 00082 gettimeofday(&tv, 0);\ 00083 v = tv.tv_sec + tv.tv_usec*1000000;\ 00084 } 00085 #endif 00086 00087 #define CS_PROFRESET(obj_reg) \ 00088 { \ 00089 csRef<iProfiler> profiler = CS_QUERY_REGISTRY (obj_reg, iProfiler); \ 00090 if (profiler) profiler->Reset (); \ 00091 } 00092 00093 #define CS_PROFDUMP(obj_reg) \ 00094 { \ 00095 csRef<iProfiler> profiler = CS_QUERY_REGISTRY (obj_reg, iProfiler); \ 00096 if (profiler) profiler->Dump (); \ 00097 } 00098 00099 #define CS_PROFSTART(tok,obj_reg) \ 00100 static bool tok##__prof__init = false; \ 00101 static uint32 tok##__prof__cnt = 0; \ 00102 static uint32 tok##__prof__time = 0; \ 00103 static uint32 tok##__prof__timemin = 1000000000; \ 00104 static uint32 tok##__prof__timemax = 0; \ 00105 if (!tok##__prof__init) \ 00106 { \ 00107 tok##__prof__init = true; \ 00108 csRef<iProfiler> profiler = CS_QUERY_REGISTRY (obj_reg, iProfiler); \ 00109 if (!profiler) \ 00110 { \ 00111 profiler.AttachNew (new csProfiler ()); \ 00112 obj_reg->Register (profiler, "iProfiler"); \ 00113 } \ 00114 if (profiler) \ 00115 profiler->RegisterProfilePoint (#tok,__FILE__, __LINE__, &tok##__prof__cnt, &tok##__prof__time, &tok##__prof__timemin, &tok##__prof__timemax); \ 00116 } \ 00117 uint32 tok##__prof__starttime; \ 00118 CS_PROFTIME(tok##__prof__starttime) 00119 00120 #define CS_PROFSTOP(tok) \ 00121 { \ 00122 uint32 prof__endtime; \ 00123 CS_PROFTIME(prof__endtime); \ 00124 uint32 prof__dt = prof__endtime - tok##__prof__starttime; \ 00125 if (prof__dt < tok##__prof__timemin) tok##__prof__timemin = prof__dt; \ 00126 if (prof__dt > tok##__prof__timemax) tok##__prof__timemax = prof__dt; \ 00127 tok##__prof__time += prof__dt; \ 00128 } \ 00129 tok##__prof__cnt++ 00130 00131 #else 00132 00133 #define CS_PROFRESET(obj_reg) 00134 #define CS_PROFDUMP(obj_reg) 00135 #define CS_PROFSTART(tok,obj_reg) 00136 #define CS_PROFSTOP(tok) 00137 00138 #endif 00139 00140 #endif //__CS_UTIL_PROFILE_H__ 00141
Generated for Crystal Space by doxygen 1.4.7