00001 //*****************************************************************************// 00002 // // 00003 // Copyright (c) 2001 // 00004 // INRIA // 00005 // 54600 VILLERS LES NANCY // 00006 // France // 00007 // // 00008 //*****************************************************************************// 00009 // // 00010 // *** NOTICE OF PROPRIETARY INFORMATION *** // 00011 // // 00012 // The information contained in this file is considered proprietary and the // 00013 // exclusive property of INRIA. This information may not be disclosed, // 00014 // duplicated or used, in whole or in part, for any purpose whatsoever // 00015 // without express written authorization from INRIA // 00016 // // 00017 //*****************************************************************************// 00018 00019 00020 #ifndef QC_CHRONO_H_ 00021 #define QC_CHRONO_H_ 00022 00023 00024 00025 #include <sys/time.h> 00026 #include <sys/resource.h> 00027 #include <unistd.h> 00028 00029 #include "QCCommon.hpp" 00030 00031 00032 00033 00038 00044 class QCChrono { 00045 00047 public: 00048 00049 00053 QCChrono (void) : 00054 totalSec(QC_ZERO), 00055 totalSec_r(QC_ZERO) 00056 {} 00057 00058 00059 00063 void reset (void) { 00064 totalSec = QC_ZERO; 00065 } 00066 00067 00068 00072 void reset_r (void) { 00073 totalSec_r = QC_ZERO; 00074 } 00075 00076 00077 00081 void start (void) { 00082 totalSec = QC_ZERO; 00083 gettimeofday (&refTime, NULL); 00084 reft = ((QCFloat)refTime.tv_sec + 00085 ((QCFloat)refTime.tv_usec)*1e-6); 00086 } 00087 00088 00089 00093 void start_r (void) { 00094 totalSec_r = QC_ZERO; 00095 getrusage (RUSAGE_SELF, &rrefTime); 00096 reft_r = ((QCFloat)rrefTime.ru_utime.tv_sec + (QCFloat)rrefTime.ru_stime.tv_sec + 00097 ((QCFloat)rrefTime.ru_utime.tv_usec + (QCFloat)rrefTime.ru_stime.tv_usec)*1e-6); 00098 } 00099 00100 00101 00105 void resume (void) { 00106 gettimeofday (&refTime, NULL); 00107 reft = ((QCFloat)refTime.tv_sec + 00108 (QCFloat)refTime.tv_usec*1e-6); 00109 } 00110 00111 00112 00116 void resume_r (void) { 00117 getrusage (RUSAGE_SELF, &rrefTime); 00118 reft_r = ((QCFloat)rrefTime.ru_utime.tv_sec + (QCFloat)rrefTime.ru_stime.tv_sec + 00119 ((QCFloat)rrefTime.ru_utime.tv_usec + (QCFloat)rrefTime.ru_stime.tv_usec)*1e-6); 00120 } 00121 00122 00123 00127 void pause (void) { 00128 gettimeofday (&elTime, NULL); 00129 elt = ((QCFloat)elTime.tv_sec + 00130 ((QCFloat)elTime.tv_usec)*1e-6); 00131 00132 totalSec += elt - reft; 00133 } 00134 00135 00136 00140 void pause_r (void) { 00141 getrusage (RUSAGE_SELF, &relTime); 00142 elt_r = ((QCFloat)relTime.ru_utime.tv_sec + (QCFloat)relTime.ru_stime.tv_sec + 00143 ((QCFloat)relTime.ru_utime.tv_usec + (QCFloat)relTime.ru_stime.tv_usec)*1e-6); 00144 00145 totalSec_r += elt_r - reft_r; 00146 } 00147 00148 00149 00150 00154 QCFloat getvalsec (void) const { return totalSec;} 00155 QCFloat getvalsec_r (void) const { return totalSec_r;} 00156 00157 00158 00159 00161 protected: 00162 00163 00165 private: 00166 00167 00170 public: 00171 protected: 00172 private: 00173 00174 00178 struct timeval refTime; 00179 00180 struct timeval elTime; 00181 00182 struct rusage rrefTime; 00183 00184 struct rusage relTime; 00185 00186 QCFloat reft; 00187 00188 QCFloat elt; 00189 00190 QCFloat reft_r; 00191 00192 QCFloat elt_r; 00193 00194 QCFloat totalSec; 00195 00196 QCFloat totalSec_r; 00197 }; 00198 00199 00200 00201 #endif // QC_CHRONO_H_