[zypp-commit] r11561 - in /trunk/sat-solver/tools: repo_rpmdb.c repo_rpmdb.h rpmdb2solv.c
Author: mlschroe Date: Fri Oct 31 16:08:13 2008 New Revision: 11561 URL: http://svn.opensuse.org/viewcvs/zypp?rev=11561&view=rev Log: - add "-P" option to rpmdb2solv, prints percentage on stderr Modified: trunk/sat-solver/tools/repo_rpmdb.c trunk/sat-solver/tools/repo_rpmdb.h trunk/sat-solver/tools/rpmdb2solv.c Modified: trunk/sat-solver/tools/repo_rpmdb.c URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/tools/repo_rpmdb.c?rev=11561&r1=11560&r2=11561&view=diff ============================================================================== --- trunk/sat-solver/tools/repo_rpmdb.c (original) +++ trunk/sat-solver/tools/repo_rpmdb.c Fri Oct 31 16:08:13 2008 @@ -1174,6 +1174,50 @@ memcpy(cookie + 24, &st->st_dev, sizeof(st->st_dev)); } +static int +count_headers(const char *rootdir, DB_ENV *dbenv) +{ + char dbpath[PATH_MAX]; + struct stat statbuf; + int byteswapped; + DB *db = 0; + DBC *dbc = 0; + int count = 0; + DBT dbkey; + DBT dbdata; + + snprintf(dbpath, PATH_MAX, "%s/var/lib/rpm/Name", rootdir); + if (stat(dbpath, &statbuf)) + return 0; + memset(&dbkey, 0, sizeof(dbkey)); + memset(&dbdata, 0, sizeof(dbdata)); + if (db_create(&db, dbenv, 0)) + { + perror("db_create"); + exit(1); + } + if (db->open(db, 0, dbpath, 0, DB_HASH, DB_RDONLY, 0664)) + { + perror("db->open var/lib/rpm/Name"); + exit(1); + } + if (db->get_byteswapped(db, &byteswapped)) + { + perror("db->get_byteswapped"); + exit(1); + } + if (db->cursor(db, NULL, &dbc, 0)) + { + perror("db->cursor"); + exit(1); + } + while (dbc->c_get(dbc, &dbkey, &dbdata, DB_NEXT) == 0) + count += dbdata.size >> 3; + dbc->c_close(dbc); + db->close(db, 0); + return count; +} + /* * read rpm db as repo * @@ -1206,6 +1250,7 @@ const unsigned char *oldcookie = 0; Id oldcookietype = 0; Repodata *data; + int count = 0, done = 0; memset(&dbkey, 0, sizeof(dbkey)); memset(&dbdata, 0, sizeof(dbdata)); @@ -1254,6 +1299,9 @@ if (!ref || !oldcookie || oldcookietype != REPOKEY_TYPE_SHA256 || memcmp(oldcookie, newcookie, 32) != 0) { Id *pkgids; + + if ((flags & RPMDB_REPORT_PROGRESS) != 0) + count = count_headers(rootdir, dbenv); if (db->open(db, 0, dbpath, 0, DB_HASH, DB_RDONLY, 0664)) { perror("db->open var/lib/rpm/Packages"); @@ -1327,6 +1375,13 @@ memset(s, 0, sizeof(*s)); s->repo = repo; } + if ((flags & RPMDB_REPORT_PROGRESS) != 0) + { + if (done < count) + done++; + if (done < count && (done - 1) * 100 / count != done * 100 / count) + pool_debug(pool, SAT_ERROR, "%%%% %d\n", done * 100 / count); + } } if (s) { @@ -1415,7 +1470,6 @@ /* sort rpmids */ qsort(rpmids, nrpmids, sizeof(*rpmids), rpmids_sort_cmp); - rp = rpmids; dbidp = (unsigned char *)&dbid; rpmheadsize = 0; rpmhead = 0; @@ -1432,12 +1486,34 @@ h = (h + 317) & refmask; refhash[h] = i + 1; /* make it non-zero */ } + + /* count the misses, they will cost us time */ + if ((flags & RPMDB_REPORT_PROGRESS) != 0) + { + for (i = 0, rp = rpmids; i < nrpmids; i++, rp++) + { + dbid = rp->dbid; + if (refhash) + { + h = dbid & refmask; + while ((id = refhash[h])) + { + if (ref->rpmdbid[id - 1] == dbid) + break; + h = (h + 317) & refmask; + } + if (id) + continue; + } + count++; + } + } s = pool_id2solvable(pool, repo_add_solvable_block(repo, nrpmids)); if (!repo->rpmdbid) repo->rpmdbid = repo_sidedata_create(repo, sizeof(Id)); - for (i = 0; i < nrpmids; i++, rp++, s++) + for (i = 0, rp = rpmids; i < nrpmids; i++, rp++, s++) { dbid = rp->dbid; repo->rpmdbid[(s - pool->solvables) - repo->start] = dbid; @@ -1517,6 +1593,13 @@ rpmhead->dp = rpmhead->data + rpmhead->cnt * 16; rpm2solv(pool, repo, data, s, rpmhead); + if ((flags & RPMDB_REPORT_PROGRESS) != 0) + { + if (done < count) + done++; + if (done < count && (done - 1) * 100 / count != done * 100 / count) + pool_debug(pool, SAT_ERROR, "%%%% %d\n", done * 100 / count); + } } if (refhash) @@ -1535,6 +1618,8 @@ if (db) db->close(db, 0); dbenv->close(dbenv, 0); + if ((flags & RPMDB_REPORT_PROGRESS) != 0) + pool_debug(pool, SAT_ERROR, "%%%% 100\n"); } Modified: trunk/sat-solver/tools/repo_rpmdb.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/tools/repo_rpmdb.h?rev=11561&r1=11560&r2=11561&view=diff ============================================================================== --- trunk/sat-solver/tools/repo_rpmdb.h (original) +++ trunk/sat-solver/tools/repo_rpmdb.h Fri Oct 31 16:08:13 2008 @@ -7,3 +7,5 @@ extern void repo_add_rpmdb(Repo *repo, Repo *ref, const char *rootdir, int flags); extern void repo_add_rpms(Repo *repo, const char **rpms, int nrpms, int flags); + +#define RPMDB_REPORT_PROGRESS (1 << 8) Modified: trunk/sat-solver/tools/rpmdb2solv.c URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/tools/rpmdb2solv.c?rev=11561&r1=11560&r2=11561&view=diff ============================================================================== --- trunk/sat-solver/tools/rpmdb2solv.c (original) +++ trunk/sat-solver/tools/rpmdb2solv.c Fri Oct 31 16:08:13 2008 @@ -53,7 +53,7 @@ Repodata *data; FILE *fp; Pool *refpool; - int c; + int c, percent = 0; int extrapool = 0; int nopacks = 0; const char *root = 0; @@ -65,7 +65,7 @@ * parse arguments */ - while ((c = getopt (argc, argv, "a:hnxb:r:p:")) >= 0) + while ((c = getopt(argc, argv, "Pa:hnxb:r:p:")) >= 0) switch (c) { case 'h': @@ -83,6 +83,9 @@ case 'n': nopacks = 1; break; + case 'P': + percent = 1; + break; case 'p': proddir = optarg; break; @@ -125,7 +128,7 @@ data = repo_add_repodata(repo, 0); if (!nopacks) - repo_add_rpmdb(repo, ref, root, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE); + repo_add_rpmdb(repo, ref, root, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | (percent ? RPMDB_REPORT_PROGRESS : 0)); if (proddir && *proddir) { -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org
participants (1)
-
mlschroe@svn.opensuse.org