forked from doniks/pycom-examples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
memory.py
35 lines (31 loc) · 993 Bytes
/
memory.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 machine
import binascii
import gc
import micropython
import pycom
def mem(verbose=False):
if verbose:
print("{:18} {:9}".format("GC total ", gc.mem_alloc() + gc.mem_free()))
micropython.mem_info()
print("{:18} {:9}".format("mp stack use", micropython.stack_use()))
print("{:18} {:9}".format("GC free", gc.mem_free()))
print("{:18} {:9}".format("heap internal free", pycom.get_free_heap()[0]))
print("{:18} {:9}".format("heap external free", pycom.get_free_heap()[1]))
def stress():
bufs = []
ct = 0
size = 1024 * 10
print("stress", size)
while True:
i = ct % 0xff
bufs.append(bytearray([i] * size))
print(ct, (ct * size)/1024, gc.mem_alloc(), gc.mem_free())
ct+=1
if __name__ == '__main__':
import binascii
import machine
uid = binascii.hexlify(machine.unique_id())
name = os.uname().sysname.lower() + '-' + uid.decode("utf-8")[-4:]
print(name)
mem()
# stress()