From 973aa59ac438d9d674b12723f8497218732b7fcb Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Sun, 31 Jul 2022 20:33:35 -0700 Subject: [PATCH] tools.profiler.sampling: faster printing in the UI --- basis/tools/profiler/sampling/sampling.factor | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/basis/tools/profiler/sampling/sampling.factor b/basis/tools/profiler/sampling/sampling.factor index c4509dd08f..dfb62a90e7 100644 --- a/basis/tools/profiler/sampling/sampling.factor +++ b/basis/tools/profiler/sampling/sampling.factor @@ -1,9 +1,9 @@ ! Copyright (C) 2011 Joe Groff. ! See http://factorcode.org/license.txt for BSD license. USING: accessors assocs combinators combinators.short-circuit -continuations formatting fry generalizations hashtables.identity -io kernel kernel.private layouts locals math math.parser -math.vectors memory namespaces prettyprint sequences +continuations formatting generalizations io io.streams.string +kernel kernel.private layouts math math.parser math.vectors +memory namespaces prettyprint sequences sequences.generalizations sets sorting ; IN: tools.profiler.sampling @@ -198,7 +198,7 @@ PRIVATE> concat ] cache write ; : by-total-time ( nodes -- nodes' ) >alist [ second total-time>> ] inv-sort-with ; @@ -209,26 +209,28 @@ PRIVATE> : percentage. ( num denom -- ) [ 100 * ] dip /f "%6.2f" printf ; -DEFER: (profile.) +DEFER: profile-depth. :: times. ( node -- ) - node { - [ depth>> number>string 4 CHAR: \s pad-head write bl ] - [ total-time>> duration. bl ] - [ [ gc-time>> ] [ total-time>> ] bi percentage. bl ] - [ [ jit-time>> ] [ total-time>> ] bi percentage. bl ] - [ [ foreign-time>> ] [ total-time>> ] bi percentage. bl ] - [ [ foreign-thread-time>> ] [ total-time>> ] bi percentage. bl ] - } cleave ; - -:: (profile-node.) ( word node depth -- ) + [ + node { + [ depth>> number>string 4 CHAR: \s pad-head write bl ] + [ total-time>> duration. bl ] + [ [ gc-time>> ] [ total-time>> ] bi percentage. bl ] + [ [ jit-time>> ] [ total-time>> ] bi percentage. bl ] + [ [ foreign-time>> ] [ total-time>> ] bi percentage. bl ] + [ [ foreign-thread-time>> ] [ total-time>> ] bi percentage. bl ] + } cleave + ] with-string-writer write ; + +:: profile-node. ( word node depth -- ) node times. depth depth. word pprint-short nl - node children>> depth 1 + (profile.) ; + node children>> depth 1 + profile-depth. ; -: (profile.) ( nodes depth -- ) - [ by-total-time ] dip '[ _ (profile-node.) ] assoc-each ; +: profile-depth. ( nodes depth -- ) + [ by-total-time ] dip '[ _ profile-node. ] assoc-each ; : profile-heading. ( -- ) "depth time ms GC % JIT % FFI % FT %" print ; @@ -237,5 +239,4 @@ DEFER: (profile.) PRIVATE> : profile. ( tree -- ) - profile-heading. - [ 0 (profile-node.) ] assoc-each ; + profile-heading. [ 0 profile-node. ] assoc-each ; -- 2.34.1