[Zodb-checkins] CVS: StandaloneZODB/bsddb3Storage/bsddb3Storage/tests - calcsize.py:1.1.2.1 fillitup.py:1.1.2.1

Barry Warsaw barry@wooz.org
Wed, 23 Jan 2002 17:50:15 -0500


Update of /cvs-repository/StandaloneZODB/bsddb3Storage/bsddb3Storage/tests
In directory cvs.zope.org:/tmp/cvs-serv29184

Added Files:
      Tag: Recovery
	calcsize.py fillitup.py 
Log Message:
Adding these because I want to blow away the directory they're in and
I don't want to lose these forever.



=== Added File StandaloneZODB/bsddb3Storage/bsddb3Storage/tests/calcsize.py ===
#! /usr/bin/env python

"""Calculate sizes of transactions and output them.

Actually just counts the size of pickles in the transaction via the iterator
protocol, so storage overheads aren't counted.

Usage: %(PROGRAM)s [options]
Options:
    -h/--help
        Print this message and exit.

    -d filename
    --database-path=filename
        Use database in filename, otherwise uses %(DBHOME)s

    -p/--plot
        Plot the size graph using gnuplot
"""

DBHOME = '/tmp/test-db'

import sys
import getopt

from ZODB import utils
#from bsddb3Storage.Full import Full
from ZODB.FileStorage import FileStorage as Storage

PROGRAM = sys.argv[0]



def usage(code, msg=''):
    print >> sys.stderr, __doc__ % globals()
    if msg:
        print >> sys.stderr, msg
    sys.exit(code)



def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'hd:p',
                                   ['help', 'database-path=', 'plot'])
    except getopt.error, msg:
        usage(1, msg)

    dbhome = DBHOME
    gnuplot = 0
    for opt, arg in opts:
        if opt in ('-h', '--help'):
            usage(0)
        elif opt in ('-d', '--database-path'):
            dbhome = arg
        elif opt in ('-p', '--plot'):
            gnuplot = 1

    if args:
        usage(1)

    storage = Storage(dbhome, read_only=1)
    iterator = storage.iterator()
    txns = []
    txnsdict = {}

    for txn in iterator:
        tid = txn.tid
        objects = 0
        size = 0
        try:
            for r in txn:
                objects += 1
                size += len(r.data)
        except KeyError:
            print >> sys.stderr, 'KeyError for transaction', utils.U64(tid)
            # keep going
        # Make an entry of (transaction id, numobjects, totalsize)
        txns.append((tid, objects, size))
        txnsdict[tid] = (objects, size)

    if gnuplot:
        for tid, objects, size in txns:
            print size
    else:
        print 'transaction id     #objs size(bytes)'
        print '--------------     ----- -----------'
        for tid, objects, size in txns:
            print '%18s %5d %9d' % (utils.U64(tid), objects, size)



if __name__ == '__main__':
    main()


=== Added File StandaloneZODB/bsddb3Storage/bsddb3Storage/tests/fillitup.py ===
DBHOME = '/tmp/test-db'

import os
import sys
import profile
import errno
import time

from ZODB import DB
from ZODB.tests.MinPO import MinPO
from bsddb3Storage.Full import Full
from Persistence import PersistentMapping

try:
    os.mkdir(DBHOME)
except OSError, e:
    if e.errno == errno.EEXIST:
        # BAW: bogus Unixism!
        os.system('rm -rf %s' % DBHOME)
        os.mkdir(DBHOME)

storage = Full(DBHOME)
db = DB(storage)

conn = db.open()
root = conn.root()

names = root['names'] = PersistentMapping()

# how many objects per transaction?
if len(sys.argv) < 2:
    pertxn = -1
else:
    pertxn = int(sys.argv[1])

counter = 0
t1 = None
try:
    t0 = time.time()
    while pertxn == -1 or counter < pertxn:
        minpo = MinPO(counter)
        names[counter] = minpo
        counter += 1
        if not (counter % 5000):
            print 'counter: %s' % counter
    t1 = time.time()
    print 'PersistentMapping filled in %s seconds' % (t1-t0)
    profile.run('get_transaction().commit()')
finally:
    print 'counter: %s' % counter
    t2 = time.time()
    if t1:
        print 'total commit run time: %s seconds' % (t2-t1)