Add some initial benchmarking for bp2build.
Test: go test -benchmark=. in bp2build directory Change-Id: I8275c38461078cc6100fbc89837177de0edc9d68
This commit is contained in:
@@ -39,6 +39,7 @@ bootstrap_go_package {
|
|||||||
"cc_library_static_conversion_test.go",
|
"cc_library_static_conversion_test.go",
|
||||||
"cc_object_conversion_test.go",
|
"cc_object_conversion_test.go",
|
||||||
"conversion_test.go",
|
"conversion_test.go",
|
||||||
|
"performance_test.go",
|
||||||
"prebuilt_etc_conversion_test.go",
|
"prebuilt_etc_conversion_test.go",
|
||||||
"python_binary_conversion_test.go",
|
"python_binary_conversion_test.go",
|
||||||
"sh_conversion_test.go",
|
"sh_conversion_test.go",
|
||||||
|
@@ -334,9 +334,7 @@ custom {
|
|||||||
config := android.TestConfig(buildDir, nil, testCase.bp, nil)
|
config := android.TestConfig(buildDir, nil, testCase.bp, nil)
|
||||||
ctx := android.NewTestContext(config)
|
ctx := android.NewTestContext(config)
|
||||||
|
|
||||||
ctx.RegisterModuleType("custom", customModuleFactory)
|
registerCustomModuleForBp2buildConversion(ctx)
|
||||||
ctx.RegisterBp2BuildMutator("custom", customBp2BuildMutator)
|
|
||||||
ctx.RegisterForBazelConversion()
|
|
||||||
|
|
||||||
_, errs := ctx.ParseFileList(dir, []string{"Android.bp"})
|
_, errs := ctx.ParseFileList(dir, []string{"Android.bp"})
|
||||||
if errored(t, "", errs) {
|
if errored(t, "", errs) {
|
||||||
|
@@ -85,6 +85,7 @@ custom = rule(
|
|||||||
"soong_module_variant": attr.string(),
|
"soong_module_variant": attr.string(),
|
||||||
"soong_module_deps": attr.label_list(providers = [SoongModuleInfo]),
|
"soong_module_deps": attr.label_list(providers = [SoongModuleInfo]),
|
||||||
"arch_paths": attr.string_list(),
|
"arch_paths": attr.string_list(),
|
||||||
|
"arch_paths_exclude": attr.string_list(),
|
||||||
# bazel_module start
|
# bazel_module start
|
||||||
# "label": attr.string(),
|
# "label": attr.string(),
|
||||||
# "bp2build_available": attr.bool(),
|
# "bp2build_available": attr.bool(),
|
||||||
@@ -114,6 +115,7 @@ custom_defaults = rule(
|
|||||||
"soong_module_variant": attr.string(),
|
"soong_module_variant": attr.string(),
|
||||||
"soong_module_deps": attr.label_list(providers = [SoongModuleInfo]),
|
"soong_module_deps": attr.label_list(providers = [SoongModuleInfo]),
|
||||||
"arch_paths": attr.string_list(),
|
"arch_paths": attr.string_list(),
|
||||||
|
"arch_paths_exclude": attr.string_list(),
|
||||||
"bool_prop": attr.bool(),
|
"bool_prop": attr.bool(),
|
||||||
"bool_ptr_prop": attr.bool(),
|
"bool_ptr_prop": attr.bool(),
|
||||||
"int64_ptr_prop": attr.int(),
|
"int64_ptr_prop": attr.int(),
|
||||||
@@ -139,6 +141,7 @@ custom_test_ = rule(
|
|||||||
"soong_module_variant": attr.string(),
|
"soong_module_variant": attr.string(),
|
||||||
"soong_module_deps": attr.label_list(providers = [SoongModuleInfo]),
|
"soong_module_deps": attr.label_list(providers = [SoongModuleInfo]),
|
||||||
"arch_paths": attr.string_list(),
|
"arch_paths": attr.string_list(),
|
||||||
|
"arch_paths_exclude": attr.string_list(),
|
||||||
"bool_prop": attr.bool(),
|
"bool_prop": attr.bool(),
|
||||||
"bool_ptr_prop": attr.bool(),
|
"bool_ptr_prop": attr.bool(),
|
||||||
"int64_ptr_prop": attr.int(),
|
"int64_ptr_prop": attr.int(),
|
||||||
|
175
bp2build/performance_test.go
Normal file
175
bp2build/performance_test.go
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
// Copyright 2021 Google Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package bp2build
|
||||||
|
|
||||||
|
// to run the benchmarks in this file, you must run go test with the -bench.
|
||||||
|
// The benchmarked portion will run for the specified time (can be set via -benchtime)
|
||||||
|
// This can mean if you are benchmarking a faster portion of a larger operation, it will take
|
||||||
|
// longer.
|
||||||
|
// If you are seeing a small number of iterations for a specific run, the data is less reliable, to
|
||||||
|
// run for longer, set -benchtime to a larger value.
|
||||||
|
|
||||||
|
import (
|
||||||
|
"android/soong/android"
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func genCustomModule(i int, convert bool) string {
|
||||||
|
var conversionString string
|
||||||
|
if convert {
|
||||||
|
conversionString = `bazel_module: { bp2build_available: true },`
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
custom {
|
||||||
|
name: "arch_paths_%[1]d",
|
||||||
|
string_list_prop: ["\t", "\n"],
|
||||||
|
string_prop: "a\t\n\r",
|
||||||
|
arch_paths: ["outer", ":outer_dep_%[1]d"],
|
||||||
|
arch: {
|
||||||
|
x86: {
|
||||||
|
arch_paths: ["abc", ":x86_dep_%[1]d"],
|
||||||
|
},
|
||||||
|
x86_64: {
|
||||||
|
arch_paths: ["64bit"],
|
||||||
|
arch_paths_exclude: ["outer"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
%[2]s
|
||||||
|
}
|
||||||
|
|
||||||
|
custom {
|
||||||
|
name: "outer_dep_%[1]d",
|
||||||
|
%[2]s
|
||||||
|
}
|
||||||
|
|
||||||
|
custom {
|
||||||
|
name: "x86_dep_%[1]d",
|
||||||
|
%[2]s
|
||||||
|
}
|
||||||
|
`, i, conversionString)
|
||||||
|
}
|
||||||
|
|
||||||
|
func genCustomModuleBp(pctConverted float64) string {
|
||||||
|
modules := 100
|
||||||
|
|
||||||
|
bp := make([]string, 0, modules)
|
||||||
|
toConvert := int(math.Round(float64(modules) * pctConverted))
|
||||||
|
|
||||||
|
for i := 0; i < modules; i++ {
|
||||||
|
bp = append(bp, genCustomModule(i, i < toConvert))
|
||||||
|
}
|
||||||
|
return strings.Join(bp, "\n\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
var pctToConvert = []float64{0.0, 0.01, 0.05, 0.10, 0.25, 0.5, 0.75, 1.0}
|
||||||
|
|
||||||
|
func BenchmarkManyModulesFull(b *testing.B) {
|
||||||
|
dir := "."
|
||||||
|
for _, tcSize := range pctToConvert {
|
||||||
|
|
||||||
|
b.Run(fmt.Sprintf("pctConverted %f", tcSize), func(b *testing.B) {
|
||||||
|
for n := 0; n < b.N; n++ {
|
||||||
|
b.StopTimer()
|
||||||
|
// setup we don't want to measure
|
||||||
|
config := android.TestConfig(buildDir, nil, genCustomModuleBp(tcSize), nil)
|
||||||
|
ctx := android.NewTestContext(config)
|
||||||
|
|
||||||
|
registerCustomModuleForBp2buildConversion(ctx)
|
||||||
|
codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
|
||||||
|
|
||||||
|
b.StartTimer()
|
||||||
|
_, errs := ctx.ParseFileList(dir, []string{"Android.bp"})
|
||||||
|
if len(errs) > 0 {
|
||||||
|
b.Fatalf("Unexpected errors: %s", errs)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, errs = ctx.ResolveDependencies(config)
|
||||||
|
if len(errs) > 0 {
|
||||||
|
b.Fatalf("Unexpected errors: %s", errs)
|
||||||
|
}
|
||||||
|
|
||||||
|
generateBazelTargetsForDir(codegenCtx, dir)
|
||||||
|
b.StopTimer()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkManyModulesResolveDependencies(b *testing.B) {
|
||||||
|
dir := "."
|
||||||
|
for _, tcSize := range pctToConvert {
|
||||||
|
|
||||||
|
b.Run(fmt.Sprintf("pctConverted %f", tcSize), func(b *testing.B) {
|
||||||
|
for n := 0; n < b.N; n++ {
|
||||||
|
b.StopTimer()
|
||||||
|
// setup we don't want to measure
|
||||||
|
config := android.TestConfig(buildDir, nil, genCustomModuleBp(tcSize), nil)
|
||||||
|
ctx := android.NewTestContext(config)
|
||||||
|
|
||||||
|
registerCustomModuleForBp2buildConversion(ctx)
|
||||||
|
codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
|
||||||
|
|
||||||
|
_, errs := ctx.ParseFileList(dir, []string{"Android.bp"})
|
||||||
|
if len(errs) > 0 {
|
||||||
|
b.Fatalf("Unexpected errors: %s", errs)
|
||||||
|
}
|
||||||
|
|
||||||
|
b.StartTimer()
|
||||||
|
_, errs = ctx.ResolveDependencies(config)
|
||||||
|
b.StopTimer()
|
||||||
|
if len(errs) > 0 {
|
||||||
|
b.Fatalf("Unexpected errors: %s", errs)
|
||||||
|
}
|
||||||
|
|
||||||
|
generateBazelTargetsForDir(codegenCtx, dir)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkManyModulesGenerateBazelTargetsForDir(b *testing.B) {
|
||||||
|
dir := "."
|
||||||
|
for _, tcSize := range pctToConvert {
|
||||||
|
|
||||||
|
b.Run(fmt.Sprintf("pctConverted %f", tcSize), func(b *testing.B) {
|
||||||
|
for n := 0; n < b.N; n++ {
|
||||||
|
b.StopTimer()
|
||||||
|
// setup we don't want to measure
|
||||||
|
config := android.TestConfig(buildDir, nil, genCustomModuleBp(tcSize), nil)
|
||||||
|
ctx := android.NewTestContext(config)
|
||||||
|
|
||||||
|
registerCustomModuleForBp2buildConversion(ctx)
|
||||||
|
codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
|
||||||
|
|
||||||
|
_, errs := ctx.ParseFileList(dir, []string{"Android.bp"})
|
||||||
|
if len(errs) > 0 {
|
||||||
|
b.Fatalf("Unexpected errors: %s", errs)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, errs = ctx.ResolveDependencies(config)
|
||||||
|
if len(errs) > 0 {
|
||||||
|
b.Fatalf("Unexpected errors: %s", errs)
|
||||||
|
}
|
||||||
|
|
||||||
|
b.StartTimer()
|
||||||
|
generateBazelTargetsForDir(codegenCtx, dir)
|
||||||
|
b.StopTimer()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@@ -33,7 +33,8 @@ type customProps struct {
|
|||||||
Nested_props nestedProps
|
Nested_props nestedProps
|
||||||
Nested_props_ptr *nestedProps
|
Nested_props_ptr *nestedProps
|
||||||
|
|
||||||
Arch_paths []string `android:"path,arch_variant"`
|
Arch_paths []string `android:"path,arch_variant"`
|
||||||
|
Arch_paths_exclude []string `android:"path,arch_variant"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type customModule struct {
|
type customModule struct {
|
||||||
@@ -155,16 +156,18 @@ func customBp2BuildMutator(ctx android.TopDownMutatorContext) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
paths := bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, m.props.Arch_paths))
|
paths := bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrcExcludes(ctx, m.props.Arch_paths, m.props.Arch_paths_exclude))
|
||||||
|
|
||||||
for axis, configToProps := range m.GetArchVariantProperties(ctx, &customProps{}) {
|
for axis, configToProps := range m.GetArchVariantProperties(ctx, &customProps{}) {
|
||||||
for config, props := range configToProps {
|
for config, props := range configToProps {
|
||||||
if archProps, ok := props.(*customProps); ok && archProps.Arch_paths != nil {
|
if archProps, ok := props.(*customProps); ok && archProps.Arch_paths != nil {
|
||||||
paths.SetSelectValue(axis, config, android.BazelLabelForModuleSrc(ctx, archProps.Arch_paths))
|
paths.SetSelectValue(axis, config, android.BazelLabelForModuleSrcExcludes(ctx, archProps.Arch_paths, archProps.Arch_paths_exclude))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
paths.ResolveExcludes()
|
||||||
|
|
||||||
attrs := &customBazelModuleAttributes{
|
attrs := &customBazelModuleAttributes{
|
||||||
String_prop: m.props.String_prop,
|
String_prop: m.props.String_prop,
|
||||||
String_list_prop: m.props.String_list_prop,
|
String_list_prop: m.props.String_list_prop,
|
||||||
@@ -216,3 +219,9 @@ func generateBazelTargetsForDir(codegenCtx *CodegenContext, dir string) BazelTar
|
|||||||
buildFileToTargets, _, _ := GenerateBazelTargets(codegenCtx, false)
|
buildFileToTargets, _, _ := GenerateBazelTargets(codegenCtx, false)
|
||||||
return buildFileToTargets[dir]
|
return buildFileToTargets[dir]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func registerCustomModuleForBp2buildConversion(ctx *android.TestContext) {
|
||||||
|
ctx.RegisterModuleType("custom", customModuleFactory)
|
||||||
|
ctx.RegisterBp2BuildMutator("custom", customBp2BuildMutator)
|
||||||
|
ctx.RegisterForBazelConversion()
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user