]> git.saurik.com Git - apt.git/blobdiff - cmdline/apt-cache.cc
Merge remote-tracking branch 'donkult/debian/sid' into debian/experimental
[apt.git] / cmdline / apt-cache.cc
index 7e569f2fc03846c5d944cd445727eb2320639135..2ed1bf5d4284316c39355972f80ebed36acedde0 100644 (file)
 // Include Files                                                       /*{{{*/
 #include<config.h>
 
-#include <apt-pkg/error.h>
+#include <apt-pkg/algorithms.h>
 #include <apt-pkg/cachefile.h>
 #include <apt-pkg/cacheset.h>
-#include <apt-pkg/init.h>
-#include <apt-pkg/progress.h>
-#include <apt-pkg/sourcelist.h>
 #include <apt-pkg/cmndline.h>
-#include <apt-pkg/strutl.h>
+#include <apt-pkg/error.h>
 #include <apt-pkg/fileutl.h>
+#include <apt-pkg/indexfile.h>
+#include <apt-pkg/init.h>
+#include <apt-pkg/metaindex.h>
 #include <apt-pkg/pkgrecords.h>
-#include <apt-pkg/srcrecords.h>
-#include <apt-pkg/version.h>
+#include <apt-pkg/pkgsystem.h>
 #include <apt-pkg/policy.h>
-#include <apt-pkg/tagfile.h>
-#include <apt-pkg/algorithms.h>
+#include <apt-pkg/progress.h>
+#include <apt-pkg/sourcelist.h>
 #include <apt-pkg/sptr.h>
-#include <apt-pkg/pkgsystem.h>
-#include <apt-pkg/indexfile.h>
-#include <apt-pkg/metaindex.h>
+#include <apt-pkg/srcrecords.h>
+#include <apt-pkg/strutl.h>
+#include <apt-pkg/tagfile.h>
+#include <apt-pkg/version.h>
+#include <apt-pkg/cacheiterators.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/depcache.h>
+#include <apt-pkg/macros.h>
+#include <apt-pkg/mmap.h>
+#include <apt-pkg/pkgcache.h>
 
-#include <apt-private/private-list.h>
-#include <apt-private/private-cmndline.h>
-#include <apt-private/private-show.h>
 #include <apt-private/private-cacheset.h>
+#include <apt-private/private-cmndline.h>
 
-#include <cassert>
-#include <locale.h>
-#include <iostream>
-#include <unistd.h>
-#include <errno.h>
 #include <regex.h>
+#include <stddef.h>
 #include <stdio.h>
-#include <iomanip>
+#include <stdlib.h>
+#include <unistd.h>
 #include <algorithm>
+#include <cstring>
+#include <iomanip>
+#include <iostream>
+#include <list>
+#include <map>
+#include <set>
+#include <string>
+#include <vector>
 
 #include <apti18n.h>
                                                                        /*}}}*/
@@ -255,10 +264,48 @@ static bool DumpPackage(CommandLine &CmdL)
    return true;
 }
                                                                        /*}}}*/
+// ShowHashTableStats - Show stats about a hashtable                   /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+template<class T>
+static void ShowHashTableStats(std::string Type,
+                               T *StartP,
+                               map_ptrloc *Hashtable,
+                               unsigned long Size)
+{
+   // hashtable stats for the HashTable
+   long NumBuckets = Size;
+   long UsedBuckets = 0;
+   long UnusedBuckets = 0;
+   long LongestBucket = 0;
+   long ShortestBucket = NumBuckets;
+   for (unsigned int i=0; i < NumBuckets; ++i)
+   {
+      T *P = StartP + Hashtable[i];
+      if(P == 0 || P == StartP)
+      {
+         UnusedBuckets++;
+         continue;
+      }
+      long ThisBucketSize = 0;
+      for (; P != StartP; P = StartP + P->Next)
+         ThisBucketSize++;
+      LongestBucket = std::max(ThisBucketSize, LongestBucket);
+      ShortestBucket = std::min(ThisBucketSize, ShortestBucket);
+      UsedBuckets += ThisBucketSize;
+   }
+   cout << "Total buckets " << Type << ": " << SizeToStr(NumBuckets) << std::endl;
+   cout << "  Unused: " << SizeToStr(UnusedBuckets) << std::endl;
+   cout << "  Used: " << UsedBuckets  << std::endl;
+   cout << "  Average entries: " << UsedBuckets/(double)NumBuckets << std::endl;
+   cout << "  Longest: " << LongestBucket << std::endl;
+   cout << "  Shortest: " << ShortestBucket << std::endl;
+}
+                                                                       /*}}}*/
 // Stats - Dump some nice statistics                                   /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-static bool Stats(CommandLine &Cmd)
+static bool Stats(CommandLine &)
 {
    pkgCacheFile CacheFile;
    pkgCache *Cache = CacheFile.GetPkgCache();
@@ -364,14 +411,20 @@ static bool Stats(CommandLine &Cmd)
            Cache->Head().VerFileCount*Cache->Head().VerFileSz +
            Cache->Head().ProvidesCount*Cache->Head().ProvidesSz;
    cout << _("Total space accounted for: ") << SizeToStr(Total) << endl;
-   
+
+   // hashtable stats
+   int HashTableSize = sizeof(Cache->HeaderP->PkgHashTable)/sizeof(map_ptrloc);
+   ShowHashTableStats<pkgCache::Package>("PkgHashTable", Cache->PkgP, Cache->HeaderP->PkgHashTable, HashTableSize);
+   HashTableSize = sizeof(Cache->HeaderP->GrpHashTable)/sizeof(map_ptrloc);
+   ShowHashTableStats<pkgCache::Group>("GrpHashTable", Cache->GrpP, Cache->HeaderP->GrpHashTable, HashTableSize);
+
    return true;
 }
                                                                        /*}}}*/
 // Dump - show everything                                              /*{{{*/
 // ---------------------------------------------------------------------
 /* This is worthless except fer debugging things */
-static bool Dump(CommandLine &Cmd)
+static bool Dump(CommandLine &)
 {
    pkgCacheFile CacheFile;
    pkgCache *Cache = CacheFile.GetPkgCache();
@@ -423,7 +476,7 @@ static bool Dump(CommandLine &Cmd)
 // ---------------------------------------------------------------------
 /* This is needed to make dpkg --merge happy.. I spent a bit of time to 
    make this run really fast, perhaps I went a little overboard.. */
-static bool DumpAvail(CommandLine &Cmd)
+static bool DumpAvail(CommandLine &)
 {
    pkgCacheFile CacheFile;
    pkgCache *Cache = CacheFile.GetPkgCache();
@@ -498,7 +551,7 @@ static bool DumpAvail(CommandLine &Cmd)
         break;
       }
 
-      FileFd PkgF(File.FileName(),FileFd::ReadOnly);
+      FileFd PkgF(File.FileName(),FileFd::ReadOnly, FileFd::Extension);
       if (_error->PendingError() == true)
         break;
       
@@ -1109,7 +1162,7 @@ static bool Dotty(CommandLine &CmdL)
 /* This displays the package record from the proper package index file. 
    It is not used by DumpAvail for performance reasons. */
 
-static unsigned char const* skipDescriptionFields(unsigned char const * DescP)
+static APT_PURE unsigned char const* skipDescriptionFields(unsigned char const * DescP)
 {
    char const * const TagName = "\nDescription";
    size_t const TagLen = strlen(TagName);
@@ -1388,7 +1441,7 @@ static bool Search(CommandLine &CmdL)
 }
                                                                        /*}}}*/
 /* ShowAuto - show automatically installed packages (sorted)           {{{*/
-static bool ShowAuto(CommandLine &CmdL)
+static bool ShowAuto(CommandLine &)
 {
    pkgCacheFile CacheFile;
    pkgCache *Cache = CacheFile.GetPkgCache();
@@ -1717,7 +1770,7 @@ static bool Madison(CommandLine &CmdL)
 // GenCaches - Call the main cache generator                           /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-static bool GenCaches(CommandLine &Cmd)
+static bool GenCaches(CommandLine &)
 {
    OpTextProgress Progress(*_config);
 
@@ -1728,7 +1781,7 @@ static bool GenCaches(CommandLine &Cmd)
 // ShowHelp - Show a help screen                                       /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-static bool ShowHelp(CommandLine &Cmd)
+static bool ShowHelp(CommandLine &)
 {
    ioprintf(cout,_("%s %s for %s compiled on %s %s\n"),PACKAGE,PACKAGE_VERSION,
            COMMON_ARCH,__DATE__,__TIME__);