00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "config.h"
00019
00020 #include <string.h>
00021 #include <sys/time.h>
00022
00023 #include <iostream>
00024 #include <fstream>
00025 #include <iomanip>
00026
00027 #include <time_util.h>
00028
00029 #include "LoggingAdvocate.hh"
00030
00031 using namespace std;
00032
00033 LoggingAdvocate::LoggingAdvocate(void)
00034 {
00035 gettimeofday(&this->la_StartTime, NULL);
00036 this->la_LastCPULog = this->la_StartTime;
00037 this->la_CPULog = NULL;
00038 this->la_LastAdviceLog = this->la_StartTime;
00039 this->la_AdviceLog = NULL;
00040 this->la_CompleteLog = NULL;
00041 this->la_HitLog = NULL;
00042 this->la_MissLog = NULL;
00043 }
00044
00045 LoggingAdvocate::~LoggingAdvocate()
00046 {
00047 if( this->la_CPULog != NULL )
00048 delete this->la_CPULog;
00049 if( this->la_AdviceLog != NULL )
00050 delete this->la_AdviceLog;
00051 if( this->la_CompleteLog != NULL )
00052 delete this->la_CompleteLog;
00053 if( this->la_HitLog != NULL )
00054 delete this->la_HitLog;
00055 if( this->la_MissLog != NULL )
00056 delete this->la_MissLog;
00057 }
00058
00059 void LoggingAdvocate::SetDelegateAttribute(const char *name,
00060 const CORBA::Any &value)
00061 throw (CORBA::SystemException)
00062 {
00063 if( (strcasecmp(name, "cpu_log") == 0) ||
00064 (strcasecmp(name, "cpu-log") == 0) ||
00065 (strcasecmp(name, "cpu log") == 0) )
00066 {
00067 const char *cpu_log;
00068
00069 if( this->la_CPULog != NULL )
00070 {
00071 throw Broker::DuplicateTaskParameter("cpu log");
00072 }
00073 else if( value >>= cpu_log )
00074 {
00075 this->la_CPULog = new ofstream(cpu_log);
00076 (*this->la_CPULog) << setfill('0');
00077 (*this->la_CPULog)
00078 << "# start: "
00079 << (long)this->la_StartTime.tv_sec
00080 << "."
00081 << setw(6) << (long)this->la_StartTime.tv_usec
00082 << endl;
00083 }
00084 else
00085 {
00086 throw CORBA::BAD_PARAM();
00087 }
00088 }
00089 else if( (strcasecmp(name, "advice_log") == 0) ||
00090 (strcasecmp(name, "advice-log") == 0) ||
00091 (strcasecmp(name, "advice log") == 0) )
00092 {
00093 const char *advice_log;
00094
00095 if( this->la_AdviceLog != NULL )
00096 {
00097 throw Broker::DuplicateTaskParameter("advice log");
00098 }
00099 else if( value >>= advice_log )
00100 {
00101 this->la_AdviceLog = new ofstream(advice_log);
00102 (*this->la_AdviceLog) << setfill('0');
00103 (*this->la_AdviceLog)
00104 << "# start: "
00105 << (long)this->la_StartTime.tv_sec
00106 << "."
00107 << setw(6) << (long)this->la_StartTime.tv_usec
00108 << endl;
00109 }
00110 else
00111 {
00112 throw CORBA::BAD_PARAM();
00113 }
00114 }
00115 else if( (strcasecmp(name, "complete_log") == 0) ||
00116 (strcasecmp(name, "complete-log") == 0) ||
00117 (strcasecmp(name, "complete log") == 0) )
00118 {
00119 const char *complete_log;
00120
00121 if( this->la_CompleteLog != NULL )
00122 {
00123 throw Broker::DuplicateTaskParameter("complete log");
00124 }
00125 else if( value >>= complete_log )
00126 {
00127 this->la_CompleteLog = new ofstream(complete_log);
00128 (*this->la_CompleteLog) << setfill('0');
00129 (*this->la_CompleteLog)
00130 << "# start: "
00131 << (long)this->la_StartTime.tv_sec
00132 << "."
00133 << setw(6) << (long)this->la_StartTime.tv_usec
00134 << endl;
00135 }
00136 else
00137 {
00138 throw CORBA::BAD_PARAM();
00139 }
00140 }
00141 else if( (strcasecmp(name, "hit_log") == 0) ||
00142 (strcasecmp(name, "hit-log") == 0) ||
00143 (strcasecmp(name, "hit log") == 0) )
00144 {
00145 const char *hit_log;
00146
00147 if( this->la_HitLog != NULL )
00148 {
00149 throw Broker::DuplicateTaskParameter("hit log");
00150 }
00151 else if( value >>= hit_log )
00152 {
00153 this->la_HitLog = new ofstream(hit_log);
00154 (*this->la_HitLog) << setfill('0');
00155 (*this->la_HitLog)
00156 << "# start: "
00157 << (long)this->la_StartTime.tv_sec
00158 << "."
00159 << setw(6) << (long)this->la_StartTime.tv_usec
00160 << endl;
00161 }
00162 else
00163 {
00164 throw CORBA::BAD_PARAM();
00165 }
00166 }
00167 else if( (strcasecmp(name, "miss_log") == 0) ||
00168 (strcasecmp(name, "miss-log") == 0) ||
00169 (strcasecmp(name, "miss log") == 0) )
00170 {
00171 const char *miss_log;
00172
00173 if( this->la_MissLog != NULL )
00174 {
00175 throw Broker::DuplicateTaskParameter("miss log");
00176 }
00177 else if( value >>= miss_log )
00178 {
00179 this->la_MissLog = new ofstream(miss_log);
00180 (*this->la_MissLog) << setfill('0');
00181 (*this->la_MissLog)
00182 << "# start: "
00183 << (long)this->la_StartTime.tv_sec
00184 << "."
00185 << setw(6) << (long)this->la_StartTime.tv_usec
00186 << endl;
00187 }
00188 else
00189 {
00190 throw CORBA::BAD_PARAM();
00191 }
00192 }
00193 else
00194 {
00195 this->RealTimeTaskDelegateImpl::SetDelegateAttribute(name, value);
00196 }
00197 }
00198
00199 CORBA::Any_ptr LoggingAdvocate::GetDelegateAttribute(const char *name)
00200 throw (CORBA::SystemException)
00201 {
00202 CORBA::Any_var retval;
00203
00204 if( name == NULL )
00205 {
00206 throw CORBA::BAD_PARAM();
00207 }
00208 else if( (strcasecmp(name, "last_advice") == 0) ||
00209 (strcasecmp(name, "last-advice") == 0) ||
00210 (strcasecmp(name, "last advice") == 0) )
00211 {
00212 retval = new CORBA::Any();
00213 (*retval) <<= this->la_LastAdvice;
00214 }
00215 else
00216 {
00217 retval = this->RealTimeTaskDelegateImpl::GetDelegateAttribute(name);
00218 }
00219 return( retval._retn() );
00220 }
00221
00222 Broker::CPUReserve LoggingAdvocate::PassCPU(Broker::RealTimeTask_ptr rtt,
00223 const Broker::CPUReserve &status,
00224 const Broker::CPUReserve &advice,
00225 const Broker::KeyedReportParameters &krp)
00226 throw (CORBA::SystemException)
00227 {
00228 if( CORBA::is_nil(this->dm_RemoteObject.in()) )
00229 {
00230 throw CORBA::BAD_INV_ORDER();
00231 }
00232
00233 this->la_LastAdvice = advice.Compute;
00234
00235 if( this->la_CompleteLog != NULL )
00236 {
00237 struct timeval tv, diff;
00238
00239 gettimeofday(&tv, NULL);
00240 timersub(&tv, &this->la_StartTime, &diff);
00241 (*this->la_CompleteLog)
00242 << (long)diff.tv_sec
00243 << "."
00244 << setw(6) << (long)diff.tv_usec
00245 << " -0.01"
00246 << endl;
00247 }
00248 if( this->la_HitLog != NULL )
00249 {
00250 struct timeval tv, st, diff;
00251 unsigned long long usecs;
00252
00253 st.tv_sec = status.Compute / 1000000;
00254 st.tv_usec = status.Compute % 1000000;
00255 gettimeofday(&tv, NULL);
00256 timersub(&tv, &this->la_LastLog, &diff);
00257 usecs = diff.tv_sec * 1000000;
00258 usecs += diff.tv_usec;
00259 if( usecs <= advice.Period )
00260 {
00261 timersub(&tv, &this->la_StartTime, &diff);
00262 (*this->la_HitLog)
00263 << (long)diff.tv_sec
00264 << "."
00265 << setw(6) << (long)diff.tv_usec
00266 << " "
00267 << (long)st.tv_sec
00268 << "."
00269 << setw(6) << (long)st.tv_usec
00270 << endl;
00271 }
00272 else
00273 {
00274
00275 }
00276 }
00277 if( this->la_MissLog != NULL )
00278 {
00279 struct timeval tv, st, diff;
00280 unsigned long long usecs;
00281
00282 st.tv_sec = status.Compute / 1000000;
00283 st.tv_usec = status.Compute % 1000000;
00284 gettimeofday(&tv, NULL);
00285 timersub(&tv, &this->la_LastLog, &diff);
00286 usecs = diff.tv_sec * 1000000;
00287 usecs += diff.tv_usec;
00288 if( usecs > advice.Period )
00289 {
00290 timersub(&tv, &this->la_StartTime, &diff);
00291 (*this->la_MissLog)
00292 << (long)diff.tv_sec
00293 << "."
00294 << setw(6) << (long)diff.tv_usec
00295 << " "
00296 << (long)st.tv_sec
00297 << "."
00298 << setw(6) << (long)st.tv_usec
00299 << endl;
00300 }
00301 }
00302 if( this->la_CPULog != NULL )
00303 {
00304 struct timeval tv, st, diff;
00305
00306 st.tv_sec = status.Compute / 1000000;
00307 st.tv_usec = status.Compute % 1000000;
00308 timersub(&this->la_LastCPULog, &this->la_StartTime, &diff);
00309 (*this->la_CPULog)
00310 << (long)diff.tv_sec
00311 << "."
00312 << setw(6) << (long)diff.tv_usec
00313 << " "
00314 << (long)st.tv_sec
00315 << "."
00316 << setw(6) << (long)st.tv_usec
00317 << endl;
00318 gettimeofday(&tv, NULL);
00319 #if 0
00320 timersub(&tv, &this->la_StartTime, &diff);
00321 (*this->la_CPULog)
00322 << (long)diff.tv_sec
00323 << "."
00324 << setw(6) << (long)diff.tv_usec
00325 << " "
00326 << (long)st.tv_sec
00327 << "."
00328 << setw(6) << (long)st.tv_usec
00329 << endl;
00330 #endif
00331 this->la_LastCPULog = tv;
00332 }
00333 if( this->la_AdviceLog != NULL )
00334 {
00335 struct timeval tv, st, diff;
00336
00337 st.tv_sec = advice.Compute / 1000000;
00338 st.tv_usec = advice.Compute % 1000000;
00339 #if 0
00340 timersub(&this->la_LastAdviceLog, &this->la_StartTime, &diff);
00341 (*this->la_AdviceLog)
00342 << (long)diff.tv_sec
00343 << "."
00344 << setw(6) << (long)diff.tv_usec
00345 << " "
00346 << (long)st.tv_sec
00347 << "."
00348 << setw(6) << (long)st.tv_usec
00349 << endl;
00350 #endif
00351 gettimeofday(&tv, NULL);
00352 timersub(&tv, &this->la_StartTime, &diff);
00353 (*this->la_AdviceLog)
00354 << (long)diff.tv_sec
00355 << "."
00356 << setw(6) << (long)diff.tv_usec
00357 << " "
00358 << (long)st.tv_sec
00359 << "."
00360 << setw(6) << (long)st.tv_usec
00361 << endl;
00362 this->la_LastAdviceLog = tv;
00363 }
00364 gettimeofday(&this->la_LastLog, NULL);
00365 return this->RealTimeTaskDelegateImpl::PassCPU(rtt, status, advice, krp);
00366 }