Skip to content

Commit 94a0f98

Browse files
committed
Add some copy methods and convert for deserialization.
This is useful for JuliaCI/BenchmarkTools.jl#347
1 parent 9239953 commit 94a0f98

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/LinuxPerf.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ struct EventType
118118
event::UInt64
119119
end
120120

121+
Base.copy(event::EventType) = EventType(event.category, event.event)
122+
123+
function Base.convert(::Type{EventType}, d::Dict{String})
124+
return EventType(d["category"], d["event"])
125+
end
126+
121127
function all_events()
122128
evts = EventType[]
123129
for (cat_name, cat_id, events) in EVENT_TYPES
@@ -356,6 +362,18 @@ struct Counter
356362
running::UInt64
357363
end
358364

365+
function Base.copy(counter::Counter)
366+
return Counter(
367+
copy(counter.event), counter.value, counter.enabled, counter.running
368+
)
369+
end
370+
371+
function Base.convert(::Type{Counter}, d::Dict{String})
372+
return Counter(
373+
convert(EventType, d["event"]), d["value"], d["enabled"], d["running"]
374+
)
375+
end
376+
359377
struct Counters
360378
counters::Vector{Counter}
361379
end
@@ -734,6 +752,14 @@ struct ThreadStats
734752
groups::Vector{Vector{Counter}}
735753
end
736754

755+
function Base.copy(thread_stats::ThreadStats)
756+
return ThreadStats(thread_stats.pid, copy(thread_stats.groups))
757+
end
758+
759+
function Base.convert(::Type{ThreadStats}, d::Dict{String})
760+
return ThreadStats(d["pid"], d["groups"])
761+
end
762+
737763
function ThreadStats(b::PerfBench)
738764
groups = Vector{Counter}[]
739765
for g in b.groups
@@ -775,6 +801,10 @@ struct Stats
775801
threads::Vector{ThreadStats}
776802
end
777803

804+
Base.copy(stats::Stats) = Stats(copy(stats.threads))
805+
806+
Base.convert(::Type{Stats}, d::Dict{String}) = Stats(d["threads"])
807+
778808
Stats(b::PerfBenchThreaded) = Stats(map(ThreadStats, b.data))
779809

780810
Base.show(io::IO, stats::Stats) = printsummary(io, stats)

0 commit comments

Comments
 (0)