[Rpm-maint] Feature request: Improved speed for 'rpm -qa'
Michael Schroeder
mls at suse.de
Tue Dec 19 16:16:41 UTC 2006
On Tue, Dec 19, 2006 at 02:17:34PM +0100, Axel Liljencrantz wrote:
> Performing a readahead on /var/lib/rpm/Packages seems to help a bit.
> Cold cache times (including readahead) stays around 6 seconds on my
> fast system, but falls from 22 seconds to 13 seconds on my slow system
> by calling 'cat /var/lib/rpm/Packages' before calling 'rpm -qa'.
Here's my rpmqpack program that list all packages by iterating
over the Name index (i.e. it's a dirty hack). It can also be used
to do a fast query if a package is installed.
#include <sys/types.h>
#include <limits.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <db.h>
DBT key;
DBT data;
int
main(int argc, char **argv)
{
DB *db = 0;
DBC *dbc = 0;
int ret = 0;
if (db_create(&db, 0, 0))
{
perror("db_create");
exit(1);
}
if (db->open(db, 0, "/var/lib/rpm/Name", 0, DB_HASH, DB_RDONLY, 0664))
{
perror("db->open");
exit(1);
}
if (argc == 1)
{
if (db->cursor(db, NULL, &dbc, 0))
{
perror("db->cursor");
exit(1);
}
while (dbc->c_get(dbc, &key, &data, DB_NEXT) == 0)
printf("%*.*s\n", (int)key.size, (int)key.size, (char *)key.data);
dbc->c_close(dbc);
}
else
{
argc--;
while (argc--)
{
argv++;
key.data = (void *)*argv;
key.size = strlen(*argv);
data.data = NULL;
data.size = 0;
if (db->get(db, 0, &key, &data, 0) == 0)
printf("%s\n", *argv);
else
ret = 1;
}
}
db->close(db, 0);
return ret;
}
Cheers,
Michael.
--
Michael Schroeder mls at suse.de
main(_){while(_=~getchar())putchar(~_-1/(~(_|32)/13*2-11)*13);}
More information about the Rpm-maint
mailing list