summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-12-04 06:57:51 -0800
committerKaz Kylheku <kaz@kylheku.com>2017-12-04 06:57:51 -0800
commitaa279b849e8a4c5fc4eb3429ac38f71f81704b2d (patch)
tree6f434fa3137d25cd437d10c876c2878e72c78464
parent4a8722ce9fcbb66abe2bd304e5a4bad03d842821 (diff)
downloadtxr-aa279b849e8a4c5fc4eb3429ac38f71f81704b2d.tar.gz
txr-aa279b849e8a4c5fc4eb3429ac38f71f81704b2d.tar.bz2
txr-aa279b849e8a4c5fc4eb3429ac38f71f81704b2d.zip
prof: deal with overflowing mem counters.
* eval.c (op_prof): Deal with the cases when alloc_bytes_t value cannot be converted to a val in a single call to unum. * lib.h (SIZEOF_ALLOC_BYTES_T): New macro.
-rw-r--r--eval.c19
-rw-r--r--lib.h2
2 files changed, 19 insertions, 2 deletions
diff --git a/eval.c b/eval.c
index 5dc34960..b4b2d7de 100644
--- a/eval.c
+++ b/eval.c
@@ -2696,9 +2696,24 @@ static val op_prof(val form, val env)
alloc_bytes_t start_mlbytes = malloc_bytes;
alloc_bytes_t start_gcbytes = gc_bytes;
val result = eval_progn(rest(form), env, form);
+ alloc_bytes_t delta_mlbytes = malloc_bytes - start_mlbytes;
+ alloc_bytes_t delta_gcbytes = gc_bytes - start_gcbytes;
+#if SIZEOF_ALLOC_BYTES_T > SIZEOF_PTR
+ val dmb = if3(delta_mlbytes <= (alloc_bytes_t) INT_PTR_MAX,
+ unum(delta_mlbytes),
+ logior(ash(unum(delta_mlbytes >> 32), num_fast(32)),
+ unum(delta_mlbytes & 0xFFFFFFFF)));
+ val dgc = if3(delta_gcbytes <= (alloc_bytes_t) INT_PTR_MAX,
+ unum(delta_gcbytes),
+ logior(ash(unum(delta_gcbytes >> 32), num_fast(32)),
+ unum(delta_gcbytes & 0xFFFFFFFF)));
+#else
+ val dmb = unum(delta_mlbytes);
+ val dgc = unum(delta_gcbytes);
+#endif
+
return list(result,
- num(malloc_bytes - start_mlbytes),
- num(gc_bytes - start_gcbytes),
+ dmb, dgc,
trunc(mul(num(clock() - start_time), num_fast(1000)), num_fast(CLOCKS_PER_SEC)),
nao);
}
diff --git a/lib.h b/lib.h
index 6c61d282..8ead3804 100644
--- a/lib.h
+++ b/lib.h
@@ -485,8 +485,10 @@ extern val prog_string;
#if HAVE_ULONGLONG_T
typedef ulonglong_t alloc_bytes_t;
+#define SIZEOF_ALLOC_BYTES_T SIZEOF_LONGLONG_T
#else
typedef unsigned long alloc_bytes_t;
+#define SIZEOF_ALLOC_BYTES_T SIZEOF_LONG
#endif
extern alloc_bytes_t malloc_bytes;