mirror of
https://github.com/mandiant/capa.git
synced 2025-12-22 15:16:22 -08:00
Merge pull request #1366 from ggold7046/patch-1
Update profile-memory.py
This commit is contained in:
@@ -16,10 +16,10 @@ def display_top(snapshot, key_type="lineno", limit=10):
|
|||||||
)
|
)
|
||||||
top_stats = snapshot.statistics(key_type)
|
top_stats = snapshot.statistics(key_type)
|
||||||
|
|
||||||
print("Top %s lines" % limit)
|
print(f"Top {limit} lines")
|
||||||
for index, stat in enumerate(top_stats[:limit], 1):
|
for index, stat in enumerate(top_stats[:limit], 1):
|
||||||
frame = stat.traceback[0]
|
frame = stat.traceback[0]
|
||||||
print("#%s: %s:%s: %.1f KiB" % (index, frame.filename, frame.lineno, stat.size / 1024))
|
print(f"#{index}: {frame.filename}:{frame.lineno}: {stat.size / 1024:.1f} KiB")
|
||||||
line = linecache.getline(frame.filename, frame.lineno).strip()
|
line = linecache.getline(frame.filename, frame.lineno).strip()
|
||||||
if line:
|
if line:
|
||||||
print(" %s" % line)
|
print(" %s" % line)
|
||||||
@@ -27,9 +27,9 @@ def display_top(snapshot, key_type="lineno", limit=10):
|
|||||||
other = top_stats[limit:]
|
other = top_stats[limit:]
|
||||||
if other:
|
if other:
|
||||||
size = sum(stat.size for stat in other)
|
size = sum(stat.size for stat in other)
|
||||||
print("%s other: %.1f KiB" % (len(other), size / 1024))
|
print(f"{len(other)} other: {size / 1024:.1f} KiB")
|
||||||
total = sum(stat.size for stat in top_stats)
|
total = sum(stat.size for stat in top_stats)
|
||||||
print("Total allocated size: %.1f KiB" % (total / 1024))
|
print(f"Total allocated size: {total / 1024:.1f} KiB")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -45,11 +45,11 @@ def main():
|
|||||||
import capa.main
|
import capa.main
|
||||||
|
|
||||||
count = int(os.environ.get("CAPA_PROFILE_COUNT", 1))
|
count = int(os.environ.get("CAPA_PROFILE_COUNT", 1))
|
||||||
print("total iterations planned: %d (set via env var CAPA_PROFILE_COUNT)." % (count))
|
print(f"total iterations planned: {count} (set via env var CAPA_PROFILE_COUNT).")
|
||||||
print()
|
print()
|
||||||
|
|
||||||
for i in range(count):
|
for i in range(count):
|
||||||
print("iteration %d/%d..." % (i + 1, count))
|
print(f"iteration {i + 1}/{count}...")
|
||||||
with contextlib.redirect_stdout(io.StringIO()):
|
with contextlib.redirect_stdout(io.StringIO()):
|
||||||
with contextlib.redirect_stderr(io.StringIO()):
|
with contextlib.redirect_stderr(io.StringIO()):
|
||||||
t0 = time.time()
|
t0 = time.time()
|
||||||
@@ -59,9 +59,9 @@ def main():
|
|||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
process = psutil.Process(os.getpid())
|
process = psutil.Process(os.getpid())
|
||||||
print(" duration: %0.02fs" % (t1 - t0))
|
print(f" duration: {t1 - t0:.02f}s")
|
||||||
print(" rss: %.1f MiB" % (process.memory_info().rss / 1024 / 1024))
|
print(f" rss: {process.memory_info().rss / 1024 / 1024:.1f} MiB")
|
||||||
print(" vms: %.1f MiB" % (process.memory_info().vms / 1024 / 1024))
|
print(f" vms: {process.memory_info().vms / 1024 / 1024:.1f} MiB")
|
||||||
|
|
||||||
print("done.")
|
print("done.")
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|||||||
Reference in New Issue
Block a user