forked from MakieOrg/Makie.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
collect_metrics.jl
142 lines (116 loc) · 4 KB
/
collect_metrics.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using Pkg
Pkg.activate("./metrics")
Pkg.instantiate()
using CSV
using DataFrames
using Distributed
using Dates
metric_target_raw = get(ENV, "METRIC_TARGET", "")
if isempty(metric_target_raw)
error("No metric target set.")
end
run(`git fetch`)
metric_targets = if startswith(metric_target_raw, "regex ")
# a workflow_dispatch input of "regex some_regex" matches tags against some_regex
tags = strip.(split(read(`git tag`, String)))
regex = match(r"regex (.*)", metric_target_raw)[1] |> strip
r = Regex(regex)
ts = filter(x -> !isnothing(match(r, x)), tags)
@info "available tags: $tags"
if isempty(ts)
error("No metric targets found with regex: $r")
end
ts
else
[metric_target_raw]
end
@info "metric targets: $metric_targets"
results = DataFrame()
# one vector of code parts for every file in metrics folder
parts_vectors = map(readdir(joinpath("metrics", "metrics"), join = true)) do file
code = read(file, String)
parts = split(code, r"^(?=## )"m, keepempty = false)
end
for metric_target in metric_targets
@info "checking out metric target $metric_target"
run(`git checkout $metric_target --`)
makieversion = match(r"version = \"(.*?)\"", read("Project.toml", String))[1]
glmakieversion = match(r"version = \"(.*?)\"", read("GLMakie/Project.toml", String))[1]
cairomakieversion = match(r"version = \"(.*?)\"", read("CairoMakie/Project.toml", String))[1]
commit_date = DateTime(
strip(String(read(`git show -s --format=%ci`)))[1:end-6],
"yyyy-mm-dd HH:MM:SS")
df = DataFrame()
date = now()
for parts in parts_vectors
local i_proc
try
i_proc = addprocs(1)[1]
@everywhere i_proc begin
using Pkg
end
@everywhere i_proc begin
pkg"activate --temp"
pkg"dev . MakieCore GLMakie CairoMakie"
Pkg.precompile()
@timed begin end
end
for part in parts
partname = match(r"^## (.*)", part)[1] |> strip
@info "executing part: $partname"
partcode = """
@timed begin
$part
nothing
end
"""
timing = remotecall_fetch(i_proc, partcode) do p
include_string(Main, p)
end
push!(df, (
date = date,
commit_date = commit_date,
metric_target = metric_target,
juliaversion = string(Sys.VERSION),
makie = makieversion,
glmakie = glmakieversion,
cairomakie = cairomakieversion,
name = partname,
time = timing.time,
allocations = timing.bytes,
gc_time = timing.gctime,
))
end
finally
rmprocs(i_proc)
end
end
append!(results, df, cols = :union)
end
branch_name = "metrics"
remote_branch = "origin/metrics"
run(`git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"`)
run(`git config --global user.name "github-actions[bot]"`)
@info "Checking out $branch_name."
if !success(`git checkout -b $branch_name $remote_branch`)
@info "branch $branch_name doesn't exist, creating new orphan branch"
run(`git checkout --orphan $branch_name --`)
run(`git rm -rf .`)
end
println("\nFiles in working directory:")
run(`ls`)
filename = "compilation_latencies.csv"
df = if !isfile(filename)
@info "$filename doesn't exist, creating empty DataFrame."
DataFrame()
else
@info "Loading DataFrame from $filename."
CSV.read(filename, DataFrame)
end
append!(df, results, cols = :union)
sort!(df, :commit_date)
@info "Writing out DataFrame to $filename."
CSV.write(filename, df)
run(`git add $filename`)
run(`git commit -m "update metrics"`)
run(`git push origin $branch_name`)