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 #include <SRPC.H>
00025 #include "Timer.H"
00026 #include "LookupStats.H"
00027
00028 #include <iomanip>
00029
00030 using std::ostream;
00031 using std::ios;
00032 using std::setw;
00033 using std::setprecision;
00034 using std::resetiosflags;
00035 using std::setiosflags;
00036
00037 inline void Indent(ostream &os, int indent) throw ()
00038 {
00039 for (int i = 0; i < indent; i++) os << " ";
00040 }
00041
00042
00043
00044 void LookupStats::Datum::Update(Timer::MicroSecs tm) throw ()
00045 {
00046 if (this->num == 0) {
00047 this->minTime = this->maxTime = tm;
00048 } else {
00049 this->minTime = min(this->minTime, tm);
00050 this->maxTime = max(this->maxTime, tm);
00051 }
00052 this->num++;
00053 this->totalTime += tm;
00054 }
00055
00056 void LookupStats::Datum::Update(const LookupStats::Datum &d) throw ()
00057 {
00058 if (d.num > 0) {
00059 if (this->num == 0) {
00060 this->minTime = d.minTime;
00061 this->maxTime = d.maxTime;
00062 } else {
00063 this->minTime = min(this->minTime, d.minTime);
00064 this->maxTime = max(this->maxTime, d.maxTime);
00065 }
00066 this->num += d.num;
00067 this->totalTime += d.totalTime;
00068 } else {
00069 assert(d.totalTime == 0UL);
00070 }
00071 }
00072
00073 void LookupStats::Datum::Send(SRPC &srpc) const throw (SRPC::failure)
00074 {
00075 srpc.send_int64(this->num);
00076 srpc.send_int64(this->totalTime);
00077 srpc.send_int64(this->minTime);
00078 srpc.send_int64(this->maxTime);
00079 }
00080
00081 void LookupStats::Datum::Recv(SRPC &srpc) throw (SRPC::failure)
00082 {
00083 this->num = srpc.recv_int64();
00084 this->totalTime = srpc.recv_int64();
00085 this->minTime = srpc.recv_int64();
00086 this->maxTime = srpc.recv_int64();
00087 }
00088
00089 void LookupStats::Datum::Print(ostream &os, const char *label,
00090 int labelWidth, Timer::MicroSecs total, int indent) const throw ()
00091 {
00092 Indent(os, indent);
00093 os << resetiosflags(ios::right) << setiosflags(ios::left)
00094 << setw(labelWidth) << label;
00095 os << setw(0) << " = ";
00096 os << resetiosflags(ios::left) << setiosflags(ios::right)
00097 << setw(6) << this->num;
00098 if (total != 0UL) {
00099 float numF = (float)(this->num);
00100 os << setw(0) << " (";
00101 os << setprecision(0) << setw(3)
00102 << setiosflags(ios::fixed) << resetiosflags(ios::showpoint)
00103 << (100.0 * numF / (float)total);
00104 os << setw(0) << "%)";
00105 if (numF != 0.0) {
00106 os << ", avg = "
00107 << setprecision(2) << setiosflags(ios::showpoint)
00108 << setw(5) << (((float)(this->totalTime) / 1000.0) / numF)
00109 << setw(0) << " ms";
00110 os << ", min/max = "
00111 << setw(5) << ((float)(this->minTime) / 1000.0) << '/'
00112 << setw(5) << ((float)(this->maxTime) / 1000.0)
00113 << setw(0) << " ms";
00114 }
00115 }
00116 os << '\n';
00117 }
00118
00119
00120
00121 void LookupStats::Rec::Send(SRPC &srpc) const throw (SRPC::failure)
00122 {
00123 for (int i = 0; i < LookupStats::NumKinds; i++) {
00124 this->datum[i].Send(srpc);
00125 }
00126 }
00127
00128 void LookupStats::Rec::Recv(SRPC &srpc) throw (SRPC::failure)
00129 {
00130 for (int i = 0; i < LookupStats::NumKinds; i++) {
00131 this->datum[i].Recv(srpc);
00132 }
00133 }
00134
00135 static const char *OutcomeNames[] = {
00136 "new hits", "warm hits", "disk hits", "all misses" };
00137
00138 void LookupStats::Rec::Print(ostream &os, int indent) const throw ()
00139 {
00140
00141 const char *lookupsLabel = "all lookups";
00142 int mw = strlen(lookupsLabel);
00143 int i;
00144 for (i = 0; i < LookupStats::NumKinds; i++) {
00145 mw = max(mw, strlen(OutcomeNames[i]));
00146 }
00147
00148
00149 LookupStats::Datum allLookups;
00150 for (i = 0; i < LookupStats::NumKinds; i++) {
00151 allLookups.Update(this->datum[i]);
00152 }
00153
00154
00155 allLookups.Print(os, "all lookups", mw, allLookups.num, indent);
00156 for (i = 0; i < LookupStats::NumKinds; i++) {
00157 this->datum[i].Print(os, OutcomeNames[i], mw, allLookups.num, indent);
00158 }
00159 }