Skip to content

Commit db69f00

Browse files
EtiennePerotgvisor-bot
authored andcommitted
PGO benchmarks: Only run a representative subset of benchmark tests.
Speeds up the PGO profile pipeline. PiperOrigin-RevId: 784392458
1 parent 7d654d3 commit db69f00

File tree

6 files changed

+51
-20
lines changed

6 files changed

+51
-20
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ benchmark-refresh-pgo: load-benchmarks $(RUNTIME_BIN) ## Refresh profiles of all
591591
mkdir -p "$$(dirname "$${PGO_PROFILE_OLD}")"; \
592592
mkdir -p "$${PLATFORM_TMPDIR}/$${PGO_BENCHMARK_BASENAME}"; \
593593
$(call install_runtime,$${PLATFORM}_$${PGO_RUNTIME_KEY}_pgo_$${PGO_BENCHMARK_BASENAME},--platform $${PLATFORM} --profile --profile-cpu="$${PLATFORM_TMPDIR}/$${PGO_BENCHMARK_BASENAME}/$${PGO_BENCHMARK_BASENAME}.%YYYY%-%MM%-%DD%_%HH%-%II%-%SS%-%NN%.pgo.pprof.pb.gz"); \
594-
$(call sudo,$${PGO_BENCHMARK_TARGET},-runtime=$${PLATFORM}_$${PGO_RUNTIME_KEY}_pgo_$${PGO_BENCHMARK_BASENAME} $(BENCHMARKS_ARGS_PGO)); \
594+
$(call sudo,$${PGO_BENCHMARK_TARGET},-runtime=$${PLATFORM}_$${PGO_RUNTIME_KEY}_pgo_$${PGO_BENCHMARK_BASENAME} -pgo-benchmarks=true $(BENCHMARKS_ARGS_PGO)); \
595595
$(call run,tools/profiletool,merge --out="$${PGO_PROFILE_NEW}" "$${PLATFORM_TMPDIR}/$${PGO_BENCHMARK_BASENAME}"); \
596596
rm -rf --one-file-system "$${PLATFORM_TMPDIR}/$${PGO_BENCHMARK_BASENAME}"; \
597597
if [[ ! -f "$${PGO_PROFILE_OLD}" ]]; then \

pkg/test/dockerutil/dockerutil.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ var (
4646
// config is the default Docker daemon configuration path.
4747
config = flag.String("config_path", "/etc/docker/daemon.json", "configuration file for reading paths")
4848

49+
// pgoBenchmarks is a flag that is set during PGO benchmarks.
50+
// This flag restricts the set of benchmark targets to run.
51+
pgoBenchmarks = flag.Bool("pgo-benchmarks", false, "set to true for PGO benchmarks; restricts the set of benchmark targets to run")
52+
4953
// The following flags are for the "pprof" profiler tool.
5054

5155
// pprofBaseDir allows the user to change the directory to which profiles are
@@ -173,6 +177,13 @@ func IsGVisorRuntime(ctx context.Context, t *testing.T) (bool, error) {
173177
return strings.Contains(output, "gVisor"), nil
174178
}
175179

180+
// SkipIfPGO skips the test if it is a PGO benchmark run.
181+
func SkipIfPGO[TB testing.TB](tb TB) {
182+
if *pgoBenchmarks {
183+
tb.Skip("Skipped as this is a PGO benchmark run.")
184+
}
185+
}
186+
176187
// UsingSystemdCgroup returns true if the docker configuration has the
177188
// native.cgroupdriver=systemd option set in "exec-opts", or if the
178189
// system is using cgroupv2, in which case systemd is the default driver.

test/benchmarks/database/redis_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ var operations []string = []string{
5252
// BenchmarkAllRedisOperations runs redis-benchmark against a redis instance and reports
5353
// data in queries per second. Each is reported by named operation (e.g. LPUSH).
5454
func BenchmarkAllRedisOperations(b *testing.B) {
55+
dockerutil.SkipIfPGO(b)
5556
doBenchmarkRedis(b, operations)
5657
}
5758

test/benchmarks/fs/fsbench/fsbench.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ type FSBenchmark struct {
4343
WantOutput string
4444
// CleanCmd, if set, is run to clean up between benchmarks.
4545
CleanCmd []string
46+
// EnableForPGO is whether this benchmark should be run for PGO benchmarks.
47+
EnableForPGO bool
4648
// Variants is a list of benchmark variants to run.
4749
// If unset, the typical set is used.
4850
Variants []Variant
@@ -56,6 +58,8 @@ type FSBenchmark struct {
5658
// Dimensions here are clean/dirty cache (do or don't drop caches)
5759
// and if the mount on which we are compiling is a tmpfs/bind mount.
5860
type Variant struct {
61+
// EnableForPGO is whether this variant should be run for PGO benchmarks.
62+
EnableForPGO bool
5963
// clearCache drops caches before running.
6064
clearCache bool
6165
// fsType is the type of filesystem to use.
@@ -67,8 +71,9 @@ func TypicalVariants() []Variant {
6771
variants := make([]Variant, 0, 8)
6872
for _, filesys := range []harness.FileSystemType{harness.BindFS, harness.TmpFS, harness.RootFS, harness.FuseFS} {
6973
variants = append(variants, Variant{
70-
clearCache: true,
71-
fsType: filesys,
74+
EnableForPGO: true,
75+
clearCache: true,
76+
fsType: filesys,
7277
})
7378
variants = append(variants, Variant{
7479
clearCache: false,
@@ -81,6 +86,9 @@ func TypicalVariants() []Variant {
8186
// RunWithDifferentFilesystems runs a
8287
func RunWithDifferentFilesystems(ctx context.Context, b *testing.B, machine harness.Machine, bm FSBenchmark) {
8388
b.Helper()
89+
if !bm.EnableForPGO {
90+
dockerutil.SkipIfPGO(b)
91+
}
8492

8593
benchmarkVariants := bm.Variants
8694
if len(benchmarkVariants) == 0 {
@@ -105,6 +113,9 @@ func RunWithDifferentFilesystems(ctx context.Context, b *testing.B, machine harn
105113
}
106114

107115
b.Run(name, func(b *testing.B) {
116+
if !variant.EnableForPGO {
117+
dockerutil.SkipIfPGO(b)
118+
}
108119
// Grab a container.
109120
container := machine.GetContainer(ctx, b)
110121
cu := cleanup.Make(func() {

test/benchmarks/fs/rubydev_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ func BenchmarkRubyNoOpTest(b *testing.B) {
5757
// https://github.com/fastlane/fastlane
5858
func BenchmarkRubySpecTest(b *testing.B) {
5959
runRubyBenchmark(b, fsbench.FSBenchmark{
60-
Image: "benchmarks/rubydev",
61-
WorkDir: "/fastlane",
62-
RunCmd: []string{"bash", "/files/run_fastlane_tests.sh"},
63-
WantOutput: "3613 examples, 0 failures",
60+
Image: "benchmarks/rubydev",
61+
WorkDir: "/fastlane",
62+
RunCmd: []string{"bash", "/files/run_fastlane_tests.sh"},
63+
EnableForPGO: true,
64+
WantOutput: "3613 examples, 0 failures",
6465
Callback: func(b *testing.B, output string) {
6566
loadTime, err := tools.ExtractRubyLoadTime(output)
6667
if err != nil {

test/benchmarks/network/iperf_test.go

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
)
2929

3030
func BenchmarkIperfOneConnection(b *testing.B) {
31+
dockerutil.SkipIfPGO(b)
3132
clientMachine, err := harness.GetMachine()
3233
if err != nil {
3334
b.Fatalf("failed to get machine: %v", err)
@@ -120,11 +121,12 @@ func BenchmarkIperfManyConnections(b *testing.B) {
120121
defer serverMachine.CleanUp()
121122
ctx := context.Background()
122123
for _, bm := range []struct {
123-
name string
124-
length int
125-
parallel int
126-
clientFunc func(context.Context, testutil.Logger) *dockerutil.Container
127-
serverFunc func(context.Context, testutil.Logger) *dockerutil.Container
124+
name string
125+
enableForPGO bool
126+
length int
127+
parallel int
128+
clientFunc func(context.Context, testutil.Logger) *dockerutil.Container
129+
serverFunc func(context.Context, testutil.Logger) *dockerutil.Container
128130
}{
129131
// We are either measuring the server or the client. The other should be
130132
// runc. e.g. Upload sees how fast the runtime under test uploads to a native
@@ -142,16 +144,18 @@ func BenchmarkIperfManyConnections(b *testing.B) {
142144
serverFunc: serverMachine.GetContainer,
143145
},
144146
{
145-
name: "Upload",
146-
parallel: 16,
147-
clientFunc: clientMachine.GetContainer,
148-
serverFunc: serverMachine.GetNativeContainer,
147+
name: "Upload",
148+
parallel: 16,
149+
enableForPGO: true,
150+
clientFunc: clientMachine.GetContainer,
151+
serverFunc: serverMachine.GetNativeContainer,
149152
},
150153
{
151-
name: "Download",
152-
parallel: 16,
153-
clientFunc: clientMachine.GetNativeContainer,
154-
serverFunc: serverMachine.GetContainer,
154+
name: "Download",
155+
parallel: 16,
156+
enableForPGO: true,
157+
clientFunc: clientMachine.GetNativeContainer,
158+
serverFunc: serverMachine.GetContainer,
155159
},
156160
{
157161
name: "Upload",
@@ -177,6 +181,9 @@ func BenchmarkIperfManyConnections(b *testing.B) {
177181
b.Fatalf("Failed to parse parameters: %v", err)
178182
}
179183
b.Run(name, func(b *testing.B) {
184+
if !bm.enableForPGO {
185+
dockerutil.SkipIfPGO(b)
186+
}
180187
// Set up the containers.
181188
server := bm.serverFunc(ctx, b)
182189
defer server.CleanUp(ctx)

0 commit comments

Comments
 (0)