Skip to content

Commit f7d8ab4

Browse files
committed
Add serialization support for perf results
1 parent 79613d4 commit f7d8ab4

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/serialization.jl

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,31 @@ function JSON.lower(x::Union{values(SUPPORTED_TYPES)...})
2929
return [string(nameof(typeof(x))), d]
3030
end
3131

32+
# Recovers LinuxPerf.Stats from serialized form
33+
function _convert(::Type{Union{Nothing,LinuxPerf.Stats}}, d)
34+
if isnothing(d)
35+
return nothing
36+
end
37+
return LinuxPerf.Stats(_convert.(LinuxPerf.ThreadStats, d["threads"]))
38+
end
39+
function _convert(::Type{LinuxPerf.ThreadStats}, d::Dict{String})
40+
return LinuxPerf.ThreadStats(
41+
d["pid"],
42+
[
43+
[_convert(LinuxPerf.Counter, counter) for counter in group] for
44+
group in d["groups"]
45+
],
46+
)
47+
end
48+
function _convert(::Type{LinuxPerf.Counter}, d::Dict{String})
49+
return LinuxPerf.Counter(
50+
_convert(LinuxPerf.EventType, d["event"]), d["value"], d["enabled"], d["running"]
51+
)
52+
end
53+
function _convert(::Type{LinuxPerf.EventType}, d::Dict{String})
54+
return LinuxPerf.EventType(d["category"], d["event"])
55+
end
56+
3257
# a minimal 'eval' function, mirroring KeyTypes, but being slightly more lenient
3358
safeeval(@nospecialize x) = x
3459
safeeval(x::QuoteNode) = x.value
@@ -50,7 +75,9 @@ function recover(x::Vector)
5075
for i in 1:fc
5176
ft = fieldtype(T, i)
5277
fn = String(fieldname(T, i))
53-
if ft <: get(SUPPORTED_TYPES, nameof(ft), Union{})
78+
if ft == Union{Nothing,LinuxPerf.Stats}
79+
xsi = _convert(ft, fields[fn])
80+
elseif ft <: get(SUPPORTED_TYPES, nameof(ft), Union{})
5481
xsi = recover(fields[fn])
5582
else
5683
xsi = if fn == "evals_set" && !haskey(fields, fn)

0 commit comments

Comments
 (0)