home *** CD-ROM | disk | FTP | other *** search
- \ portable RUNTIME PROFILER Version 1.03
- \ 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
- \needs /cell alias /cell /n
- \needs cell+ alias cell+ na1+
-
- variable timer-link \ base of link-list bound to 0
- here timer-link link! 0 ,
- variable used-time
- defer scan-action \ ( anf -- )
-
- ms/tick td 1000 * constant usec/tick \ 100hz ticker
- : scan-all \ ( -- ) scan-action is done with all timer-linked words
- timer-link
- begin link@ dup link@ exit? not and
- while dup cell+ l>name scan-action
- repeat drop ;
-
- : ticker-data \ ( anf -- adr-timer adr-data )
- name> >body cell+ dup cell+ 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 / [char] m >r dup 30000 >
- if 499 + 1000 / r> drop bl >r then
- else [char] 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
- ifdef see
- : .runtime-info ( ip -- ip' )
- +indent .." \ <-- profiler-information available, "
- cell+ dup @ .d ." calls, " cell+ dup @ .d ." ticks." cell+ -indent ;
- : skip-runtime-info ( ip -- ip' )
- cell+ cell+ cell+ ;
- ' (time ' .runtime-info ' skip-runtime-info install-decomp
- ifend
-
- : (forget true abort" forget is not allowed with profiler loaded!" ;
- : (save-forth true abort" save-forth is not allowed with profiler 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.03 (c) 1993,94 Hanno Schwalm"
- cr #columns 0 do [char] _ 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 [char] _ emit loop cr cr ;
-
- : profile \ name ( -- ) make runtime-profile of name
- new '
- get-ticks >r execute get-ticks r> - used-time ! ;
-
- : : \ name ( -- ) redefined colon, using runtimer
- runtimer @ 0= if : exit then
- here timer-link link@ link, timer-link link!
- : \ make a colon definition
- postpone (time 0 , 0 , ; immediate
-
- only forth also definitions decimal
- runtimer on
-