]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Consolidate the OPFS VFS's metrics-tracking code.
authorstephan <stephan@noemail.net>
Wed, 4 Mar 2026 16:30:51 +0000 (16:30 +0000)
committerstephan <stephan@noemail.net>
Wed, 4 Mar 2026 16:30:51 +0000 (16:30 +0000)
FossilOrigin-Name: b71c79ef9672c77a72a976ffcd7cbebfaf0ff314dff97b274f7d092de6a7773f

ext/wasm/api/opfs-common-shared.c-pp.js
ext/wasm/api/sqlite3-vfs-opfs-wl.c-pp.js
ext/wasm/api/sqlite3-vfs-opfs.c-pp.js
ext/wasm/mkwasmbuilds.c
manifest
manifest.uuid

index 077f4c5a6ae19ef01a7c49507322f061d10a8e56..376780217d3ff7c8d1c782abb885a9926a96d5bd 100644 (file)
@@ -453,6 +453,40 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
     const vfsName = wasm.cstrToJs(opfsVfs.$zName);
     const isWebLocker = 'opfs-wl'===vfsName;
     const state = util.nu();
+    opfsVfs.metrics = util.nu({
+      counters: util.nu(),
+      dump: function(){
+        let k, n = 0, t = 0, w = 0;
+        for(k in state.opIds){
+          const m = metrics[k];
+          n += m.count;
+          t += m.time;
+          w += m.wait;
+          m.avgTime = (m.count && m.time) ? (m.time / m.count) : 0;
+          m.avgWait = (m.count && m.wait) ? (m.wait / m.count) : 0;
+        }
+        sqlite3.config.log(globalThis.location.href,
+                    "metrics for",globalThis.location.href,":",metrics,
+                    "\nTotal of",n,"op(s) for",t,
+                    "ms (incl. "+w+" ms of waiting on the async side)");
+        sqlite3.config.log("Serialization metrics:",opfsVfs.metrics.counters.s11n);
+        //W.postMessage({type:'opfs-async-metrics'});
+      },
+      reset: function(){
+        let k;
+        const r = (m)=>(m.count = m.time = m.wait = 0);
+        const m = opfsVfs.metrics.counters;
+        for(k in state.opIds){
+          r(m[k] = Object.create(null));
+        }
+        let s = m.s11n = Object.create(null);
+        s = s.serialize = Object.create(null);
+        s.count = s.time = 0;
+        s = m.s11n.deserialize = Object.create(null);
+        s.count = s.time = 0;
+      }
+    })/*opfsVfs.metrics*/;
+
     /**
        asyncIdleWaitTime is how long (ms) to wait, in the async proxy,
        for each Atomics.wait() when waiting on inbound VFS API calls.
@@ -638,12 +672,15 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
       defaultUnlockAsap: false
     });
 
-//#if nope
-/* does not yet work this way */
-//#define opfs-has-metrics
+    opfsVfs.metrics.reset();
+//#if not defined nope
+//#// does not yet work this way
+//#define vfs.metrics.enable
+    const metrics = opfsVfs.metrics.counters;
 //#include api/opfs-common-inline.c-pp.js
-//#undef opfs-has-metrics
-    state.initS11n = initS11n;
+//#// import initS11n()
+//#undef vfs.metrics.enable
+    opfsVfs.initS11n = initS11n;
 //#endif
     return state;
   }/*createVfsStateObject()*/;
index dee1f6d190eba3842d92ec4ee683a889b3c43649..288f01e6509e3c5679310451dbbb25eae9fe84d3 100644 (file)
@@ -134,43 +134,8 @@ const installOpfsWlVfs = function callee(options){
     );
     const state = opfsUtil.createVfsStateObject(opfsVfs);
     state.verbose = options.verbose;
-    const metrics = Object.create(null);
-//#define opfs-has-metrics
-//#include api/opfs-common-inline.c-pp.js
-//#undef opfs-has-metrics
-
-    const vfsMetrics = {
-      dump: function(){
-        let k, n = 0, t = 0, w = 0;
-        for(k in state.opIds){
-          const m = metrics[k];
-          n += m.count;
-          t += m.time;
-          w += m.wait;
-          m.avgTime = (m.count && m.time) ? (m.time / m.count) : 0;
-          m.avgWait = (m.count && m.wait) ? (m.wait / m.count) : 0;
-        }
-        sqlite3.config.log(globalThis.location.href,
-                    "metrics for",globalThis.location.href,":",metrics,
-                    "\nTotal of",n,"op(s) for",t,
-                    "ms (incl. "+w+" ms of waiting on the async side)");
-        sqlite3.config.log("Serialization metrics:",metrics.s11n);
-        W.postMessage({type:'opfs-async-metrics'});
-      },
-      reset: function(){
-        let k;
-        const r = (m)=>(m.count = m.time = m.wait = 0);
-        for(k in state.opIds){
-          r(metrics[k] = Object.create(null));
-        }
-        let s = metrics.s11n = Object.create(null);
-        s = s.serialize = Object.create(null);
-        s.count = s.time = 0;
-        s = metrics.s11n.deserialize = Object.create(null);
-        s.count = s.time = 0;
-      }
-    }/*vfsMetrics*/;
-    vfsMetrics.reset();
+    const metrics = opfsVfs.metrics.counters;
+
     let promiseWasRejected = undefined;
     const promiseReject = (err)=>{
       promiseWasRejected = true;
@@ -643,8 +608,6 @@ const installOpfsWlVfs = function callee(options){
       }
     }/*sanityCheck()*/;
 
-    //const initS11n = state.initS11n || toss("Missing state.initS11n()");
-    //delete state.initS11n;
     W.onmessage = function({data}){
       //log("Worker.onmessage:",data);
       switch(data.type){
@@ -674,7 +637,8 @@ const installOpfsWlVfs = function callee(options){
               state.sabOPView = new Int32Array(state.sabOP);
               state.sabFileBufView = new Uint8Array(state.sabIO, 0, state.fileBufferSize);
               state.sabS11nView = new Uint8Array(state.sabIO, state.sabS11nOffset, state.sabS11nSize);
-              initS11n();
+              opfsVfs.initS11n();
+              delete opfsVfs.initS11n;
               if(options.sanityChecks){
                 warn("Running sanity checks because of opfs-sanity-check URL arg...");
                 sanityCheck();
@@ -720,7 +684,7 @@ globalThis.sqlite3ApiBootstrap.initializersAsync.push(async (sqlite3)=>{
       //sqlite3.config.warn("installOpfsWlVfs.defaultProxyUri =",installOpfsWlVfs.defaultProxyUri);
     }
     return installOpfsWlVfs().catch((e)=>{
-      sqlite3.config.warn("Ignoring inability to install OPFS-WL sqlite3_vfs:",e.message);
+      sqlite3.config.warn("Ignoring inability to install OPFS-WL sqlite3_vfs:",e);
     });
   }catch(e){
     sqlite3.config.error("installOpfsWlVfs() exception:",e);
index b294163236dd293a14e3d43c864147e7aeb91b3d..ba5fe9918ef1dd92eb2211fc8312ce3b4f9260f6 100644 (file)
@@ -181,43 +181,7 @@ const installOpfsVfs = function callee(options){
     */
     const state = opfsUtil.createVfsStateObject(opfsVfs);
     state.verbose = options.verbose;
-    const metrics = Object.create(null);
-//#define opfs-has-metrics
-//#include api/opfs-common-inline.c-pp.js
-//#undef opfs-has-metrics
-
-    const vfsMetrics = {
-      dump: function(){
-        let k, n = 0, t = 0, w = 0;
-        for(k in state.opIds){
-          const m = metrics[k];
-          n += m.count;
-          t += m.time;
-          w += m.wait;
-          m.avgTime = (m.count && m.time) ? (m.time / m.count) : 0;
-          m.avgWait = (m.count && m.wait) ? (m.wait / m.count) : 0;
-        }
-        sqlite3.config.log(globalThis.location.href,
-                    "metrics for",globalThis.location.href,":",metrics,
-                    "\nTotal of",n,"op(s) for",t,
-                    "ms (incl. "+w+" ms of waiting on the async side)");
-        sqlite3.config.log("Serialization metrics:",metrics.s11n);
-        W.postMessage({type:'opfs-async-metrics'});
-      },
-      reset: function(){
-        let k;
-        const r = (m)=>(m.count = m.time = m.wait = 0);
-        for(k in state.opIds){
-          r(metrics[k] = Object.create(null));
-        }
-        let s = metrics.s11n = Object.create(null);
-        s = s.serialize = Object.create(null);
-        s.count = s.time = 0;
-        s = metrics.s11n.deserialize = Object.create(null);
-        s.count = s.time = 0;
-      }
-    }/*metrics*/;
-    vfsMetrics.reset();
+    const metrics = opfsVfs.metrics.counters;
     let promiseWasRejected = undefined;
     const promiseReject = (err)=>{
       promiseWasRejected = true;
@@ -666,8 +630,6 @@ const installOpfsVfs = function callee(options){
       }
     }/*sanityCheck()*/;
 
-    //const initS11n = state.initS11n || toss("Missing state.initS11n()");
-    //delete state.initS11n;
     W.onmessage = function({data}){
       //log("Worker.onmessage:",data);
       switch(data.type){
@@ -697,7 +659,8 @@ const installOpfsVfs = function callee(options){
               state.sabOPView = new Int32Array(state.sabOP);
               state.sabFileBufView = new Uint8Array(state.sabIO, 0, state.fileBufferSize);
               state.sabS11nView = new Uint8Array(state.sabIO, state.sabS11nOffset, state.sabS11nSize);
-              initS11n();
+              opfsVfs.initS11n();
+              delete opfsVfs.initS11n;
               if(options.sanityChecks){
                 warn("Running sanity checks because of opfs-sanity-check URL arg...");
                 sanityCheck();
@@ -743,7 +706,7 @@ globalThis.sqlite3ApiBootstrap.initializersAsync.push(async (sqlite3)=>{
       //sqlite3.config.warn("installOpfsVfs.defaultProxyUri =",installOpfsVfs.defaultProxyUri);
     }
     return installOpfsVfs().catch((e)=>{
-      sqlite3.config.warn("Ignoring inability to install OPFS sqlite3_vfs:",e.message);
+      sqlite3.config.warn("Ignoring inability to install OPFS sqlite3_vfs:",e);
     });
   }catch(e){
     sqlite3.config.error("installOpfsVfs() exception:",e);
index 748594f4ca5c393eb6e023ca08bc509581297006..022a926397f3b07a8496f11be8bb3408034c5cd6 100644 (file)
@@ -747,6 +747,12 @@ static void emit_api_js(char const *zBuildName){
      zBuildName, zBuildName, zBuildName);
   pf("$(out.%s.js): $(sqlite3-api.%s.js)\n",
      zBuildName, zBuildName);
+  pf("$(sqlite3-api.%s.js):"
+     /* Extra deps needed by the OPFS pieces... */
+     " $(dir.api)/opfs-common-shared.c-pp.js"
+     " $(dir.api)/opfs-common-inline.c-pp.js"
+     "\n",
+     zBuildName);
 }
 
 /*
index 82c6c5bf4ac1e6de54662f8cbfe8bb7c8296ee94..ea250bde8e4cf4151d494dfbe3ca79ecfb0ced02 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Baby\ssteps\sin\sconsolidating\scommon\sOPFS\sVFS\scode.
-D 2026-03-04T14:33:33.214
+C Consolidate\sthe\sOPFS\sVFS's\smetrics-tracking\scode.
+D 2026-03-04T16:30:51.574
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -585,7 +585,7 @@ F ext/wasm/api/README.md a905d5c6bfc3e2df875bd391d6d6b7b48d41b43bdee02ad115b4724
 F ext/wasm/api/extern-post-js.c-pp.js d9f42ecbedc784c0d086bc37800e52946a14f7a21600b291daa3f963c314f930
 F ext/wasm/api/extern-pre-js.js cc61c09c7a24a07dbecb4c352453c3985170cec12b4e7e7e7a4d11d43c5c8f41
 F ext/wasm/api/opfs-common-inline.c-pp.js 5be8d6d91963849e218221b48206ae55612630bb2cd7f30b1b6fcf7a9e374b76
-F ext/wasm/api/opfs-common-shared.c-pp.js fdebcb821f9f732eb263e3ee2dbd6af5709aaa5fec9da6eaa0e10fd93b72f547
+F ext/wasm/api/opfs-common-shared.c-pp.js e00a2f18b6ed6d560b19503d9adce49f2151d1b488cbca24545a631bbed72d25
 F ext/wasm/api/post-js-footer.js a50c1a2c4d008aede7b2aa1f18891a7ee71437c2f415b8aeb3db237ddce2935b
 F ext/wasm/api/post-js-header.js f35d2dcf1ab7f22a93d565f8e0b622a2934fc4e743edf3b708e4dd8140eeff55
 F ext/wasm/api/pre-js.c-pp.js 9234ea680a2f6a2a177e8dcd934bdc5811a9f8409165433a252b87f4c07bba6f
@@ -598,8 +598,8 @@ F ext/wasm/api/sqlite3-opfs-async-proxy.c-pp.js f0a2aa8712211ff9db2ef548ae8b676b
 F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c8fb7f0630264e6c7fa0e57515d
 F ext/wasm/api/sqlite3-vfs-kvvfs.c-pp.js 2ccf4322f42063aefc150972943e750c77f7926b866f1639d40eec05df075b6e
 F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 1575ea6bbcf2da1e6df6892c17521a0c1c1c199a672e9090176ea0b88de48bd9
-F ext/wasm/api/sqlite3-vfs-opfs-wl.c-pp.js c6e5a281756e8ed7bbabf086dae765021486e17b91b6c4eee3c08dc2485fa348
-F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js b8db3ccfedb457634cc07df7a955bc44c6d1be8b40d35f47822c2168ab8b1968
+F ext/wasm/api/sqlite3-vfs-opfs-wl.c-pp.js 007430b82089b2aa8720a5866a9a9b0e9a7ddf3a1e7bafd1b652bec6c6a18196
+F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 9061455eb3a51aa898d02737aae1210c439d9f412b97d342ae9123746f72fcad
 F ext/wasm/api/sqlite3-vtab-helper.c-pp.js 366596d8ff73d4cefb938bbe95bc839d503c3fab6c8335ce4bf52f0d8a7dee81
 F ext/wasm/api/sqlite3-wasm.c 45bb20e19b245136711f9b78584371233975811b6560c29ed9b650e225417e29
 F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js aa9715f661fb700459a5a6cb1c32a4d6a770723b47aa9ac0e16c2cf87d622a66
@@ -628,7 +628,7 @@ F ext/wasm/index.html 475bc283338749db4e3fbf24cf3f5aa020cc85a1fffb780d400a915fcb
 F ext/wasm/jaccwabyt/jaccwabyt.js 4e2b797dc170851c9c530c3567679f4aa509eec0fab73b466d945b00b356574b
 F ext/wasm/jaccwabyt/jaccwabyt.md 6aa90fa1a973d0ad10d077088bea163b241d8470c75eafdef87620a1de1dea41
 F ext/wasm/mkdist.sh f8883b077a2ca47cf92e6f0ce305fbf72ca648c3501810125056c4b09c2d5554 x
-F ext/wasm/mkwasmbuilds.c b1ed20dfba178e6ccae91b4594ac9439992fd0cb783f202c639ca761f1b1d2a3
+F ext/wasm/mkwasmbuilds.c 5961177b9d6ad2b49efbdbb3076527e6886fecef7adf99d71cce58bfca89be08
 F ext/wasm/module-symbols.html e54f42112e0aac2a31f850ab33e7f2630a2ea4f63496f484a12469a2501e07e2
 F ext/wasm/scratchpad-wasmfs.html a3d7388f3c4b263676b58b526846e9d02dfcb4014ff29d3a5040935286af5b96
 F ext/wasm/scratchpad-wasmfs.mjs 66034b9256b218de59248aad796760a1584c1dd842231505895eff00dbd57c63
@@ -2191,8 +2191,8 @@ F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee
 F tool/warnings.sh d924598cf2f55a4ecbc2aeb055c10bd5f48114793e7ba25f9585435da29e7e98
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
 F tool/winmain.c 00c8fb88e365c9017db14c73d3c78af62194d9644feaf60e220ab0f411f3604c
-P db19a6e9663c3a44996178cb8c35dc4ccd60f48cb4b81b6c214411a56c57def7
-R a1c4d958895cbdc094c8287aa9f23443
+P b0dd23299e97ff975f213cb3a8b051f4d7b785b29def82e01f53427fdf77ecb6
+R 950709f8ceba3a494ed70c19c6d2296a
 U stephan
-Z b1a56499cd2b6bf9891139561c1b1fe5
+Z a91e3522d6c27cde9f5c40c8510d95f1
 # Remove this line to create a well-formed Fossil manifest.
index 8f61158031a7dc64acfa370bd9aa5083fb4b610d..3dfa0db211e320cc2f966e72f568f8c1c1aa3d86 100644 (file)
@@ -1 +1 @@
-b0dd23299e97ff975f213cb3a8b051f4d7b785b29def82e01f53427fdf77ecb6
+b71c79ef9672c77a72a976ffcd7cbebfaf0ff314dff97b274f7d092de6a7773f