Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,12 @@ WARMUP_ITRS=10 MIN_BENCH_ITRS=1 HARNESS=callgrind \
```

Setup and `WARMUP_ITRS` iterations (default: 10) run without instrumentation.
The harness then starts instrumentation, zeros counters, profiles exactly
`MIN_BENCH_ITRS` iterations (default: the benchmark's iteration hint), stops
instrumentation, and dumps stats. Unlike sampling profilers, this harness does
not use `MIN_BENCH_TIME`: even one iteration can be slow under Callgrind.
The harness then zeros counters, starts instrumentation, profiles exactly
`MIN_BENCH_ITRS` iterations (default: the benchmark's iteration hint), dumps
stats, and stops instrumentation. The dump's `summary:` and `totals:` lines
both hold the instruction count of the profiled iterations. Unlike sampling
profilers, this harness does not use `MIN_BENCH_TIME`: even one iteration can
be slow under Callgrind.
On a measured-iteration failure it still dumps a partial profile and propagates
the exception without writing results.

Expand Down
9 changes: 6 additions & 3 deletions harness/callgrind.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,23 @@ def run_benchmark(num_itrs_hint, **, &block)
warmup << get_time - start
end

name = benchmark_name
begin
Valgrind.callgrind_start_instrumentation
Valgrind.callgrind_zero_stats
Valgrind.callgrind_start_instrumentation
bench_itrs.times do
start = get_time
block.call
bench << get_time - start
end
ensure
# Preserve a partial profile on failure, but never leave instrumentation on.
# Dump before stopping so the summary line matches the totals; zero this thread so its exit dump is empty.
Valgrind.callgrind_dump_stats(name)
Valgrind.callgrind_stop_instrumentation
Valgrind.callgrind_dump_stats(benchmark_name)
Valgrind.callgrind_zero_stats
end

puts "Callgrind stats dumped for #{benchmark_name} (output controlled by --callgrind-out-file)."
puts "Callgrind stats dumped for #{name} (output controlled by --callgrind-out-file)."
return_results(warmup, bench) if ENV['RESULT_JSON_PATH']
end
10 changes: 5 additions & 5 deletions test/callgrind_harness_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,18 @@ def return_results(warmup, bench)
end

def test_profiles_hint_iterations_after_warmup
assert_equal ['stop', 'stop', 'work', 'work', 'start', 'zero',
'work', 'work', 'work', 'stop', 'dump:-e', ['results', 2, 3]], run_harness
assert_equal ['stop', 'stop', 'work', 'work', 'zero', 'start',
'work', 'work', 'work', 'dump:-e', 'stop', 'zero', ['results', 2, 3]], run_harness
end

def test_iteration_overrides_and_zero_warmup
assert_equal ['stop', 'stop', 'start', 'zero', 'work', 'stop', 'dump:-e', ['results', 0, 1]],
assert_equal ['stop', 'stop', 'zero', 'start', 'work', 'dump:-e', 'stop', 'zero', ['results', 0, 1]],
run_harness({ 'WARMUP_ITRS' => '0', 'MIN_BENCH_ITRS' => '1' })
end

def test_failure_stops_and_dumps_without_results
assert_equal ['stop', 'stop', 'work', 'work', 'start', 'zero', 'work',
'stop', 'dump:-e', 'workload failed'], run_harness({}, fail_at: 3)
assert_equal ['stop', 'stop', 'work', 'work', 'zero', 'start', 'work',
'dump:-e', 'stop', 'zero', 'workload failed'], run_harness({}, fail_at: 3)
end

def test_warmup_failure_never_starts_profiling
Expand Down
Loading