diff options
author | Yun Peng <pcloudy@google.com> | 2017-02-01 16:31:08 +0000 |
---|---|---|
committer | Yun Peng <pcloudy@google.com> | 2017-02-01 16:36:43 +0000 |
commit | efe3bf98b0430497ea1926b80e6dbb0b3642eac6 (patch) | |
tree | 76f34ab8132e551eb689fbe7c2adc1931e1fe4c8 /src/tools/benchmark/java | |
parent | 59450eb3770f539352c959dfae7ba04fd32e47b3 (diff) |
Rollback of commit fe90b36498085142c40f2226a6a8f3798272bae6.
*** Reason for rollback ***
BazelBuilderTest failed to build on ci.bazel.io
See https://github.com/bazelbuild/bazel/issues/2468
*** Original change description ***
Benchmark part 2 (preparation for benchmark)
Builders: tools to benchmark the performance.
BuildCases: provide all targets for Builders to build.
--
PiperOrigin-RevId: 146246621
MOS_MIGRATED_REVID=146246621
Diffstat (limited to 'src/tools/benchmark/java')
7 files changed, 0 insertions, 514 deletions
diff --git a/src/tools/benchmark/java/com/google/devtools/build/benchmark/BUILD b/src/tools/benchmark/java/com/google/devtools/build/benchmark/BUILD deleted file mode 100644 index 8d433d9cd9..0000000000 --- a/src/tools/benchmark/java/com/google/devtools/build/benchmark/BUILD +++ /dev/null @@ -1,28 +0,0 @@ -package(default_visibility = ["//src/tools/benchmark:__subpackages__"]) - -load("//tools/build_rules:genproto.bzl", "java_proto_library") - -java_proto_library( - name = "build_data_proto", - src = "build_data.proto", -) - -java_library( - name = "benchmark_lib", - testonly = 1, - srcs = glob(["*.java"]), - deps = [ - ":build_data_proto", - "//src/main/java/com/google/devtools/build/lib:shell", - "//src/main/java/com/google/devtools/build/lib:vfs", - "//src/main/java/com/google/devtools/common/options", - "//src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator:codegenerator_lib", - "//third_party:guava", - "//third_party/protobuf", - ], -) - -filegroup( - name = "srcs", - srcs = glob(["**"]), -) diff --git a/src/tools/benchmark/java/com/google/devtools/build/benchmark/BazelBuildCase.java b/src/tools/benchmark/java/com/google/devtools/build/benchmark/BazelBuildCase.java deleted file mode 100644 index 6ee57967ea..0000000000 --- a/src/tools/benchmark/java/com/google/devtools/build/benchmark/BazelBuildCase.java +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright 2017 The Bazel Authors. 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 com.google.devtools.build.benchmark; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.devtools.build.benchmark.codegenerator.JavaCodeGenerator; -import com.google.devtools.build.lib.shell.CommandException; -import com.google.devtools.build.lib.vfs.FileSystem; -import com.google.devtools.build.lib.vfs.FileSystemUtils; -import com.google.devtools.build.lib.vfs.FileSystems; -import java.io.IOException; -import java.nio.file.Path; - -/** Provides all build target information for Bazel. */ -final class BazelBuildCase implements BuildCase { - - private static final ImmutableMap<String, String> BUILD_TARGET_NAME_TO_DESCRIPTION = - ImmutableMap.of( - "AFewFiles", "Target: A Few Files", - "ManyFiles", "Target: Many Files", - "LongChainedDeps", "Target: Long Chained Deps", - "ParallelDeps", "Target: Parallel Deps"); - private static final String WORKSPACE_FILE_NAME = "WORKSPACE"; - private static final ImmutableList<BuildTargetConfig> defaultBuildTargetConfigs = - getDefaultBuildTargetConfigs(); - private static final boolean INCLUDE_TARGET_A_FEW_FILES = true; - private static final boolean INCLUDE_TARGET_MANY_FILES = true; - private static final boolean INCLUDE_TARGET_LONG_CHAINED_DEPS = true; - private static final boolean INCLUDE_TARGET_PARALLEL_DEPS = true; - - private static final BuildEnvConfig FULL_CLEAN_BUILD_CONFIG = - BuildEnvConfig.newBuilder() - .setDescription("Full clean build") - .setCleanBeforeBuild(true) - .setIncremental(false) - .build(); - private static final BuildEnvConfig INCREMENTAL_BUILD_CONFIG = - BuildEnvConfig.newBuilder() - .setDescription("Incremental build") - .setCleanBeforeBuild(false) - .setIncremental(true) - .build(); - private static final ImmutableList<BuildEnvConfig> BUILD_ENV_CONFIGS = - ImmutableList.of(FULL_CLEAN_BUILD_CONFIG, INCREMENTAL_BUILD_CONFIG); - - private static final FileSystem fileSystem = FileSystems.initDefaultAsJavaIo(); - - @Override - public ImmutableList<BuildTargetConfig> getBuildTargetConfigs() { - return defaultBuildTargetConfigs; - } - - @Override - public ImmutableList<String> getCodeVersions(Builder builder, String from, String to) - throws IOException, CommandException { - return builder.getCodeVersionsBetween(from, to); - } - - @Override - public ImmutableList<BuildEnvConfig> getBuildEnvConfigs() { - return BUILD_ENV_CONFIGS; - } - - // TODO(yueg): configurable target, we may not want to run benchmark for all kinds of target - @Override - public void prepareGeneratedCode(Path copyDir, Path generatedCodePath) throws IOException { - // Prepare generated code for copy - if (!copyDir.toFile().exists()) { - JavaCodeGenerator.generateNewProject( - copyDir.toString(), - INCLUDE_TARGET_A_FEW_FILES, - INCLUDE_TARGET_MANY_FILES, - INCLUDE_TARGET_LONG_CHAINED_DEPS, - INCLUDE_TARGET_PARALLEL_DEPS); - } - - // Clean generated code path - if (generatedCodePath.toFile().exists()) { - try { - FileSystemUtils.deleteTreesBelow(fileSystem.getPath(generatedCodePath.toString())); - } catch (IOException e) { - throw new IOException("Failed to clean directory for generated code", e); - } - } else { - generatedCodePath.toFile().mkdirs(); - } - - // Copy - try { - FileSystemUtils.copyTreesBelow( - fileSystem.getPath(copyDir.toString()), fileSystem.getPath(generatedCodePath.toString())); - } catch (IOException e) { - throw new IOException("Failed to copy generated code", e); - } - if (!generatedCodePath.resolve(WORKSPACE_FILE_NAME).toFile().createNewFile()) { - throw new IOException("Failed to create workspace file"); - } - } - - private static ImmutableList<BuildTargetConfig> getDefaultBuildTargetConfigs() { - ImmutableList.Builder<BuildTargetConfig> builder = ImmutableList.builder(); - for (ImmutableMap.Entry<String, String> entry : BUILD_TARGET_NAME_TO_DESCRIPTION.entrySet()) { - builder.add( - BuildTargetConfig.newBuilder() - .setBuildTarget(entry.getKey()) - .setDescription(entry.getValue()) - .build()); - } - return builder.build(); - } -} diff --git a/src/tools/benchmark/java/com/google/devtools/build/benchmark/BazelBuilder.java b/src/tools/benchmark/java/com/google/devtools/build/benchmark/BazelBuilder.java deleted file mode 100644 index a228143d90..0000000000 --- a/src/tools/benchmark/java/com/google/devtools/build/benchmark/BazelBuilder.java +++ /dev/null @@ -1,154 +0,0 @@ -// Copyright 2017 The Bazel Authors. 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 com.google.devtools.build.benchmark; - -import static java.nio.charset.StandardCharsets.UTF_8; - -import com.google.common.collect.ImmutableList; -import com.google.devtools.build.lib.shell.Command; -import com.google.devtools.build.lib.shell.CommandException; -import com.google.devtools.build.lib.shell.CommandResult; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** Class that provides all needed feature of Bazel for benchmark. */ -class BazelBuilder implements Builder { - - private static final Logger logger = Logger.getLogger(BazelBuilder.class.getName()); - - private static final String BAZEL_BINARY_PATH = "bazel-bin/src/bazel"; - private static final Pattern ELAPSED_TIME_PATTERN = Pattern.compile("(?<=Elapsed time: )[0-9.]+"); - - private final Path generatedCodeDir; - private final Path builderDir; - private Path buildBinary = null; - private String currentCodeVersion = ""; - - BazelBuilder(Path generatedCodeDir, Path builderDir) { - this.generatedCodeDir = generatedCodeDir; - this.builderDir = builderDir; - } - - @Override - public ImmutableList<String> getCodeVersionsBetween(String from, String to) - throws CommandException { - String[] gitLogCommand = {"git", "log", from + ".." + to, "--pretty=format:%H", "--reverse"}; - Command cmd = new Command(gitLogCommand, null, builderDir.toFile()); - CommandResult result = cmd.execute(); - String output = new String(result.getStdout(), UTF_8).trim(); - return ImmutableList.copyOf(output.split("\n")); - } - - @Override - public Path getBuildBinary(String codeVersion) throws IOException, CommandException { - if (buildBinary != null && currentCodeVersion.equals(codeVersion)) { - return buildBinary; - } - - // git checkout codeVersion - String[] checkoutCommand = {"git", "checkout", codeVersion}; - Command cmd = new Command(checkoutCommand, null, builderDir.toFile()); - cmd.execute(); - - // bazel build src:bazel - String[] buildBazelCommand = {"bazel", "build", "src:bazel"}; - cmd = new Command(buildBazelCommand, null, builderDir.toFile()); - CommandResult result = cmd.execute(); - - // Get binary path, bazel output is in stderr - String output = new String(result.getStderr(), UTF_8).trim(); - if (!output.contains(BAZEL_BINARY_PATH)) { - throw new IOException("Bazel binary " + BAZEL_BINARY_PATH + " is not in output of build."); - } - buildBinary = builderDir.resolve(BAZEL_BINARY_PATH); - currentCodeVersion = codeVersion; - return buildBinary; - } - - @Override - public ImmutableList<String> getCommandFromConfig( - BuildTargetConfig targetConfig, BuildEnvConfig envConfig) { - return ImmutableList.<String>builder() - .add("build") - .add(targetConfig.getBuildTarget()) - .addAll(envConfig.getBuildArgsList()) - .build(); - } - - @Override - public double buildAndGetElapsedTime(Path buildBinary, ImmutableList<String> args) - throws CommandException { - List<String> cmdList = new ArrayList<>(); - cmdList.add(buildBinary.toString()); - cmdList.addAll(args); - String[] cmdArr = new String[cmdList.size()]; - cmdArr = cmdList.toArray(cmdArr); - - // Run build command - Command cmd = new Command(cmdArr, null, generatedCodeDir.toFile()); - CommandResult result = cmd.execute(); - - // Get elapsed time from output - String output = new String(result.getStderr(), UTF_8).trim(); - Matcher m = ELAPSED_TIME_PATTERN.matcher(output); - - if (m.find()) { - try { - return (Double.parseDouble(m.group(0))); - } catch (NumberFormatException e) { - // Should not be here since we look for [0-9.]+ - logger.log(Level.SEVERE, "Cannot parse " + m.group(0)); - } - } - throw new CommandException(cmd, "Command didn't provide parsable output."); - } - - @Override - public void clean() throws CommandException { - String[] cleanCommand = {"bazel", "clean"}; - Command cmd = new Command(cleanCommand, null, generatedCodeDir.toFile()); - cmd.execute(); - } - - @Override - public void prepare() throws IOException, CommandException { - if (builderDir.toFile().exists() && !builderDir.toFile().isDirectory()) { - try { - Files.delete(builderDir); - } catch (IOException e) { - throw new IOException(builderDir + " is a file and cannot be deleted", e); - } - } - if (Files.notExists(builderDir)) { - try { - Files.createDirectories(builderDir); - } catch (IOException e) { - throw new IOException("Failed to create directory for bazel", e); - } - - String[] gitCloneCommand = {"git", "clone", "https://github.com/bazelbuild/bazel.git", "."}; - Command cmd = new Command(gitCloneCommand, null, builderDir.toFile()); - cmd.execute(); - } - // Assume the directory is what we need if not empty - } -} diff --git a/src/tools/benchmark/java/com/google/devtools/build/benchmark/BenchmarkOptions.java b/src/tools/benchmark/java/com/google/devtools/build/benchmark/BenchmarkOptions.java deleted file mode 100644 index 54e8d2facb..0000000000 --- a/src/tools/benchmark/java/com/google/devtools/build/benchmark/BenchmarkOptions.java +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2017 The Bazel Authors. 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 com.google.devtools.build.benchmark; - -import com.google.devtools.common.options.Option; -import com.google.devtools.common.options.OptionsBase; - -/** Class that contains arguments for running the benchmark. */ -public class BenchmarkOptions extends OptionsBase { - - @Option( - name = "workspace", - defaultValue = "", - category = "benchmark", - valueHelp = "path", - help = "Directory where we put all the code and results." - ) - public String workspace; - - @Option( - name = "output", - defaultValue = "", - category = "benchmark", - valueHelp = "path", - help = "Path to put benchmark result (json format)." - ) - public String output; - - @Option( - name = "from", - defaultValue = "", - category = "benchmark", - valueHelp = "string", - help = "Use code versions from this (not included)." - ) - public String from; - - @Option( - name = "to", - defaultValue = "", - category = "benchmark", - valueHelp = "string", - help = "Use code versions to this (included)." - ) - public String to; -} diff --git a/src/tools/benchmark/java/com/google/devtools/build/benchmark/BuildCase.java b/src/tools/benchmark/java/com/google/devtools/build/benchmark/BuildCase.java deleted file mode 100644 index f29ce89448..0000000000 --- a/src/tools/benchmark/java/com/google/devtools/build/benchmark/BuildCase.java +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2017 The Bazel Authors. 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 com.google.devtools.build.benchmark; - -import com.google.common.collect.ImmutableList; -import com.google.devtools.build.lib.shell.CommandException; -import java.io.IOException; -import java.nio.file.Path; - -/** Interface that includes methods for a build case including all build target information. */ -interface BuildCase { - - /** Returns a list of build environment configs. */ - ImmutableList<BuildEnvConfig> getBuildEnvConfigs(); - - /** Returns a list of build target configs. */ - ImmutableList<BuildTargetConfig> getBuildTargetConfigs(); - - /** - * Returns a list of code versions (can be anything you specified) in {@code (from, to]} (can be - * any interval you specified) of {@code builder}. - */ - ImmutableList<String> getCodeVersions(Builder builder, String from, String to) - throws IOException, CommandException; - - /** - * Prepares generated code for build. - * - * @param copyDir the source code path for copy - * @param generatedCodePath the path to put generated code - */ - void prepareGeneratedCode(Path copyDir, Path generatedCodePath) throws IOException; -} diff --git a/src/tools/benchmark/java/com/google/devtools/build/benchmark/Builder.java b/src/tools/benchmark/java/com/google/devtools/build/benchmark/Builder.java deleted file mode 100644 index 603fd526d1..0000000000 --- a/src/tools/benchmark/java/com/google/devtools/build/benchmark/Builder.java +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2017 The Bazel Authors. 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 com.google.devtools.build.benchmark; - -import com.google.common.collect.ImmutableList; -import com.google.devtools.build.lib.shell.CommandException; -import java.io.IOException; -import java.nio.file.Path; - -/** Interface that includes methods for a building tool. */ -interface Builder { - - /** Prepare anything the build needs. */ - void prepare() throws IOException, CommandException; - - /** Returns the binary path of the build tool of a specific {@code codeVersion}. */ - Path getBuildBinary(String codeVersion) throws IOException, CommandException; - - /** Return a list of code versions in {@code (from, to]}. */ - ImmutableList<String> getCodeVersionsBetween(String from, String to) throws CommandException; - - /** Returns a command for build under specific config. */ - ImmutableList<String> getCommandFromConfig( - BuildTargetConfig targetConfig, BuildEnvConfig envConfig); - - /** - * Build the given buildConfig using the given binary. - * - * @return elapsed time of the build - */ - double buildAndGetElapsedTime(Path buildBinary, ImmutableList<String> args) - throws CommandException; - - /** Clean the previous build results. */ - void clean() throws CommandException; -} diff --git a/src/tools/benchmark/java/com/google/devtools/build/benchmark/build_data.proto b/src/tools/benchmark/java/com/google/devtools/build/benchmark/build_data.proto deleted file mode 100644 index f43ecdfea1..0000000000 --- a/src/tools/benchmark/java/com/google/devtools/build/benchmark/build_data.proto +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2017 The Bazel Authors. 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. -syntax = "proto3"; - -package benchmark; - -option java_package = "com.google.devtools.build.benchmark"; -option java_multiple_files = true; - -// Environment config for a build (how we build a target) -message BuildEnvConfig { - string description = 1; - repeated string build_args = 2; - bool clean_before_build = 3; - bool incremental = 4; -} - -// Build results (elapsed time) for a specific code version -// results are used for running benchmark for several times for now -message SingleBuildResult { - string code_version = 1; - repeated double results = 2; -} - -// Build results for a specific environment config -message BuildEnvResult { - BuildEnvConfig config = 1; - repeated SingleBuildResult results = 2; -} - -// Target config for a build (what to build) -message BuildTargetConfig { - string description = 1; - string build_target = 2; -} - -// Build results for a specific target config -message BuildTargetResult { - BuildTargetConfig build_target_config = 1; - repeated BuildEnvResult build_env_results = 2; -} - -// Build results for a group (environment * target) -message BuildGroupResult { - repeated BuildTargetResult build_target_results = 1; -} |