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.
|
||||
policy = ConflictPolicy(args)
|
||||
writer = uid = batch = None
|
||||
writer = uid = batch = ms = None
|
||||
memlog_fh = None
|
||||
prev_avail = None
|
||||
if args.profile_memory:
|
||||
uid = get_uid(connection)
|
||||
ms = MemorySession(channel)
|
||||
ms.select()
|
||||
m = ms.select()
|
||||
prev_avail = m["available_persistent"] if m else None
|
||||
batch = ms.batch()
|
||||
_reauth(oath, pw)
|
||||
new_file = not os.path.exists(args.memlog)
|
||||
@@ -731,13 +733,14 @@ def main(argv=None):
|
||||
continue
|
||||
try:
|
||||
if args.profile_memory:
|
||||
before = MemorySession(channel).available()
|
||||
_reauth(oath, pw)
|
||||
oath.put(c)
|
||||
after = MemorySession(channel).available()
|
||||
_reauth(oath, pw)
|
||||
consumed = (before - after) if (before is not None
|
||||
and after is not None) else ""
|
||||
cur = ms.available() # SELECT memory (GC) -> deselects OATH
|
||||
_reauth(oath, pw) # re-select OATH for the next PUT
|
||||
if prev_avail is not None and cur is not None:
|
||||
before, after, consumed = prev_avail, cur, prev_avail - cur
|
||||
prev_avail = cur
|
||||
else:
|
||||
before = after = consumed = ""
|
||||
writer.writerow([datetime.datetime.now().isoformat(timespec="seconds"),
|
||||
uid, batch, c.cred_id, before, after, consumed])
|
||||
print(f" ok {c.cred_id} (consumed ~{consumed} B)")
|
||||
|
||||
Reference in New Issue
Block a user