build: add ng_benchmark macro to run perf benchmarks (#33389)

this makes running and profiling tests much easier. Example usage:

```
yarn bazel run --define=compile=aot //packages/core/test/render3/perf:noop_change_detection
```

See README.md update for more info.

PS: I considered moving the ng_rollup bundle into the macro but I didn't want to make
  too many changes in this PR. If we find running benchmarks in this way useful, we
  should refactor the build file more, and move the ng_rollup_bundle targets into the
  macro.

PR Close #33389
This commit is contained in:
Igor Minar
2019-10-24 17:40:17 -07:00
committed by Andrew Kushnir
parent 14c4b1b205
commit 4b81bb5c97
4 changed files with 111 additions and 17 deletions

View File

@ -6,6 +6,7 @@ load("@npm_bazel_karma//:index.bzl", _karma_web_test = "karma_web_test", _karma_
load("@npm_bazel_typescript//:index.bzl", _ts_library = "ts_library")
load("//packages/bazel:index.bzl", _ng_module = "ng_module", _ng_package = "ng_package")
load("//packages/bazel/src:ng_rollup_bundle.bzl", _ng_rollup_bundle = "ng_rollup_bundle")
load("//tools:ng_benchmark.bzl", _ng_benchmark = "ng_benchmark")
_DEFAULT_TSCONFIG_TEST = "//packages:tsconfig-test"
_INTERNAL_NG_MODULE_API_EXTRACTOR = "//packages/bazel/src/api-extractor:api_extractor"
@ -271,6 +272,10 @@ def karma_web_test_suite(bootstrap = [], deps = [], **kwargs):
**kwargs
)
def ng_benchmark(**kwargs):
"""Default values for ng_benchmark"""
_ng_benchmark(**kwargs)
def nodejs_binary(data = [], **kwargs):
"""Default values for nodejs_binary"""
_nodejs_binary(

32
tools/ng_benchmark.bzl Normal file
View File

@ -0,0 +1,32 @@
# Copyright Google Inc. All Rights Reserved.
#
# Use of this source code is governed by an MIT-style license that can be
# found in the LICENSE file at https://angular.io/license
"""Bazel macro for running Angular benchmarks"""
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")
def ng_benchmark(name, bundle):
"""
This macro creates two targets, one that is runnable and prints results and one that can be used for profiling via chrome://inspect.
Args:
name: name of the runnable rule to create
bundle: label of the ng_rollup_bundle to run
"""
nodejs_binary(
name = name,
data = [bundle],
entry_point = bundle + ".min_debug.es2015.js",
tags = ["local"],
)
nodejs_binary(
name = name + "_profile",
data = [bundle],
entry_point = bundle + ".min_debug.es2015.js",
args = ["--node_options=--no-turbo-inlining --node_options=--inspect-brk"],
tags = ["local"],
)