diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2020-11-20 10:43:52 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-20 10:43:52 -0800 |
commit | 68294338a1cc7337e808671e75933b1134d18a90 (patch) | |
tree | 3266b2af930177121d9dd8ad4851f6778ab08f4f /test/lit/wasm-split | |
parent | 171cba44fe6fdaff63fff79d2c660b02d7a79747 (diff) | |
download | binaryen-68294338a1cc7337e808671e75933b1134d18a90.tar.gz binaryen-68294338a1cc7337e808671e75933b1134d18a90.tar.bz2 binaryen-68294338a1cc7337e808671e75933b1134d18a90.zip |
[wasm-split] Initial instrumentation (#3389)
Implement an instrumentation pass that records the timestamp at which each
defined function is first called. Timestamps are not actual time, but rather
snapshots of a monotonically increasing counter. The instrumentation exports a
function that the embedder can call to dump the profile data into a memory
buffer at a given offset and size. The function returns the total size of the
profile data so the embedder can know how much to read out of the buffer or how
much it needs to grow the buffer.
Parsing and using the profile is left as future work, as is recording a hash of
the input file that will be used to guard against accidentally instrumenting one
module and trying to use the resulting profile to split a different module.
Diffstat (limited to 'test/lit/wasm-split')
-rw-r--r-- | test/lit/wasm-split/export-name-already-exists.wast | 8 | ||||
-rw-r--r-- | test/lit/wasm-split/instrument-funcs.wast | 75 | ||||
-rw-r--r-- | test/lit/wasm-split/instrument-memory-too-small.wast | 10 |
3 files changed, 93 insertions, 0 deletions
diff --git a/test/lit/wasm-split/export-name-already-exists.wast b/test/lit/wasm-split/export-name-already-exists.wast new file mode 100644 index 000000000..708929e98 --- /dev/null +++ b/test/lit/wasm-split/export-name-already-exists.wast @@ -0,0 +1,8 @@ +;; RUN: not wasm-split %s --instrument --profile-export=foo 2>&1 \ +;; RUN: | filecheck %s + +;; CHECK: error: Export foo already exists. + +(module + (export "foo" (memory 0 0)) +) diff --git a/test/lit/wasm-split/instrument-funcs.wast b/test/lit/wasm-split/instrument-funcs.wast new file mode 100644 index 000000000..bdd222d82 --- /dev/null +++ b/test/lit/wasm-split/instrument-funcs.wast @@ -0,0 +1,75 @@ +;; RUN: wasm-split %s --instrument -S -o - | filecheck %s + +;; Check that the output round trips and validates as well +;; RUN: wasm-split %s --instrument -g -o %t +;; RUN: wasm-opt %t --print | filecheck %s + +(module + (import "env" "foo" (func $foo)) + (export "bar" (func $bar)) + (func $bar + (call $foo) + ) + (func $baz (param i32) (result i32) + (local.get 0) + ) +) + +;; Check that a memory has been added +;; CHECK: (memory $0 1 1) + +;; Check that the counter and timestamps have been added +;; CHECK: (global $monotonic_counter (mut i32) (i32.const 0)) +;; CHECK: (global $bar_timestamp (mut i32) (i32.const 0)) +;; CHECK: (global $baz_timestamp (mut i32) (i32.const 0)) + +;; And the profiling function exported +;; CHECK: (export "__write_profile" (func $__write_profile)) + +;; Check that the function instrumentation is correct + +;; CHECK: (func $baz (param $0 i32) (result i32) +;; CHECK-NEXT: (if +;; CHECK-NEXT: (i32.eqz +;; CHECK-NEXT: (global.get $baz_timestamp) +;; CHECK-NEXT: ) +;; CHECK-NEXT: (block +;; CHECK-NEXT: (global.set $monotonic_counter +;; CHECK-NEXT: (i32.add +;; CHECK-NEXT: (global.get $monotonic_counter) +;; CHECK-NEXT: (i32.const 1) +;; CHECK-NEXT: ) +;; CHECK-NEXT: ) +;; CHECK-NEXT: (global.set $baz_timestamp +;; CHECK-NEXT: (global.get $monotonic_counter) +;; CHECK-NEXT: ) +;; CHECK-NEXT: ) +;; CHECK-NEXT: ) +;; CHECK-NEXT: (local.get $0) +;; CHECK-NEXT: ) + +;; Check that the profiling function is correct. + +;; CHECK: (func $__write_profile (param $addr i32) (param $size i32) (result i32) +;; CHECK-NEXT: (if +;; CHECK-NEXT: (i32.ge_u +;; CHECK-NEXT: (local.get $size) +;; CHECK-NEXT: (i32.const 16) +;; CHECK-NEXT: ) +;; CHECK-NEXT: (block +;; CHECK-NEXT: (i64.store align=1 +;; CHECK-NEXT: (local.get $addr) +;; CHECK-NEXT: (i64.const 0) +;; CHECK-NEXT: ) +;; CHECK-NEXT: (i32.store offset=8 align=1 +;; CHECK-NEXT: (local.get $addr) +;; CHECK-NEXT: (global.get $bar_timestamp) +;; CHECK-NEXT: ) +;; CHECK-NEXT: (i32.store offset=12 align=1 +;; CHECK-NEXT: (local.get $addr) +;; CHECK-NEXT: (global.get $baz_timestamp) +;; CHECK-NEXT: ) +;; CHECK-NEXT: ) +;; CHECK-NEXT: ) +;; CHECK-NEXT: (i32.const 16) +;; CHECK-NEXT: ) diff --git a/test/lit/wasm-split/instrument-memory-too-small.wast b/test/lit/wasm-split/instrument-memory-too-small.wast new file mode 100644 index 000000000..3c5017390 --- /dev/null +++ b/test/lit/wasm-split/instrument-memory-too-small.wast @@ -0,0 +1,10 @@ +;; Test that the instrumentation increases the memory bounds if necessary + +;; RUN: wasm-split %s --instrument -S -o - | filecheck %s + +;; CHECK: (memory $0 1 1) +;; CHECK: (export "__write_profile" (func $__write_profile)) + +(module + (memory $0 0 0) +) |