! Copyright (C) 2007, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: kernel quotations accessors fry assocs present math.order math.vectors arrays locals models.search models.sort models sequences vocabs tools.profiler words prettyprint ui ui.commands ui.gadgets ui.gadgets.panes ui.gadgets.scrollers ui.gadgets.tracks ui.gestures ui.gadgets.buttons ui.gadgets.tables ui.gadgets.search-tables ui.gadgets.labelled ui.gadgets.buttons ui.gadgets.packs ui.gadgets.labels ui.gadgets.tabbed ui.gadgets.status-bar ui.tools.browser ui.tools.common ; FROM: models.filter => ; FROM: models.compose => ; IN: ui.tools.profiler TUPLE: profiler-gadget < tool sort vocabs vocab words methods generic class ; { 700 400 } profiler-gadget set-tool-dim SINGLETONS: word-renderer vocab-renderer ; UNION: profiler-renderer word-renderer vocab-renderer ; ! Value is a { word count } pair M: profiler-renderer row-columns drop [ [ present ] map ] [ { "All" "" } ] if* ; M: profiler-renderer row-value drop dup [ first ] when ; M: vocab-renderer row-value call-next-method dup [ vocab ] when ; SINGLETON: method-renderer ! Value is a { method-body count } pair M: method-renderer row-columns drop [ first synopsis ] [ second present ] bi 2array ; M: method-renderer row-value drop first ; : ( values profiler -- model ) [ [ filter-counts ] ] [ sort>> ] bi* ; : ( profiler -- model ) [ [ words>> ] [ vocab>> ] bi [ [ [ first vocabulary>> ] [ vocab-name ] bi* = ] when* ] ] keep ; : match? ( pair/f str -- ? ) swap dup [ first present subseq? ] [ 2drop t ] if ; : ( model -- table ) [ match? ] { 0 1 } >>column-alignment 0 >>filled-column ; : ( counts profiler -- model' ) [ ] dip [ f prefix ] ; : ( profiler -- model ) [ vocab-counters ] dip ; : ( profiler -- model ) [ generic-counters ] dip ; : ( profiler -- model ) [ class-counters ] dip ; : method-matches? ( method generic class -- ? ) [ first ] 2dip [ drop dup [ subwords memq? ] [ 2drop t ] if ] [ nip dup [ swap "method-class" word-prop = ] [ 2drop t ] if ] 3bi and ; : ( profiler -- model ) [ [ method-counters ] dip [ generic>> ] [ class>> ] bi 3array [ first3 '[ _ _ method-matches? ] filter ] ] keep ; : sort-options ( -- alist ) { { [ [ first ] compare ] "by name" } { [ [ second ] compare invert-comparison ] "by call count" } } ; : ( model -- gadget ) sort-options { 1 0 } >>orientation ; : ( profiler -- gadget ) { 5 5 } >>gap over add-gadget "Sort by:"