summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-02-10 11:02:28 +0000
committerDamien George <damien.p.george@gmail.com>2015-02-10 11:02:28 +0000
commitea0461dcd390135561651036f39606d50ce12999 (patch)
treed2db3ac831ea5d7aa60011d8ac562a2fbfa3f0c3
parent53716fcc3effbce1b7cca49d8df30ecaad8bc1dc (diff)
downloadmicropython-ea0461dcd390135561651036f39606d50ce12999.tar.gz
micropython-ea0461dcd390135561651036f39606d50ce12999.zip
py: Add option to micropython.qstr_info() to dump actual qstrs.
-rw-r--r--py/modmicropython.c9
-rw-r--r--py/qstr.c11
-rw-r--r--py/qstr.h1
3 files changed, 19 insertions, 2 deletions
diff --git a/py/modmicropython.c b/py/modmicropython.c
index 7d1b6bf38b..edd1375796 100644
--- a/py/modmicropython.c
+++ b/py/modmicropython.c
@@ -77,14 +77,19 @@ mp_obj_t mp_micropython_mem_info(mp_uint_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_micropython_mem_info_obj, 0, 1, mp_micropython_mem_info);
-STATIC mp_obj_t qstr_info(void) {
+STATIC mp_obj_t mp_micropython_qstr_info(mp_uint_t n_args, const mp_obj_t *args) {
+ (void)args;
mp_uint_t n_pool, n_qstr, n_str_data_bytes, n_total_bytes;
qstr_pool_info(&n_pool, &n_qstr, &n_str_data_bytes, &n_total_bytes);
printf("qstr pool: n_pool=" UINT_FMT ", n_qstr=" UINT_FMT ", n_str_data_bytes=" UINT_FMT ", n_total_bytes=" UINT_FMT "\n",
n_pool, n_qstr, n_str_data_bytes, n_total_bytes);
+ if (n_args == 1) {
+ // arg given means dump qstr data
+ qstr_dump_data();
+ }
return mp_const_none;
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_qstr_info_obj, qstr_info);
+STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_micropython_qstr_info_obj, 0, 1, mp_micropython_qstr_info);
#endif // MICROPY_PY_MICROPYTHON_MEM_INFO
diff --git a/py/qstr.c b/py/qstr.c
index 813f251502..2d57f22221 100644
--- a/py/qstr.c
+++ b/py/qstr.c
@@ -26,6 +26,7 @@
#include <assert.h>
#include <string.h>
+#include <stdio.h>
#include "py/mpstate.h"
#include "py/qstr.h"
@@ -229,3 +230,13 @@ void qstr_pool_info(mp_uint_t *n_pool, mp_uint_t *n_qstr, mp_uint_t *n_str_data_
}
*n_total_bytes += *n_str_data_bytes;
}
+
+#if MICROPY_PY_MICROPYTHON_MEM_INFO
+void qstr_dump_data(void) {
+ for (qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL && pool != &const_pool; pool = pool->prev) {
+ for (const byte **q = pool->qstrs, **q_top = pool->qstrs + pool->len; q < q_top; q++) {
+ printf("Q(%s)\n", Q_GET_DATA(*q));
+ }
+ }
+}
+#endif
diff --git a/py/qstr.h b/py/qstr.h
index 776c2ab8f7..58823d4ec7 100644
--- a/py/qstr.h
+++ b/py/qstr.h
@@ -72,5 +72,6 @@ mp_uint_t qstr_len(qstr q);
const byte* qstr_data(qstr q, mp_uint_t *len);
void qstr_pool_info(mp_uint_t *n_pool, mp_uint_t *n_qstr, mp_uint_t *n_str_data_bytes, mp_uint_t *n_total_bytes);
+void qstr_dump_data(void);
#endif // __MICROPY_INCLUDED_PY_QSTR_H__