 : trim-flat ( root-node -- root-node' )
     dup '[ [ nip _ redundant-flat-node? not ] assoc-filter ] change-children ;
 
-: (flat) ( samples -- flat )
+: flat* ( profile-data -- flat )
     collect-threads
     [ [ collect-flat ] <profile-root-node> trim-flat ] assoc-map ;
 
 : flat ( -- tree )
-    get-raw-profile-data (flat) ;
+    most-recent-profile-data flat* ;
 
 : nth-or-last ( n seq -- elt )
     [ drop f ] [

    ] each
    per-word-samples [ f depth <profile-node> ] assoc-map ;

:: (cross-section) ( depth samples -- flat )
    samples collect-threads
    [ [ depth collect-cross-section ] <profile-root-node> ] assoc-map ;

: cross-section ( depth -- tree )
    get-raw-profile-data (cross-section) ;

: depth. ( depth -- )
    [ "  " write ] times ;

: trim-root ( root -- root' )
    dup redundant-root-node? [ children>> values first trim-root ] when ;

:: (top-down) ( profile-data depth -- tree )
    profile-data collect-threads
    [ [ depth collect-tops ] <profile-root-node> trim-root ] assoc-map ;

: top-down* ( profile-data -- tree )
    0 (top-down) ;

: top-down ( -- tree )
    most-recent-profile-data top-down* ;

:: counts+at ( key assoc sample -- )
    key assoc [ zero-counts or sample sample-counts-slice v+ ] change-at ;
