Verified Commit 2c5c2eb8 authored by Camil Staps's avatar Camil Staps 🚀

Read profiles up to version 2; correct for estimated overhead

parent 395c2ef4
......@@ -7,6 +7,8 @@ from Data.Set import :: Set
{ modules :: !.{#String}
, cost_centres :: !.{#CostCentre}
, profile :: !ProfileStack
, overhead_per_1000_calls :: !Int
, cpu_frequency :: !Int
}
:: CostCentre =
......@@ -30,4 +32,16 @@ from Data.Set import :: Set
read_profile :: !*File -> (!MaybeError String Profile, !*File)
/**
* Perform a number of analyses on a raw profile:
* - Remove excluded functions.
* - Lift all garbage collector entries to the top level.
* - Compute aggregates `cumulative_ticks` and `cumulative_words`.
* - Prune small subtrees (based on minimum cumulative ticks).
* - Correct for estimated profiling overhead.
*
* @param Minimum number of (cumulative ticks). Cost centres with fewer ticks
* will be pruned from the tree.
* @param Functions to exclude, in the format MODULE:FUNCTION.
*/
prepare :: !Int !(Set String) !Profile -> Profile
......@@ -15,11 +15,15 @@ read_profile f
| header <> "prof" = (Error "invalid header",f)
# (ok,version,f) = freadi f
| not ok = (unexpected_eof,f)
| version <> 1 = (Error "invalid version number",f)
| version <> 1 && version <> 2 = (Error "invalid version number",f)
# (ok,n_modules,f) = freadi f
| not ok = (unexpected_eof,f)
# (ok,n_cost_centres,f) = freadi f
| not ok = (unexpected_eof,f)
# (ok,cpu_frequency,f) = if (version<2) (True,0,f) (read_var_width_int f)
| not ok = (unexpected_eof,f)
# (ok,overhead_per_1000_calls,f) = if (version<2) (True,0,f) (read_var_width_int f)
| not ok = (unexpected_eof,f)
# (modules,f) = read_modules 0 n_modules (unsafeCreateArray n_modules) f
| isError modules = (Error (fromError modules),f)
# (cost_centres,f) = read_cost_centres 0 n_cost_centres (unsafeCreateArray n_cost_centres) f
......@@ -32,6 +36,8 @@ read_profile f
{ modules = fromOk modules
, cost_centres = fromOk cost_centres
, profile = fromOk profile
, overhead_per_1000_calls = overhead_per_1000_calls
, cpu_frequency = cpu_frequency
}
= (Ok profile,f)
where
......@@ -126,7 +132,7 @@ prepare :: !Int !('Data.Set'.Set String) !Profile -> Profile
prepare min_cumulative_ticks excluded p =
{ p
& profile =
compute_sums_prune_and_sort (fromMaybe -1 gc_id) min_cumulative_ticks $
compute_sums_prune_and_sort (fromMaybe -1 gc_id) min_cumulative_ticks p.overhead_per_1000_calls $
(case gc_id of
Nothing -> id
Just id -> lift_garbage_collector id) $
......@@ -186,9 +192,10 @@ where
# (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)
compute_sums_prune_and_sort :: !Int !Int !ProfileStack -> ProfileStack
compute_sums_prune_and_sort gc_id min_cumulative_ticks s
# children = reverse (sort [compute_sums_prune_and_sort gc_id min_cumulative_ticks c \\ c <- s.children])
compute_sums_prune_and_sort :: !Int !Int !Int !ProfileStack -> ProfileStack
compute_sums_prune_and_sort gc_id min_cumulative_ticks 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])
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_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]
......
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