Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

LoggingAdvocate.cc

Go to the documentation of this file.
00001 /*
00002  * LoggingAdvocate.cc
00003  *
00004  * Copyright (c) 2003 The University of Utah and the Flux Group.
00005  * All rights reserved.
00006  *
00007  * This file is licensed under the terms of the GNU Public License.  
00008  * See the file "license.terms" for restrictions on redistribution 
00009  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
00010  */
00011 
00012 /**
00013  * @file LoggingAdvocate.cc
00014  *
00015  * Implementation of the LoggingAdvocate class.
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 "LoggingAdvocate.hh"
00028 
00029 LoggingAdvocate::LoggingAdvocate(void)
00030 {
00031     gettimeofday(&this->eta_StartTime, NULL);
00032     this->eta_LastCPULog = this->eta_StartTime;
00033     this->eta_CPULog = NULL;
00034     this->eta_LastAdviceLog = this->eta_StartTime;
00035     this->eta_AdviceLog = NULL;
00036     this->eta_CompleteLog = NULL;
00037 }
00038 
00039 LoggingAdvocate::~LoggingAdvocate()
00040 {
00041     if( this->eta_CPULog != NULL )
00042         delete this->eta_CPULog;
00043     if( this->eta_AdviceLog != NULL )
00044         delete this->eta_AdviceLog;
00045     if( this->eta_CompleteLog != NULL )
00046         delete this->eta_CompleteLog;
00047 }
00048 
00049 void LoggingAdvocate::SetDelegateAttribute(const char *name,
00050                                            const CORBA::Any &value)
00051     throw (CORBA::SystemException)
00052 {
00053     if( (strcasecmp(name, "cpu_log") == 0) ||
00054         (strcasecmp(name, "cpu-log") == 0) ||
00055         (strcasecmp(name, "cpu log") == 0) )
00056     {
00057         const char *cpu_log;
00058         
00059         if( this->eta_CPULog != NULL )
00060         {
00061             throw Broker::DuplicateTaskParameter("cpu log");
00062         }
00063         else if( value >>= cpu_log )
00064         {
00065             this->eta_CPULog = new ofstream(cpu_log);
00066             (*this->eta_CPULog) << setfill('0');
00067             (*this->eta_CPULog)
00068                 << "# start: "
00069                 << (long)this->eta_StartTime.tv_sec
00070                 << "."
00071                 << setw(6) << (long)this->eta_StartTime.tv_usec
00072                 << endl;
00073         }
00074         else
00075         {
00076             throw CORBA::BAD_PARAM();
00077         }
00078     }
00079     else if( (strcasecmp(name, "advice_log") == 0) ||
00080              (strcasecmp(name, "advice-log") == 0) ||
00081              (strcasecmp(name, "advice log") == 0) )
00082     {
00083         const char *advice_log;
00084         
00085         if( this->eta_AdviceLog != NULL )
00086         {
00087             throw Broker::DuplicateTaskParameter("advice log");
00088         }
00089         else if( value >>= advice_log )
00090         {
00091             this->eta_AdviceLog = new ofstream(advice_log);
00092             (*this->eta_AdviceLog) << setfill('0');
00093             (*this->eta_AdviceLog)
00094                 << "# start: "
00095                 << (long)this->eta_StartTime.tv_sec
00096                 << "."
00097                 << setw(6) << (long)this->eta_StartTime.tv_usec
00098                 << endl;
00099         }
00100         else
00101         {
00102             throw CORBA::BAD_PARAM();
00103         }
00104     }
00105     else if( (strcasecmp(name, "complete_log") == 0) ||
00106              (strcasecmp(name, "complete-log") == 0) ||
00107              (strcasecmp(name, "complete log") == 0) )
00108     {
00109         const char *complete_log;
00110         
00111         if( this->eta_CompleteLog != NULL )
00112         {
00113             throw Broker::DuplicateTaskParameter("complete log");
00114         }
00115         else if( value >>= complete_log )
00116         {
00117             this->eta_CompleteLog = new ofstream(complete_log);
00118             (*this->eta_CompleteLog) << setfill('0');
00119             (*this->eta_CompleteLog)
00120                 << "# start: "
00121                 << (long)this->eta_StartTime.tv_sec
00122                 << "."
00123                 << setw(6) << (long)this->eta_StartTime.tv_usec
00124                 << endl;
00125         }
00126         else
00127         {
00128             throw CORBA::BAD_PARAM();
00129         }
00130     }
00131     else
00132     {
00133         this->RealTimeTaskDelegateImpl::SetDelegateAttribute(name, value);
00134     }
00135 }
00136 
00137 void LoggingAdvocate::ReportCPU(Broker::RealTimeTask_ptr rtt,
00138                                 CORBA::ULong status,
00139                                 CORBA::ULong advice)
00140     throw (CORBA::SystemException)
00141 {
00142     if( CORBA::is_nil(this->dm_RemoteObject) )
00143     {
00144         throw CORBA::BAD_INV_ORDER();
00145     }
00146     
00147     if( this->eta_CompleteLog != NULL )
00148     {
00149         struct timeval tv, diff;
00150         
00151         gettimeofday(&tv, NULL);
00152         timersub(&tv, &this->eta_StartTime, &diff);
00153         (*this->eta_CompleteLog)
00154             << (long)diff.tv_sec
00155             << "."
00156             << setw(6) << (long)diff.tv_usec
00157             << " -0.01"
00158             << endl;
00159     }
00160     if( this->eta_CPULog != NULL )
00161     {
00162         struct timeval tv, st, diff;
00163         
00164         timersub(&this->eta_LastCPULog, &this->eta_StartTime, &diff);
00165         st.tv_sec = status / 1000000;
00166         st.tv_usec = status % 1000000;
00167         (*this->eta_CPULog)
00168             << (long)diff.tv_sec
00169             << "."
00170             << setw(6) << (long)diff.tv_usec
00171             << " "
00172             << (long)st.tv_sec
00173             << "."
00174             << setw(6) << (long)st.tv_usec
00175             << endl;
00176         gettimeofday(&tv, NULL);
00177         timersub(&tv, &this->eta_StartTime, &diff);
00178         (*this->eta_CPULog)
00179             << (long)diff.tv_sec
00180             << "."
00181             << setw(6) << (long)diff.tv_usec
00182             << " "
00183             << (long)st.tv_sec
00184             << "."
00185             << setw(6) << (long)st.tv_usec
00186             << endl;
00187         this->eta_LastCPULog = tv;
00188     }
00189     if( this->eta_AdviceLog != NULL )
00190     {
00191         struct timeval tv, st, diff;
00192 
00193         st.tv_sec = advice / 1000000;
00194         st.tv_usec = advice % 1000000;
00195 #if 0
00196         timersub(&this->eta_LastAdviceLog, &this->eta_StartTime, &diff);
00197         (*this->eta_AdviceLog)
00198             << (long)diff.tv_sec
00199             << "."
00200             << setw(6) << (long)diff.tv_usec
00201             << " "
00202             << (long)st.tv_sec
00203             << "."
00204             << setw(6) << (long)st.tv_usec
00205             << endl;
00206 #endif
00207         gettimeofday(&tv, NULL);
00208         timersub(&tv, &this->eta_StartTime, &diff);
00209         (*this->eta_AdviceLog)
00210             << (long)diff.tv_sec
00211             << "."
00212             << setw(6) << (long)diff.tv_usec
00213             << " "
00214             << (long)st.tv_sec
00215             << "."
00216             << setw(6) << (long)st.tv_usec
00217             << endl;
00218         this->eta_LastAdviceLog = tv;
00219     }
00220     this->RealTimeTaskDelegateImpl::ReportCPU(rtt, status, advice);
00221 }

Generated on Mon Dec 1 16:29:06 2003 for CPU Broker by doxygen 1.3.4