shithub: femtolisp

Download patch

ref: 0769956a24915cb1f30f6e720e2f2051e755d0e0
parent: 6eababf840dc0d255196dfd6fca1c9be3053f769
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Tue Nov 12 20:51:05 EST 2024

add (*vm-stats*) to print out a bit of vm statistics

--- a/flisp.c
+++ b/flisp.c
@@ -449,6 +449,7 @@
 	uint32_t i, f, top;
 	fl_readstate_t *rs;
 
+	FL(gccalls)++;
 	FL(curheap) = FL(tospace);
 	if(FL(grew))
 		FL(lim) = FL(curheap)+FL(heapsize)*2-sizeof(cons_t);
@@ -2150,6 +2151,17 @@
 		argcount(nargs, 1);
 	double s = nargs > 0 ? todouble(args[0]) : 0;
 	sleep_ms(s * 1000.0);
+	return FL(t);
+}
+
+BUILTIN("*vm-stats*", vm_stats)
+{
+	USED(args);
+	argcount(nargs, 0);
+	ios_printf(ios_stderr, "nstack        %"PRIu32"\n", FL(nstack));
+	ios_printf(ios_stderr, "heapsize      %"PRIu32"\n", FL(heapsize));
+	ios_printf(ios_stderr, "maxfinalizers %"PRIu64"\n", (uint64_t)FL(maxfinalizers));
+	ios_printf(ios_stderr, "gc calls      %"PRIu64"\n", (uint64_t)FL(gccalls));
 	return FL(t);
 }
 
--- a/flisp.h
+++ b/flisp.h
@@ -341,6 +341,7 @@
 	uint8_t *lim;
 	uint32_t heapsize;//bytes
 	uint32_t *consflags;
+	size_t gccalls;
 
 	fl_readstate_t *readstate;
 	symbol_t *symtab;