- Add Package::filelist, faster and less memory consuming
authorMichael Andres <ma@suse.de>
Thu, 18 Dec 2008 12:05:46 +0000 (12:05 +0000)
committerMichael Andres <ma@suse.de>
Thu, 18 Dec 2008 12:05:46 +0000 (12:05 +0000)
  implementation of Package::filenames (now deprecated).

devel/devel.ma/Test.cc
package/libzypp.changes
zypp/Package.cc
zypp/Package.h
zypp/sat/LookupAttrTools.h

index 6960e05..20e6d28 100644 (file)
@@ -2,23 +2,45 @@
 #include <zypp/ResObjects.h>
 
 #include <zypp/sat/LookupAttr.h>
+#include <zypp/PoolQuery.h>
 
-  static std::string pidAndAppname()
+static std::string pidAndAppname()
+{
+  static std::string _val;
+  if ( _val.empty() )
   {
-    static std::string _val;
-    if ( _val.empty() )
-    {
-      pid_t mypid = getpid();
-      Pathname p( "/proc/"+str::numstring(mypid)+"/exe" );
-      Pathname myname( filesystem::readlink( p ) );
+    pid_t mypid = getpid();
+    Pathname p( "/proc/"+str::numstring(mypid)+"/exe" );
+    Pathname myname( filesystem::readlink( p ) );
 
-      _val += str::numstring(mypid);
-      _val += ":";
-      _val += myname.basename();
-    }
-    return _val;
+    _val += str::numstring(mypid);
+    _val += ":";
+    _val += myname.basename();
+  }
+  return _val;
+}
+
+bool solve()
+{
+  static unsigned run = 0;
+  USR << "Solve " << run++ << endl;
+  bool rres = false;
+  {
+    zypp::base::LogControl::TmpLineWriter shutUp;
+    rres = getZYpp()->resolver()->resolvePool();
+  }
+  if ( ! rres )
+  {
+    ERR << "resolve " << rres << endl;
+    getZYpp()->resolver()->problems();
+    return false;
   }
 
+  return true;
+}
+
+typedef sat::ArrayAttr<std::string,std::string> FileList;
+
 /******************************************************************
 **
 **      FUNCTION NAME : main
@@ -28,37 +50,60 @@ int main( int argc, char * argv[] )
 {
   INT << "===[START]==========================================" << endl;
 
-  SEC << pidAndAppname() << endl;
-
-
-  INT << "===[END]============================================" << endl << endl;
-  return 0;
-  Pathname mroot( "/tmp/Bb" );
+  Pathname mroot( "/tmp/ToolScanRepos" );
   TestSetup test( mroot, Arch_x86_64 );
-  test.loadRepo( "/Local/ROOT/cache/raw/11.1-update" );
-  test.loadRepo( "/Local/ROOT/cache/raw/11.0-update" );
+  test.loadRepo("/Local/ROOT/cache/solv/@System/solv");
 
-  sat::Pool satpool( test.satpool() );
-  for_( it, satpool.reposBegin(), satpool.reposEnd() )
+  ResPool pool( test.pool() );
+  {
+    Measure x("filelist");
+    unsigned p = 0;
+    unsigned f = 0;
+    std::string a;
+    for_( it, pool.byKindBegin<Package>(), pool.byKindEnd<Package>() )
+    {
+      ++p;
+      f += (*it)->asKind<Package>()->filelist().size();
+      for_( i, (*it)->asKind<Package>()->filelist().begin(), (*it)->asKind<Package>()->filelist().end() )
+        a = *i;
+    }
+    SEC << p << " : " << f << endl;
+  }
   {
-    MIL << *it << endl;
-    DBG << it->generatedTimestamp() << endl;
-    DBG << it->suggestedExpirationTimestamp() << endl;
+    Measure x("filenames");
+    unsigned p = 0;
+    unsigned f = 0;
+    std::string a;
+    for_( it, pool.byKindBegin<Package>(), pool.byKindEnd<Package>() )
+    {
+      ++p;
+      std::list<std::string> l( (*it)->asKind<Package>()->filenames() );
+      f += l.size();
+      for_( i, l.begin(), l.end() )
+        a = *i;
+    }
+    SEC << p << " : " << f << endl;
   }
 
   INT << "===[END]============================================" << endl << endl;
   return 0;
 
-  sat::LookupRepoAttr q( sat::SolvAttr::repositoryAddedFileProvides );
-  USR << q << endl;
-  USR << dump(q) << endl;
-  for_( it, q.begin(), q.end() )
-  {
-    MIL << it << endl;
-  }
 
 
+  //ui::Selectable::Ptr getSel( const std::string & name_r )
+  getSel<Package>( "gcompris" )->setToInstall();
 
+  vdumpPoolStats( USR << "Transacting:"<< endl,
+                  make_filter_begin<resfilter::ByTransact>(pool),
+                  make_filter_end<resfilter::ByTransact>(pool) ) << endl;
+
+  if ( solve() )
+  {
+    vdumpPoolStats( USR << "Transacting:"<< endl,
+                    make_filter_begin<resfilter::ByTransact>(pool),
+                    make_filter_end<resfilter::ByTransact>(pool) ) << endl;
+    SEC << getSel<Package>( "librsvg" ) << endl;
+  }
   INT << "===[END]============================================" << endl << endl;
   return 0;
 }
index 0a6cbff..d7d8f89 100644 (file)
@@ -1,4 +1,11 @@
 -------------------------------------------------------------------
+Thu Dec 18 13:02:27 CET 2008 - ma@suse.de
+
+- Add Package::filelist, faster and less memory consuming 
+  implementation of Package::filenames (now deprecated).
+- revision 11949
+
+-------------------------------------------------------------------
 Thu Dec 11 21:39:50 CET 2008 - ma@suse.de
 
 - Add str::hexencode and str::hexdecode to encode special characters 
index 8409156..3263a94 100644 (file)
@@ -122,15 +122,13 @@ namespace zypp
     return ret;
   }
 
+  Package::FileList Package::filelist() const
+  { return FileList( sat::SolvAttr::filelist, satSolvable() ); }
+
   std::list<std::string> Package::filenames() const
   {
-    std::list<std::string> files;
-    sat::LookupAttr q( sat::SolvAttr::filelist, *this );
-    for_( it, q.begin(), q.end() )
-    {
-        files.push_back(it.asString());
-    }
-    return files;
+    FileList f( filelist() );
+    return std::list<std::string>( f.begin(), f.end() );
   }
 
   CheckSum Package::checksum() const
index fbfa572..1879592 100644 (file)
@@ -39,13 +39,14 @@ namespace zypp
 
   public:
     typedef sat::ArrayAttr<PackageKeyword,IdString> Keywords;
+    typedef sat::ArrayAttr<std::string,std::string> FileList;
 
   public:
 
     /**
      * Returns the level of supportability the vendor
      * gives to this package.
-     * 
+     *
      * This is one value from \ref VendorSupportOption
      */
     VendorSupportOption vendorSupport() const;
@@ -77,8 +78,15 @@ namespace zypp
     ByteCount sourcesize() const;
     /** */
     std::list<std::string> authors() const;
-    /** */
-    std::list<std::string> filenames() const;
+
+    /** Return the packages filelist (if available).
+     * The returned \ref FileList appears to be a container of
+     * \c std::string. In fact it is a query, so it does not
+     * consume much memory.
+    */
+    FileList filelist() const;
+    /** \deprecated Use filelist, it's faster and saves memeory. */
+    std::list<std::string> filenames() const ZYPP_DEPRECATED;
 
     /** Name of the source rpm this package was built from.
      */
index 8302707..800e9c2 100644 (file)
@@ -172,7 +172,8 @@ namespace zypp
         {}
 
       public:
-        typedef sat::LookupAttr::transformIterator<_ResultT,_AttrT> iterator;
+        typedef LookupAttr::transformIterator<_ResultT,_AttrT> iterator;
+        typedef LookupAttr::size_type size_type;
 
         iterator begin() const
         { return iterator( _q.begin() ); }
@@ -183,6 +184,14 @@ namespace zypp
         bool empty() const
         { return _q.empty(); }
 
+        size_type size() const
+        {
+          size_type count = 0;
+          for_( it, begin(), end() )
+            ++count;
+          return count;
+        }
+
       public:
 
         iterator find( const _ResultT & key_r ) const