Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members
TimeMeasureAdaptor.cpp
00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: Adaptor.cpp * 00006 * * 00007 * * 00008 * * 00009 * ITEC institute of the University of Klagenfurt (Austria) * 00010 * http://www.itec.uni-klu.ac.at * 00011 * * 00012 * * 00013 * For more information visit the ViTooKi homepage: * 00014 * http://ViTooKi.sourceforge.net * 00015 * vitooki-user@lists.sourceforge.net * 00016 * vitooki-devel@lists.sourceforge.net * 00017 * * 00018 * This file is part of ViTooKi, a free video toolkit. * 00019 * ViTooKi is free software; you can redistribute it and/or * 00020 * modify it under the terms of the GNU General Public License * 00021 * as published by the Free Software Foundation; either version 2 * 00022 * of the License, or (at your option) any later version. * 00023 * * 00024 * This program is distributed in the hope that it will be useful, * 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00027 * GNU General Public License for more details. * 00028 * * 00029 * You should have received a copy of the GNU General Public License * 00030 * along with this program; if not, write to the Free Software * 00031 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * 00032 * MA 02111-1307, USA. * 00033 * * 00034 ***********************************************************************/ 00035 00036 /*********************************************************************** 00037 * * 00038 * REVISION HISTORY: * 00039 * * 00040 * * 00041 * * 00042 ***********************************************************************/ 00043 00044 #include "TimeMeasureAdaptor.hpp" 00045 #include "../ESInfo.hpp" 00046 #include "../Adaptor.hpp" 00047 #include <assert.h> 00048 00049 TimeMeasureAdaptor::TimeMeasureAdaptor(Adaptor* a,FILE* fp): 00050 adaptor(a),muiTimeSpent(0),muiTimeSpentLastFrame(0),output(fp) 00051 { 00052 assert(a!=NULL); 00053 const char* tmp=adaptor->getName(); 00054 strcpy(name,"TimeMeasureAdaptor:"); 00055 strcat(name,tmp); 00056 initialized=false; 00057 }; 00058 00059 TimeMeasureAdaptor::~TimeMeasureAdaptor() 00060 { 00061 if(adaptor) 00062 delete adaptor; 00063 }; 00064 00065 long TimeMeasureAdaptor::getdifftime(struct timeval *t1, struct timeval *t2) 00066 { 00067 long ret = 0; 00068 00069 ret = t2->tv_usec - t1->tv_usec; 00070 ret += (t2->tv_sec - t1->tv_sec) * 1000000; 00071 00072 return ret; 00073 }; 00074 00075 unsigned int TimeMeasureAdaptor::getTimeSpent() 00076 { 00077 return muiTimeSpent; 00078 }; 00079 00080 unsigned int TimeMeasureAdaptor::getTimeSpentForLastFrame() 00081 { 00082 return muiTimeSpentLastFrame; 00083 }; 00084 00085 00086 void TimeMeasureAdaptor::startTimer() 00087 { 00088 gettimeofday(&mtStart, NULL); 00089 }; 00090 00091 void TimeMeasureAdaptor::endTimer() 00092 { 00093 gettimeofday(&mtEnd, NULL); 00094 muiTimeSpentLastFrame = getdifftime(&mtStart, &mtEnd); 00095 muiTimeSpent+=muiTimeSpentLastFrame; 00096 }; 00097 00113 list<Frame*> TimeMeasureAdaptor::adapt(Frame * frm) 00114 { 00115 if(!initialized) 00116 initialize(); 00117 startTimer(); 00118 list<Frame*> f=adaptor->adapt(frm); 00119 endTimer(); 00120 return f; 00121 }; 00122 00132 list<Frame*> TimeMeasureAdaptor::close() 00133 { 00134 startTimer(); 00135 list<Frame*> f=adaptor->close(); 00136 endTimer(); 00137 if(output) { 00138 fseek(output,0,SEEK_END); 00139 fprintf(output,"%s(%s):spent %u microsec\n",name, 00140 (adaptor->getESInfo()?adaptor->getESInfo()->getInput():"Unknown ESInfo"),getTimeSpent()); 00141 } 00142 return f; 00143 }; 00144 00151 Adaptor* TimeMeasureAdaptor::clone() 00152 { 00153 Adaptor *a= adaptor->clone(); 00154 return new TimeMeasureAdaptor(a,output); 00155 }; 00156 00161 void TimeMeasureAdaptor::setESInfo(ESInfo * esi) 00162 { 00163 adaptor->setESInfo(esi); 00164 }; 00165 00166 ESInfo * TimeMeasureAdaptor::getESInfo() 00167 { 00168 return adaptor->getESInfo(); 00169 }; 00170 00174 void TimeMeasureAdaptor::initialize() 00175 { 00176 if(initialized) 00177 return; 00178 initialized=true; 00179 muiTimeSpent=0; 00180 startTimer(); 00181 adaptor->initialize(); 00182 endTimer(); 00183 if(output) { 00184 fseek(output,0,SEEK_END); 00185 fprintf(output,"%s(%s):spent %u microsec in Initialize\n",name, 00186 (adaptor->getESInfo()?adaptor->getESInfo()->getInput():"Unknown ESInfo"),getTimeSpent()); 00187 } 00188 }; 00189