diff options
author | Andrew J. Schorr <aschorr@telemetry-investments.com> | 2019-09-01 11:48:01 -0400 |
---|---|---|
committer | Andrew J. Schorr <aschorr@telemetry-investments.com> | 2019-09-01 11:48:01 -0400 |
commit | 5c41849e0e78e45db0dc4421f1779ef7bec726da (patch) | |
tree | ab2ac8627c02a10f763650d30d58aac4b4c372ab | |
parent | 8cc45af919dc56011dbf4c8965b9c1e4784e56d7 (diff) | |
download | egawk-5c41849e0e78e45db0dc4421f1779ef7bec726da.tar.gz egawk-5c41849e0e78e45db0dc4421f1779ef7bec726da.tar.bz2 egawk-5c41849e0e78e45db0dc4421f1779ef7bec726da.zip |
Hack the typeof function to return memory count info when the 2nd arg is PROCINFO.
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | awk.h | 3 | ||||
-rw-r--r-- | builtin.c | 13 | ||||
-rw-r--r-- | node.c | 9 |
4 files changed, 28 insertions, 7 deletions
@@ -1,3 +1,13 @@ +2019-09-01 Andrew J. Schorr <aschorr@telemetry-investments.com> + + * awk.h (block_header): Add cnt field even when MEMDEBUG is not + defined, and add a name field. + * node.c (nextfree): Initialize new name field. + (more_blocks): Bump nextfree[id].cnt by BLOCKCHUNK. + * builtin.c (do_typeof): When the 1st argument is PROCINFO and the + 2nd arg is provided, return new "count_<blah>" fields containing + the memory allocation accounts of the various block types. + 2019-08-30 Andrew J. Schorr <aschorr@telemetry-investments.com> * configure.ac (.developing): Add -DMEMDEBUG to CFLAGS. @@ -1061,9 +1061,8 @@ struct block_item { struct block_header { struct block_item *freep; size_t size; -#ifdef MEMDEBUG + const char *name; long cnt; -#endif }; enum block_id { @@ -4049,8 +4049,19 @@ do_typeof(int nargs) /* Node_var_array is never UPREF'ed */ res = "array"; deref = false; - if (dbg) + if (dbg) { assoc_set(dbg, make_string("array_type", 10), make_string(arg->array_funcs->name, strlen(arg->array_funcs->name))); + if (arg == PROCINFO_node) { + int i; + for (i = 0; i < BLOCK_MAX; i++) { + char *p; + size_t l = 6 + strlen(nextfree[i].name); + emalloc(p, char *, l+1, "do_typeof"); + sprintf(p, "count_%s", nextfree[i].name); + assoc_set(dbg, make_str_node(p, l, ALREADY_MALLOCED), make_number((AWKNUM) (nextfree[i].cnt))); + } + } + } break; case Node_val: switch (fixtype(arg)->flags & (STRING|NUMBER|USER_INPUT|REGEX)) { @@ -1026,11 +1026,11 @@ void init_btowc_cache() #define BLOCKCHUNK 100 struct block_header nextfree[BLOCK_MAX] = { - { NULL, sizeof(NODE) }, - { NULL, sizeof(BUCKET) }, + { NULL, sizeof(NODE), "node" }, + { NULL, sizeof(BUCKET), "bucket" }, #ifdef HAVE_MPFR - { NULL, sizeof(mpfr_t) }, - { NULL, sizeof(mpz_t) }, + { NULL, sizeof(mpfr_t), "mpfr" }, + { NULL, sizeof(mpz_t), "mpz" }, #endif }; @@ -1081,6 +1081,7 @@ more_blocks(int id) np->freep = next; } nextfree[id].freep = freep->freep; + nextfree[id].cnt += BLOCKCHUNK; return freep; } |