Skip to content

Commit 7557257

Browse files
committed
Add copy for LinuxPerf.Stats and include perf stats when indexing into Trials
1 parent 36a15d9 commit 7557257

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

src/trials.jl

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22
# Trial #
33
#########
44

5+
# Move into LinuxPerf.jl
6+
Base.copy(stats::LinuxPerf.Stats) = LinuxPerf.Stats(copy(stats.threads))
7+
function Base.copy(thread_stats::LinuxPerf.ThreadStats)
8+
return LinuxPerf.ThreadStats(thread_stats.pid, copy(thread_stats.groups))
9+
end
10+
function Base.copy(counter::LinuxPerf.Counter)
11+
return LinuxPerf.Counter(
12+
copy(counter.event), counter.value, counter.enabled, counter.running
13+
)
14+
end
15+
Base.copy(event::LinuxPerf.EventType) = LinuxPerf.EventType(event.category, event.event)
16+
517
mutable struct Trial
618
params::Parameters
719
times::Vector{Float64}
@@ -40,7 +52,7 @@ function Base.copy(t::Trial)
4052
copy(t.gctimes),
4153
t.memory,
4254
t.allocs,
43-
nothing, # There is no copy method for LinuxPerf.Stats or LinuxPerf.ThreadStats
55+
isnothing(t.linux_perf_stats) ? nothing : copy(t.linux_perf_stats),
4456
)
4557
end
4658

@@ -68,12 +80,18 @@ function Base.getindex(t::Trial, i::Number)
6880
return push!(
6981
Trial(t.params),
7082
TrialContents(
71-
t.times[i], t.gctimes[i], t.memory, t.allocs, nothing, nothing, nothing
83+
t.times[i],
84+
t.gctimes[i],
85+
t.memory,
86+
t.allocs,
87+
nothing,
88+
nothing,
89+
t.linux_perf_stats,
7290
),
7391
)
7492
end
7593
function Base.getindex(t::Trial, i)
76-
return Trial(t.params, t.times[i], t.gctimes[i], t.memory, t.allocs, nothing)
94+
return Trial(t.params, t.times[i], t.gctimes[i], t.memory, t.allocs, t.linux_perf_stats)
7795
end
7896
Base.lastindex(t::Trial) = length(t)
7997

@@ -145,11 +163,18 @@ function Base.:(==)(a::TrialEstimate, b::TrialEstimate)
145163
a.time == b.time &&
146164
a.gctime == b.gctime &&
147165
a.memory == b.memory &&
148-
a.allocs == b.allocs
166+
a.allocs == b.allocs
149167
end
150168

151169
function Base.copy(t::TrialEstimate)
152-
return TrialEstimate(copy(t.params), t.time, t.gctime, t.memory, t.allocs, t.linux_perf_stats) # TODO: copy linux_perf_stats
170+
return TrialEstimate(
171+
copy(t.params),
172+
t.time,
173+
t.gctime,
174+
t.memory,
175+
t.allocs,
176+
isnothing(t.linux_perf_stats) ? nothing : copy(t.linux_perf_stats),
177+
)
153178
end
154179

155180
function Base.minimum(trial::Trial)

0 commit comments

Comments
 (0)