! Copyright (C) 2007, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors arrays assocs combinators.short-circuit combinators.smart definitions.icons fry kernel locals math.order models models.search models.sort present see sequences tools.profiler.counting ui.baseline-alignment ui.commands ui.gadgets ui.gadgets.borders ui.gadgets.buttons ui.gadgets.labeled ui.gadgets.labels ui.gadgets.packs ui.gadgets.search-tables ui.gadgets.status-bar ui.gadgets.tabbed ui.gadgets.tables ui.gadgets.tracks ui.gestures ui.images ui.operations ui.tools.browser ui.tools.common vocabs words ; FROM: models.arrow => ; FROM: models.arrow.smart => ; FROM: models.product => ; IN: ui.tools.profiler TUPLE: profiler-gadget < tool sort vocabs vocab words methods generic class ; SINGLETONS: word-renderer vocab-renderer ; UNION: profiler-renderer word-renderer vocab-renderer ; array ; inline PRIVATE> ! Value is a { word count } pair M: profiler-renderer row-columns drop [ [ [ [ definition-icon ] [ present ] bi ] [ present ] bi* ] with-datastack* ] [ { "" "All" "" } ] if* ; M: profiler-renderer prototype-row drop \ = definition-icon "" "" 3array ; M: profiler-renderer row-value drop dup [ first ] when ; M: profiler-renderer column-alignment drop { 0 0 1 } ; M: profiler-renderer filled-column drop 1 ; M: word-renderer column-titles drop { "" "Word" "Count" } ; M: vocab-renderer column-titles drop { "" "Vocabulary" "Count" } ; SINGLETON: method-renderer M: method-renderer column-alignment drop { 0 0 1 } ; M: method-renderer filled-column drop 1 ; ! Value is a { method count } pair M: method-renderer row-columns drop [ [ [ definition-icon ] [ synopsis ] bi ] [ present ] bi* ] with-datastack* ; M: method-renderer row-value drop first ; M: method-renderer column-titles drop { "" "Method" "Count" } ; : ( values profiler -- model ) [ [ filter-counts ] ] [ sort>> ] bi* ; : ( profiler -- model ) [ [ words>> ] [ vocab>> ] bi [ [ [ first vocabulary>> ] [ vocab-name ] bi* = ] when* ] ] keep ; : ( model renderer -- table ) [ dup [ first present ] when ] [ invoke-primary-operation ] >>action ; : ( counts profiler -- model' ) [ ] dip [ f prefix ] ; : ( profiler -- model ) [ vocab-counters [ [ lookup-vocab ] dip ] assoc-map ] dip ; : ( profiler -- model ) [ generic-counters ] dip ; : ( profiler -- model ) [ class-counters ] dip ; : method-matches? ( method generic class -- ? ) [ first ] 2dip { [ drop dup [ subwords member-eq? ] [ 2drop t ] if ] [ nip dup [ swap "method-class" word-prop = ] [ 2drop t ] if ] } 3&& ; : ( profiler -- model ) [ [ method-counters ] dip [ generic>> ] [ class>> ] bi [ '[ _ _ method-matches? ] filter ] ] keep ; : sort-by-name ( obj1 obj2 -- <=> ) [ first name>> ] compare ; : sort-by-call-count ( obj1 obj2 -- <=> ) [ second ] compare invert-comparison ; : sort-options ( -- alist ) { { [ sort-by-name ] "by name" } { [ sort-by-call-count ] "by call count" } } ; : ( model -- gadget ) +baseline+ >>align { 5 5 } >>gap "Sort by:"