3
3
*
4
4
* The MIT License (MIT)
5
5
*
6
- * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
6
+ * Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
7
7
*
8
8
* Permission is hereby granted, free of charge, to any person obtaining a copy
9
9
* of this software and associated documentation files (the "Software"), to deal
38
38
//| def __init__(self):
39
39
//| """Tracks the number of allocations in power of two buckets.
40
40
//|
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
42
42
//| meaning frees are ignored. Reallocated memory is counted twice, at allocation and when
43
43
//| reallocated with the larger size.
44
44
//|
47
47
//| per block, typically 16. Bucket 2 will be less than or equal to 4 blocks. See
48
48
//| `bytes_per_block` to convert blocks to bytes.
49
49
//|
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.
53
51
//|
54
52
//| Track allocations::
55
53
//|
56
54
//| import memorymonitor
57
55
//|
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)
63
59
//|
64
- //| # Clear the buckets
65
- //| mm.clear( )
60
+ //| for bucket, count in enumerate(mm):
61
+ //| print("<", 2 ** bucket, count )
66
62
//|
67
- //| # Resume allocation tracking
68
- //| mm.resume()"""
63
+ //| """
69
64
//| ...
70
65
//|
71
66
STATIC 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,
78
73
}
79
74
80
75
//| def __enter__(self, ) -> Any:
81
- //| """No-op used by Context Managers ."""
76
+ //| """Clears counts and resumes tracking ."""
82
77
//| ...
83
78
//|
84
79
STATIC 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 = {
118
113
};
119
114
120
115
//| def __len__(self, ) -> Any:
121
- //| """Returns the current pulse length
116
+ //| """Returns the number of allocation buckets.
122
117
//|
123
118
//| This allows you to::
124
119
//|
125
- //| pulses = pulseio.PulseIn(pin )
126
- //| print(len(pulses ))"""
120
+ //| mm = memorymonitor.AllocationSize( )
121
+ //| print(len(mm ))"""
127
122
//| ...
128
123
//|
129
124
STATIC 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
137
132
}
138
133
139
134
//| 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 .
141
136
//|
142
137
//| This allows you to::
143
138
//|
144
- //| pulses = pulseio.PulseIn(pin )
145
- //| print(pulses [0])"""
139
+ //| mm = memorymonitor.AllocationSize( )
140
+ //| print(mm [0])"""
146
141
//| ...
147
142
//|
148
143
STATIC mp_obj_t memorymonitor_allocationsize_subscr (mp_obj_t self_in , mp_obj_t index_obj , mp_obj_t value ) {
0 commit comments