Add new alloc metric: peak_bytes_allocated.
This is just max value of current_bytes_allocated seen.
This commit is contained in:
parent
02de0c57d2
commit
780f555b2e
10
py/malloc.c
10
py/malloc.c
@ -5,6 +5,9 @@
|
|||||||
|
|
||||||
static int total_bytes_allocated = 0;
|
static int total_bytes_allocated = 0;
|
||||||
static int current_bytes_allocated = 0;
|
static int current_bytes_allocated = 0;
|
||||||
|
static int peak_bytes_allocated = 0;
|
||||||
|
|
||||||
|
#define UPDATE_PEAK() { if (current_bytes_allocated > peak_bytes_allocated) peak_bytes_allocated = current_bytes_allocated; }
|
||||||
|
|
||||||
void *m_malloc(int num_bytes) {
|
void *m_malloc(int num_bytes) {
|
||||||
if (num_bytes == 0) {
|
if (num_bytes == 0) {
|
||||||
@ -17,6 +20,7 @@ void *m_malloc(int num_bytes) {
|
|||||||
}
|
}
|
||||||
total_bytes_allocated += num_bytes;
|
total_bytes_allocated += num_bytes;
|
||||||
current_bytes_allocated += num_bytes;
|
current_bytes_allocated += num_bytes;
|
||||||
|
UPDATE_PEAK();
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,6 +35,7 @@ void *m_malloc0(int num_bytes) {
|
|||||||
}
|
}
|
||||||
total_bytes_allocated += num_bytes;
|
total_bytes_allocated += num_bytes;
|
||||||
current_bytes_allocated += num_bytes;
|
current_bytes_allocated += num_bytes;
|
||||||
|
UPDATE_PEAK();
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,6 +57,7 @@ void *m_realloc(void *ptr, int old_num_bytes, int new_num_bytes) {
|
|||||||
int diff = new_num_bytes - old_num_bytes;
|
int diff = new_num_bytes - old_num_bytes;
|
||||||
total_bytes_allocated += diff;
|
total_bytes_allocated += diff;
|
||||||
current_bytes_allocated += diff;
|
current_bytes_allocated += diff;
|
||||||
|
UPDATE_PEAK();
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,3 +75,7 @@ int m_get_total_bytes_allocated(void) {
|
|||||||
int m_get_current_bytes_allocated(void) {
|
int m_get_current_bytes_allocated(void) {
|
||||||
return current_bytes_allocated;
|
return current_bytes_allocated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int m_get_peak_bytes_allocated(void) {
|
||||||
|
return peak_bytes_allocated;
|
||||||
|
}
|
||||||
|
@ -33,6 +33,7 @@ void m_free(void *ptr, int num_bytes);
|
|||||||
|
|
||||||
int m_get_total_bytes_allocated(void);
|
int m_get_total_bytes_allocated(void);
|
||||||
int m_get_current_bytes_allocated(void);
|
int m_get_current_bytes_allocated(void);
|
||||||
|
int m_get_peak_bytes_allocated(void);
|
||||||
|
|
||||||
/** unichar / UTF-8 *********************************************/
|
/** unichar / UTF-8 *********************************************/
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user