Verified Commit d48653a4 authored by Camil Staps's avatar Camil Staps 🚀

Add --min-words option

parent 103666ab
...@@ -40,8 +40,10 @@ read_profile :: !*File -> (!MaybeError String Profile, !*File) ...@@ -40,8 +40,10 @@ read_profile :: !*File -> (!MaybeError String Profile, !*File)
* - Prune small subtrees (based on minimum cumulative ticks). * - Prune small subtrees (based on minimum cumulative ticks).
* - Correct for estimated profiling overhead. * - Correct for estimated profiling overhead.
* *
* @param Minimum number of (cumulative ticks). Cost centres with fewer ticks * @param Minimum number of (cumulative) ticks. Cost centres with fewer ticks
* will be pruned from the tree.
* @param Minimum number of (cumulative) words. Cost centres with fewer words
* will be pruned from the tree. * will be pruned from the tree.
* @param Functions to exclude, in the format MODULE:FUNCTION. * @param Functions to exclude, in the format MODULE:FUNCTION.
*/ */
prepare :: !Int !(Set String) !Profile -> Profile prepare :: !Int !Int !(Set String) !Profile -> Profile
...@@ -128,11 +128,11 @@ where ...@@ -128,11 +128,11 @@ where
= (True,i,f) = (True,i,f)
= read i (sft+7) f = read i (sft+7) f
prepare :: !Int !('Data.Set'.Set String) !Profile -> Profile prepare :: !Int !Int !('Data.Set'.Set String) !Profile -> Profile
prepare min_cumulative_ticks excluded p = prepare min_cumulative_ticks min_cumulative_words excluded p =
{ p { p
& profile = & profile =
compute_sums_prune_and_sort (fromMaybe -1 gc_id) min_cumulative_ticks p.overhead_per_1000_calls $ compute_sums_prune_and_sort (fromMaybe -1 gc_id) min_cumulative_ticks min_cumulative_words p.overhead_per_1000_calls $
(case gc_id of (case gc_id of
Nothing -> id Nothing -> id
Just id -> lift_garbage_collector id) $ Just id -> lift_garbage_collector id) $
...@@ -192,13 +192,17 @@ where ...@@ -192,13 +192,17 @@ where
# (children,counts) = mapSt (\c (ts,cs) -> walk c ts cs) s.children (ticks,calls) # (children,counts) = mapSt (\c (ts,cs) -> walk c ts cs) s.children (ticks,calls)
= ({s & children=[c \\ c <- children | c.cost_centre <> cost_centre_id]}, counts) = ({s & children=[c \\ c <- children | c.cost_centre <> cost_centre_id]}, counts)
compute_sums_prune_and_sort :: !Int !Int !Int !ProfileStack -> ProfileStack compute_sums_prune_and_sort :: !Int !Int !Int !Int !ProfileStack -> ProfileStack
compute_sums_prune_and_sort gc_id min_cumulative_ticks overhead_per_1000_calls s compute_sums_prune_and_sort gc_id min_cumulative_ticks min_cumulative_words overhead_per_1000_calls s
# children = reverse (sort [compute_sums_prune_and_sort gc_id min_cumulative_ticks overhead_per_1000_calls c \\ c <- s.children]) # children = reverse (sort [compute_sums_prune_and_sort gc_id min_cumulative_ticks min_cumulative_words overhead_per_1000_calls c \\ c <- s.children])
s & ticks = max 0 (s.ticks - (s.profiler_calls * overhead_per_1000_calls) / 1000) s & ticks = max 0 (s.ticks - (s.profiler_calls * overhead_per_1000_calls) / 1000)
s & cumulative_ticks = s.ticks + sum [c.cumulative_ticks \\ c <- children] s & cumulative_ticks = s.ticks + sum [c.cumulative_ticks \\ c <- children]
s & cumulative_words = s.words + sum [c.cumulative_words \\ c <- children] s & cumulative_words = s.words + sum [c.cumulative_words \\ c <- children]
s & children = [c \\ c <- children | c.cumulative_ticks >= min_cumulative_ticks || c.cost_centre==gc_id] # s & children =
[ c \\ c <- children
| c.cumulative_ticks >= min_cumulative_ticks && c.cumulative_words >= min_cumulative_words
|| c.cost_centre==gc_id
]
= s = s
instance < ProfileStack where < a b = a.cumulative_ticks < b.cumulative_ticks instance < ProfileStack where (<) a b = a.cumulative_ticks < b.cumulative_ticks
...@@ -17,12 +17,14 @@ import PGCL ...@@ -17,12 +17,14 @@ import PGCL
{ input :: !FilePath { input :: !FilePath
, output :: !FilePath , output :: !FilePath
, min_cumulative_ticks :: !Int , min_cumulative_ticks :: !Int
, min_cumulative_words :: !Int
, exclude :: !'Data.Set'.Set String , exclude :: !'Data.Set'.Set String
} }
defaultOptions = defaultOptions =
{ input = "" { input = ""
, output = "" , output = ""
, min_cumulative_ticks = 0 , min_cumulative_ticks = 0
, min_cumulative_words = 0
, exclude = 'Data.Set'.newSet , exclude = 'Data.Set'.newSet
} }
...@@ -44,7 +46,7 @@ Start w ...@@ -44,7 +46,7 @@ Start w
# (_,w) = fclose input w # (_,w) = fclose input w
| isError profile | isError profile
= exit ("Could not parse input: "+++fromError profile) w = exit ("Could not parse input: "+++fromError profile) w
# profile = prepare args.min_cumulative_ticks args.exclude (fromOk profile) # profile = prepare args.min_cumulative_ticks args.min_cumulative_words args.exclude (fromOk profile)
# costs = compute_aggregate_costs profile # costs = compute_aggregate_costs profile
# calls = compute_call_matrix profile # calls = compute_call_matrix profile
# (ok,f,w) = fopen args.output FWriteText w # (ok,f,w) = fopen args.output FWriteText w
...@@ -79,6 +81,16 @@ where ...@@ -79,6 +81,16 @@ where
-> Ok {opts & min_cumulative_ticks=t}) -> Ok {opts & min_cumulative_ticks=t})
"N" "N"
"Only include cost centres with at least N ticks (cumulatively)" "Only include cost centres with at least N ticks (cumulatively)"
, Option "--min-words"
(\t opts -> case toInt t of
0
| t=="0"
-> Ok {opts & min_cumulative_words=0}
-> Error [concat ["--min-words: invalid integer '",t,"'"]]
t
-> Ok {opts & min_cumulative_words=t})
"N"
"Only include cost centres with at least N words (cumulatively)"
, Operand , Operand
False False
(\ip opts (\ip opts
......
...@@ -22,12 +22,14 @@ import PGCL ...@@ -22,12 +22,14 @@ import PGCL
{ input :: !FilePath { input :: !FilePath
, output :: !FilePath , output :: !FilePath
, min_cumulative_ticks :: !Int , min_cumulative_ticks :: !Int
, min_cumulative_words :: !Int
, exclude :: !'Data.Set'.Set String , exclude :: !'Data.Set'.Set String
} }
defaultOptions = defaultOptions =
{ input = "" { input = ""
, output = "" , output = ""
, min_cumulative_ticks = 0 , min_cumulative_ticks = 0
, min_cumulative_words = 0
, exclude = 'Data.Set'.newSet , exclude = 'Data.Set'.newSet
} }
...@@ -49,7 +51,7 @@ Start w ...@@ -49,7 +51,7 @@ Start w
# (_,w) = fclose input w # (_,w) = fclose input w
| isError profile | isError profile
= exit ("Could not parse input: "+++fromError profile) w = exit ("Could not parse input: "+++fromError profile) w
# profile = prepare args.min_cumulative_ticks args.exclude (fromOk profile) # profile = prepare args.min_cumulative_ticks args.min_cumulative_words args.exclude (fromOk profile)
# (css,w) = readFile (exec_directory </> "profile.css") w # (css,w) = readFile (exec_directory </> "profile.css") w
| isError css | isError css
= exit ("Could not open supporting CSS: "+++toString (fromError css)) w = exit ("Could not open supporting CSS: "+++toString (fromError css)) w
...@@ -91,6 +93,16 @@ where ...@@ -91,6 +93,16 @@ where
-> Ok {opts & min_cumulative_ticks=t}) -> Ok {opts & min_cumulative_ticks=t})
"N" "N"
"Only include cost centres with at least N ticks (cumulatively)" "Only include cost centres with at least N ticks (cumulatively)"
, Option "--min-words"
(\t opts -> case toInt t of
0
| t=="0"
-> Ok {opts & min_cumulative_words=0}
-> Error [concat ["--min-words: invalid integer '",t,"'"]]
t
-> Ok {opts & min_cumulative_words=t})
"N"
"Only include cost centres with at least N words (cumulatively)"
, Operand , Operand
False False
(\ip opts (\ip opts
......
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