Skip to content

Instantly share code, notes, and snippets.

@stefantalpalaru
Created March 31, 2019 17:51
Show Gist options
  • Save stefantalpalaru/0b502def452591aaca289ec8fc119e8b to your computer and use it in GitHub Desktop.
Save stefantalpalaru/0b502def452591aaca289ec8fc119e8b to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
import sys, re, matplotlib.pyplot as plt, matplotlib.dates as mpdates, datetime
timestamps = []
heap_total = []
alloc_diff = []
re_timestamp = re.compile(r'^===(\d+)')
re_heap = re.compile(r'^\[Heap\] total number of bytes: (\d+)')
re_alloc = re.compile(r'^\[Heap\] allocs/deallocs: (\d+)/(\d+)')
with open(sys.argv[1], 'r') as f:
for line in f:
match = re_timestamp.search(line)
if match:
timestamps.append(datetime.datetime.fromtimestamp(int(match.group(1))))
match = re_heap.search(line)
if match:
heap_total.append(int(match.group(1)) / 1024 / 1024)
match = re_alloc.search(line)
if match:
alloc_diff.append(int(match.group(1)) - int(match.group(2)))
fig, ax1 = plt.subplots()
fig.set_size_inches(14, 10)
ax1.xaxis.set_major_formatter(mpdates.DateFormatter('%H:%M'))
ax1.plot(timestamps, heap_total, color="blue")
ax1.set_title("Nimbus heap during initial sync")
ax1.set_xlabel("time")
ax1.set_ylabel("heap total (MiB)", color="blue")
ax1.tick_params('y', colors='blue')
ax2 = ax1.twinx()
ax2.xaxis.set_major_formatter(mpdates.DateFormatter('%H:%M'))
ax2.plot(timestamps, alloc_diff, color="red")
ax2.set_ylabel("no. allocs - no. deallocs", color="red")
ax2.tick_params('y', colors='red')
fig.tight_layout()
fig.savefig("heap.svg", dpi=100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment