Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

perfMon.cpp

Go to the documentation of this file.
00001 /* ***********************************************************************************
00002         Writer:         Sebastien Bloc
00003         Copyright:      2003-2004
00004         eMail:          sebastien.bloc@free.fr
00005         URL:            http://mignonsoft.free.fr
00006 
00007         This program is free software; you can redistribute it and/or
00008         modify it under the terms of the GNU General Public License
00009         as published by the Free Software Foundation; either version 2
00010         of the License, or (at your option) any later version.
00011 
00012         This program is distributed in the hope that it will be useful,
00013         but WITHOUT ANY WARRANTY; without even the implied warranty of
00014         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015         GNU General Public License for more details.
00016         http://www.gnu.org/copyleft/gpl.html    
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         // ajout dans la list des records
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 }

Generated on Fri Aug 20 19:19:48 2004 for 3d Controls by doxygen 1.3.6