<commit_before>! Copyright (C) 2007, 2008 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors words sequences math prettyprint kernel arrays io
io.styles namespaces assocs kernel.private strings combinators
sorting math.parser vocabs definitions tools.profiler.private
continuations generic ;
IN: tools.profiler

: profile ( quot -- )
    [ t profiling call ] [ f profiling ] [ ] cleanup ;

: counters ( words -- assoc )
    [ dup counter>> ] { } map>assoc ;

GENERIC: (profile.) ( obj -- )

TUPLE: usage-profile word ;

C: <usage-profile> usage-profile

M: word (profile.)
    dup unparse swap <usage-profile> write-object ;

TUPLE: vocab-profile vocab ;

C: <vocab-profile> vocab-profile

M: string (profile.)
    dup <vocab-profile> write-object ;

M: method-body (profile.)
    dup synopsis swap "method-generic" word-prop
    <usage-profile> write-object ;

: counter. ( obj n -- )
    [
        [ [ (profile.) ] with-cell ] dip
        [ number>string write ] with-cell
    ] with-row ;

: counters. ( assoc -- )
    [ second 0 > ] filter sort-values
    standard-table-style [
        [ counter. ] assoc-each
    ] tabular-output ;

: profile. ( -- )
    "Call counts for all words:" print
    all-words counters counters. ;

: vocab-profile. ( vocab -- )
    "Call counts for words in the " write
    dup dup vocab write-object
    " vocabulary:" print
    words counters counters. ;

: usage-profile. ( word -- )
    "Call counts for words which call " write
    dup pprint
    ":" print
    smart-usage [ word? ] filter counters counters. ;

: vocabs-profile. ( -- )
    "Call counts for all vocabularies:" print
    vocabs [
        dup words
        [ "predicating" word-prop not ] filter
        [ counter>> ] map sum
    ] { } map>assoc counters. ;

: method-profile. ( -- )
    all-words [ subwords ] map concat
    counters counters. ;<commit_msg>Profiler's usage-profile word is now more useful: it uses compiled-usage instead of usage<commit_after>! Copyright (C) 2007, 2008 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors words sequences math prettyprint kernel arrays io
io.styles namespaces assocs kernel.private strings combinators
sorting math.parser vocabs definitions tools.profiler.private
continuations generic compiler.units sets ;
IN: tools.profiler

: profile ( quot -- )
    [ t profiling call ] [ f profiling ] [ ] cleanup ;

: counters ( words -- assoc )
    [ dup counter>> ] { } map>assoc ;

GENERIC: (profile.) ( obj -- )

TUPLE: usage-profile word ;

C: <usage-profile> usage-profile

M: word (profile.)
    [ name>> "( no name )" or ] [ <usage-profile> ] bi write-object ;

TUPLE: vocab-profile vocab ;

C: <vocab-profile> vocab-profile

M: string (profile.)
    dup <vocab-profile> write-object ;

M: method-body (profile.)
    [ synopsis ] [ "method-generic" word-prop <usage-profile> ] bi
    write-object ;

: counter. ( obj n -- )
    [
        [ [ (profile.) ] with-cell ] dip
        [ number>string write ] with-cell
    ] with-row ;

: counters. ( assoc -- )
    [ second 0 > ] filter sort-values
    standard-table-style [
        [ counter. ] assoc-each
    ] tabular-output ;

: profile. ( -- )
    "Call counts for all words:" print
    all-words counters counters. ;

: vocab-profile. ( vocab -- )
    "Call counts for words in the " write
    dup dup vocab write-object
    " vocabulary:" print
    words counters counters. ;

: usage-profile. ( word -- )
    "Call counts for words which call " write
    dup pprint
    ":" print
    [ smart-usage [ word? ] filter ]
    [ compiled-generic-usage keys ]
    [ compiled-usage keys ]
    tri 3append prune counters counters. ;

: vocabs-profile. ( -- )
    "Call counts for all vocabularies:" print
    vocabs [
        dup words
        [ "predicating" word-prop not ] filter
        [ counter>> ] map sum
    ] { } map>assoc counters. ;

: method-profile. ( -- )
    all-words [ subwords ] map concat
    counters counters. ;
{'fraction_non_alphanumeric': 0.12374749498997996, 'fraction_numerical': 0.004759519038076153, 'mean_word_length': 2.6005410279531107, 'pattern_counts': {'":': 2, '<': 15, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7571636', 'n_tokens_mistral': 1285, 'n_tokens_neox': 1240, 'n_words': 380}