00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <Basics.H>
00024
00025 #include <time.h>
00026
00027 extern "C" char* _Pctime_r(const time_t *timer, char *buffer);
00028
00029 #include <SRPC.H>
00030 #include "CacheState.H"
00031
00032 using std::ostream;
00033 using std::endl;
00034
00035 inline void Indent(ostream &os, int indent) throw ()
00036 {
00037 for (int i = 0; i < indent; i++) os << " ";
00038 }
00039
00040 void CacheId::Print(ostream &os, int k) const throw ()
00041 {
00042 Indent(os, k); os << "Hostname: " << this->host << endl;
00043 Indent(os, k); os << "Port number: " << this->port << endl;
00044 Indent(os, k); os << "Stable cache: " << this->stableDir << endl;
00045 Indent(os, k); os << "Cache version: " << this->cacheVersion << endl;
00046 Indent(os, k); os << "Intf version: " << this->intfVersion << endl;
00047 char buffer[64];
00048 Indent(os, k); os << "Up since: ";
00049 os << ctime_r(&(this->startTime), buffer);
00050 Indent(os, k); os << "Current time: ";
00051 time_t now = time((time_t *)NULL);
00052 assert(now >= 0);
00053 os << ctime_r(&now, buffer);
00054 }
00055
00056 void CacheId::Send(SRPC &srpc) const throw (SRPC::failure)
00057 {
00058 srpc.send_Text(this->host);
00059 srpc.send_Text(this->port);
00060 srpc.send_Text(this->stableDir);
00061 srpc.send_Text(this->cacheVersion);
00062 srpc.send_int(this->intfVersion);
00063 srpc.send_int((int)(this->startTime));
00064 }
00065
00066 void CacheId::Recv(SRPC &srpc) throw (SRPC::failure)
00067 {
00068 srpc.recv_Text( this->host);
00069 srpc.recv_Text( this->port);
00070 srpc.recv_Text( this->stableDir);
00071 srpc.recv_Text( this->cacheVersion);
00072 this->intfVersion = srpc.recv_int();
00073 this->startTime = (time_t)(srpc.recv_int());
00074 }
00075
00076 bool operator==(const MethodCnts &c1, const MethodCnts &c2) throw ()
00077 {
00078 return ((c1.freeVarsCnt == c2.freeVarsCnt)
00079 && (c1.lookupCnt == c2.lookupCnt)
00080 && (c1.addEntryCnt == c2.addEntryCnt));
00081 }
00082
00083 EntryState& EntryState::operator+=(const EntryState &s) throw ()
00084 {
00085 this->newEntryCnt += s.newEntryCnt;
00086 this->oldEntryCnt += s.oldEntryCnt;
00087 this->newPklSize += s.newPklSize;
00088 this->oldPklSize += s.oldPklSize;
00089 return *this;
00090 }
00091
00092 void CacheState::Print(ostream &os, int k) const throw ()
00093 {
00094 Indent(os, k); os <<"Image size: "<< this->virtualSize << endl;
00095 Indent(os, k); os <<"Resident size: "<< this->physicalSize<< endl;
00096 Indent(os, k); os <<"FreeVars calls: "<< this->cnt.freeVarsCnt<<endl;
00097 Indent(os, k); os <<"Lookup calls: "<< this->cnt.lookupCnt << endl;
00098 Indent(os, k); os <<"AddEntry calls: "<< this->cnt.addEntryCnt<<endl;
00099 Indent(os, k); os <<"Num VMultiPKFiles: "<< this->vmpkCnt << endl;
00100 Indent(os, k); os <<"Num VPKFiles: "<< this->vpkCnt << endl;
00101 Indent(os, k); os <<"Num total entries: "<< this->entryCnt << endl;
00102 Indent(os, k); os <<"Num new entries: "<< this->s.newEntryCnt << endl;
00103 Indent(os, k); os <<"Num old entries: "<< this->s.oldEntryCnt << endl;
00104 Indent(os, k); os <<"New pickle size: "<< this->s.newPklSize << endl;
00105 Indent(os, k); os <<"Old pickle size: "<< this->s.oldPklSize << endl;
00106 Indent(os, k); os <<"HitFilter size: "<< this->hitFilterCnt << endl;
00107 Indent(os, k); os <<"Num entries to del: "<< this->delEntryCnt << endl;
00108 Indent(os, k); os <<"Num MPKFiles to weed: "<< this->delEntryCnt << endl;
00109 }
00110
00111 void CacheState::Send(SRPC &srpc) const throw (SRPC::failure)
00112 {
00113 srpc.send_int(this->virtualSize);
00114 srpc.send_int(this->physicalSize);
00115 srpc.send_int(this->cnt.freeVarsCnt);
00116 srpc.send_int(this->cnt.lookupCnt);
00117 srpc.send_int(this->cnt.addEntryCnt);
00118 srpc.send_int(this->vmpkCnt);
00119 srpc.send_int(this->vpkCnt);
00120 srpc.send_int(this->entryCnt);
00121 srpc.send_int(this->s.newEntryCnt);
00122 srpc.send_int(this->s.oldEntryCnt);
00123 srpc.send_int(this->s.newPklSize);
00124 srpc.send_int(this->s.oldPklSize);
00125 srpc.send_int(this->hitFilterCnt);
00126 srpc.send_int(this->delEntryCnt);
00127 srpc.send_int(this->mpkWeedCnt);
00128 }
00129
00130 void CacheState::Recv(SRPC &srpc) throw (SRPC::failure)
00131 {
00132 this->virtualSize = srpc.recv_int();
00133 this->physicalSize = srpc.recv_int();
00134 this->cnt.freeVarsCnt = srpc.recv_int();
00135 this->cnt.lookupCnt = srpc.recv_int();
00136 this->cnt.addEntryCnt = srpc.recv_int();
00137 this->vmpkCnt = srpc.recv_int();
00138 this->vpkCnt = srpc.recv_int();
00139 this->entryCnt = srpc.recv_int();
00140 this->s.newEntryCnt = srpc.recv_int();
00141 this->s.oldEntryCnt = srpc.recv_int();
00142 this->s.newPklSize = srpc.recv_int();
00143 this->s.oldPklSize = srpc.recv_int();
00144 this->hitFilterCnt = srpc.recv_int();
00145 this->delEntryCnt = srpc.recv_int();
00146 this->mpkWeedCnt = srpc.recv_int();
00147 }