00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "perfMon.h"
00020
00021 BOOL PerfMonitor::Save()
00022 {
00023 FILE *fich = fopen(fileName,"wt");
00024 if (!fich) return FALSE;
00025
00026 for (points.i=0;points.i.More();points.i++)
00027 {
00028 PerfMonitorPoint *point = points.i.GetElemPtr();
00029 fprintf(fich,"%s \t",(char *)point->name);
00030 }
00031
00032 for (records.i=0;records.i.More();records.i++)
00033 {
00034 fprintf(fich,"\n");
00035 MyListOfDouble *recordCur = records.i.GetElemPtr();
00036 for (recordCur->i=0;recordCur->i.More();recordCur->i++)
00037 fprintf(fich,"%lf \t",recordCur->i.GetElem());
00038 }
00039 return TRUE;
00040 }
00041
00042 PerfMonitor::PerfMonitor()
00043 {
00044 enable=TRUE;
00045 fileName="perfMon.txt";
00046 }
00047
00048 PerfMonitor::~PerfMonitor()
00049 {
00050 if (enable) Save();
00051 }
00052
00053 PerfMonitorPoint * PerfMonitor::AddTitle(char *name)
00054 {
00055 PerfMonitorPoint *point = points.i.AddNewLast();
00056 point->Set(name,this);
00057 return point;
00058 }
00059
00060 void PerfMonitor::AddRecord()
00061 {
00062 if (! enable) return;
00063 MyListOfDouble *listValue = records.i.AddNewLast();
00064
00065
00066 for (points.i=0;points.i.More();points.i++)
00067 listValue->i.AddLast(points.i.GetElemPtr()->value);
00068 }
00069
00071
00072 void PerfMonitor::Reset()
00073 {
00074 for (points.i=0;points.i.More();points.i++)
00075 points.i.GetElemPtr()->Reset();
00076 }
00077
00078 PerfMonitorPoint * PerfMonitor::Find(char *name,BOOL addIfNotExist)
00079 {
00080 PerfMonitorPoint *pt;
00081 for (points.i=0;points.i.More();points.i++)
00082 {
00083 pt = points.i.GetElemPtr();
00084 if (pt->name==name) return pt;
00085 }
00086
00087 if (addIfNotExist) return AddTitle(name);
00088 return NULL;
00089 }
00090
00091 void PerfMonitor::Reset(char *name)
00092 {
00093 if (!enable) return;
00094 PerfMonitorPoint * pt = Find(name,TRUE);
00095 pt->Reset();
00096 }
00097
00098 void PerfMonitor::Begin(char *name,BOOL reset)
00099 {
00100 if (!enable) return;
00101 PerfMonitorPoint * pt = Find(name,TRUE);
00102 pt->Begin(reset);
00103 }
00104
00105 void PerfMonitor::End(char *name)
00106 {
00107 if (!enable) return;
00108 PerfMonitorPoint * pt = Find(name,TRUE);
00109 pt->End();
00110 }
00111
00112
00113
00114 PerfMonitorPoint::PerfMonitorPoint()
00115 {
00116 monitor=NULL;
00117 name="not used";
00118 Reset();
00119 }
00120 void PerfMonitorPoint::operator=(PerfMonitorPoint &src)
00121 {
00122 name=src.name;
00123 timer=src.timer;
00124 monitor=src.monitor;
00125 value=src.value;
00126 nbValue=src.nbValue;
00127 }
00128
00129 PerfMonitorPoint::PerfMonitorPoint(char *_name,PerfMonitor *_monitor)
00130 {
00131 Set(_name,_monitor);
00132 }
00133
00134 void PerfMonitorPoint::Set(char *_name,PerfMonitor *_monitor)
00135 {
00136 name=_name;
00137 monitor=_monitor;
00138 }
00139
00140 void PerfMonitorPoint::Reset()
00141 {
00142 value=0;
00143 nbValue=0;
00144 }
00145
00146 void PerfMonitorPoint::Begin(BOOL reset)
00147 {
00148 if (reset) Reset();
00149 timer.GetDeltaTime(TRUE);
00150 }
00151
00152 void PerfMonitorPoint::End()
00153 {
00154 value+=timer.GetDeltaTime();
00155 nbValue++;
00156 }