Skip to content

Commit ea0461d

Browse files
committed
py: Add option to micropython.qstr_info() to dump actual qstrs.
1 parent 53716fc commit ea0461d

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

py/modmicropython.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,19 @@ mp_obj_t mp_micropython_mem_info(mp_uint_t n_args, const mp_obj_t *args) {
7777
}
7878
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_micropython_mem_info_obj, 0, 1, mp_micropython_mem_info);
7979

80-
STATIC mp_obj_t qstr_info(void) {
80+
STATIC mp_obj_t mp_micropython_qstr_info(mp_uint_t n_args, const mp_obj_t *args) {
81+
(void)args;
8182
mp_uint_t n_pool, n_qstr, n_str_data_bytes, n_total_bytes;
8283
qstr_pool_info(&n_pool, &n_qstr, &n_str_data_bytes, &n_total_bytes);
8384
printf("qstr pool: n_pool=" UINT_FMT ", n_qstr=" UINT_FMT ", n_str_data_bytes=" UINT_FMT ", n_total_bytes=" UINT_FMT "\n",
8485
n_pool, n_qstr, n_str_data_bytes, n_total_bytes);
86+
if (n_args == 1) {
87+
// arg given means dump qstr data
88+
qstr_dump_data();
89+
}
8590
return mp_const_none;
8691
}
87-
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_qstr_info_obj, qstr_info);
92+
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_micropython_qstr_info_obj, 0, 1, mp_micropython_qstr_info);
8893

8994
#endif // MICROPY_PY_MICROPYTHON_MEM_INFO
9095

py/qstr.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include <assert.h>
2828
#include <string.h>
29+
#include <stdio.h>
2930

3031
#include "py/mpstate.h"
3132
#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_
229230
}
230231
*n_total_bytes += *n_str_data_bytes;
231232
}
233+
234+
#if MICROPY_PY_MICROPYTHON_MEM_INFO
235+
void qstr_dump_data(void) {
236+
for (qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL && pool != &const_pool; pool = pool->prev) {
237+
for (const byte **q = pool->qstrs, **q_top = pool->qstrs + pool->len; q < q_top; q++) {
238+
printf("Q(%s)\n", Q_GET_DATA(*q));
239+
}
240+
}
241+
}
242+
#endif

py/qstr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,6 @@ mp_uint_t qstr_len(qstr q);
7272
const byte* qstr_data(qstr q, mp_uint_t *len);
7373

7474
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);
75+
void qstr_dump_data(void);
7576

7677
#endif // __MICROPY_INCLUDED_PY_QSTR_H__

0 commit comments

Comments
 (0)