aboutsummaryrefslogtreecommitdiff
path: root/amforth-6.5/common/lib/profiler.frt
diff options
context:
space:
mode:
Diffstat (limited to 'amforth-6.5/common/lib/profiler.frt')
-rw-r--r--amforth-6.5/common/lib/profiler.frt31
1 files changed, 31 insertions, 0 deletions
diff --git a/amforth-6.5/common/lib/profiler.frt b/amforth-6.5/common/lib/profiler.frt
new file mode 100644
index 0000000..d2515e7
--- /dev/null
+++ b/amforth-6.5/common/lib/profiler.frt
@@ -0,0 +1,31 @@
+\ A profiler counts the number of calls
+\ of any word being defined afterwards.
+\
+\ global state: on and off
+variable profiling?
+: profile:on -1 profiling? ! ;
+: profile:off 0 profiling? ! ;
+
+: profiler profiling? @ if 1 swap +! else drop then ;
+\ re-define colon
+: : :
+ here 2 allot postpone literal postpone profiler
+;
+
+\ get the address of the profiling data.
+: xt>prf ( xt -- addr )
+ cell+ @i
+;
+
+\ useful stuff
+: .prf xt>prf @ u. ;
+: prf-reset xt>prf 0 swap ! ;
+
+\ usage
+\ : foo bar baz ;
+\ profile:on -- turn on profiling
+\ ' foo .prf -- gets the number of calls to foo
+\ ' foo prf-reset -- resets this number
+\ profile:off -- turn off profiling
+\ wanna profile system words? just re-define them now ;)
+\ e.g. : + + ;