From: stephan Date: Tue, 4 Oct 2022 00:54:00 +0000 (+0000) Subject: Add a test/debug mechanism to shut down the OPFS async listener so that it can be... X-Git-Tag: version-3.40.0~169^2~18 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3c272ba380084e48e583c13898aeac1aa3cc4f86;p=thirdparty%2Fsqlite.git Add a test/debug mechanism to shut down the OPFS async listener so that it can be inspected (it normally can't be because its tight event-listening loop ties up the thread) and then restarted. FossilOrigin-Name: 7d0bcff4e9b899cd25b393b9f0a02c5dcee2e229f0a0fa01719c7dcd7dcbe7c1 --- diff --git a/ext/wasm/api/sqlite3-api-opfs.js b/ext/wasm/api/sqlite3-api-opfs.js index 42c0e11662..7b85ac06c8 100644 --- a/ext/wasm/api/sqlite3-api-opfs.js +++ b/ext/wasm/api/sqlite3-api-opfs.js @@ -142,7 +142,7 @@ const installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri){ "\nTotal of",n,"op(s) for",t, "ms (incl. "+w+" ms of waiting on the async side)"); console.log("Serialization metrics:",metrics.s11n); - opRun('async-metrics'); + W.postMessage({type:'opfs-async-metrics'}); }, reset: function(){ let k; @@ -285,7 +285,8 @@ const installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri){ state.opIds.xTruncate = i++; state.opIds.xWrite = i++; state.opIds.mkdir = i++; - state.opIds['async-metrics'] = i++; + state.opIds['opfs-async-metrics'] = i++; + state.opIds['opfs-async-shutdown'] = i++; state.sabOP = new SharedArrayBuffer(i * 4/*sizeof int32*/); opfsUtil.metrics.reset(); } @@ -888,6 +889,20 @@ const installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri){ ); }; + /** + Only for test/development use. + */ + opfsUtil.debug = { + asyncShutdown: ()=>{ + warn("Shutting down OPFS async listener. OPFS will no longer work."); + opRun('opfs-async-shutdown'); + }, + asyncRestart: ()=>{ + warn("Attempting to restart OPFS async listener. Might work, might not."); + W.postMessage({type: 'opfs-async-restart'}); + } + }; + //TODO to support fiddle db upload: //opfsUtil.createFile = function(absName, content=undefined){...} @@ -1028,6 +1043,7 @@ const installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri){ break; } }; + })/*thePromise*/; return thePromise; }/*installOpfsVfs()*/; diff --git a/ext/wasm/sqlite3-opfs-async-proxy.js b/ext/wasm/sqlite3-opfs-async-proxy.js index 0abc3ee233..58bbf79284 100644 --- a/ext/wasm/sqlite3-opfs-async-proxy.js +++ b/ext/wasm/sqlite3-opfs-async-proxy.js @@ -207,18 +207,29 @@ const wTimeEnd = ()=>( metrics[waitTimer.op].wait += performance.now() - waitTimer.start ); +/** + Set to true by the 'opfs-async-shutdown' command to quite the wait loop. + This is only intended for debugging purposes: we cannot inspect this + file's state while the tight waitLoop() is running. +*/ +let flagAsyncShutdown = false; + /** Asynchronous wrappers for sqlite3_vfs and sqlite3_io_methods methods. Maintenance reminder: members are in alphabetical order to simplify finding them. */ const vfsAsyncImpls = { - 'async-metrics': async ()=>{ - mTimeStart('async-metrics'); + 'opfs-async-metrics': async ()=>{ + mTimeStart('opfs-async-metrics'); metrics.dump(); - storeAndNotify('async-metrics', 0); + storeAndNotify('opfs-async-metrics', 0); mTimeEnd(); }, + 'opfs-async-shutdown': async ()=>{ + flagAsyncShutdown = true; + storeAndNotify('opfs-async-shutdown', 0); + }, mkdir: async (dirname)=>{ mTimeStart('mkdir'); let rc = 0; @@ -597,7 +608,7 @@ const waitLoop = async function f(){ const relinquishTime = 1000; let lastOpTime = performance.now(); let now; - while(true){ + while(!flagAsyncShutdown){ try { if('timed-out'===Atomics.wait( state.sabOPView, state.opIds.whichOp, 0, waitTime @@ -669,6 +680,16 @@ navigator.storage.getDirectory().then(function(d){ waitLoop(); break; } + case 'opfs-async-restart': + if(flagAsyncShutdown){ + warn("Restarting after opfs-async-shutdown. Might or might not work."); + flagAsyncShutdown = false; + waitLoop(); + } + break; + case 'opfs-async-metrics': + metrics.dump(); + break; } }; wMsg('opfs-async-loaded'); diff --git a/manifest b/manifest index 3e7ab37952..53cf33f4a3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Set\sdefault\spage\scache\ssize\sto\s16mb\sin\swasm\sbuilds.\sFix\san\soff-by-one\scounter\sin\ssqlite3_wasm_enum_json().\sMinor\scoding\sstyle\sconformance\stweaks. -D 2022-10-03T23:13:05.622 +C Add\sa\stest/debug\smechanism\sto\sshut\sdown\sthe\sOPFS\sasync\slistener\sso\sthat\sit\scan\sbe\sinspected\s(it\snormally\scan't\sbe\sbecause\sits\stight\sevent-listening\sloop\sties\sup\sthe\sthread)\sand\sthen\srestarted. +D 2022-10-04T00:54:00.533 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -487,7 +487,7 @@ F ext/wasm/api/pre-js.js 2db711eb637991b383fc6b5c0f3df65ec48a7201e5730e304beba8d F ext/wasm/api/sqlite3-api-cleanup.js 5d22d1d3818ecacb23bfa223d5970cd0617d8cdbb48c8bc4bbd463f05b021a99 F ext/wasm/api/sqlite3-api-glue.js 24a283a49759914f2433b3118865145efbb2f67f52643e445065e02ccecc081b F ext/wasm/api/sqlite3-api-oo1.js ac1e08d36bdfb5aa0a2d75b7d4c892fd51819d34c932370c3282810672bcc086 -F ext/wasm/api/sqlite3-api-opfs.js 3d17da752181d67847bd2e3d1f4662df31c5023a1bed5424ebcdeb89770046af +F ext/wasm/api/sqlite3-api-opfs.js d82870cffef9eef6511c650759c3798b59f10c8338587789abd84be2d9d845c3 F ext/wasm/api/sqlite3-api-prologue.js 61f28bf7a51479c7b401e2da636b2a0710de77d86f68961445d572a3761dd170 F ext/wasm/api/sqlite3-api-worker1.js 7f4f46cb6b512a48572d7567233896e6a9c46570c44bdc3d13419730c7c221c8 F ext/wasm/api/sqlite3-wasi.h 25356084cfe0d40458a902afb465df8c21fc4152c1d0a59b563a3fba59a068f9 @@ -522,7 +522,7 @@ F ext/wasm/speedtest1.html e4cb5d722b494104fc1249e7c008ca018f820a784833c51004c95 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 -F ext/wasm/sqlite3-opfs-async-proxy.js 5c6748361f2eb2ee0f2941890917fd9f2d9271de80ec1b65695fb023435b8375 +F ext/wasm/sqlite3-opfs-async-proxy.js 3f8086e543a576a556c17f8ee7c75009fb8e2d3f9bbb9c0de6b9c285dd7f5634 F ext/wasm/sqlite3-worker1-promiser.js 307d7837420ca6a9d3780dfc81194f1c0715637e6d9540e935514086b96913d8 F ext/wasm/sqlite3-worker1.js 466e9bd39409ab03f3e00999887aaffc11e95b416e2689596e3d7f1516673fdf F ext/wasm/test-opfs-vfs.html eb69dda21eb414b8f5e3f7c1cc0f774103cc9c0f87b2d28a33419e778abfbab5 @@ -2029,8 +2029,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 5b8f8e33afc47c9f0c64dbe34643d7d1c37a0a82afb4656e714a86ef54a9ce6f -R 9e18661e1500a3e4cdfa05bc23635f3f +P 72a9e589cc318ec50941739e2edf2c0636284b316c3bf87b71fd363b37619da3 +R b598562b6232b1a22591d878d099e519 U stephan -Z e3d9878d6daf198d0150d0ecad381b11 +Z 962cbcc757fdf40c47c3a7056efb3d7c # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 3874ec261e..912cd619c4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -72a9e589cc318ec50941739e2edf2c0636284b316c3bf87b71fd363b37619da3 \ No newline at end of file +7d0bcff4e9b899cd25b393b9f0a02c5dcee2e229f0a0fa01719c7dcd7dcbe7c1 \ No newline at end of file