Skip to content

Commit

Permalink
[monitors] LoopMonitor does not report 0-count loops by default
Browse files Browse the repository at this point in the history
  • Loading branch information
titzer committed Jan 18, 2024
1 parent 6d2b057 commit 8e3f9f3
Show file tree
Hide file tree
Showing 90 changed files with 929 additions and 5 deletions.
2 changes: 2 additions & 0 deletions issues.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Prio Component Issue
-------------------------------
fast-int Optimize 4-byte sidetable entry loads
spc,fast-int Remove checks for Throwable at returns
spc Improve prologue; assume instance, mem0_base in registers
spc Optimize PolyBenchC: adi, fdtd-2d, gemm, heat-3d, jacobi-2d, seidel-2d, symm, syr2k, syrk
Expand Down Expand Up @@ -191,6 +192,7 @@ Inline WasmObject.values array

Done
--------------------------------
loop-monitor Don't show output of 0-count loops by default
v3-int implement simd
fast-int tune: loop for repeated blocks
ext multi-memory
Expand Down
8 changes: 7 additions & 1 deletion src/monitors/LoopMonitor.v3
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@
// See LICENSE for details of Apache 2.0 license.

// Implements a simple monitor that counts the number of iterations of each loop.
var inCodeMode = false;
var showZeroCounts = false;
class LoopMonitor extends Monitor {
def entries = Vector<LmEntry>.new();
def it = BytecodeIterator.new();
var inCodeMode = false;

def configure(args: string) -> string {
def argMap = MonitorUtil.argMapFrom(args);
if (argMap.has("code") || argMap.has("c")) {
inCodeMode = true;
return null;
}
if (argMap.has("zero") || argMap.has("z")) {
showZeroCounts = true;
return null;
}
def buf = StringBuilder.new();
buf.put1("invalid argument(s) \"%s\"", args);
return buf.toString();
Expand Down Expand Up @@ -150,6 +155,7 @@ def report(entries: Vector<LmEntry>) {
var prev: FuncDecl;
for (j < entries.length) {
var e = entries[j];
if (e.count == 0 && !showZeroCounts) continue;
if (e.func != prev) {
prev = e.func;
OUT.puts(Palette.FUNC)
Expand Down
Binary file modified test/wizeng/loop_monitor0.wasm
Binary file not shown.
2 changes: 2 additions & 0 deletions test/wizeng/loop_monitor0.wat
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@
(br_if $l3 (local.get $cnt))
)
)
(func $empty
(loop))
)
3 changes: 3 additions & 0 deletions test/wizeng/monitors/br_return.wasm.calls-c-.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
func "main": 1
+9: call [1]: 10
func "foo": 10
5 changes: 5 additions & 0 deletions test/wizeng/monitors/branch_monitor.wasm.calls-c-.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
func "main": 1
+1: call [1]: 1
func "start": 1
+25: call [2]: 1
func "foo": 1
1 change: 1 addition & 0 deletions test/wizeng/monitors/branch_monitor0.wasm.calls-c-.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
func "main": 1
2 changes: 0 additions & 2 deletions test/wizeng/monitors/branch_monitor0.wasm.loops.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
func "main":
+7 ... +20 loop: 5
func "start":
+7 ... +20 loop: 0
15 changes: 15 additions & 0 deletions test/wizeng/monitors/brret0.wasm.calls-c-.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
func "main": 1
+1: call [2]: 1
func "do": 1
+1: call [3]: 1
+3: call [3]: 1
+5: call [3]: 1
+7: call [4]: 1
+9: call [4]: 1
+11: call [4]: 1
+13: call [5]: 1
+15: call [5]: 1
+17: call [5]: 1
func "foo": 3
func "bar": 3
func "baz": 3
15 changes: 15 additions & 0 deletions test/wizeng/monitors/calls1.wasm.calls-c-.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
func "main": 1
+9: call [2]: 10
+11: call [3]: 10
+13: call [2]: 10
+15: call [4]: 10
+17: call [2]: 10
+19: call [2]: 10
+21: call [2]: 10
+23: call [3]: 10
+25: call [3]: 10
+27: call [2]: 10
func "foo": 60
func "bar": 30
+1: call [4]: 30
func "baz": 40
17 changes: 17 additions & 0 deletions test/wizeng/monitors/calls2.wasm.calls-c-.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
func #1: 40
func "main": 1
+9: call [3]: 10
+11: call [4]: 10
+13: call [3]: 10
+15: call [5]: 10
+17: call [3]: 10
+19: call [3]: 10
+21: call [3]: 10
+23: call [4]: 10
+25: call [4]: 10
+27: call [3]: 10
func "foo": 60
func "bar": 30
+1: call [5]: 30
func #5: 40
+1: call [1]: 40
3 changes: 3 additions & 0 deletions test/wizeng/monitors/calls3.wasm.calls-c-.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
func "main": 1
+10: call [2]: 1005
func "foo": 1005
26 changes: 26 additions & 0 deletions test/wizeng/monitors/calls4.wasm.branches-c-.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
func #1:
+3 i32.const[3]
+5 local.set[0]
+7 loop[] <-- +44: 2
+9 call[func=2]
+11 call[func=3]
+13 call[func=4]
+15 local.get[0]
+17 i32.const[1]
+19 i32.ge_s
+20 if[] --> +26: 3, +22: 0
+22 i32.const[123] <-- +20: 0
+25 drop
+26 else <-- +20: 3
+27 i32.const[456]
+30 drop
+31 end
+32 local.get[0]
+34 call_indirect[sig=0,table=0]
+37 local.get[0]
+39 i32.const[1]
+41 i32.sub
+42 local.tee[0]
+44 br_if[depth=0] --> +7: 2, +46: 1
+46 end <-- +44: 1
+47 end
3 changes: 3 additions & 0 deletions test/wizeng/monitors/calls4.wasm.branches.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
func #1:
+20 if: [0, 3]
+44 br_if: [1, 2]
11 changes: 11 additions & 0 deletions test/wizeng/monitors/calls4.wasm.calls-c-.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
func #1: 1
+9: call [2]: 3
+11: call [3]: 3
+13: call [4]: 3
+34: call_indirect:
<wasm func #4>: 2
<wasm func #3>: 1
func #2: 3
func #3: 4
+1: call [4]: 4
func #4: 9
36 changes: 36 additions & 0 deletions test/wizeng/monitors/calls4.wasm.coverage-c-.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
func #0:
+1 call[func=1]
- end
func #1:
+3 --> i32.const[3]
- local.set[0]
+7 --> loop[]
- call[func=2]
- call[func=3]
- call[func=4]
- local.get[0]
- i32.const[1]
- i32.ge_s
- if[]
+22 --> i32.const[123]
- drop
- else
+27 i32.const[456]
- drop
- end
+32 --> local.get[0]
- call_indirect[sig=0,table=0]
- local.get[0]
- i32.const[1]
- i32.sub
- local.tee[0]
- br_if[depth=0]
+46 --> end
+47 --> end
func #2:
+1 --> end
func #3:
+1 --> call[func=4]
- end
func #4:
+1 --> end
36 changes: 36 additions & 0 deletions test/wizeng/monitors/calls4.wasm.coverage-c-i-.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
func #0:
+1 call[func=1]
+3 end
func #1:
+3 * i32.const[3]
+5 * local.set[0]
+7 * loop[]
+9 * call[func=2]
+11 * call[func=3]
+13 * call[func=4]
+15 * local.get[0]
+17 * i32.const[1]
+19 * i32.ge_s
+20 * if[]
+22 * i32.const[123]
+25 * drop
+26 * else
+27 i32.const[456]
+30 drop
+31 * end
+32 * local.get[0]
+34 * call_indirect[sig=0,table=0]
+37 * local.get[0]
+39 * i32.const[1]
+41 * i32.sub
+42 * local.tee[0]
+44 * br_if[depth=0]
+46 * end
+47 * end
func #2:
+1 * end
func #3:
+1 * call[func=4]
+3 * end
func #4:
+1 * end
2 changes: 2 additions & 0 deletions test/wizeng/monitors/calls4.wasm.coverage.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Instr coverage: 27 / 31 (87.0%)
Block coverage: 9 / 11 (81.8%)
1 change: 1 addition & 0 deletions test/wizeng/monitors/calls4.wasm.globals.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#R #W
42 changes: 42 additions & 0 deletions test/wizeng/monitors/calls4.wasm.hotness-c-.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
----- reach 50%
----- reach 75%
----- reach 90%
----- reach 95%
----- reach 99%
---- reach 100%
func #0:
+1 0 call[func=1]
+3 0 end
func #1:
+3 1 i32.const[3]
+5 1 local.set[0]
+7 3 loop[]
+9 3 call[func=2]
+11 3 call[func=3]
+13 3 call[func=4]
+15 3 local.get[0]
+17 3 i32.const[1]
+19 3 i32.ge_s
+20 3 if[]
+22 3 i32.const[123]
+25 3 drop
+26 3 else
+27 0 i32.const[456]
+30 0 drop
+31 3 end
+32 3 local.get[0]
+34 3 call_indirect[sig=0,table=0]
+37 3 local.get[0]
+39 3 i32.const[1]
+41 3 i32.sub
+42 3 local.tee[0]
+44 3 br_if[depth=0]
+46 1 end
+47 1 end
func #2:
+1 3 end
func #3:
+1 4 call[func=4]
+3 4 end
func #4:
+1 9 end
37 changes: 37 additions & 0 deletions test/wizeng/monitors/calls4.wasm.hotness.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
func #4 +1: 9
func #3 +1: 4
func #3 +3: 4
func #1 +7: 3
func #1 +9: 3
func #1 +11: 3
func #1 +13: 3
func #1 +15: 3
func #1 +17: 3
func #1 +19: 3
func #1 +20: 3
11 instrs reach 50%
func #1 +22: 3
func #1 +25: 3
func #1 +26: 3
func #1 +31: 3
func #1 +32: 3
func #1 +34: 3
func #1 +37: 3
18 instrs reach 75%
func #1 +39: 3
func #1 +41: 3
func #1 +42: 3
func #1 +44: 3
22 instrs reach 90%
func #2 +1: 3
23 instrs reach 95%
func #1 +3: 1
func #1 +5: 1
func #1 +46: 1
26 instrs reach 99%
func #1 +47: 1
27 instrs reach 100%
func #0 +1: 0
func #0 +3: 0
func #1 +27: 0
func #1 +30: 0
26 changes: 26 additions & 0 deletions test/wizeng/monitors/calls4.wasm.loops-c-.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
func #1:
+3 i32.const[3]
+5 local.set[0]
+7 --> loop[]
+9 | call[func=2]
+11 | call[func=3]
+13 | call[func=4]
+15 | local.get[0]
+17 | i32.const[1]
+19 | i32.ge_s
+20 | if[]
+22 | i32.const[123]
+25 | drop
+26 (3) else
+27 | i32.const[456]
+30 | drop
+31 | end
+32 | local.get[0]
+34 | call_indirect[sig=0,table=0]
+37 | local.get[0]
+39 | i32.const[1]
+41 | i32.sub
+42 | local.tee[0]
+44 | br_if[depth=0]
+46 <-- end
+47 end
2 changes: 2 additions & 0 deletions test/wizeng/monitors/calls4.wasm.loops.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
func #1:
+7 ... +46 loop: 3
Empty file.
3 changes: 3 additions & 0 deletions test/wizeng/monitors/coverage_monitor0.wasm.calls-c-.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
func #0: 1
+1: call [2]: 1
func #2: 1
27 changes: 27 additions & 0 deletions test/wizeng/monitors/echo.wasm.branches-c-.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
echo.wasm 1 222 3ABC
func #3:
+3 block[]
+5 loop[]
+7 local.get[1]
+9 local.get[0]
+11 i32.ge_u
+12 br_if[depth=1] --> +44: 1, +14: 4
+14 i32.const[1] <-- +12: 4
+16 i32.const[100]
+19 local.get[1]
+21 i32.const[100]
+24 i32.const[64000]
+28 call[func=1]
+30 call[func=2]
+32 drop
+33 call[func=4]
+35 local.get[1]
+37 i32.const[1]
+39 i32.add
+40 local.set[1]
+42 br[depth=0]
+44 end <-- +12: 1
+45 end
+46 call[func=5]
+48 i32.const[0]
+50 end
3 changes: 3 additions & 0 deletions test/wizeng/monitors/echo.wasm.branches.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
echo.wasm 1 222 3ABC
func #3:
+12 br_if: [4, 1]
Loading

0 comments on commit 8e3f9f3

Please sign in to comment.