From: stephan Date: Fri, 9 Sep 2022 04:50:18 +0000 (+0000) Subject: speedtest1 wasm: add a link in the worker variant which launches the main-thread... X-Git-Tag: version-3.40.0~169^2~130 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e66b26818b3a6347dd395df4db568b92f9fe662e;p=thirdparty%2Fsqlite.git speedtest1 wasm: add a link in the worker variant which launches the main-thread variant with the selected CLI flags. Append collected stdout/stderr to the main-thread page after execution is finished to avoid having to open the dev tools (which inexplicably slows down wasm execution). FossilOrigin-Name: 02709ee2beab36d144b807fd9ffaee639e3c1bdd1908a34e05f3fd23dad2ef66 --- diff --git a/ext/wasm/common/SqliteTestUtil.js b/ext/wasm/common/SqliteTestUtil.js index 51cd64108e..779f271fb4 100644 --- a/ext/wasm/common/SqliteTestUtil.js +++ b/ext/wasm/common/SqliteTestUtil.js @@ -113,6 +113,46 @@ ++this.counter; if(!this.toBool(expr)) throw new Error(msg || "throwUnless() failed"); return this; + }, + + /** + Parses window.location.search-style string into an object + containing key/value pairs of URL arguments (already + urldecoded). The object is created using Object.create(null), + so contains only parsed-out properties and has no prototype + (and thus no inherited properties). + + If the str argument is not passed (arguments.length==0) then + window.location.search.substring(1) is used by default. If + neither str is passed in nor window exists then false is returned. + + On success it returns an Object containing the key/value pairs + parsed from the string. Keys which have no value are treated + has having the boolean true value. + + Pedantic licensing note: this code has appeared in other source + trees, but was originally written by the same person who pasted + it into those trees. + */ + processUrlArgs: function(str) { + if( 0 === arguments.length ) { + if( ('undefined' === typeof window) || + !window.location || + !window.location.search ) return false; + else str = (''+window.location.search).substring(1); + } + if( ! str ) return false; + str = (''+str).split(/#/,2)[0]; // remove #... to avoid it being added as part of the last value. + const args = Object.create(null); + const sp = str.split(/&+/); + const rx = /^([^=]+)(=(.+))?/; + var i, m; + for( i in sp ) { + m = rx.exec( sp[i] ); + if( ! m ) continue; + args[decodeURIComponent(m[1])] = (m[3] ? decodeURIComponent(m[3]) : true); + } + return args; } }; diff --git a/ext/wasm/speedtest1-worker.html b/ext/wasm/speedtest1-worker.html index 7f913be98b..74ccf66737 100644 --- a/ext/wasm/speedtest1-worker.html +++ b/ext/wasm/speedtest1-worker.html @@ -32,10 +32,11 @@
TODO? Options which require values are not represented here.
-
- - - +
+
+ speedtest1.html +
@@ -105,6 +106,8 @@ content:"Selected flags: "; } #toolbar-selected-flags { + display: flex; + flex-direction: column; font-family: monospace; justify-content: flex-start; } @@ -138,14 +141,14 @@ log2('warning', ...args); }; - const spacePad = function(str,len=18){ + const spacePad = function(str,len=21){ 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){ + const nbspPad = function(str,len=21){ if(str.length===len) return str; else if(str.length>len) return str.substr(0,len); const a = []; a.length = len - str.length; @@ -159,15 +162,20 @@ const eFlags = E('#select-flags'); const eSelectedFlags = E('#toolbar-selected-flags'); - + const eLinkMainThread = E('#link-main-thread'); const getSelectedFlags = ()=>Array.prototype.map.call(eFlags.selectedOptions, (v)=>v.value); const updateSelectedFlags = function(){ eSelectedFlags.innerText = ''; - getSelectedFlags().forEach(function(f){ + const flags = getSelectedFlags(); + flags.forEach(function(f){ const e = document.createElement('span'); e.innerText = f; eSelectedFlags.appendChild(e); }); + const rxStripDash = /^(-+)?/; + const comma = flags.map((v)=>v.replace(rxStripDash,'')).join(','); + eLinkMainThread.setAttribute('target', 'main-thread-'+comma); + eLinkMainThread.href = 'speedtest1.html?flags='+comma; }; eFlags.addEventListener('change', updateSelectedFlags ); { diff --git a/ext/wasm/speedtest1.html b/ext/wasm/speedtest1.html index 0f95145eb4..bc8b4ec9f1 100644 --- a/ext/wasm/speedtest1.html +++ b/ext/wasm/speedtest1.html @@ -28,16 +28,14 @@
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.
-
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.
-
Achtung: running it with the dev tools open drastically - slows it down: by a factor of 2.5+. For faster results, keep the dev tools closed - when running it! -
-
-
+
Achtung: running it with the dev tools open may + drastically slow it down. For faster results, keep the dev + tools closed when running it!
+
Output is delayed/buffered because we cannot update the UI while the + speedtest is running. Output will appear below when ready... +
@@ -78,16 +76,20 @@ eOut.append(ln); //this.e.output.lastElementChild.scrollIntoViewIfNeeded(); }; - const doHtmlOutput = false + const logList = []; + const dumpLogList = function(){ + logList.forEach((v)=>log2('',v)); + logList.length = 0; + }; /* can't update DOM while speedtest is running unless we run speedtest in a worker thread. */; const log = (...args)=>{ console.log(...args); - if(doHtmlOutput) log2('', ...args); + logList.push(args.join(' ')); }; const logErr = function(...args){ console.error(...args); - if(doHtmlOutput) log2('error', ...args); + logList.push('ERROR: '+args.join(' ')); }; const runTests = function(EmscriptenModule){ @@ -107,31 +109,38 @@ } const scope = wasm.scopedAllocPush(); const dbFile = 0 ? "" : pDir+"/speedtest1.db"; - const argv = [ - // TODO: accept flags via URL arguments and/or a - // UI control. A multi-SELECT element should do - // nicely. - "speedtest1", - "--singlethread", - "--nomutex", - "--nosync", - "--nomemstat", - "--big-transactions", // important for tests 410 and 510! + const urlArgs = self.SqliteTestUtil.processUrlArgs(); + const argv = ["speedtest1"]; + if(urlArgs.flags){ + // transform flags=a,b,c to ["--a", "--b", "--c"] + argv.push(...(urlArgs.flags.split(',').map((v)=>'--'+v))); + }else{ + argv.push( + "--singlethread", + "--nomutex", + "--nosync", + "--nomemstat" + ); //"--memdb", // note that memdb trumps the filename arg - dbFile - ]; + argv.push("--big-transactions"/*important for tests 410 and 510!*/, + dbFile); + } console.log("argv =",argv); // These log messages are not emitted to the UI until after main() returns. Fixing that // requires moving the main() call and related cleanup into a timeout handler. - log2('',"Starting native main() with flags:",argv.join(' ')); - log2('',"This will take a while and the browser might warn about the runaway JS. Give it time."); + if(pDir) unlink(dbFile); + log2('',"Starting native app:\n ",argv.join(' ')); + log2('',"This will take a while and the browser might warn about the runaway JS.", + "Give it time..."); + logList.length = 0; setTimeout(function(){ wasm.xCall('__main_argc_argv', argv.length, wasm.scopedAllocMainArgv(argv)); wasm.scopedAllocPop(scope); if(pDir) unlink(dbFile); - log2('',"Done running native main(). Check dev console for output."); - }, 100); + logList.unshift("Done running native main(). Output:"); + dumpLogList(); + }, 50); }/*runTests()*/; self.sqlite3TestModule.print = log; diff --git a/manifest b/manifest index ff1338362f..771a1e4d08 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\suse\sof\sthe\s--big-transactions\sflag\sin\sthe\sspeedtest1\sJS\sapps. -D 2022-09-08T21:33:50.335 +C speedtest1\swasm:\sadd\sa\slink\sin\sthe\sworker\svariant\swhich\slaunches\sthe\smain-thread\svariant\swith\sthe\sselected\sCLI\sflags.\sAppend\scollected\sstdout/stderr\sto\sthe\smain-thread\spage\safter\sexecution\sis\sfinished\sto\savoid\shaving\sto\sopen\sthe\sdev\stools\s(which\sinexplicably\sslows\sdown\swasm\sexecution). +D 2022-09-09T04:50:18.498 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -491,7 +491,7 @@ F ext/wasm/api/sqlite3-wasi.h 25356084cfe0d40458a902afb465df8c21fc4152c1d0a59b56 F ext/wasm/api/sqlite3-wasm.c 19c3797edc35821e362a8b60ce45d1adfe6d24fca7cd1f55f89d2086ef33870e F ext/wasm/batch-runner.html 23209ade7981acce7ecd79d6eff9f4c5a4e8b14ae867ac27cd89b230be640fa6 F ext/wasm/batch-runner.js a727cbbffe63fd17fb5a590dc679f0b13bd51880e8f84b461d7df246417689e8 -F ext/wasm/common/SqliteTestUtil.js 7a543e238c2ebda922c85076abda017d0480944fdfee576692a0c3a580319ebd +F ext/wasm/common/SqliteTestUtil.js 529161a624265ba84271a52db58da022649832fa1c71309fb1e02cc037327a2b F ext/wasm/common/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d69513dd6ef1f289ada3f F ext/wasm/common/testing.css 3a5143699c2b73a85b962271e1a9b3241b30d90e30d895e4f55665e648572962 F ext/wasm/common/whwasmutil.js f7282ef36c9625330d4e6e82d1beec6678cd101e95e7108cd85db587a788c145 @@ -511,9 +511,9 @@ F ext/wasm/scratchpad-opfs-main.js 69e960e9161f6412fd0c30f355d4112f1894d6609eb43 F ext/wasm/scratchpad-opfs-worker.html 66c1d15d678f3bd306373d76b61c6c8aef988f61f4a8dd40185d452f9c6d2bf5 F ext/wasm/scratchpad-opfs-worker.js 3ec2868c669713145c76eb5877c64a1b20741f741817b87c907a154b676283a9 F ext/wasm/scratchpad-opfs-worker2.js 5f2237427ac537b8580b1c659ff14ad2621d1694043eaaf41ae18dbfef2e48c0 -F ext/wasm/speedtest1-worker.html 23b91da39859b890d73b28bd74629442c6873f38dc4d7ca94cacdc1be1202fb1 +F ext/wasm/speedtest1-worker.html 516f8434623e229d98554d34be64faeb9651083f20f2d0ebac2e67ea715574e8 F ext/wasm/speedtest1-worker.js 356b9953add4449acf199793db9b76b11ee016021918d8daffd19f08ec68d305 -F ext/wasm/speedtest1.html ffda8a118c09d5429bc34b1ddfd05a963b6786ac83f2deae4f5241c2f5437f83 +F ext/wasm/speedtest1.html 8f61cbe68300acca25dd9fa74dce79b774786e2b4feeb9bcbc46e1cefbfa6262 F ext/wasm/split-speedtest1-script.sh a3e271938d4d14ee49105eb05567c6a69ba4c1f1293583ad5af0cd3a3779e205 x F ext/wasm/sql/000-mandelbrot.sql 775337a4b80938ac8146aedf88808282f04d02d983d82675bd63d9c2d97a15f0 F ext/wasm/sql/001-sudoku.sql 35b7cb7239ba5d5f193bc05ec379bcf66891bce6f2a5b3879f2f78d0917299b5 @@ -2019,8 +2019,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 51395c005da46b7fa5a5f28809dd8fea263a6bac2b1492759b3d5a5aa7d399ca -R 838553aa9700f04488b76fccfa35dc26 +P f2846dcbcaac7880394fb14597c3a60ed310419128c4c5b863cd771a7e5cdeb5 +R 76ac17000a84c98911a70f4e46426ce1 U stephan -Z 42d1e2550cb35842fb99b726ce6e4b2a +Z 8dd38cd18f4d355043f091ca5e469e89 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 8b41f7137e..b814c009b3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f2846dcbcaac7880394fb14597c3a60ed310419128c4c5b863cd771a7e5cdeb5 \ No newline at end of file +02709ee2beab36d144b807fd9ffaee639e3c1bdd1908a34e05f3fd23dad2ef66 \ No newline at end of file