! Copyright (C) 2005, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors kernel math sorting words parser io summary quotations sequences prettyprint continuations effects definitions compiler.units namespaces assocs tools.time generic inspector fry locals generalizations macros ; IN: tools.annotations : reset ( word -- ) [ (reset) ] with-compilation-unit ; ERROR: cannot-annotate-twice word ; M: cannot-annotate-twice summary drop "Cannot annotate a word twice" ; > 2dup "unannotated-def" set-word-prop ] dip call( old -- new ) define ; PRIVATE> : annotate ( word quot -- ) [ (annotate) ] with-compilation-unit ; values values length :> n [ "--- " write str write bl word . n ndup n narray values swap zip simple-table. flush ] ; inline MACRO: entering ( word -- quot ) dup stack-effect [ in>> ] "Entering" trace-quot ; MACRO: leaving ( word -- quot ) dup stack-effect [ out>> ] "Leaving" trace-quot ; : (watch) ( word def -- def ) over '[ _ entering @ _ leaving ] ; PRIVATE> : watch ( word -- ) dup '[ [ _ ] dip (watch) ] annotate ; assoc describe @ ] ; PRIVATE> : watch-vars ( word vars -- ) dupd '[ [ _ _ ] dip (watch-vars) ] annotate ; SYMBOL: word-timing word-timing [ H{ } clone ] initialize : reset-word-timing ( -- ) word-timing get clear-assoc ; : add-timing ( word -- ) dup '[ _ (add-timing) ] annotate ; : word-timing. ( -- ) word-timing get >alist [ 1000000 /f ] assoc-map sort-values simple-table. ;