aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew J. Schorr <aschorr@telemetry-investments.com>2019-09-01 11:48:01 -0400
committerAndrew J. Schorr <aschorr@telemetry-investments.com>2019-09-01 11:48:01 -0400
commit5c41849e0e78e45db0dc4421f1779ef7bec726da (patch)
treeab2ac8627c02a10f763650d30d58aac4b4c372ab
parent8cc45af919dc56011dbf4c8965b9c1e4784e56d7 (diff)
downloadegawk-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--ChangeLog10
-rw-r--r--awk.h3
-rw-r--r--builtin.c13
-rw-r--r--node.c9
4 files changed, 28 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index a64478c0..54bc721d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/awk.h b/awk.h
index 345d87b3..b55b0488 100644
--- a/awk.h
+++ b/awk.h
@@ -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 {
diff --git a/builtin.c b/builtin.c
index 1c107d3b..46943909 100644
--- a/builtin.c
+++ b/builtin.c
@@ -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)) {
diff --git a/node.c b/node.c
index eacd17b3..5333e848 100644
--- a/node.c
+++ b/node.c
@@ -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;
}