home *** CD-ROM | disk | FTP | other *** search
- \ portable RUNTIMER Version 1.02
- \ USE: -- runtime-profiling of colon definitions.
- \ mini manual:
- \ 1) load the cpu specific runtimer file, this file should be loaded automatically.
- \ fload extend\??cpu??\runtimer.fth
- \ fload extend\runtime.fth
- \ 2) From now on all colon definitions have an internal time measuring code part which is
- \ executed by calling the word.
- \ 3) Glossary:
- \ new ( -- )
- \ clear all timing information
- \ .times ( -- )
- \ display timing information
- \ profile ( -- ) name
- \ the word name is executed and the timing takes place. name could be a "benchmark" or
- \ the timing critical part of your application.
- \ see is patched, it will give correct information and knows about the timer information data
- \ structure
- \
- \ 4) example
- \ : test1 dup dup dup ;
- \ : test2 drop drop drop ;
- \ : test3 swap swap swap ;
- \ : test4 test1 test3 test2 test1 test3 test2 ;
- \ : test5 10000 0 do test4 test4 loop ;
- \ profile test5 .times
-
- \
- \ User words of runtimer Version 1.0
- \ new (-- ) set all calls and ticks to 0
- \ .times ( -- ) print runtimes
- \ profile name ( -- ) make a runtime profile of word name)
- \ Lit. [1] "Laufzeitmessung von Forthworten", Bernd Pennemann, VD2/87
- \ [2] Formacs User's Guide, Mitch Bradley
- \
- \ After loading the runtimer every colon definition is linked by an extra
- \ link-list for easy finding of all words.
-
- \ Structure of new colon definition:
- \ timer-link-list long
- \ standard forthmacs header
- \ apf parameter field address of word
- \ 0 (time
- \ 4 calls
- \ 8 #time
- \ 12 compiled code continues ......
-
- only forth also hidden also definitions decimal
-
- ifdef profile \ this file shouldn't be compiled twice
- ??cr error-output .( don't load runtimer twice ! ) cr restore-output fexit
- ifend
-
- ifndef (time \ defined in cpu-specific file
- ??cr error-output .( needs cpu-specific runtimer-file first!)
- restore-output cr abort
- ifend
-
-
- variable timer-link \ base of link-list bound to 0
- here timer-link token! 0 ,
- variable used-time
- defer scan-action \ ( anf -- )
-
- : scan-all \ ( -- ) scan-action is done with all timer-linked words
- timer-link
- begin @ dup @ exit? not and
- while dup /n + l>name scan-action
- repeat drop ;
-
- : ticker-data \ ( anf -- adr-timer adr-data )
- name> >body ta1+ dup ta1+ swap ;
- : new-data \ ( anf -- ) Call-nr und Time-nr = 0
- ticker-data off off used-time off ;
- : legal-data \ ( anf -- )
- ticker-data drop @ 2- used-time @ >
- if used-time off then ;
- : .percent \ ( n -- )
- used-time @ dup 100000 >
- if 100 / else swap 1005 * 10 / swap then / ( n -- )
- ?dup if 4 .r else ." < 1" then ." %" ;
-
- : .usec \ ( usec -- )
- dup 30000 >
- if 499 + 1000 / ascii m >r dup 30000 >
- if 499 + 1000 / r> drop bl >r then
- else ascii u >r
- then ( n -- )
- ?dup if 8 .r else ." -" then space r> emit ." sec" ;
- : .one-data \ ( anf -- ) prints data of one word
- dup ticker-data @ swap @ swap
- dup 0= ( anf #time calls flag )
- if 2drop drop exit then
- rot .id 20 to-column
- 2dup 8 .r ." Calls" usec/tick * .usec
- 2dup swap usec/tick * swap / .usec ." /call"
- drop used-time @
- if .percent else drop then ??cr ;
-
- \ support for the decompiler, this isn't portable at all!!
- ifdef see
- : my->body (s cfa -- )
- >body dup token@ ['] (time <> ?exit
- ['] legal-data is scan-action scan-all
- dup >name ticker-data @ swap @ or
- if ." \ Runtimer info: " dup >name .one-data indent
- then d# 12 + ;
- ' .pfa >body dup token@ ' dup = over ta1+ token@ ' scan-pfa @ and
- iftrue patch my->body >body .pfa
- ifend
- ifend
-
- : (forget true abort" forget is not allowed with runtimer loaded!" ;
- : (save-forth true abort" save-forth is not allowed with runtimer loaded!" ;
- ' (forget ' forget >body token!
- ' (save-forth ' save-forth >body token!
-
- forth definitions
-
- variable runtimer runtimer off \ on -> the runtimer code is compiled
- : new \ ( -- ) set all ticks and calls to 0
- ['] new-data is scan-action scan-all ;
- : .times \ ( -- ) prints data of all words
- ??cr cr ." Runtime profiler V 1.02 (c) 1993 Hanno Schwalm"
- cr #columns 0 do ascii _ emit loop cr cr
- ['] legal-data is scan-action scan-all
- ['] .one-data is scan-action
- base @ >r decimal scan-all r> base !
- cr #columns 0 do ascii _ emit loop cr cr ;
-
- : profile \ name ( -- ) make runtime-profile of name
- new '
- ticker @ @ >r execute ticker @ @ r> - used-time ! ;
-
- : : \ name ( -- ) redefined colon, using runtimer
- runtimer @ 0= if [compile] : beep exit then
- here timer-link token@ token, timer-link token!
- [compile] : \ make a colon definition
- compile (time 0 , 0 , ; immediate
-
- only forth also definitions decimal
- runtimer on
-