aboutsummaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/wasm/batch-runner.html28
-rw-r--r--ext/wasm/common/testing.css20
-rw-r--r--ext/wasm/index.html54
-rw-r--r--ext/wasm/speedtest1-worker.html315
-rw-r--r--ext/wasm/speedtest1-worker.js99
-rw-r--r--ext/wasm/speedtest1.html4
6 files changed, 491 insertions, 29 deletions
diff --git a/ext/wasm/batch-runner.html b/ext/wasm/batch-runner.html
index 10f7e45df..38f38070c 100644
--- a/ext/wasm/batch-runner.html
+++ b/ext/wasm/batch-runner.html
@@ -59,33 +59,5 @@
<script src="sqlite3.js"></script>
<script src="common/SqliteTestUtil.js"></script>
<script src="batch-runner.js"></script>
- <style>
- body {
- display: flex;
- flex-direction: column;
- flex-wrap: wrap;
- }
- .warning { color: firebrick; }
- .input-wrapper {
- white-space: nowrap;
- }
- #test-output {
- border: 1px inset;
- padding: 0.25em;
- /*max-height: 30em;*/
- overflow: auto;
- white-space: break-spaces;
- display: flex; flex-direction: column;
- }
- #test-output.reverse {
- flex-direction: column-reverse;
- }
- .hidden {
- position: absolute !important;
- opacity: 0 !important;
- pointer-events: none !important;
- display: none !important;
- }
- </style>
</body>
</html>
diff --git a/ext/wasm/common/testing.css b/ext/wasm/common/testing.css
index 09c570f48..e112fd0a8 100644
--- a/ext/wasm/common/testing.css
+++ b/ext/wasm/common/testing.css
@@ -1,3 +1,8 @@
+body {
+ display: flex;
+ flex-direction: column;
+ flex-wrap: wrap;
+}
textarea {
font-family: monospace;
}
@@ -29,4 +34,17 @@ span.labeled-input {
color: red;
background-color: yellow;
}
-#test-output { font-family: monospace }
+.warning { color: firebrick; }
+.input-wrapper { white-space: nowrap; }
+#test-output {
+ border: 1px inset;
+ padding: 0.25em;
+ /*max-height: 30em;*/
+ overflow: auto;
+ white-space: break-spaces;
+ display: flex; flex-direction: column;
+ font-family: monospace;
+}
+#test-output.reverse {
+ flex-direction: column-reverse;
+}
diff --git a/ext/wasm/index.html b/ext/wasm/index.html
new file mode 100644
index 000000000..def70cce0
--- /dev/null
+++ b/ext/wasm/index.html
@@ -0,0 +1,54 @@
+<!doctype html>
+<html lang="en-us">
+ <head>
+ <meta charset="utf-8">
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
+ <link rel="stylesheet" href="common/testing.css"/>
+ <title>sqlite3 WASM Testing Page Index</title>
+ </head>
+ <body>
+ <header id='titlebar'><span>sqlite3 WASM test pages</span></header>
+ <hr>
+ <div>Below is the list of test pages for the sqlite3 WASM
+ builds. All of them require that this directory have been
+ "make"d first. The intent is that <em>this</em> page be run
+ using:</div>
+ <blockquote><pre>althttpd -page index.html</pre></blockquote>
+ <div>and the individual tests be started in their own tab.</div>
+ <div>Warnings and Caveats:
+ <ul class='warning'>
+ <li>Some of these pages require that
+ the web server emit the so-called COOP and COEP headers. The
+ default build of althttpd <em>does not</em>.
+ </li>
+ <li>Whether or not WASMFS/OPFS support is enabled on any given
+ page may depend on build-time options which are <em>off by
+ default</em> because they currently (as of 2022-09-08) break
+ with Worker-based pages.
+ </li>
+ </ul>
+ </div>
+ <div>The tests...
+ <ul id='test-list'>
+ <li><a href='testing1.html'>testing1</a>: sanity tests of the core APIs and surrounding utility code.</li>
+ <li><a href='testing2.html'>testing2</a>: Worker-based test of OO API #1.</li>
+ <li><a href='testing-worker1-promiser.html'>testing-worker1-promiser</a>:
+ tests for the Promise-based wrapper of the Worker-based API.</li>
+ <li><a href='batch-runner.html'>batch-runner</a>: runs batches of SQL exported from speedtest1.</li>
+ <li><a href='speedtest1.html'>speedtest1</a>: a main-thread WASM build of speedtest1.</li>
+ <li><a href='speedtest1-worker.html'>speedtest1-worker</a>: an interactive Worker-thread variant of speedtest1.</li>
+ <li><a href='demo-oo1.html'>demo-oo1</a>: demonstration of the OO API #1.</li>
+ <!--li><a href='x.html'></a></li-->
+ </ul>
+ </div>
+ <style>
+ #test-list { font-size: 120%; }
+ </style>
+ <script>//Assign a distinct target tab name for each test page...
+ document.querySelectorAll('a').forEach(function(e){
+ e.target = e.href;
+ });
+ </script>
+ </body>
+</html>
diff --git a/ext/wasm/speedtest1-worker.html b/ext/wasm/speedtest1-worker.html
new file mode 100644
index 000000000..60c475798
--- /dev/null
+++ b/ext/wasm/speedtest1-worker.html
@@ -0,0 +1,315 @@
+<!doctype html>
+<html lang="en-us">
+ <head>
+ <meta charset="utf-8">
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
+ <link rel="stylesheet" href="common/emscripten.css"/>
+ <link rel="stylesheet" href="common/testing.css"/>
+ <title>speedtest1.wasm Worker</title>
+ </head>
+ <body>
+ <header id='titlebar'>speedtest1.wasm Worker</header>
+ <div>See also: <a href='speedtest1.html'>A main-thread variant of this page.</a></div>
+ <!-- emscripten bits -->
+ <figure id="module-spinner">
+ <div class="spinner"></div>
+ <div class='center'><strong>Initializing app...</strong></div>
+ <div class='center'>
+ On a slow internet connection this may take a moment. If this
+ message displays for "a long time", intialization may have
+ failed and the JavaScript console may contain clues as to why.
+ </div>
+ </figure>
+ <div class="emscripten" id="module-status">Downloading...</div>
+ <div class="emscripten">
+ <progress value="0" max="100" id="module-progress" hidden='1'></progress>
+ </div><!-- /emscripten bits -->
+ <fieldset id='ui-controls' class='hidden'>
+ <legend>Options</legend>
+ <div id='toolbar'>
+ <div id='toolbar-select'>
+ <select id='select-flags' size='10' multiple></select>
+ <div>TODO? Options which require values are not represented here.</div>
+ </div>
+ <div class='toolbar-inner-vertical' id='toolbar-selected-flags'>
+ <button id='btn-reset-flags'>Reset Flags</button>
+ <button id='btn-output-clear'>Clear output</button>
+ <button id='btn-run'>Run</button>
+ </div>
+ <div class='toolbar-inner-vertical' id='toolbar-runner-controls'>
+ <button id='btn-reset-flags'>Reset Flags</button>
+ <button id='btn-output-clear'>Clear output</button>
+ <button id='btn-run'>Run</button>
+ </div>
+ </div>
+ </fieldset>
+ <div>
+ <span class='input-wrapper'>
+ <input type='checkbox' class='disable-during-eval' id='cb-reverse-log-order' checked></input>
+ <label for='cb-reverse-log-order' id='lbl-reverse-log-order'>Reverse log order</label>
+ </span>
+ </div>
+ <div id='test-output'></div>
+ <style>
+ #test-output {
+ white-space: break-spaces;
+ overflow: auto;
+ }
+ #toolbar {
+ display: flex;
+ flex-direction: row;
+ flex-wrap: wrap;
+ }
+ #toolbar > * {
+ margin: 0 0.5em;
+ }
+ .toolbar-inner-vertical {
+ display: flex;
+ flex-direction: column;
+ justify-content: space-between;
+ }
+ #toolbar-select {
+ display: flex;
+ flex-direction: column;
+ }
+ .toolbar-inner-vertical > *, #toolbar-select > * {
+ margin: 0.2em 0;
+ }
+ #select-flags > option {
+ white-space: pre;
+ font-family: monospace;
+ }
+ fieldset {
+ border-radius: 0.5em;
+ }
+ #toolbar-runner-controls { flex-grow: 1 }
+ #toolbar-runner-controls > * { flex: 1 0 auto }
+ #toolbar-selected-flags::before {
+ font-family: initial;
+ content:"Selected flags: ";
+ }
+ #toolbar-selected-flags {
+ font-family: monospace;
+ justify-content: flex-start;
+ }
+ </style>
+ <script>(function(){
+ 'use strict';
+ const E = (sel)=>document.querySelector(sel);
+ const eOut = E('#test-output');
+ const log2 = function(cssClass,...args){
+ let ln;
+ if(1 || cssClass){
+ ln = document.createElement('div');
+ if(cssClass) ln.classList.add(cssClass);
+ ln.append(document.createTextNode(args.join(' ')));
+ }else{
+ // This doesn't work with the "reverse order" option!
+ ln = document.createTextNode(args.join(' ')+'\n');
+ }
+ eOut.append(ln);
+ };
+ const log = (...args)=>{
+ //console.log(...args);
+ log2('', ...args);
+ };
+ const logErr = function(...args){
+ //console.error(...args);
+ log2('error', ...args);
+ };
+ const logWarn = function(...args){
+ //console.warn(...args);
+ log2('warning', ...args);
+ };
+
+ const spacePad = function(str,len=18){
+ if(str.length===len) return str;
+ else if(str.length>len) return str.substr(0,len);
+ const a = []; a.length = len - str.length;
+ return str+a.join(' ');
+ };
+ // OPTION elements seem to ignore white-space:pre, so do this the hard way...
+ const nbspPad = function(str,len=18){
+ if(str.length===len) return str;
+ else if(str.length>len) return str.substr(0,len);
+ const a = []; a.length = len - str.length;
+ return str+a.join('&nbsp;');
+ };
+
+ const W = new Worker("speedtest1-worker.js");
+ const mPost = function(msgType,payload){
+ W.postMessage({type: msgType, data: payload});
+ };
+
+ const eFlags = E('#select-flags');
+ const eSelectedFlags = E('#toolbar-selected-flags');
+
+ const getSelectedFlags = ()=>Array.prototype.map.call(eFlags.selectedOptions, (v)=>v.value);
+ const updateSelectedFlags = function(){
+ eSelectedFlags.innerText = '';
+ getSelectedFlags().forEach(function(f){
+ const e = document.createElement('span');
+ e.innerText = f;
+ eSelectedFlags.appendChild(e);
+ });
+ };
+ eFlags.addEventListener('change', updateSelectedFlags );
+ {
+ const flags = Object.create(null);
+ /* TODO? Flags which require values need custom UI
+ controls and some of them make little sense here
+ (e.g. --script FILE). */
+ flags["autovacuum"] = "Enable AUTOVACUUM mode";
+ //flags["cachesize"] = "N Set the cache size to N";
+ flags["checkpoint"] = "Run PRAGMA wal_checkpoint after each test case";
+ flags["exclusive"] = "Enable locking_mode=EXCLUSIVE";
+ flags["explain"] = "Like --sqlonly but with added EXPLAIN keywords";
+ //flags["heap"] = "SZ MIN Memory allocator uses SZ bytes & min allocation MIN";
+ flags["incrvacuum"] = "Enable incremenatal vacuum mode";
+ //flags["journal"] = "M Set the journal_mode to M";
+ //flags["key"] = "KEY Set the encryption key to KEY";
+ //flags["lookaside"] = "N SZ Configure lookaside for N slots of SZ bytes each";
+ flags["memdb"] = "Use an in-memory database";
+ //flags["mmap"] = "SZ MMAP the first SZ bytes of the database file";
+ flags["multithread"] = "Set multithreaded mode";
+ flags["nomemstat"] = "Disable memory statistics";
+ flags["nosync"] = "Set PRAGMA synchronous=OFF";
+ flags["notnull"] = "Add NOT NULL constraints to table columns";
+ //flags["output"] = "FILE Store SQL output in FILE";
+ //flags["pagesize"] = "N Set the page size to N";
+ //flags["pcache"] = "N SZ Configure N pages of pagecache each of size SZ bytes";
+ //flags["primarykey"] = "Use PRIMARY KEY instead of UNIQUE where appropriate";
+ //flags["repeat"] = "N Repeat each SELECT N times (default: 1)";
+ flags["reprepare"] = "Reprepare each statement upon every invocation";
+ //flags["reserve"] = "N Reserve N bytes on each database page";
+ //flags["script"] = "FILE Write an SQL script for the test into FILE";
+ flags["serialized"] = "Set serialized threading mode";
+ flags["singlethread"] = "Set single-threaded mode - disables all mutexing";
+ flags["sqlonly"] = "No-op. Only show the SQL that would have been run.";
+ flags["shrink"] = "memory Invoke sqlite3_db_release_memory() frequently.";
+ //flags["size"] = "N Relative test size. Default=100";
+ flags["strict"] = "Use STRICT table where appropriate";
+ flags["stats"] = "Show statistics at the end";
+ //flags["temp"] = "N N from 0 to 9. 0: no temp table. 9: all temp tables";
+ //flags["testset"] = "T Run test-set T (main, cte, rtree, orm, fp, debug)";
+ flags["trace"] = "Turn on SQL tracing";
+ //flags["threads"] = "N Use up to N threads for sorting";
+ /*
+ The core API's WASM build does not support UTF16, but in
+ this app it's not an issue because the data are not crossing
+ JS/WASM boundaries.
+ */
+ flags["utf16be"] = "Set text encoding to UTF-16BE";
+ flags["utf16le"] = "Set text encoding to UTF-16LE";
+ flags["verify"] = "Run additional verification steps.";
+ flags["without"] = "rowid Use WITHOUT ROWID where appropriate";
+ const preselectedFlags = [
+ 'singlethread',
+ 'memdb'
+ ];
+ Object.keys(flags).sort().forEach(function(f){
+ const opt = document.createElement('option');
+ eFlags.appendChild(opt);
+ const lbl = nbspPad('--'+f)+flags[f];
+ //opt.innerText = lbl;
+ opt.innerHTML = lbl;
+ opt.value = '--'+f;
+ if(preselectedFlags.indexOf(f) >= 0) opt.selected = true;
+ });
+
+ const cbReverseLog = E('#cb-reverse-log-order');
+ const lblReverseLog = E('#lbl-reverse-log-order');
+ if(cbReverseLog.checked){
+ lblReverseLog.classList.add('warning');
+ eOut.classList.add('reverse');
+ }
+ cbReverseLog.addEventListener('change', function(){
+ if(this.checked){
+ eOut.classList.add('reverse');
+ lblReverseLog.classList.add('warning');
+ }else{
+ eOut.classList.remove('reverse');
+ lblReverseLog.classList.remove('warning');
+ }
+ }, false);
+ updateSelectedFlags();
+ }
+ E('#btn-output-clear').addEventListener('click', ()=>{
+ eOut.innerText = '';
+ });
+ E('#btn-reset-flags').addEventListener('click',()=>{
+ eFlags.value = '';
+ updateSelectedFlags();
+ });
+ E('#btn-run').addEventListener('click',function(){
+ log("Running speedtest1. UI controls will be disabled until it completes.");
+ mPost('run', getSelectedFlags());
+ });
+
+ const eControls = E('#ui-controls');
+ /** Update Emscripten-related UI elements while loading the module. */
+ const updateLoadStatus = function f(text){
+ if(!f.last){
+ f.last = { text: '', step: 0 };
+ const E = (cssSelector)=>document.querySelector(cssSelector);
+ f.ui = {
+ status: E('#module-status'),
+ progress: E('#module-progress'),
+ spinner: E('#module-spinner')
+ };
+ }
+ if(text === f.last.text) return;
+ f.last.text = text;
+ if(f.ui.progress){
+ f.ui.progress.value = f.last.step;
+ f.ui.progress.max = f.last.step + 1;
+ }
+ ++f.last.step;
+ if(text) {
+ f.ui.status.classList.remove('hidden');
+ f.ui.status.innerText = text;
+ }else{
+ if(f.ui.progress){
+ f.ui.progress.remove();
+ f.ui.spinner.remove();
+ delete f.ui.progress;
+ delete f.ui.spinner;
+ }
+ f.ui.status.classList.add('hidden');
+ }
+ };
+
+ log("Control-click the flags to (de)select multiple flags.");
+ logWarn("\nThe easiest way to try different optimization levels is, from this directory:\n"+
+ " $ make clean; make -e emcc_opt='-O2' speedtest1\n"+
+ "Then reload this page. -O2 seems to consistently produce the fastest results.\n");
+ logWarn('\nAchtung: the Worker thread overhead slightly reduces the speed',
+ 'compared to running the same options via speedtest1.html.\n'+
+ 'TODO: add a link in this app which launches the main-thread',
+ 'version with the same flags.\n');
+
+ W.onmessage = function(msg){
+ msg = msg.data;
+ switch(msg.type){
+ case 'ready': log("Worker is ready."); eControls.classList.remove('hidden'); break;
+ case 'stdout': log(msg.data); break;
+ case 'stdout': logErr(msg.data); break;
+ case 'run-start':
+ eControls.disabled = true;
+ log("Running speedtest1 with argv =",msg.data.join(' '));
+ break;
+ case 'run-end': log("speedtest1 finished.");
+ eControls.disabled = false;
+ // app output is in msg.data
+ break;
+ case 'error': logErr(msg.data); break;
+ case 'load-status': updateLoadStatus(msg.data); break;
+ default:
+ logErr("Unhandled worker message type:",arguments[0]);
+ break;
+ }
+ };
+ })();</script>
+ </body>
+</html>
diff --git a/ext/wasm/speedtest1-worker.js b/ext/wasm/speedtest1-worker.js
new file mode 100644
index 000000000..8512bdbbf
--- /dev/null
+++ b/ext/wasm/speedtest1-worker.js
@@ -0,0 +1,99 @@
+'use strict';
+(function(){
+ importScripts('common/whwasmutil.js','speedtest1.js');
+ /**
+ If this environment contains OPFS, this function initializes it and
+ returns the name of the dir on which OPFS is mounted, else it returns
+ an empty string.
+ */
+ const opfsDir = function f(wasmUtil){
+ if(undefined !== f._) return f._;
+ const pdir = '/persistent';
+ if( !self.FileSystemHandle
+ || !self.FileSystemDirectoryHandle
+ || !self.FileSystemFileHandle){
+ return f._ = "";
+ }
+ try{
+ if(0===wasmUtil.xCallWrapped(
+ 'sqlite3_wasm_init_opfs', 'i32', ['string'], pdir
+ )){
+ return f._ = pdir;
+ }else{
+ return f._ = "";
+ }
+ }catch(e){
+ // sqlite3_wasm_init_opfs() is not available
+ return f._ = "";
+ }
+ };
+ opfsDir._ = undefined;
+
+ const mPost = function(msgType,payload){
+ postMessage({type: msgType, data: payload});
+ };
+
+ const App = Object.create(null);
+ App.logBuffer = [];
+ const logMsg = (type,msgArgs)=>{
+ const msg = msgArgs.join(' ');
+ App.logBuffer.push(msg);
+ mPost(type,msg);
+ };
+ const log = (...args)=>logMsg('stdout',args);
+ const logErr = (...args)=>logMsg('stderr',args);
+
+ const runSpeedtest = function(cliFlagsArray){
+ const scope = App.wasm.scopedAllocPush();
+ const dbFile = 0 ? "" : App.pDir+"/speedtest1.db";
+ try{
+ const argv = [
+ "speedtest1.wasm", ...cliFlagsArray, dbFile
+ ];
+ App.logBuffer.length = 0;
+ mPost('run-start', [...argv]);
+ App.wasm.xCall('__main_argc_argv', argv.length,
+ App.wasm.scopedAllocMainArgv(argv));
+ }catch(e){
+ mPost('error',e.message);
+ }finally{
+ App.wasm.scopedAllocPop(scope);
+ App.unlink(dbFile);
+ mPost('run-end', App.logBuffer.join('\n'));
+ App.logBuffer.length = 0;
+ }
+ };
+
+ self.onmessage = function(msg){
+ msg = msg.data;
+ switch(msg.type){
+ case 'run': runSpeedtest(msg.data || []); break;
+ default:
+ logErr("Unhandled worker message type:",msg.type);
+ break;
+ }
+ };
+
+ const EmscriptenModule = {
+ print: log,
+ printErr: logErr,
+ setStatus: (text)=>mPost('load-status',text)
+ };
+ self.sqlite3Speedtest1InitModule(EmscriptenModule).then(function(EmscriptenModule){
+ log("Module inited.");
+ App.wasm = {
+ exports: EmscriptenModule.asm,
+ alloc: (n)=>EmscriptenModule._malloc(n),
+ dealloc: (m)=>EmscriptenModule._free(m),
+ memory: EmscriptenModule.asm.memory || EmscriptenModule.wasmMemory
+ };
+ //console.debug('wasm =',wasm);
+ self.WhWasmUtilInstaller(App.wasm);
+ App.unlink = App.wasm.xWrap("sqlite3_wasm_vfs_unlink", "int", ["string"]);
+ App.pDir = opfsDir(App.wasm);
+ if(App.pDir){
+ log("Persistent storage:",pDir);
+ }
+ mPost('ready',true);
+ });
+})();
diff --git a/ext/wasm/speedtest1.html b/ext/wasm/speedtest1.html
index 5e05feed2..fad2b2812 100644
--- a/ext/wasm/speedtest1.html
+++ b/ext/wasm/speedtest1.html
@@ -10,6 +10,7 @@
</head>
<body>
<header id='titlebar'><span>speedtest1.wasm</span></header>
+ <div>See also: <a href='speedtest1-worker.html'>A Worker-thread variant of this page.</a></div>
<!-- emscripten bits -->
<figure id="module-spinner">
<div class="spinner"></div>
@@ -24,6 +25,9 @@
<div class="emscripten">
<progress value="0" max="100" id="module-progress" hidden='1'></progress>
</div><!-- /emscripten bits -->
+ <div class='warning'>This page starts running the main exe when it loads, which will
+ block the UI until it finishes! Adding UI controls to manually configure and start it
+ are TODO.</div>
<div>Output is sent to the dev console because we cannot update the UI while the
speedtest is running unless/until we move the speedtest to a worker thread.</div>
<hr>