summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/passes/Metrics.cpp6
-rw-r--r--test/passes/metrics.txt35
-rw-r--r--test/passes/metrics.wast29
3 files changed, 68 insertions, 2 deletions
diff --git a/src/passes/Metrics.cpp b/src/passes/Metrics.cpp
index 03f8bc447..9673b8873 100644
--- a/src/passes/Metrics.cpp
+++ b/src/passes/Metrics.cpp
@@ -30,8 +30,7 @@ struct Metrics : public WalkerPass<WasmWalker<Metrics>> {
map<const char *, int> counts;
void walk(Expression *&curr) override {
WalkerPass::walk(curr);
- if (!curr)
- return;
+ if (!curr) return;
auto name = getExpressionName(curr);
counts[name]++;
}
@@ -40,8 +39,10 @@ struct Metrics : public WalkerPass<WasmWalker<Metrics>> {
o << "Counts"
<< "\n";
vector<const char*> keys;
+ int total = 0;
for (auto i : counts) {
keys.push_back(i.first);
+ total += i.second;
}
sort(keys.begin(), keys.end(), [](const char* a, const char* b) -> bool {
return strcmp(b, a) > 0;
@@ -68,6 +69,7 @@ struct Metrics : public WalkerPass<WasmWalker<Metrics>> {
}
o << "\n";
}
+ o << left << setw(16) << "Total" << ": " << setw(8) << total << '\n';
lastMetricsPass = this;
}
};
diff --git a/test/passes/metrics.txt b/test/passes/metrics.txt
new file mode 100644
index 000000000..5614756de
--- /dev/null
+++ b/test/passes/metrics.txt
@@ -0,0 +1,35 @@
+Counts
+ binary : 1
+ block : 1
+ const : 12
+ if : 4
+Total : 18
+(module
+ (memory 16777216 16777216)
+ (func $ifs
+ (block $block0
+ (if
+ (i32.const 0)
+ (i32.const 1)
+ )
+ (if_else
+ (i32.const 0)
+ (i32.const 1)
+ (i32.const 2)
+ )
+ (if_else
+ (i32.const 4)
+ (i32.const 5)
+ (i32.const 6)
+ )
+ (i32.eq
+ (if_else
+ (i32.const 4)
+ (i32.const 5)
+ (i32.const 6)
+ )
+ (i32.const 177)
+ )
+ )
+ )
+)
diff --git a/test/passes/metrics.wast b/test/passes/metrics.wast
new file mode 100644
index 000000000..11c44fadf
--- /dev/null
+++ b/test/passes/metrics.wast
@@ -0,0 +1,29 @@
+(module
+ (memory 16777216 16777216)
+ (func $ifs
+ (block
+ (if
+ (i32.const 0)
+ (i32.const 1)
+ )
+ (if_else
+ (i32.const 0)
+ (i32.const 1)
+ (i32.const 2)
+ )
+ (if_else
+ (i32.const 4)
+ (i32.const 5)
+ (i32.const 6)
+ )
+ (i32.eq
+ (if_else
+ (i32.const 4)
+ (i32.const 5)
+ (i32.const 6)
+ )
+ (i32.const 177)
+ )
+ )
+ )
+)