From 4d5b28cd0886a565b69f035bb8b3713050636cac Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 29 Jan 2014 18:56:46 +0000 Subject: Add qstr_info() function and bindings for unix port. --- py/qstr.c | 16 ++++++++++++++++ py/qstr.h | 2 ++ 2 files changed, 18 insertions(+) (limited to 'py') diff --git a/py/qstr.c b/py/qstr.c index f12cbceff..f9f927f58 100644 --- a/py/qstr.c +++ b/py/qstr.c @@ -185,3 +185,19 @@ const byte *qstr_data(qstr q, uint *len) { *len = Q_GET_LENGTH(qd); return Q_GET_DATA(qd); } + +void qstr_pool_info(uint *n_pool, uint *n_qstr, uint *n_str_data_bytes, uint *n_total_bytes) { + *n_pool = 0; + *n_qstr = 0; + *n_str_data_bytes = 0; + *n_total_bytes = 0; + for (qstr_pool_t *pool = last_pool; pool != NULL && pool != &const_pool; pool = pool->prev) { + *n_pool += 1; + *n_qstr += pool->len; + for (const byte **q = pool->qstrs, **q_top = pool->qstrs + pool->len; q < q_top; q++) { + *n_str_data_bytes += Q_GET_ALLOC(*q); + } + *n_total_bytes += sizeof(qstr_pool_t) + sizeof(qstr) * pool->alloc; + } + *n_total_bytes += *n_str_data_bytes; +} diff --git a/py/qstr.h b/py/qstr.h index 9224d48a1..779ebcb4a 100644 --- a/py/qstr.h +++ b/py/qstr.h @@ -36,3 +36,5 @@ machine_uint_t qstr_hash(qstr q); const char* qstr_str(qstr q); uint qstr_len(qstr q); const byte* qstr_data(qstr q, uint *len); + +void qstr_pool_info(uint *n_pool, uint *n_qstr, uint *n_str_data_bytes, uint *n_total_bytes); -- cgit v1.2.3