From a3a91fd7bab34983a008854728baf26034d4033e Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 20 Jun 2014 20:28:54 +0200 Subject: count strings more accurately for stats So far, only the few strings stored in stringitems were counted, but many more strings are directly inserted into the cache. We account for this now by identifying all these different strings and measure their length. We are still not at the correct size of the cache in 'stats' this way, but we are now again a bit closer. Git-Dch: Ignore --- cmdline/apt-cache.cc | 53 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 14 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 1447feb81..4030ce4e6 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -375,31 +375,56 @@ static bool Stats(CommandLine &) SizeToStr(Cache->Head().DescFileCount*Cache->Head().DescFileSz) << ')' << endl; cout << _("Total Provides mappings: ") << Cache->Head().ProvidesCount << " (" << SizeToStr(Cache->Head().ProvidesCount*Cache->Head().ProvidesSz) << ')' << endl; - - // String list stats - unsigned long Size = 0; - unsigned long Count = 0; - for (pkgCache::StringItem *I = Cache->StringItemP + Cache->Head().StringList; - I!= Cache->StringItemP; I = Cache->StringItemP + I->NextItem) - { - Count++; - Size += strlen(Cache->StrP + I->String) + 1; - } - cout << _("Total globbed strings: ") << Count << " (" << SizeToStr(Size) << ')' << endl; - unsigned long DepVerSize = 0; + // String list stats + std::set stritems; + for (pkgCache::GrpIterator G = Cache->GrpBegin(); G.end() == false; ++G) + stritems.insert(G->Name); for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; ++P) { + stritems.insert(P->Arch); for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; ++V) { + if (V->VerStr != 0) + stritems.insert(V->VerStr); + if (V->Section != 0) + stritems.insert(V->Section); for (pkgCache::DepIterator D = V.DependsList(); D.end() == false; ++D) { if (D->Version != 0) - DepVerSize += strlen(D.TargetVer()) + 1; + stritems.insert(D->Version); + } + for (pkgCache::DescIterator D = V.DescriptionList(); D.end() == false; ++D) + { + stritems.insert(D->md5sum); + stritems.insert(D->language_code); } } + for (pkgCache::PrvIterator Prv = P.ProvidesList(); Prv.end() == false; ++Prv) + { + if (Prv->ProvideVersion != 0) + stritems.insert(Prv->ProvideVersion); + } } - cout << _("Total dependency version space: ") << SizeToStr(DepVerSize) << endl; + for (pkgCache::PkgFileIterator F = Cache->FileBegin(); F != Cache->FileEnd(); ++F) + { + stritems.insert(F->FileName); + stritems.insert(F->Archive); + stritems.insert(F->Codename); + stritems.insert(F->Component); + stritems.insert(F->Version); + stritems.insert(F->Origin); + stritems.insert(F->Label); + stritems.insert(F->Architecture); + stritems.insert(F->Site); + stritems.insert(F->IndexType); + } + unsigned long Size = 0; + for (std::set::const_iterator i = stritems.begin(); i != stritems.end(); ++i) + Size += strlen(Cache->StrP + *i) + 1; + + cout << _("Total globbed strings: ") << stritems.size() << " (" << SizeToStr(Size) << ')' << endl; + stritems.clear(); unsigned long Slack = 0; for (int I = 0; I != 7; I++) -- cgit v1.2.3