00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4ProfileTimer.h"
00017
00018 #include <iostream.h>
00019 #include <string.h>
00020 #include <unistd.h>
00021
00022 ClassImp(TGo4ProfileTimer)
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 Int_t TGo4ProfileTimer::Start(void)
00033 {
00034 gettimeofday (&this->fxBeginTime, 0);
00035 this->fxLastTime = this->fxBeginTime;
00036 getrusage (RUSAGE_SELF, &this->fxBeginUsage);
00037 this->fxLastUsage = this->fxBeginUsage;
00038 return 0;
00039 }
00040
00041
00042 Int_t TGo4ProfileTimer::Stop(void)
00043 {
00044 this->fxLastTime = this->fxEndTime;
00045 gettimeofday (&this->fxEndTime, 0);
00046 this->fxLastUsage = this->fxEndUsage;
00047 getrusage (RUSAGE_SELF, &this->fxEndUsage);
00048
00049 return 0;
00050 }
00051
00052
00053
00054 TGo4ProfileTimer::~TGo4ProfileTimer (void)
00055 {
00056 }
00057
00058 void
00059 TGo4ProfileTimer::Dump (void) const
00060 {
00061 }
00062
00063
00064
00065 void
00066 TGo4ProfileTimer::Resume (void)
00067 {
00068 int rc;
00069 TGo4ElapsedTime et;
00070 TGo4ProfileTimer::Rusage ru;
00071
00072
00073 rc = this->ElapsedTime(et);
00074
00075 this->ElapsedRusage(ru);
00076
00077 cout << "\nResource Usage: Timing [s]\n";
00078 cout << "Real:\t" << et.fdRealTime << endl;
00079
00080 cout << "User:\t" << (float)(ru.ru_utime.tv_sec + (float)ru.ru_utime.tv_usec/1000000.) << endl;
00081
00082 cout << "System:\t" << (float)(ru.ru_stime.tv_sec + (float)ru.ru_stime.tv_usec/1000000.) << endl;
00083 cout << "\n";
00084 }
00085
00086
00087
00088
00089 void
00090 TGo4ProfileTimer::Memory (void)
00091 {
00092 TGo4ProfileTimer::Rusage ru;
00093
00094
00095 this->ElapsedRusage(ru);
00096
00097 cout << "\nResource Usage: Memory etc.\n";
00098 cout << "maximum resident set size \t";
00099 cout << ru.ru_maxrss << endl;
00100 cout << "integral shared memory size \t";
00101 cout << ru.ru_ixrss << endl;
00102 cout << "integral unshared data \t";
00103 cout << ru.ru_idrss << endl;
00104 cout << "integral unshared stack \t";
00105 cout << ru.ru_isrss << endl;
00106 cout << "page reclaims - total vmfaults\t";
00107 cout << ru.ru_minflt << endl;
00108 cout << "page faults \t";
00109 cout << ru.ru_majflt << endl;
00110 cout << "swaps \t";
00111 cout << ru.ru_nswap << endl;
00112 cout << "block input operations \t";
00113 cout << ru.ru_inblock << endl;
00114 cout << "block output operations \t";
00115 cout << ru.ru_oublock << endl;
00116 cout << "messages sent \t";
00117 cout << ru.ru_msgsnd << endl;
00118 cout << "messages received \t";
00119 cout << ru.ru_msgrcv << endl;
00120 cout << "signals received \t";
00121 cout << ru.ru_nsignals << endl;
00122 cout << "voluntary context switches \t";
00123 cout << ru.ru_nvcsw << endl;
00124 cout << "involuntary context switches \t";
00125 cout << ru.ru_nivcsw << endl;
00126 cout << "\n";
00127 }
00128
00129
00130
00131
00132 TGo4ProfileTimer::TGo4ProfileTimer (void)
00133 {
00134 memset (&this->fxEndUsage, 0, sizeof this->fxEndUsage);
00135 memset (&this->fxBeginUsage, 0, sizeof this->fxBeginUsage);
00136 memset (&this->fxLastUsage, 0, sizeof this->fxLastUsage);
00137
00138 memset (&this->fxBeginTime, 0, sizeof this->fxBeginTime);
00139 memset (&this->fxEndTime, 0, sizeof this->fxEndTime);
00140 memset (&this->fxLastTime, 0, sizeof this->fxLastTime);
00141
00142 char buf[20];
00143 snprintf (buf,19, "/proc/%d", getpid ());
00144
00145 cout << "Profile_Timer created for (" << buf << ")" << endl;
00146 }
00147
00148
00149
00150 void
00151 TGo4ProfileTimer::GetRusage (TGo4ProfileTimer::Rusage &usage)
00152 {
00153 usage = this->fxEndUsage;
00154 }
00155
00156
00157
00158 void
00159 TGo4ProfileTimer::ElapsedRusage (TGo4ProfileTimer::Rusage &usage)
00160 {
00161
00162 usage.ru_maxrss = this->fxEndUsage.ru_maxrss - this->fxLastUsage.ru_maxrss;
00163
00164 usage.ru_ixrss = this->fxEndUsage.ru_ixrss - this->fxLastUsage.ru_ixrss;
00165
00166 usage.ru_idrss = this->fxEndUsage.ru_idrss - this->fxLastUsage.ru_idrss;
00167
00168 usage.ru_isrss = this->fxEndUsage.ru_isrss - this->fxLastUsage.ru_isrss;
00169
00170 usage.ru_minflt = this->fxEndUsage.ru_minflt - this->fxLastUsage.ru_minflt;
00171
00172 usage.ru_majflt = this->fxEndUsage.ru_majflt - this->fxLastUsage.ru_majflt;
00173
00174 usage.ru_nswap = this->fxEndUsage.ru_nswap - this->fxLastUsage.ru_nswap;
00175
00176 usage.ru_inblock = this->fxEndUsage.ru_inblock -
00177 this->fxLastUsage.ru_inblock;
00178
00179 usage.ru_oublock = this->fxEndUsage.ru_oublock -
00180 this->fxLastUsage.ru_oublock;
00181
00182 usage.ru_msgsnd = this->fxEndUsage.ru_msgsnd - this->fxLastUsage.ru_msgsnd;
00183
00184 usage.ru_msgrcv = this->fxEndUsage.ru_msgrcv - this->fxLastUsage.ru_msgrcv;
00185
00186 usage.ru_nsignals = this->fxEndUsage.ru_nsignals -
00187 this->fxLastUsage.ru_nsignals;
00188
00189 usage.ru_nvcsw = this->fxEndUsage.ru_nvcsw - this->fxLastUsage.ru_nvcsw;
00190
00191 usage.ru_nivcsw = this->fxEndUsage.ru_nivcsw - this->fxLastUsage.ru_nivcsw;
00192 this->Subtract (usage.ru_utime, this->fxEndUsage.ru_utime, this->fxLastUsage.ru_utime);
00193 this->Subtract (usage.ru_stime, this->fxEndUsage.ru_stime, this->fxLastUsage.ru_stime);
00194 }
00195
00196
00197
00198 void
00199 TGo4ProfileTimer::ComputeTimes (TGo4ElapsedTime &et)
00200 {
00201 timeval td;
00202
00203
00204
00205
00206 this->Subtract (td, this->fxEndTime, this->fxBeginTime);
00207 et.fdRealTime = td.tv_sec + ((double) td.tv_usec) / ONE_SECOND_IN_USECS;
00208
00209 this->Subtract (td, this->fxEndUsage.ru_utime, this->fxBeginUsage.ru_utime);
00210 et.fdUserTime = td.tv_sec + ((double) td.tv_usec) / ONE_SECOND_IN_USECS;
00211
00212 this->Subtract (td, this->fxEndUsage.ru_stime, this->fxBeginUsage.ru_stime);
00213 et.fdSystemTime = td.tv_sec + ((double) td.tv_usec) / ONE_SECOND_IN_USECS;
00214 }
00215
00216
00217
00218 void
00219 TGo4ProfileTimer::Subtract (timeval &tdiff, timeval &t1, timeval &t0)
00220 {
00221 tdiff.tv_sec = t1.tv_sec - t0.tv_sec;
00222 tdiff.tv_usec = t1.tv_usec - t0.tv_usec;
00223
00224
00225
00226 while (tdiff.tv_usec < 0)
00227 {
00228 tdiff.tv_sec--;
00229 tdiff.tv_usec += ONE_SECOND_IN_USECS;
00230 }
00231 }
00232
00233
00234
00235 Int_t
00236 TGo4ProfileTimer::ElapsedTime (TGo4ElapsedTime &et)
00237 {
00238 this->ComputeTimes (et);
00239 return 0;
00240 }
00241 TGo4ProfileTimer::TGo4ElapsedTime::TGo4ElapsedTime(): fdRealTime(0.), fdUserTime(0.), fdSystemTime(0.)
00242 {
00243
00244 }
00245
00246
00247
00248
00249