Verified Commit 416012f7 authored by Camil Staps's avatar Camil Staps 🚀

Add --min-ticks option to get smaller profiles

parent 696572fe
......@@ -34,14 +34,16 @@ import qualified Text.HTML
derive JSONDecode Profile, Stack
:: Options =
{ input :: !FilePath
, output :: !FilePath
, exclude :: !'Data.Set'.Set String
{ input :: !FilePath
, output :: !FilePath
, min_cumulative_ticks :: !Int
, exclude :: !'Data.Set'.Set String
}
defaultOptions =
{ input = ""
, output = ""
, exclude = 'Data.Set'.newSet
{ input = ""
, output = ""
, min_cumulative_ticks = 0
, exclude = 'Data.Set'.newSet
}
Start w
......@@ -60,7 +62,7 @@ Start w
# input = fromJSON (fromString (fromOk input))
| isNothing input
= exit "Could not parse input" w
# input = prepare args.exclude (fromJust input)
# input = prepare args.min_cumulative_ticks args.exclude (fromJust input)
# (ok,f,w) = fopen args.output FWriteText w
| not ok
= exit "Could not open output file" w
......@@ -81,17 +83,27 @@ where
(\e opts -> Ok {opts & exclude='Data.Set'.insert e opts.exclude})
"MODULE:FUNCTION"
"A function to exclude (may be specified multiple times)"
, Option "--min-ticks"
(\t opts -> case toInt t of
0
| t=="0"
-> Ok {opts & min_cumulative_ticks=0}
-> Error [concat ["--min-ticks: invalid integer '",t,"'"]]
t
-> Ok {opts & min_cumulative_ticks=t})
"N"
"Only include cost centres with at least N ticks (cumulatively)"
]
exit err w
# (_,w) = fclose (stderr <<< err <<< '\n') w
= setReturnCode -1 w
prepare :: !('Data.Set'.Set String) !Profile -> Profile
prepare excluded p =
prepare :: !Int !('Data.Set'.Set String) !Profile -> Profile
prepare min_cumulative_ticks excluded p =
{ p
& profile =
compute_sums_and_sort $
compute_sums_prune_and_sort min_cumulative_ticks $
lift_garbage_collector $
(if ('Data.Set'.size excluded==0) id (remove_excluded_functions excluded))
p.profile
......@@ -136,11 +148,12 @@ where
where
is_gc s = s.file=="System" && s.function=="garbage_collector"
compute_sums_and_sort :: !Stack -> Stack
compute_sums_and_sort s
# s & children = reverse (sort (map compute_sums_and_sort s.children))
s & cumulative_ticks = Just (s.ticks + sum [t \\ {cumulative_ticks=Just t} <- s.children])
s & cumulative_words = Just (s.words + sum [w \\ {cumulative_words=Just w} <- s.children])
compute_sums_prune_and_sort :: !Int !Stack -> Stack
compute_sums_prune_and_sort min_cumulative_ticks s
# children = reverse (sort (map (compute_sums_prune_and_sort min_cumulative_ticks) s.children))
s & cumulative_ticks = Just (s.ticks + sum [t \\ {cumulative_ticks=Just t} <- children])
s & cumulative_words = Just (s.words + sum [w \\ {cumulative_words=Just w} <- children])
s & children = [c \\ c <- children | fromJust c.cumulative_ticks >= min_cumulative_ticks]
= s
instance < Stack
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment