Skip to content

Commit f9147a3

Browse files
committed
Document how to use the perf(1) harness
1 parent 9c0843d commit f9147a3

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

harness-perf/harness.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
require_relative "../harness/harness-common"
1+
# frozen_string_literal: true
2+
#
3+
# This is a relatively minimal harness meant for use with Linux perf(1).
4+
# Example usage:
5+
#
6+
# $ PERF='record -e cycles' ruby -Iharness-perf benchmarks/fib.rb
7+
#
8+
# When recording with perf(1), make sure the benchmark runs long enough; you
9+
# can tweak the MIN_BENCH_ITRS environment variable to lengthen the run. A race
10+
# condition is possible where the benchmark finishes before the perf(1)
11+
# subprocess has a chance to attach, in which case perf outputs no profile.
212

3-
# This harness is meant for use with perf stat
4-
# All it does is run the benchmark a number of times
13+
require_relative "../harness/harness-common"
514

615
# Takes a block as input
716
def run_benchmark(num_itrs_hint)
@@ -23,6 +32,9 @@ def run_benchmark(num_itrs_hint)
2332
cmd.push('-o', File.expand_path('../perf.data', __dir__))
2433
end
2534
pid = Process.spawn(*cmd)
35+
# _Race_: we, the parent process might finish before perf attaches.
36+
# Ideally, we would wait for attachment before running benchmark
37+
# iterations, but implementing that seems complicated.
2638
end
2739

2840
# Run benchmark

0 commit comments

Comments
 (0)