! 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 combinators.smart definitions.icons see 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.labeled ui.gadgets.packs ui.gadgets.labels ui.gadgets.tabbed ui.gadgets.status-bar ui.gadgets.borders ui.tools.browser ui.tools.common ui.baseline-alignment ui.operations ui.images ; 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-body 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 [ [ 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 memq? ] [ 2drop t ] if ] [ nip dup [ swap "method-class" word-prop = ] [ 2drop t ] if ] 3bi and ; : ( 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:"