Commit 1da20e8c authored by Grégory Wisniewski's avatar Grégory Wisniewski

Update perfs tool to not rewrite a patched copyTransactionsFrom().

Allow use our own copyTransactionsFrom with a smarter monkey patch to
compute statistics.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1928 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 8b708006
...@@ -15,54 +15,37 @@ from neo.profiling import PROFILING_ENABLED, profiler_decorator, \ ...@@ -15,54 +15,37 @@ from neo.profiling import PROFILING_ENABLED, profiler_decorator, \
def runImport(neo, datafs): def runImport(neo, datafs):
@profiler_decorator def counter(wrapped, d):
def _copyTransactionsFrom(self, other): @profiler_decorator
""" taken from ZODB.BaseStorage that build stat during import """ def wrapper(*args, **kw):
def inc(d):
# count number of tick per second # count number of tick per second
t = int(time()) t = int(time())
d.setdefault(t, 0) d.setdefault(t, 0)
d[t] += 1 d[t] += 1
def updateLastSerial(oid, result): # call original method
if result: wrapped(*args, **kw)
if isinstance(result, str): return wrapper
assert oid is not None
preindex[oid] = result
else:
for oid, serial in result:
assert isinstance(serial, str), serial
preindex[oid] = serial
txn = {}
obj = {}
preindex = {}
fiter = other.iterator()
for transaction in fiter:
inc(txn)
self.tpc_begin(transaction, transaction.tid, transaction.status)
for r in transaction:
inc(obj)
pre = preindex.get(r.oid, None)
s = self.store(r.oid, pre, r.data, r.version, transaction)
updateLastSerial(r.oid, s)
updateLastSerial(None, self.tpc_vote(transaction))
self.tpc_finish(transaction)
fiter.close()
return {
'Transactions': txn.values(),
'Objects': obj.values(),
}
# open storages clients # open storages clients
neo_storage = neo.getZODBStorage() neo_storage = neo.getZODBStorage()
dfs_storage = FileStorage(file_name=datafs) dfs_storage = FileStorage(file_name=datafs)
dfs_size = os.path.getsize(datafs) dfs_size = os.path.getsize(datafs)
# monkey patch import method and run the import # monkey patch storage
txn_dict, obj_dict = {}, {}
neo_storage.app.tpc_begin = counter(neo_storage.app.tpc_begin, txn_dict)
neo_storage.app.store = counter(neo_storage.app.store, obj_dict)
# run import
start = time() start = time()
Storage.copyTransactionsFrom = _copyTransactionsFrom
stats = neo_storage.copyTransactionsFrom(dfs_storage) stats = neo_storage.copyTransactionsFrom(dfs_storage)
elapsed = time() - start elapsed = time() - start
# return stats
stats = {
'Transactions': txn_dict.values(),
'Objects': obj_dict.values(),
}
return (dfs_size, elapsed, stats) return (dfs_size, elapsed, stats)
def buildReport(config, dfs_size, elapsed, stats): def buildReport(config, dfs_size, elapsed, stats):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment