Skip to content

Commit afcc376

Browse files
committed
Deserialize LinuxPerf.Counter correctly and add methods for comparing deserialization with original value
1 parent bbe262e commit afcc376

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/serialization.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function Base.convert(::Type{LinuxPerf.EventType}, d::Dict{String})
4545
end
4646
function Base.convert(::Type{LinuxPerf.Counter}, d::Dict{String})
4747
return LinuxPerf.Counter(
48-
convert(LinuxPerf.EventType, d["event"]), d["running"], d["enabled"], d["value"]
48+
convert(LinuxPerf.EventType, d["event"]), d["value"], d["enabled"], d["running"]
4949
)
5050
end
5151

@@ -181,7 +181,7 @@ function load(io::IO, args...)
181181
),
182182
)
183183
end
184-
parsed = JSON.parse(io)
184+
parsed = JSON.parse(io; dicttype=Dict)
185185
if !isa(parsed, Vector) ||
186186
length(parsed) != 2 ||
187187
!isa(parsed[1], Dict) ||

test/SerializationTests.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
module SerializationTests
22

3-
using BenchmarkTools
3+
using BenchmarkTools, LinuxPerf
44
using Test
55

66
function eq(x::T, y::T) where {T<:Union{values(BenchmarkTools.SUPPORTED_TYPES)...}}
77
return all(i -> eq(getfield(x, i), getfield(y, i)), 1:fieldcount(T))
88
end
9+
function eq(x::@NamedTuple{events::Expr, spaces::Expr, threads::Bool}, y::@NamedTuple{events::Expr, spaces::Expr, threads::Bool})
10+
x == y
11+
end
12+
function eq(x::LinuxPerf.Stats, y::LinuxPerf.Stats)
13+
all(a->eq(a[1], a[2]), zip(x.threads, y.threads))
14+
end
15+
function eq(x::LinuxPerf.ThreadStats, y::LinuxPerf.ThreadStats)
16+
x.pid == y.pid && x.groups == y.groups
17+
end
918
eq(x::T, y::T) where {T} = isapprox(x, y)
1019

1120
function withtempdir(f::Function)

0 commit comments

Comments
 (0)