33 *
44 * The MIT License (MIT)
55 *
6- * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
6+ * Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
77 *
88 * Permission is hereby granted, free of charge, to any person obtaining a copy
99 * of this software and associated documentation files (the "Software"), to deal
3838//| def __init__(self):
3939//| """Tracks the number of allocations in power of two buckets.
4040//|
41- //| It will have 32 16bit buckets to track allocation counts. It is total allocations
41+ //| It will have 16 16bit buckets to track allocation counts. It is total allocations
4242//| meaning frees are ignored. Reallocated memory is counted twice, at allocation and when
4343//| reallocated with the larger size.
4444//|
4747//| per block, typically 16. Bucket 2 will be less than or equal to 4 blocks. See
4848//| `bytes_per_block` to convert blocks to bytes.
4949//|
50- //| Multiple AllocationSizes can be used to track different boundaries.
51- //|
52- //| Active AllocationSizes will not be freed so make sure and pause before deleting.
50+ //| Multiple AllocationSizes can be used to track different code boundaries.
5351//|
5452//| Track allocations::
5553//|
5654//| import memorymonitor
5755//|
58- //| mm = memorymonitor.AllocationSizes()
59- //| print("hello world" * 3)
60- //| mm.pause()
61- //| for bucket in mm:
62- //| print("<", 2 ** bucket, mm[bucket])
56+ //| mm = memorymonitor.AllocationSize()
57+ //| with mm:
58+ //| print("hello world" * 3)
6359//|
64- //| # Clear the buckets
65- //| mm.clear( )
60+ //| for bucket, count in enumerate(mm):
61+ //| print("<", 2 ** bucket, count )
6662//|
67- //| # Resume allocation tracking
68- //| mm.resume()"""
63+ //| """
6964//| ...
7065//|
7166STATIC mp_obj_t memorymonitor_allocationsize_make_new (const mp_obj_type_t * type , size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
@@ -78,7 +73,7 @@ STATIC mp_obj_t memorymonitor_allocationsize_make_new(const mp_obj_type_t *type,
7873}
7974
8075//| def __enter__(self, ) -> Any:
81- //| """No-op used by Context Managers ."""
76+ //| """Clears counts and resumes tracking ."""
8277//| ...
8378//|
8479STATIC mp_obj_t memorymonitor_allocationsize_obj___enter__ (mp_obj_t self_in ) {
@@ -118,12 +113,12 @@ const mp_obj_property_t memorymonitor_allocationsize_bytes_per_block_obj = {
118113};
119114
120115//| def __len__(self, ) -> Any:
121- //| """Returns the current pulse length
116+ //| """Returns the number of allocation buckets.
122117//|
123118//| This allows you to::
124119//|
125- //| pulses = pulseio.PulseIn(pin )
126- //| print(len(pulses ))"""
120+ //| mm = memorymonitor.AllocationSize( )
121+ //| print(len(mm ))"""
127122//| ...
128123//|
129124STATIC mp_obj_t memorymonitor_allocationsize_unary_op (mp_unary_op_t op , mp_obj_t self_in ) {
@@ -137,12 +132,12 @@ STATIC mp_obj_t memorymonitor_allocationsize_unary_op(mp_unary_op_t op, mp_obj_t
137132}
138133
139134//| def __getitem__(self, index: Any) -> Any:
140- //| """Returns the value at the given index or values in slice .
135+ //| """Returns the allocation count for the given bucket .
141136//|
142137//| This allows you to::
143138//|
144- //| pulses = pulseio.PulseIn(pin )
145- //| print(pulses [0])"""
139+ //| mm = memorymonitor.AllocationSize( )
140+ //| print(mm [0])"""
146141//| ...
147142//|
148143STATIC mp_obj_t memorymonitor_allocationsize_subscr (mp_obj_t self_in , mp_obj_t index_obj , mp_obj_t value ) {
0 commit comments