--experimental_action_listeners 是否计入 --jobs?
Are --experimental_action_listeners counted against --jobs?
我们 运行 作为动作监听器非常整洁。它可以很容易地消耗与 gcc 编译一样多的 CPU,如果不是更多的话。
这些会根据 --jobs 计数收费,还是我们必须自己为听众计划(例如,当 "right-sizing" 和 machine/container/whatever 时)?
是的。
演示
我 运行 3 次操作 + 3 次额外操作。他们每个人都睡 3 秒,并在开始和结束时打印。
使用--jobs=2
,可以看到leaf2和leaf3一起构建(从15:10:00开始),然后是leaf1和leaf1 listener(在15:10:03),最后是leaf2 listener和leaf3 侦听器(在 15:10:06)。
$ bazel clean >&/dev/null && time bazel build //:root --jobs=2 --experimental_action_listener="//:clang-tidy-listener" 2>/dev/null
Start action listener at 15:10:03, argc=1, argv=(--extra_action_file=bazel-out/local-fastbuild/extra_actions/clang-tidy/cc4b710d2c96f16eb0bcc5df6f009f08.xa)
Done action listener at 15:10:06
Start action listener at 15:10:06, argc=1, argv=(--extra_action_file=bazel-out/local-fastbuild/extra_actions/clang-tidy/3001ea27a871bf7b111ee4bbbc1d79dc.xa)
Done action listener at 15:10:09
Start action listener at 15:10:06, argc=1, argv=(--extra_action_file=bazel-out/local-fastbuild/extra_actions/clang-tidy/f88e13a970ce3a66354583c477067b29.xa)
Done action listener at 15:10:09
real 0m9.698s
user 0m0.004s
sys 0m0.012s
$ cat bazel-genfiles/root.txt
leaf1.txt
start: 15:10:03
start: 15:10:06
leaf2.txt
start: 15:10:00
start: 15:10:03
leaf3.txt
start: 15:10:00
start: 15:10:03
使用 --jobs=8
,所有操作开始于 15:08:58:
$ bazel clean >&/dev/null && time bazel build //:root --jobs=8 --experimental_action_listener="//:clang-tidy-listener" 2>/dev/null
Start action listener at 15:08:58, argc=1, argv=(--extra_action_file=bazel-out/local-fastbuild/extra_actions/clang-tidy/f88e13a970ce3a66354583c477067b29.xa)
Done action listener at 15:09:01
Start action listener at 15:08:58, argc=1, argv=(--extra_action_file=bazel-out/local-fastbuild/extra_actions/clang-tidy/3001ea27a871bf7b111ee4bbbc1d79dc.xa)
Done action listener at 15:09:01
Start action listener at 15:08:58, argc=1, argv=(--extra_action_file=bazel-out/local-fastbuild/extra_actions/clang-tidy/cc4b710d2c96f16eb0bcc5df6f009f08.xa)
Done action listener at 15:09:01
real 0m3.609s
user 0m0.004s
sys 0m0.016s
$ cat bazel-genfiles/root.txt
leaf1.txt
start: 15:08:58
start: 15:09:01
leaf2.txt
start: 15:08:58
start: 15:09:01
leaf3.txt
start: 15:08:58
start: 15:09:01
来源
//:BUILD
:
load(":myrule.bzl", "myrule")
genrule(
name = "root",
srcs = [
"leaf1",
"leaf2",
"leaf3",
],
outs = ["root.txt"],
cmd = "( for f in $(SRCS); do basename $$f ; cat $$f ; echo ; done ; ) > $@",
)
[myrule(name = "leaf%d" % i) for i in [1, 2, 3]]
sh_binary(
name = "listener",
srcs = ["listener.sh"],
)
action_listener(
name = "clang-tidy-listener",
mnemonics = ["FooAction"],
extra_actions = [":clang-tidy"],
)
extra_action(
name = "clang-tidy",
tools = [":listener"],
cmd = "$(location :listener) --extra_action_file=$(EXTRA_ACTION_FILE)",
)
//:myrule.bzl
:
# Based on https://bazel.build/versions/master/docs/skylark/cookbook.html#simple-shell-command
def _impl(ctx):
output = ctx.outputs.out
ctx.action(
outputs=[output],
mnemonic="FooAction",
command="( echo \"start: $(date +%%H:%%M:%%S)\" ; sleep 3 ; echo \"start: $(date +%%H:%%M:%%S)\" ; ) > %s" % output.path)
myrule = rule(
implementation=_impl,
outputs={"out": "%{name}.txt"},
)
//:listener.sh
:
#!/bin/bash
echo "Start action listener at $(date +%H:%M:%S), argc=$#, argv=($@)"
sleep 3
echo "Done action listener at $(date +%H:%M:%S)"
我们 运行 作为动作监听器非常整洁。它可以很容易地消耗与 gcc 编译一样多的 CPU,如果不是更多的话。
这些会根据 --jobs 计数收费,还是我们必须自己为听众计划(例如,当 "right-sizing" 和 machine/container/whatever 时)?
是的。
演示
我 运行 3 次操作 + 3 次额外操作。他们每个人都睡 3 秒,并在开始和结束时打印。
使用--jobs=2
,可以看到leaf2和leaf3一起构建(从15:10:00开始),然后是leaf1和leaf1 listener(在15:10:03),最后是leaf2 listener和leaf3 侦听器(在 15:10:06)。
$ bazel clean >&/dev/null && time bazel build //:root --jobs=2 --experimental_action_listener="//:clang-tidy-listener" 2>/dev/null
Start action listener at 15:10:03, argc=1, argv=(--extra_action_file=bazel-out/local-fastbuild/extra_actions/clang-tidy/cc4b710d2c96f16eb0bcc5df6f009f08.xa)
Done action listener at 15:10:06
Start action listener at 15:10:06, argc=1, argv=(--extra_action_file=bazel-out/local-fastbuild/extra_actions/clang-tidy/3001ea27a871bf7b111ee4bbbc1d79dc.xa)
Done action listener at 15:10:09
Start action listener at 15:10:06, argc=1, argv=(--extra_action_file=bazel-out/local-fastbuild/extra_actions/clang-tidy/f88e13a970ce3a66354583c477067b29.xa)
Done action listener at 15:10:09
real 0m9.698s
user 0m0.004s
sys 0m0.012s
$ cat bazel-genfiles/root.txt
leaf1.txt
start: 15:10:03
start: 15:10:06
leaf2.txt
start: 15:10:00
start: 15:10:03
leaf3.txt
start: 15:10:00
start: 15:10:03
使用 --jobs=8
,所有操作开始于 15:08:58:
$ bazel clean >&/dev/null && time bazel build //:root --jobs=8 --experimental_action_listener="//:clang-tidy-listener" 2>/dev/null
Start action listener at 15:08:58, argc=1, argv=(--extra_action_file=bazel-out/local-fastbuild/extra_actions/clang-tidy/f88e13a970ce3a66354583c477067b29.xa)
Done action listener at 15:09:01
Start action listener at 15:08:58, argc=1, argv=(--extra_action_file=bazel-out/local-fastbuild/extra_actions/clang-tidy/3001ea27a871bf7b111ee4bbbc1d79dc.xa)
Done action listener at 15:09:01
Start action listener at 15:08:58, argc=1, argv=(--extra_action_file=bazel-out/local-fastbuild/extra_actions/clang-tidy/cc4b710d2c96f16eb0bcc5df6f009f08.xa)
Done action listener at 15:09:01
real 0m3.609s
user 0m0.004s
sys 0m0.016s
$ cat bazel-genfiles/root.txt
leaf1.txt
start: 15:08:58
start: 15:09:01
leaf2.txt
start: 15:08:58
start: 15:09:01
leaf3.txt
start: 15:08:58
start: 15:09:01
来源
//:BUILD
:
load(":myrule.bzl", "myrule")
genrule(
name = "root",
srcs = [
"leaf1",
"leaf2",
"leaf3",
],
outs = ["root.txt"],
cmd = "( for f in $(SRCS); do basename $$f ; cat $$f ; echo ; done ; ) > $@",
)
[myrule(name = "leaf%d" % i) for i in [1, 2, 3]]
sh_binary(
name = "listener",
srcs = ["listener.sh"],
)
action_listener(
name = "clang-tidy-listener",
mnemonics = ["FooAction"],
extra_actions = [":clang-tidy"],
)
extra_action(
name = "clang-tidy",
tools = [":listener"],
cmd = "$(location :listener) --extra_action_file=$(EXTRA_ACTION_FILE)",
)
//:myrule.bzl
:
# Based on https://bazel.build/versions/master/docs/skylark/cookbook.html#simple-shell-command
def _impl(ctx):
output = ctx.outputs.out
ctx.action(
outputs=[output],
mnemonic="FooAction",
command="( echo \"start: $(date +%%H:%%M:%%S)\" ; sleep 3 ; echo \"start: $(date +%%H:%%M:%%S)\" ; ) > %s" % output.path)
myrule = rule(
implementation=_impl,
outputs={"out": "%{name}.txt"},
)
//:listener.sh
:
#!/bin/bash
echo "Start action listener at $(date +%H:%M:%S), argc=$#, argv=($@)"
sleep 3
echo "Done action listener at $(date +%H:%M:%S)"