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

LookupStats.C

Go to the documentation of this file.
00001 // Copyright (C) 2001, Compaq Computer Corporation
00002 // 
00003 // This file is part of Vesta.
00004 // 
00005 // Vesta is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 // 
00010 // Vesta is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with Vesta; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 // Last modified on Tue Aug  3 17:56:48 EDT 2004 by ken@xorian.net  
00020 //      modified on Sat Feb 12 11:52:55 PST 2000 by mann  
00021 //      modified on Mon Nov 10 12:41:27 PST 1997 by heydon
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 // LookupStats::Datum ---------------------------------------------------------
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 // LookupStats::Rec -----------------------------------------------------------
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     // compute max label width
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     // aggregate lookup statistics
00149     LookupStats::Datum allLookups;
00150     for (i = 0; i < LookupStats::NumKinds; i++) {
00151         allLookups.Update(this->datum[i]);
00152     }
00153 
00154     // print outcome stats
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 }

Generated on Mon May 8 00:48:32 2006 for Vesta by  doxygen 1.4.2