-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathflame_test.jl
119 lines (94 loc) · 3.35 KB
/
flame_test.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import Test: @test, @testset
import Profile
import Base: view
include("ProfileCanvasDiff.jl")
import .ProfileCanvasDiff
import JLD2
if isinteractive()
buildkite_cc_dir = build_path = "."
else
buildkite_number = ENV["BUILDKITE_BUILD_NUMBER"]
buildkite_cc_dir = "/central/scratch/esm/slurm-buildkite/climacoupler-ci/"
build_path = "/central/scratch/esm/slurm-buildkite/climacoupler-ci/$buildkite_number/climacoupler-ci/perf/"
end
output_dir = joinpath(buildkite_cc_dir, "test/")
mkpath(output_dir)
# dummy functions to analyze
function cumsum_sqrt(x)
y = cumsum(x)
sqrt.(y)
end
function get_y(x)
f = collect(1:1:10000) .* x
cumsum(f)
end
function step_coupler!(n, y_all = [])
for i in collect(1:1:n)
y = get_y(i)
push!(y_all, y)
end
return y_all
end
# init
step_coupler!(1)
# clear compiler allocs
Profile.clear_malloc_data()
Profile.clear()
# profile the coupling loop
prof = Profile.@profile begin
step_coupler!(100)
end
# ref file
ref_file = joinpath(output_dir, "reference.jld2")
tracked_list = isfile(ref_file) ? JLD2.load(ref_file) : Dict{String, Float64}()
# save ref file
profile_data, new_tracked_list = ProfileCanvasDiff.view(Profile.fetch(), tracked_list = tracked_list, self_count = true);
JLD2.save(ref_file, new_tracked_list) # reset ref_file upon staging
"""
find_child(flame_tree, target_name; self_count = false)
Helper function to find a particular flame tree node.
"""
function find_child(flame_tree, target_name; self_count = false)
line = flame_tree.line
file = flame_tree.file
func = flame_tree.func
node_name = "$func.$file.$line"
node_name = self_count ? "self_count_" * node_name : node_name
if node_name == target_name
global out = flame_tree
else
if !(isempty(flame_tree.children))
for sf in flame_tree.children
find_child(sf, target_name, self_count = self_count)
end
end
end
return @isdefined(out) && out
end
@testset "flame diff tests" begin
# load the dictionary of tracked counts from the reference file
tracked_list = isfile(ref_file) ? JLD2.load(ref_file) : Dict{String, Float64}()
test_func_name = "get_y.flame_test.jl.26"
# test flame diff
tracked_list["$test_func_name"] = 100 # reference value for node count with child sum
profile_data, new_tracked_list =
ProfileCanvasDiff.view(Profile.fetch(), tracked_list = tracked_list, self_count = false)
node = find_child(profile_data.data["all"], test_func_name, self_count = false)
@test node.count_change == node.count - 100
# test flame diff with self_count
tracked_list["self_count_$test_func_name"] = 50 # reference value for node count w/o child sum
profile_data, new_tracked_list =
ProfileCanvasDiff.view(Profile.fetch(), tracked_list = tracked_list, self_count = true)
node = find_child(profile_data.data["all"], test_func_name, self_count = false)
child_sum = sum(map(x -> x.count, node.children))
@test node.count_change == (node.count - child_sum) - 50
# html_file test
ProfileCanvasDiff.html_file(
joinpath(output_dir, "flame_diff.html"),
build_path = build_path,
tracked_list = tracked_list,
self_count = false,
)
@test isfile(joinpath(output_dir, "flame_diff.html"))
rm(output_dir; recursive = true, force = true)
end