]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
speedtest1 wasm: add a link in the worker variant which launches the main-thread...
authorstephan <stephan@noemail.net>
Fri, 9 Sep 2022 04:50:18 +0000 (04:50 +0000)
committerstephan <stephan@noemail.net>
Fri, 9 Sep 2022 04:50:18 +0000 (04:50 +0000)
FossilOrigin-Name: 02709ee2beab36d144b807fd9ffaee639e3c1bdd1908a34e05f3fd23dad2ef66

ext/wasm/common/SqliteTestUtil.js
ext/wasm/speedtest1-worker.html
ext/wasm/speedtest1.html
manifest
manifest.uuid

index 51cd64108eed54745c4214621229ac36e8c98947..779f271fb4f9fd20e30eab0376bd512f3adeccf3 100644 (file)
       ++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;
     }
   };
 
index 7f913be98b12641d99b628ca4eee30361d53d9d9..74ccf667374ab325415438f204fe60cc00dd1522 100644 (file)
           <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 class='toolbar-inner-vertical'>
+          <div id='toolbar-selected-flags'></div>
+          <span>&rarr; <a id='link-main-thread' href='#' target='main-thread'
+                          title='Start speedtest1.html with the selected flags'>speedtest1.html</a>
+          </span>
         </div>
         <div class='toolbar-inner-vertical' id='toolbar-runner-controls'>
           <button id='btn-reset-flags'>Reset Flags</button>
         content:"Selected flags: ";
       }
       #toolbar-selected-flags {
+        display: flex;
+        flex-direction: column;
         font-family: monospace;
         justify-content: flex-start;
       }
         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;
 
       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 );
       {
index 0f95145eb4a17e6585e28aa752e481ef63facc3e..bc8b4ec9f1460cdde9327ed141e32e8e549ddc76 100644 (file)
     <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>
-      <div class='warning'>Achtung: running it with the dev tools open <em>drastically</em>
-        slows it down: by a factor of 2.5+. For faster results, keep the dev tools closed
-        when running it!
-    </div>
-    <hr>
-    <div id='test-output'>
+    <div class='warning'>Achtung: running it with the dev tools open may
+      <em>drastically</em> slow it down. For faster results, keep the dev
+      tools closed when running it!
     </div>
+    <div>Output is delayed/buffered because we cannot update the UI while the
+      speedtest is running. Output will appear below when ready...
+    <div id='test-output'></div>
     <script src="common/whwasmutil.js"></script>
     <script src="common/SqliteTestUtil.js"></script>
     <script src="speedtest1.js"></script>
           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){
           }
           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;
index ff1338362f5121bb32b8bfea242bf14cc400dd88..771a1e4d083fa1542e4a44a5efa29ab467d113ec 100644 (file)
--- 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.
index 8b41f7137e6fc1f4c1be25f7d22939f0cdfff3c9..b814c009b30961a98f6c366333be468a22eea9e2 100644 (file)
@@ -1 +1 @@
-f2846dcbcaac7880394fb14597c3a60ed310419128c4c5b863cd771a7e5cdeb5
\ No newline at end of file
+02709ee2beab36d144b807fd9ffaee639e3c1bdd1908a34e05f3fd23dad2ef66
\ No newline at end of file