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 #ifndef __CS_CSUTIL_TIMEMEASURE_H__
00021 #define __CS_CSUTIL_TIMEMEASURE_H__
00022
00027 #include "csutil/csstring.h"
00028 #include "csutil/util.h"
00029 #include "csutil/sysfunc.h"
00030
00031 namespace CS
00032 {
00033
00054 class CS_CRYSTALSPACE_EXPORT MeasureTime
00055 {
00056 protected:
00057 int64 offsetTime;
00058 csString text;
00059 void PrintTime (const char* prefix, int64 time, const char* suffix);
00060 public:
00064 MeasureTime (const char* format, ...)
00065 {
00066 va_list args;
00067 va_start (args, format);
00068 text.FormatV (format, args);
00069 va_end (args);
00070
00071 offsetTime = csGetMicroTicks ();
00072 }
00073
00074 ~MeasureTime ()
00075 {
00076 csTicks endTime = csGetMicroTicks ();
00077 PrintTime ((text + ": ").GetData(), endTime - offsetTime,
00078 " \xC2\xB5s\n");
00079 }
00080
00082 void PrintIntermediate (const char* descr, ...)
00083 {
00084 int64 currentTime = csGetMicroTicks ();
00085
00086 csPrintf ("(%s)", text.GetData());
00087 va_list args;
00088 va_start (args, descr);
00089 csPrintfV (descr, args);
00090 va_end (args);
00091 PrintTime (": ", currentTime - offsetTime, " \xC2\xB5s\n");
00092
00093 int64 currentTime2 = csGetMicroTicks ();
00094
00095 offsetTime += currentTime2 - currentTime;
00096 }
00097 };
00098
00101 }
00102
00103 #endif