forked from pi-mst/micropython-memory-profiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmem_dump.py
35 lines (27 loc) · 950 Bytes
/
mem_dump.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import time
import micropython
_MEM_DUMP_PERIOD_MS = 350
_FIRST = True
def mem_dump(_):
global _FIRST
if _FIRST:
# Print ticks_ms/RTC synchronisation values, and do initial memory dump.
# Unix supplies an extra - ninth - item (for dst). Restrict to 8
# elements.
print("@@@", time.ticks_ms(), time.localtime()[:8])
_FIRST = False
print("@@@", time.ticks_ms())
micropython.mem_info(1)
print("@@@")
def start_timer(period_ms=_MEM_DUMP_PERIOD_MS):
from machine import Timer
# Start a timer to periodically dump the heap.
Timer(period=period_ms, callback=mem_dump)
async def start_async(period_ms=_MEM_DUMP_PERIOD_MS):
import asyncio
# Start a background asyncio task to periodically dump the heap.
async def _mem_dump_task():
while True:
mem_dump(True)
await asyncio.sleep_ms(period_ms)
asyncio.create_task(_mem_dump_task())