Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Current Trunk
apply to the most recent --foo pass on the commandline, if foo is a pass
(while global pass arguments - that are not the name of a pass - remain, as
before, global for all passes). (#6687)
- The Metrics pass now takes an optional argument to use as the title,
`--metrics=text` will show that text before the metrics. Each instance of
Metrics can have unique text, `--metrics=before -O3 --metrics=after`. (#6792)
- Add C and JS APIs to control more pass options (trapsNeverHappen,
closedWorld, generateStackIR, optimizeStackIR, and the list of skipped
passes). (#6713)
Expand Down
7 changes: 7 additions & 0 deletions src/passes/Metrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ struct Metrics
}

void doWalkModule(Module* module) {
std::string title = getArgumentOrDefault("metrics", "");
std::cout << "Metrics";
if (!title.empty()) {
std::cout << ": " << title;
}
std::cout << '\n';

ImportInfo imports(*module);

// global things
Expand Down
4 changes: 3 additions & 1 deletion src/passes/pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ void PassRegistry::registerPasses() {
createMergeSimilarFunctionsPass);
registerPass(
"merge-locals", "merges locals when beneficial", createMergeLocalsPass);
registerPass("metrics", "reports metrics", createMetricsPass);
registerPass("metrics",
"reports metrics (with an optional title, --metrics[=TITLE])",
createMetricsPass);
registerPass("minify-imports",
"minifies import names (only those, and not export names), and "
"emits a mapping to the minified ones",
Expand Down
4 changes: 3 additions & 1 deletion test/lit/help/wasm-metadce.test
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@
;; CHECK-NEXT: --merge-similar-functions merges similar functions when
;; CHECK-NEXT: benefical
;; CHECK-NEXT:
;; CHECK-NEXT: --metrics reports metrics
;; CHECK-NEXT: --metrics reports metrics (with an
;; CHECK-NEXT: optional title,
;; CHECK-NEXT: --metrics[=TITLE])
;; CHECK-NEXT:
;; CHECK-NEXT: --minify-imports minifies import names (only
;; CHECK-NEXT: those, and not export names),
Expand Down
4 changes: 3 additions & 1 deletion test/lit/help/wasm-opt.test
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@
;; CHECK-NEXT: --merge-similar-functions merges similar functions when
;; CHECK-NEXT: benefical
;; CHECK-NEXT:
;; CHECK-NEXT: --metrics reports metrics
;; CHECK-NEXT: --metrics reports metrics (with an
;; CHECK-NEXT: optional title,
;; CHECK-NEXT: --metrics[=TITLE])
;; CHECK-NEXT:
;; CHECK-NEXT: --minify-imports minifies import names (only
;; CHECK-NEXT: those, and not export names),
Expand Down
4 changes: 3 additions & 1 deletion test/lit/help/wasm2js.test
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@
;; CHECK-NEXT: --merge-similar-functions merges similar functions when
;; CHECK-NEXT: benefical
;; CHECK-NEXT:
;; CHECK-NEXT: --metrics reports metrics
;; CHECK-NEXT: --metrics reports metrics (with an
;; CHECK-NEXT: optional title,
;; CHECK-NEXT: --metrics[=TITLE])
;; CHECK-NEXT:
;; CHECK-NEXT: --minify-imports minifies import names (only
;; CHECK-NEXT: those, and not export names),
Expand Down
30 changes: 30 additions & 0 deletions test/lit/passes/metrics.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
;; Test that we can pass an optional title to metrics instances.
;;
;; RUN: wasm-opt %s --metrics --metrics=second --remove-unused-module-elements --metrics=third --metrics -q | filecheck %s
;;
;; The number of functions decreases to 0 after --remove-unused-module-elements,
;; showing that we display the proper metrics at each point in time.
;;
;; CHECK: Metrics
;; CHECK-NEXT: total
;; CHECK-NEXT: [exports] : 0
;; CHECK-NEXT: [funcs] : 1
;;
;; CHECK: Metrics: second
;; CHECK-NEXT: total
;; CHECK-NEXT: [exports] : 0
;; CHECK-NEXT: [funcs] : 1
;;
;; CHECK: Metrics: third
;; CHECK-NEXT: total
;; CHECK-NEXT: [exports] : 0
;; CHECK-NEXT: [funcs] : 0 -1
;;
;; CHECK: Metrics
;; CHECK-NEXT: total
;; CHECK-NEXT: [exports] : 0
;; CHECK-NEXT: [funcs] : 0

(module
(func $foo)
)
1 change: 1 addition & 0 deletions test/passes/O3_low-memory-unused_metrics.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Metrics
total
[exports] : 1
[funcs] : 1
Expand Down
3 changes: 3 additions & 0 deletions test/passes/converge_O3_metrics.bin.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Metrics
total
[exports] : 2
[funcs] : 6
Expand Down Expand Up @@ -231,6 +232,7 @@ total
(i32.const 0)
)
)
Metrics
total
[exports] : 2
[funcs] : 6
Expand Down Expand Up @@ -457,6 +459,7 @@ total
(i32.const 0)
)
)
Metrics
total
[exports] : 2
[funcs] : 6
Expand Down
6 changes: 6 additions & 0 deletions test/passes/func-metrics.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Metrics
global
[exports] : 0
[funcs] : 3
Expand Down Expand Up @@ -106,6 +107,7 @@ func: ifs
)
)
)
Metrics
global
[exports] : 0
[funcs] : 0
Expand All @@ -117,6 +119,7 @@ global
[total] : 0
(module
)
Metrics
global
[exports] : 2
[funcs] : 3
Expand Down Expand Up @@ -194,6 +197,7 @@ export: b (func_b)
(call $waka)
)
)
Metrics
global
[exports] : 1
[funcs] : 1
Expand Down Expand Up @@ -228,6 +232,7 @@ start: func_a
(call $waka)
)
)
Metrics
global
[exports] : 0
[funcs] : 1
Expand Down Expand Up @@ -258,6 +263,7 @@ start: func_a
(call $waka)
)
)
Metrics
global
[exports] : 1
[funcs] : 1
Expand Down
1 change: 1 addition & 0 deletions test/passes/fuzz_metrics_noprint.bin.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Metrics
total
[exports] : 23
[funcs] : 34
Expand Down
2 changes: 2 additions & 0 deletions test/passes/metrics_all-features.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Metrics
total
[exports] : 0
[funcs] : 1
Expand Down Expand Up @@ -80,6 +81,7 @@ total
)
)
)
Metrics
total
[exports] : 0
[funcs] : 0
Expand Down
2 changes: 2 additions & 0 deletions test/passes/metrics_strip-debug_metrics.bin.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Metrics
total
[exports] : 1
[funcs] : 1
Expand All @@ -9,6 +10,7 @@ total
[total] : 1
[vars] : 0
Nop : 1
Metrics
total
[exports] : 1
[funcs] : 1
Expand Down
2 changes: 2 additions & 0 deletions test/passes/metrics_strip-producers_metrics.bin.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Metrics
total
[exports] : 1
[funcs] : 1
Expand All @@ -9,6 +10,7 @@ total
[total] : 1
[vars] : 0
Nop : 1
Metrics
total
[exports] : 1
[funcs] : 1
Expand Down
1 change: 1 addition & 0 deletions test/passes/print_g_metrics.bin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
(nop)
)
)
Metrics
total
[exports] : 3
[funcs] : 3
Expand Down
2 changes: 2 additions & 0 deletions test/passes/sparse_matrix_liveness.bin.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Metrics
total
[exports] : 1
[funcs] : 1
Expand All @@ -12,6 +13,7 @@ total
Const : 1
LocalGet : 1
LocalSet : 1
Metrics
total
[exports] : 1
[funcs] : 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Metrics
total
[exports] : 5
[funcs] : 9
Expand Down