summaryrefslogtreecommitdiff
path: root/test/lit/wasm-split/call_exports.mjs
diff options
context:
space:
mode:
authorThomas Lively <7121787+tlively@users.noreply.github.com>2020-11-24 21:16:30 -0800
committerGitHub <noreply@github.com>2020-11-24 21:16:30 -0800
commit2aa6aa62c6182317679596f7372dde6ee3665d15 (patch)
treed8e842321db3383aa263ec6226a74ca8741119a9 /test/lit/wasm-split/call_exports.mjs
parent78ccc1976bac069ae65b2ec227e8c2c515a02801 (diff)
downloadbinaryen-2aa6aa62c6182317679596f7372dde6ee3665d15.tar.gz
binaryen-2aa6aa62c6182317679596f7372dde6ee3665d15.tar.bz2
binaryen-2aa6aa62c6182317679596f7372dde6ee3665d15.zip
[wasm-split] Read and use profiles (#3400)
Read the profiles produced by wasm-split's instrumentation to guide splitting. In this initial implementation, all functions that the profile shows to have been called are kept in the initial module. In the future, users may be able to tune this so that functions that are run later will still be split out.
Diffstat (limited to 'test/lit/wasm-split/call_exports.mjs')
-rw-r--r--test/lit/wasm-split/call_exports.mjs25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/lit/wasm-split/call_exports.mjs b/test/lit/wasm-split/call_exports.mjs
new file mode 100644
index 000000000..546564d2e
--- /dev/null
+++ b/test/lit/wasm-split/call_exports.mjs
@@ -0,0 +1,25 @@
+// Instantiates an instrumented module, calls the given exports, then collects
+// its wasm-split profile and writes it to a given file.
+//
+// Usage:
+//
+// node call_exports.mjs <module> <profile> <export>*
+
+import * as fs from 'fs';
+
+let wasm = process.argv[2];
+let outFile = process.argv[3];
+
+// Create the Wasm instance
+let { _, instance } = await WebAssembly.instantiate(fs.readFileSync(wasm));
+
+// Call the specified exports
+for (let i = 4; i < process.argv.length; i++) {
+ console.log('calling', process.argv[i]);
+ instance.exports[process.argv[i]]();
+}
+
+// Create and read the profile
+let profileSize = instance.exports['__write_profile'](0, 2**32 - 1);
+let profileData = Buffer.from(instance.exports.memory.buffer, 0, profileSize);
+fs.writeFileSync(outFile, profileData);