Speed up --profile-memory with one memory read per credential
Reuse each credential's post-PUT memory reading as the baseline for the next, halving the memory-applet SELECTs (each triggers a garbage collection). A 34-credential profiling run now completes in seconds.
This commit is contained in:
@@ -707,12 +707,14 @@ def main(argv=None):
|
|||||||
|
|
||||||
# 6. Import.
|
# 6. Import.
|
||||||
policy = ConflictPolicy(args)
|
policy = ConflictPolicy(args)
|
||||||
writer = uid = batch = None
|
writer = uid = batch = ms = None
|
||||||
memlog_fh = None
|
memlog_fh = None
|
||||||
|
prev_avail = None
|
||||||
if args.profile_memory:
|
if args.profile_memory:
|
||||||
uid = get_uid(connection)
|
uid = get_uid(connection)
|
||||||
ms = MemorySession(channel)
|
ms = MemorySession(channel)
|
||||||
ms.select()
|
m = ms.select()
|
||||||
|
prev_avail = m["available_persistent"] if m else None
|
||||||
batch = ms.batch()
|
batch = ms.batch()
|
||||||
_reauth(oath, pw)
|
_reauth(oath, pw)
|
||||||
new_file = not os.path.exists(args.memlog)
|
new_file = not os.path.exists(args.memlog)
|
||||||
@@ -731,13 +733,14 @@ def main(argv=None):
|
|||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
if args.profile_memory:
|
if args.profile_memory:
|
||||||
before = MemorySession(channel).available()
|
|
||||||
_reauth(oath, pw)
|
|
||||||
oath.put(c)
|
oath.put(c)
|
||||||
after = MemorySession(channel).available()
|
cur = ms.available() # SELECT memory (GC) -> deselects OATH
|
||||||
_reauth(oath, pw)
|
_reauth(oath, pw) # re-select OATH for the next PUT
|
||||||
consumed = (before - after) if (before is not None
|
if prev_avail is not None and cur is not None:
|
||||||
and after is not None) else ""
|
before, after, consumed = prev_avail, cur, prev_avail - cur
|
||||||
|
prev_avail = cur
|
||||||
|
else:
|
||||||
|
before = after = consumed = ""
|
||||||
writer.writerow([datetime.datetime.now().isoformat(timespec="seconds"),
|
writer.writerow([datetime.datetime.now().isoformat(timespec="seconds"),
|
||||||
uid, batch, c.cred_id, before, after, consumed])
|
uid, batch, c.cred_id, before, after, consumed])
|
||||||
print(f" ok {c.cred_id} (consumed ~{consumed} B)")
|
print(f" ok {c.cred_id} (consumed ~{consumed} B)")
|
||||||
|
|||||||
Reference in New Issue
Block a user