mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-29 08:01:23 +03:00
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
This commit is contained in:
@ -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()*/;
|
||||
|
@ -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');
|
||||
|
Reference in New Issue
Block a user