From 6d4a205d50490b4712fcbae743ad9684599b5ba0 Mon Sep 17 00:00:00 2001 From: Martin Probst Date: Fri, 16 Feb 2018 15:55:18 +0100 Subject: [PATCH] Produce a nodejs profile together with a perf_trace. (#149) This allows source level profiling of the JavaScript code, in addition to the more coarsely grained application level profile. --- .../rules_typescript/internal/build_defs.bzl | 13 ++++--- .../internal/common/compilation.bzl | 35 ++++++++++++++++--- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/packages/concatjs/third_party/google3/rules_typescript/internal/build_defs.bzl b/packages/concatjs/third_party/google3/rules_typescript/internal/build_defs.bzl index 85cc23ffe5..a111292f55 100644 --- a/packages/concatjs/third_party/google3/rules_typescript/internal/build_defs.bzl +++ b/packages/concatjs/third_party/google3/rules_typescript/internal/build_defs.bzl @@ -21,7 +21,7 @@ load(":executables.bzl", "get_tsc") load(":common/tsconfig.bzl", "create_tsconfig") load(":ts_config.bzl", "TsConfigInfo") -def _compile_action(ctx, inputs, outputs, tsconfig_file): +def _compile_action(ctx, inputs, outputs, tsconfig_file, node_opts): externs_files = [] action_outputs = [] for output in outputs: @@ -48,14 +48,17 @@ def _compile_action(ctx, inputs, outputs, tsconfig_file): if TsConfigInfo in ctx.attr.tsconfig: action_inputs += ctx.attr.tsconfig[TsConfigInfo].deps + # Pass actual options for the node binary in the special "--node_options" argument. + arguments = ["--node_options=%s" % opt for opt in node_opts] # One at-sign makes this a params-file, enabling the worker strategy. # Two at-signs escapes the argument so it's passed through to tsc_wrapped # rather than the contents getting expanded. if ctx.attr.supports_workers: - arguments = ["@@" + tsconfig_file.path] + arguments.append("@@" + tsconfig_file.path) mnemonic = "TypeScriptCompile" else: - arguments = ["-p", tsconfig_file.path] + arguments.append("-p") + arguments.append(tsconfig_file.path) mnemonic = "tsc" ctx.action( @@ -80,8 +83,8 @@ def _compile_action(ctx, inputs, outputs, tsconfig_file): ) -def _devmode_compile_action(ctx, inputs, outputs, tsconfig_file): - _compile_action(ctx, inputs, outputs, tsconfig_file) +def _devmode_compile_action(ctx, inputs, outputs, tsconfig_file, node_opts): + _compile_action(ctx, inputs, outputs, tsconfig_file, node_opts) def tsc_wrapped_tsconfig(ctx, files, diff --git a/packages/concatjs/third_party/google3/rules_typescript/internal/common/compilation.bzl b/packages/concatjs/third_party/google3/rules_typescript/internal/common/compilation.bzl index 995baaa7ee..edfdecc7a5 100644 --- a/packages/concatjs/third_party/google3/rules_typescript/internal/common/compilation.bzl +++ b/packages/concatjs/third_party/google3/rules_typescript/internal/common/compilation.bzl @@ -230,11 +230,24 @@ def compile_ts(ctx, tsconfig_es6["compilerOptions"]["declaration"] = False tsconfig_es6["compilerOptions"].pop("declarationDir") outputs = transpiled_closure_js + tsickle_externs + + node_profile_args = [] if perf_trace and has_sources: perf_trace_file = ctx.new_file(ctx.label.name + ".es6.trace") tsconfig_es6["bazelOptions"]["perfTracePath"] = perf_trace_file.path outputs.append(perf_trace_file) - files += [perf_trace_file] + + profile_file = ctx.new_file(ctx.label.name + ".es6.v8.log") + node_profile_args = ["--prof", + # Without nologfile_per_isolate, v8 embeds an + # unpredictable hash code in the file name, which + # doesn't work with blaze. + "--nologfile_per_isolate", + "--logfile=" + profile_file.path] + outputs.append(profile_file) + + files += [perf_trace_file, profile_file] + ctx.file_action(output=ctx.outputs.tsconfig, content=json_marshal(tsconfig_es6)) @@ -244,7 +257,8 @@ def compile_ts(ctx, if has_sources: inputs = compilation_inputs + [ctx.outputs.tsconfig] - replay_params = compile_action(ctx, inputs, outputs, ctx.outputs.tsconfig) + replay_params = compile_action(ctx, inputs, outputs, ctx.outputs.tsconfig, + node_profile_args) devmode_manifest = ctx.new_file(ctx.label.name + ".es5.MF") tsconfig_json_es5 = ctx.new_file(ctx.label.name + "_es5_tsconfig.json") @@ -256,15 +270,28 @@ def compile_ts(ctx, jsx_factory=jsx_factory, devmode_manifest=devmode_manifest.path, allowed_deps=allowed_deps) + node_profile_args = [] if perf_trace: perf_trace_file = ctx.new_file(ctx.label.name + ".es5.trace") tsconfig_es5["bazelOptions"]["perfTracePath"] = perf_trace_file.path outputs.append(perf_trace_file) - files += [perf_trace_file] + + profile_file = ctx.new_file(ctx.label.name + ".es5.v8.log") + node_profile_args = ["--prof", + # Without nologfile_per_isolate, v8 embeds an + # unpredictable hash code in the file name, which + # doesn't work with blaze. + "--nologfile_per_isolate", + "--logfile=" + profile_file.path] + outputs.append(profile_file) + + files += [perf_trace_file, profile_file] + ctx.file_action(output=tsconfig_json_es5, content=json_marshal( tsconfig_es5)) inputs = compilation_inputs + [tsconfig_json_es5] - devmode_compile_action(ctx, inputs, outputs, tsconfig_json_es5) + devmode_compile_action(ctx, inputs, outputs, tsconfig_json_es5, + node_profile_args) # TODO(martinprobst): Merge the generated .d.ts files, and enforce strict # deps (do not re-export transitive types from the transitive closure).