Пример #1
0
 def iterator(self, start=None, stop=None):
     if start:
         try:
             index = self._tidindex
         except AttributeError:
             logging.info("Building index for faster lookup of"
                          " transactions in the FileStorage DB.")
             # Cache a sorted list of all the file pos from oid index.
             # To reduce memory usage, the list is splitted in arrays of
             # low order 32-bit words.
             tindex = defaultdict(lambda: array(typecode))
             for x in self._index.itervalues():
                 tindex[x >> 32].append(x & 0xffffffff)
             index = self._tidindex = []
             for h, l in sorted(tindex.iteritems()):
                 l = array(typecode, sorted(l))
                 x = self._read_data_header(h << 32 | l[0])
                 index.append((x.tid, h, l))
             logging.info("... index built")
         x = bisect(index, (start,)) - 1
         if x >= 0:
             x, h, index = index[x]
             x = self._read_data_header
             h = x(h << 32 | index[bisect(index, Start(x, h, start)) - 1])
             return FileIterator(self._file_name, start, stop, h.tloc)
     return FileIterator(self._file_name, start, stop)
Пример #2
0
def run(path, tid):
    f = open(path, "rb")
    f.seek(0, 2)

    th = prev_txn(f)
    while (str(TimeStamp(th.tid)) != tid):
        th = th.prev_txn()

    reader = Reader()
    iterator = FileIterator(path, pos=th._pos)
    header = TxnHeader(f, th._pos)
    for i in iterator:
        if (str(TimeStamp(i.tid)) == tid):
            print "\nTRANSACTION: ", TimeStamp(
                i.tid), i.user, i.description, pretty_size(header.length), "\n"
            header = header.next_txn()
            object_types = {}
            for o in i:
                ot = reader.getIdentity(o.data)
                print " - ", ot, pretty_size(len(o.data))
                ob = cPickle.loads(o.data)
                # Not sure why some objects are stored as tuple (object, ())
                if type(ob) == tuple and len(ob) == 2:
                    ob = ob[0]
                if hasattr(ob, "__dict__"):
                    for i in ob.__dict__.items():
                        if str(i[0]) == "__doc__":
                            print "\t('__doc__',", i[1], ")"
                        elif not callable(i[1]):
                            print "\t", i
                else:
                    print "can't extract:" + str(ob)
            break
    f.close()
Пример #3
0
def run(path, days, notPacked):
    f = open(path, "rb")
    f.seek(0, 2)
    now = datetime.date.today()

    #day->size
    stats = {}
    th = prev_txn(f)

    bool = True
    while bool:
        ts = TimeStamp(th.tid)
        then = datetime.date(int(ts.year()), int(ts.month()), int(ts.day()))
        delta = timedelta(days=int(days))
        if( not(now - then < delta)):
            bool = False
        th = th.prev_txn()

    reader = Reader()
    iterator = FileIterator(path, pos=th._pos)
    for i in iterator:
        object_types = {}
        for o in i:
            ot = reader.getIdentity(o.data)
            try:
                stats[ot] = stats[ot] + 1
            except KeyError:
                stats[ot] = 1
    f.close()

    for (o,n) in sorted(stats.items(), key=lambda (k,v): v, reverse=True):
        print "%6d: %s" % (n,o)
Пример #4
0
def run(path, ntxn, orderTransactions):
    f = open(path, "rb")
    f.seek(0, 2)

    th = prev_txn(f)
    for i in range(ntxn - 1):
        th = th.prev_txn()

    reader = Reader()
    iterator = FileIterator(path, pos=th._pos)
    header = TxnHeader(f, th._pos)
    transactions = []

    for i in iterator:
        transactions.append({
            "tid": TimeStamp(i.tid),
            "user": i.user,
            "desc": i.description,
            "len": header.length,
            "objs": None
        })

        header = header.next_txn()

        object_types = {}
        for o in i:
            ot = reader.getIdentity(o.data)
            if ot in object_types:
                size, count = object_types[ot]
                object_types[ot] = (size + len(o.data), count + 1)
            else:
                object_types[ot] = (len(o.data), 1)

        keys = object_types.keys()
        transactions[-1]["objs"] = object_types

    f.close()
    if orderTransactions:
        transactions = sorted(transactions,
                              key=lambda (d): d["len"],
                              reverse=True)
    for tr in transactions:
        print "\n\nTRANSACTION: ", tr["tid"], tr["user"], tr[
            "desc"], pretty_size(tr["len"])
        object_types = tr["objs"]
        keys = object_types.keys()
        for k in sorted(keys, key=lambda (k): object_types[k][0],
                        reverse=True):
            # count, class, size (aggregate)
            print " - ", object_types[k][1], k, pretty_size(object_types[k][0])
Пример #5
0
 def iterator(self, start=None, stop=None):
     if start:
         try:
             index = self._tidindex
         except AttributeError:
             # Cache a sorted list of all the file pos from oid index.
             # To reduce memory usage, the list is splitted in arrays of
             # low order 32-bit words.
             tindex = defaultdict(lambda: array(typecode))
             for x in self._index.itervalues():
                 tindex[x >> 32].append(x & 0xffffffff)
             index = self._tidindex = []
             for h, l in sorted(tindex.iteritems()):
                 x = array('I')
                 x.fromlist(sorted(l))
                 l = self._read_data_header(h << 32 | x[0])
                 index.append((l.tid, h, x))
         x = bisect(index, (start, )) - 1
         if x >= 0:
             x, h, index = index[x]
             x = self._read_data_header
             h = x(h << 32 | index[bisect(index, Start(x, h, start)) - 1])
             return FileIterator(self._file_name, start, stop, h.tloc)
     return FileIterator(self._file_name, start, stop)