Add jj subcommands to easily compare revisions.
* `jj before-after` builds two copies of gn in parallel, before and after a change.
* `HYPERFINE_OPTS="--warmup 1 --runs 5" jj compare-perf` compares the performance of those two copies of GN across 5 invocations of GN gen each.
* It caches the benchmarking results to improve performance, which
particularly helps given that "before" is unlikely to change.
Change-Id: Iff7ef7965ebf7c1b9d2769ca23abdac36a6a6964
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/25720
Commit-Queue: Matt Stark <msta@google.com>
Reviewed-by: Takuto Ikuta <tikuta@google.com>
diff --git a/tools/jj/config.toml b/tools/jj/config.toml
index 57413ed..9546641 100644
--- a/tools/jj/config.toml
+++ b/tools/jj/config.toml
@@ -6,6 +6,7 @@
[revset-aliases]
"trunk()" = "main@origin"
+"before" = "trunk()"
# For users of jj-on-piper, this is enabled by default for *all* repos.
# We want GN's formatters, not google3's.
@@ -16,6 +17,41 @@
command = ["/dev/null"]
patterns = ["null"]
+[aliases]
+compare = [
+ "run",
+ "-j2",
+ "--revision=before=before",
+ "--revision=after=@",
+ # Allow running on immutable commits
+ "--ignore-changes",
+ "--",
+ "bash",
+ "-c",
+]
+
+# Runs ninja on /tmp/before and /tmp/after
+before-after = [
+ "compare",
+ "python3 build/gen.py --out-path=/tmp/$JJ_LABEL ${GN_OPTS:-} && ninja -C /tmp/$JJ_LABEL ${NINJA_TARGETS:-gn}",
+]
+
+compare-perf = [
+ "util",
+ "exec",
+ "--",
+ "bash",
+ "-c",
+ """
+ GN_OPTS="--gen=${SRC:-$HOME/chromium/src}=${OUT_DIR:-out/\\$JJ_LABEL}" \
+ NINJA_TARGETS=gen_bench \
+ jj --config "revset-aliases.before=\\"${BEFORE:-trunk()}\\"" before-after && \
+ python3 "$JJ_WORKSPACE_ROOT/tools/compare_traces.py" \
+ --before /tmp/before/gen_bench_[0-9]*.trace \
+ --after /tmp/after/gen_bench_[0-9]*.trace
+ """,
+]
+
[fix.tools.clang-format]
command = ["clang/bin/clang-format", "--assume-filename=$path"]
patterns = [