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

Add --min-ticks option to get smaller profiles

parent 696572fe
...@@ -36,11 +36,13 @@ derive JSONDecode Profile, Stack ...@@ -36,11 +36,13 @@ derive JSONDecode Profile, Stack
:: Options = :: Options =
{ input :: !FilePath { input :: !FilePath
, output :: !FilePath , output :: !FilePath
, min_cumulative_ticks :: !Int
, exclude :: !'Data.Set'.Set String , exclude :: !'Data.Set'.Set String
} }
defaultOptions = defaultOptions =
{ input = "" { input = ""
, output = "" , output = ""
, min_cumulative_ticks = 0
, exclude = 'Data.Set'.newSet , exclude = 'Data.Set'.newSet
} }
...@@ -60,7 +62,7 @@ Start w ...@@ -60,7 +62,7 @@ Start w
# input = fromJSON (fromString (fromOk input)) # input = fromJSON (fromString (fromOk input))
| isNothing input | isNothing input
= exit "Could not parse input" w = 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 # (ok,f,w) = fopen args.output FWriteText w
| not ok | not ok
= exit "Could not open output file" w = exit "Could not open output file" w
...@@ -81,17 +83,27 @@ where ...@@ -81,17 +83,27 @@ where
(\e opts -> Ok {opts & exclude='Data.Set'.insert e opts.exclude}) (\e opts -> Ok {opts & exclude='Data.Set'.insert e opts.exclude})
"MODULE:FUNCTION" "MODULE:FUNCTION"
"A function to exclude (may be specified multiple times)" "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 exit err w
# (_,w) = fclose (stderr <<< err <<< '\n') w # (_,w) = fclose (stderr <<< err <<< '\n') w
= setReturnCode -1 w = setReturnCode -1 w
prepare :: !('Data.Set'.Set String) !Profile -> Profile prepare :: !Int !('Data.Set'.Set String) !Profile -> Profile
prepare excluded p = prepare min_cumulative_ticks excluded p =
{ p { p
& profile = & profile =
compute_sums_and_sort $ compute_sums_prune_and_sort min_cumulative_ticks $
lift_garbage_collector $ lift_garbage_collector $
(if ('Data.Set'.size excluded==0) id (remove_excluded_functions excluded)) (if ('Data.Set'.size excluded==0) id (remove_excluded_functions excluded))
p.profile p.profile
...@@ -136,11 +148,12 @@ where ...@@ -136,11 +148,12 @@ where
where where
is_gc s = s.file=="System" && s.function=="garbage_collector" is_gc s = s.file=="System" && s.function=="garbage_collector"
compute_sums_and_sort :: !Stack -> Stack compute_sums_prune_and_sort :: !Int !Stack -> Stack
compute_sums_and_sort s compute_sums_prune_and_sort min_cumulative_ticks s
# s & children = reverse (sort (map compute_sums_and_sort s.children)) # 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} <- 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} <- s.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 = s
instance < Stack 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