1 ! Copyright (C) 2024 John Benediktsson
2 ! See https://factorcode.org/license.txt for BSD license
4 USING: accessors arrays assocs io io.encodings.utf8 io.files
5 io.files.temp io.launcher io.pathnames kernel math math.parser
6 prettyprint sequences tools.profiler.sampling ;
12 :: write-flamegraph-node ( word node depth -- )
13 depth word unparse-short suffix [
14 ";" join write bl node total-time>> 1000 *
15 >integer number>string print
18 '[ _ write-flamegraph-node ] assoc-each
21 : write-flamegraph ( -- )
22 top-down >alist first second children>>
23 [ { } write-flamegraph-node ] assoc-each ;
28 "output.txt" temp-file
29 [ utf8 [ flamegraph. ] with-file-writer ]
30 [ "vocab:flamegraph/flamegraph.pl" absolute-path swap 2array process-contents ] bi
31 "output.svg" temp-file
32 [ utf8 set-file-contents ]
33 [ { "open" "-a" "Safari" } swap suffix try-process ] bi ;