00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <Basics.H>
00025 #include "CacheEntry.H"
00026 #include "SPKFileRep.H"
00027 #include "SPKFile.H"
00028 #include "StatNames.H"
00029 #include "StatCFP.H"
00030 #include "StatPKFile.H"
00031
00032 int PKFileObj::Search(int verbose,
00033 Stat::Collection &stats)
00034 const throw ()
00035 {
00036
00037 int childLevel = 1;
00038 long int preNumEntries = (stats.fanout.size() > childLevel)
00039 ? (stats.fanout.get(childLevel))->SumTotal() : 0L;
00040
00041
00042 int cnt;
00043 {
00044 CFPObj *cfp = (CFPObj *) 0;
00045 PKFileIter it(this);
00046 for (cnt = 0; it.Next( cfp); cnt++) {
00047 (void) cfp->Search(verbose, stats);
00048 }
00049 cfp = (CFPObj *) 0;
00050 }
00051
00052
00053 stats.entryStats[Stat::PKFileSize].AddVal(this->len, this->loc);
00054 const FV::ListApp *allNames = this->pkFile->AllNames();
00055 stats.entryStats[Stat::NumNames].AddVal(allNames->len, this->loc);
00056 for (int i = 0; i < allNames->len; i++) {
00057 int nameLen = (allNames->name[i]).Length();
00058 stats.entryStats[Stat::NameSize].AddVal(nameLen, this->loc);
00059 }
00060 long int postNumEntries = (stats.fanout.get(childLevel))->SumTotal();
00061 int numEntries = (int)(postNumEntries - preNumEntries);
00062 stats.entryStats[Stat::NumEntries].AddVal(numEntries, this->loc);
00063 if (allNames->len > 0) {
00064 int numCommonNms = this->pkFile->CommonNames()->Cardinality();
00065 stats.entryStats[Stat::NumCommonNames].AddVal(numCommonNms, this->loc);
00066 float totalF = (float)(allNames->len);
00067 float commonF = (float)numCommonNms;
00068 int pcntCommon = (int)(0.49 + (100.0 * commonF / totalF));
00069 stats.entryStats[Stat::PcntCommonNames].AddVal(pcntCommon, this->loc);
00070 }
00071
00072
00073 int thisLevel = childLevel + 1;
00074 StatCount *sc;
00075 if (stats.fanout.size() <= thisLevel) {
00076 assert(stats.fanout.size() == thisLevel);
00077 sc = NEW(StatCount);
00078 stats.fanout.addhi(sc);
00079 } else {
00080 sc = stats.fanout.get(thisLevel);
00081 }
00082 sc->AddVal(cnt, this->loc);
00083 return thisLevel;
00084 }
00085
00086 PKFileIter::PKFileIter(const PKFileObj *pkf) throw ()
00087 : pkf(pkf), pkHdr(pkf->pkHdr), cfpIndex(0)
00088 {
00089 this->cfpEntryMap = pkf->pkFile->OldEntries();
00090 }
00091
00092 bool PKFileIter::Next( CFPObj* &cfp) throw ()
00093 {
00094 bool res = (this->cfpIndex < this->pkHdr->num);
00095 if (res) {
00096 SPKFileRep::HeaderEntry *he = &(this->pkHdr->entry[this->cfpIndex++]);
00097 CE::List *entries;
00098 bool inTbl = this->cfpEntryMap->Get(he->cfp, entries);
00099 assert(inTbl);
00100 Stat::Location *cfp_loc =
00101 NEW_CONSTR(Stat::Location,
00102 (pkf->loc->add_cfp(pkf->pkFile->NamesEpoch(),
00103 he->cfp)));
00104 cfp = NEW_CONSTR(CFPObj, (cfp_loc, pkf->pkFile, he->cfp, entries));
00105 }
00106 return res;
00107 }