2022-08-29 15:39:34 +03:00
|
|
|
/*
|
|
|
|
2022-08-29
|
|
|
|
|
|
|
|
The author disclaims copyright to this source code. In place of a
|
|
|
|
legal notice, here is a blessing:
|
|
|
|
|
|
|
|
* May you do good and not evil.
|
|
|
|
* May you find forgiveness for yourself and forgive others.
|
|
|
|
* May you share freely, never taking more than you give.
|
|
|
|
|
|
|
|
***********************************************************************
|
|
|
|
|
2022-09-03 14:41:44 +03:00
|
|
|
A basic batch SQL runner for sqlite3-api.js. This file must be run in
|
2022-08-29 15:39:34 +03:00
|
|
|
main JS thread and sqlite3.js must have been loaded before it.
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
(function(){
|
|
|
|
const toss = function(...args){throw new Error(args.join(' '))};
|
2022-08-29 21:58:38 +03:00
|
|
|
const warn = console.warn.bind(console);
|
2022-09-13 22:27:03 +03:00
|
|
|
let sqlite3;
|
2022-08-29 15:39:34 +03:00
|
|
|
|
|
|
|
const App = {
|
|
|
|
e: {
|
|
|
|
output: document.querySelector('#test-output'),
|
|
|
|
selSql: document.querySelector('#sql-select'),
|
|
|
|
btnRun: document.querySelector('#sql-run'),
|
2022-08-29 21:58:38 +03:00
|
|
|
btnRunNext: document.querySelector('#sql-run-next'),
|
|
|
|
btnRunRemaining: document.querySelector('#sql-run-remaining'),
|
2022-08-30 20:57:50 +03:00
|
|
|
btnExportMetrics: document.querySelector('#export-metrics'),
|
2022-08-29 21:58:38 +03:00
|
|
|
btnClear: document.querySelector('#output-clear'),
|
2022-08-30 20:57:50 +03:00
|
|
|
btnReset: document.querySelector('#db-reset'),
|
|
|
|
cbReverseLog: document.querySelector('#cb-reverse-log-order')
|
2022-08-29 15:39:34 +03:00
|
|
|
},
|
2022-09-13 22:27:03 +03:00
|
|
|
db: Object.create(null),
|
2022-08-29 21:58:38 +03:00
|
|
|
cache:{},
|
2022-08-30 20:57:50 +03:00
|
|
|
metrics:{
|
|
|
|
/**
|
|
|
|
Map of sql-file to timing metrics. We currently only store
|
|
|
|
the most recent run of each file, but we really should store
|
|
|
|
all runs so that we can average out certain values which vary
|
|
|
|
significantly across runs. e.g. a mandelbrot-generating query
|
|
|
|
will have a wide range of runtimes when run 10 times in a
|
|
|
|
row.
|
|
|
|
*/
|
|
|
|
},
|
2022-08-29 15:39:34 +03:00
|
|
|
log: console.log.bind(console),
|
|
|
|
warn: console.warn.bind(console),
|
|
|
|
cls: function(){this.e.output.innerHTML = ''},
|
|
|
|
logHtml2: function(cssClass,...args){
|
|
|
|
const ln = document.createElement('div');
|
|
|
|
if(cssClass) ln.classList.add(cssClass);
|
|
|
|
ln.append(document.createTextNode(args.join(' ')));
|
|
|
|
this.e.output.append(ln);
|
2022-08-29 21:58:38 +03:00
|
|
|
//this.e.output.lastElementChild.scrollIntoViewIfNeeded();
|
2022-08-29 15:39:34 +03:00
|
|
|
},
|
|
|
|
logHtml: function(...args){
|
|
|
|
console.log(...args);
|
|
|
|
if(1) this.logHtml2('', ...args);
|
|
|
|
},
|
|
|
|
logErr: function(...args){
|
|
|
|
console.error(...args);
|
|
|
|
if(1) this.logHtml2('error', ...args);
|
|
|
|
},
|
|
|
|
|
2022-08-29 21:58:38 +03:00
|
|
|
openDb: function(fn, unlinkFirst=true){
|
2022-09-13 22:27:03 +03:00
|
|
|
if(this.db.ptr){
|
2022-08-29 15:39:34 +03:00
|
|
|
toss("Already have an opened db.");
|
|
|
|
}
|
|
|
|
const capi = this.sqlite3.capi, wasm = capi.wasm;
|
|
|
|
const stack = wasm.scopedAllocPush();
|
|
|
|
let pDb = 0;
|
|
|
|
try{
|
2022-09-13 22:27:03 +03:00
|
|
|
if(unlinkFirst && fn){
|
|
|
|
if(':'!==fn[0]) capi.wasm.sqlite3_wasm_vfs_unlink(fn);
|
|
|
|
this.clearStorage();
|
2022-08-30 13:26:33 +03:00
|
|
|
}
|
2022-08-29 15:39:34 +03:00
|
|
|
const oFlags = capi.SQLITE_OPEN_CREATE | capi.SQLITE_OPEN_READWRITE;
|
|
|
|
const ppDb = wasm.scopedAllocPtr();
|
|
|
|
const rc = capi.sqlite3_open_v2(fn, ppDb, oFlags, null);
|
|
|
|
pDb = wasm.getPtrValue(ppDb)
|
2022-08-30 20:57:50 +03:00
|
|
|
if(rc){
|
|
|
|
if(pDb) capi.sqlite3_close_v2(pDb);
|
|
|
|
toss("sqlite3_open_v2() failed with code",rc);
|
|
|
|
}
|
2022-08-29 15:39:34 +03:00
|
|
|
}finally{
|
|
|
|
wasm.scopedAllocPop(stack);
|
|
|
|
}
|
2022-08-29 21:58:38 +03:00
|
|
|
this.db.filename = fn;
|
|
|
|
this.db.ptr = pDb;
|
|
|
|
this.logHtml("Opened db:",fn);
|
|
|
|
return this.db.ptr;
|
2022-08-29 15:39:34 +03:00
|
|
|
},
|
|
|
|
|
2022-08-29 21:58:38 +03:00
|
|
|
closeDb: function(unlink=false){
|
2022-09-13 22:27:03 +03:00
|
|
|
if(this.db.ptr){
|
2022-08-29 21:58:38 +03:00
|
|
|
this.sqlite3.capi.sqlite3_close_v2(this.db.ptr);
|
|
|
|
this.logHtml("Closed db",this.db.filename);
|
2022-09-13 22:27:03 +03:00
|
|
|
if(unlink){
|
|
|
|
capi.wasm.sqlite3_wasm_vfs_unlink(this.db.filename);
|
|
|
|
this.clearStorage();
|
|
|
|
}
|
2022-08-29 21:58:38 +03:00
|
|
|
this.db.ptr = this.db.filename = undefined;
|
2022-08-29 15:39:34 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-08-30 20:57:50 +03:00
|
|
|
/**
|
|
|
|
Loads batch-runner.list and populates the selection list from
|
|
|
|
it. Returns a promise which resolves to nothing in particular
|
|
|
|
when it completes. Only intended to be run once at the start
|
|
|
|
of the app.
|
|
|
|
*/
|
2022-08-29 15:39:34 +03:00
|
|
|
loadSqlList: async function(){
|
|
|
|
const sel = this.e.selSql;
|
|
|
|
sel.innerHTML = '';
|
|
|
|
this.blockControls(true);
|
|
|
|
const infile = 'batch-runner.list';
|
|
|
|
this.logHtml("Loading list of SQL files:", infile);
|
|
|
|
let txt;
|
|
|
|
try{
|
|
|
|
const r = await fetch(infile);
|
|
|
|
if(404 === r.status){
|
|
|
|
toss("Missing file '"+infile+"'.");
|
|
|
|
}
|
|
|
|
if(!r.ok) toss("Loading",infile,"failed:",r.statusText);
|
|
|
|
txt = await r.text();
|
2022-08-29 21:58:38 +03:00
|
|
|
const warning = document.querySelector('#warn-list');
|
|
|
|
if(warning) warning.remove();
|
2022-08-29 15:39:34 +03:00
|
|
|
}catch(e){
|
|
|
|
this.logErr(e.message);
|
|
|
|
throw e;
|
|
|
|
}finally{
|
|
|
|
this.blockControls(false);
|
|
|
|
}
|
2022-08-29 21:58:38 +03:00
|
|
|
const list = txt.split(/\n+/);
|
2022-08-29 15:39:34 +03:00
|
|
|
let opt;
|
|
|
|
if(0){
|
|
|
|
opt = document.createElement('option');
|
|
|
|
opt.innerText = "Select file to evaluate...";
|
|
|
|
opt.value = '';
|
|
|
|
opt.disabled = true;
|
|
|
|
opt.selected = true;
|
|
|
|
sel.appendChild(opt);
|
|
|
|
}
|
|
|
|
list.forEach(function(fn){
|
2022-08-29 21:58:38 +03:00
|
|
|
if(!fn) return;
|
2022-08-29 15:39:34 +03:00
|
|
|
opt = document.createElement('option');
|
2022-08-30 13:04:08 +03:00
|
|
|
opt.value = fn;
|
|
|
|
opt.innerText = fn.split('/').pop();
|
2022-08-29 15:39:34 +03:00
|
|
|
sel.appendChild(opt);
|
|
|
|
});
|
|
|
|
this.logHtml("Loaded",infile);
|
|
|
|
},
|
|
|
|
|
|
|
|
/** Fetch ./fn and return its contents as a Uint8Array. */
|
2022-08-29 21:58:38 +03:00
|
|
|
fetchFile: async function(fn, cacheIt=false){
|
|
|
|
if(cacheIt && this.cache[fn]) return this.cache[fn];
|
2022-08-29 15:39:34 +03:00
|
|
|
this.logHtml("Fetching",fn,"...");
|
|
|
|
let sql;
|
|
|
|
try {
|
|
|
|
const r = await fetch(fn);
|
|
|
|
if(!r.ok) toss("Fetch failed:",r.statusText);
|
|
|
|
sql = new Uint8Array(await r.arrayBuffer());
|
|
|
|
}catch(e){
|
|
|
|
this.logErr(e.message);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
this.logHtml("Fetched",sql.length,"bytes from",fn);
|
2022-08-29 21:58:38 +03:00
|
|
|
if(cacheIt) this.cache[fn] = sql;
|
2022-08-29 15:39:34 +03:00
|
|
|
return sql;
|
2022-08-29 21:58:38 +03:00
|
|
|
}/*fetchFile()*/,
|
2022-08-29 15:39:34 +03:00
|
|
|
|
2022-08-29 21:58:38 +03:00
|
|
|
/** Throws if the given sqlite3 result code is not 0. */
|
2022-08-29 15:39:34 +03:00
|
|
|
checkRc: function(rc){
|
2022-08-29 21:58:38 +03:00
|
|
|
if(this.db.ptr && rc){
|
|
|
|
toss("Prepare failed:",this.sqlite3.capi.sqlite3_errmsg(this.db.ptr));
|
2022-08-29 15:39:34 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-08-29 21:58:38 +03:00
|
|
|
/** Disable or enable certain UI controls. */
|
|
|
|
blockControls: function(disable){
|
|
|
|
document.querySelectorAll('.disable-during-eval').forEach((e)=>e.disabled = disable);
|
2022-08-29 15:39:34 +03:00
|
|
|
},
|
2022-08-29 21:58:38 +03:00
|
|
|
|
2022-08-30 20:57:50 +03:00
|
|
|
/**
|
|
|
|
Converts this.metrics() to a form which is suitable for easy conversion to
|
|
|
|
CSV. It returns an array of arrays. The first sub-array is the column names.
|
|
|
|
The 2nd and subsequent are the values, one per test file (only the most recent
|
|
|
|
metrics are kept for any given file).
|
|
|
|
*/
|
|
|
|
metricsToArrays: function(){
|
|
|
|
const rc = [];
|
|
|
|
Object.keys(this.metrics).sort().forEach((k)=>{
|
|
|
|
const m = this.metrics[k];
|
|
|
|
delete m.evalFileStart;
|
|
|
|
delete m.evalFileEnd;
|
|
|
|
const mk = Object.keys(m).sort();
|
|
|
|
if(!rc.length){
|
|
|
|
rc.push(['file', ...mk]);
|
|
|
|
}
|
|
|
|
const row = [k.split('/').pop()/*remove dir prefix from filename*/];
|
|
|
|
rc.push(row);
|
|
|
|
mk.forEach((kk)=>row.push(m[kk]));
|
|
|
|
});
|
|
|
|
return rc;
|
|
|
|
},
|
|
|
|
|
|
|
|
metricsToBlob: function(colSeparator='\t'){
|
|
|
|
const ar = [], ma = this.metricsToArrays();
|
|
|
|
if(!ma.length){
|
|
|
|
this.logErr("Metrics are empty. Run something.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ma.forEach(function(row){
|
|
|
|
ar.push(row.join(colSeparator),'\n');
|
|
|
|
});
|
|
|
|
return new Blob(ar);
|
|
|
|
},
|
|
|
|
|
|
|
|
downloadMetrics: function(){
|
|
|
|
const b = this.metricsToBlob();
|
|
|
|
if(!b) return;
|
|
|
|
const url = URL.createObjectURL(b);
|
|
|
|
const a = document.createElement('a');
|
|
|
|
a.href = url;
|
2022-09-03 14:41:44 +03:00
|
|
|
a.download = 'batch-runner-js-'+((new Date().getTime()/1000) | 0)+'.csv';
|
2022-08-30 20:57:50 +03:00
|
|
|
this.logHtml("Triggering download of",a.download);
|
|
|
|
document.body.appendChild(a);
|
|
|
|
a.click();
|
|
|
|
setTimeout(()=>{
|
|
|
|
document.body.removeChild(a);
|
|
|
|
URL.revokeObjectURL(url);
|
|
|
|
}, 500);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
Fetch file fn and eval it as an SQL blob. This is an async
|
|
|
|
operation and returns a Promise which resolves to this
|
|
|
|
object on success.
|
|
|
|
*/
|
2022-08-29 15:39:34 +03:00
|
|
|
evalFile: async function(fn){
|
|
|
|
const sql = await this.fetchFile(fn);
|
2022-08-29 21:58:38 +03:00
|
|
|
const banner = "========================================";
|
|
|
|
this.logHtml(banner,
|
|
|
|
"Running",fn,'('+sql.length,'bytes)...');
|
2022-08-29 15:39:34 +03:00
|
|
|
const capi = this.sqlite3.capi, wasm = capi.wasm;
|
|
|
|
let pStmt = 0, pSqlBegin;
|
|
|
|
const stack = wasm.scopedAllocPush();
|
2022-08-30 20:57:50 +03:00
|
|
|
const metrics = this.metrics[fn] = Object.create(null);
|
2022-08-29 15:39:34 +03:00
|
|
|
metrics.prepTotal = metrics.stepTotal = 0;
|
|
|
|
metrics.stmtCount = 0;
|
2022-08-30 20:57:50 +03:00
|
|
|
metrics.malloc = 0;
|
|
|
|
metrics.strcpy = 0;
|
2022-08-29 15:39:34 +03:00
|
|
|
this.blockControls(true);
|
2022-08-29 21:58:38 +03:00
|
|
|
if(this.gotErr){
|
|
|
|
this.logErr("Cannot run ["+fn+"]: error cleanup is pending.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Run this async so that the UI can be updated for the above header...
|
|
|
|
const ff = function(resolve, reject){
|
|
|
|
metrics.evalFileStart = performance.now();
|
2022-08-29 15:39:34 +03:00
|
|
|
try {
|
|
|
|
let t;
|
|
|
|
let sqlByteLen = sql.byteLength;
|
|
|
|
const [ppStmt, pzTail] = wasm.scopedAllocPtr(2);
|
2022-08-30 20:57:50 +03:00
|
|
|
t = performance.now();
|
2022-08-29 21:58:38 +03:00
|
|
|
pSqlBegin = wasm.alloc( sqlByteLen + 1/*SQL + NUL*/) || toss("alloc(",sqlByteLen,") failed");
|
2022-08-30 20:57:50 +03:00
|
|
|
metrics.malloc = performance.now() - t;
|
|
|
|
metrics.byteLength = sqlByteLen;
|
2022-08-29 15:39:34 +03:00
|
|
|
let pSql = pSqlBegin;
|
|
|
|
const pSqlEnd = pSqlBegin + sqlByteLen;
|
2022-08-30 20:57:50 +03:00
|
|
|
t = performance.now();
|
2022-08-29 15:39:34 +03:00
|
|
|
wasm.heap8().set(sql, pSql);
|
|
|
|
wasm.setMemValue(pSql + sqlByteLen, 0);
|
2022-08-30 20:57:50 +03:00
|
|
|
metrics.strcpy = performance.now() - t;
|
2022-08-29 21:58:38 +03:00
|
|
|
let breaker = 0;
|
|
|
|
while(pSql && wasm.getMemValue(pSql,'i8')){
|
2022-08-29 15:39:34 +03:00
|
|
|
wasm.setPtrValue(ppStmt, 0);
|
|
|
|
wasm.setPtrValue(pzTail, 0);
|
|
|
|
t = performance.now();
|
|
|
|
let rc = capi.sqlite3_prepare_v3(
|
2022-08-29 21:58:38 +03:00
|
|
|
this.db.ptr, pSql, sqlByteLen, 0, ppStmt, pzTail
|
2022-08-29 15:39:34 +03:00
|
|
|
);
|
|
|
|
metrics.prepTotal += performance.now() - t;
|
|
|
|
this.checkRc(rc);
|
|
|
|
pStmt = wasm.getPtrValue(ppStmt);
|
|
|
|
pSql = wasm.getPtrValue(pzTail);
|
|
|
|
sqlByteLen = pSqlEnd - pSql;
|
|
|
|
if(!pStmt) continue/*empty statement*/;
|
2022-08-29 21:58:38 +03:00
|
|
|
++metrics.stmtCount;
|
2022-08-29 15:39:34 +03:00
|
|
|
t = performance.now();
|
|
|
|
rc = capi.sqlite3_step(pStmt);
|
2022-08-29 21:58:38 +03:00
|
|
|
capi.sqlite3_finalize(pStmt);
|
|
|
|
pStmt = 0;
|
2022-08-29 15:39:34 +03:00
|
|
|
metrics.stepTotal += performance.now() - t;
|
|
|
|
switch(rc){
|
|
|
|
case capi.SQLITE_ROW:
|
|
|
|
case capi.SQLITE_DONE: break;
|
|
|
|
default: this.checkRc(rc); toss("Not reached.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}catch(e){
|
2022-08-29 21:58:38 +03:00
|
|
|
if(pStmt) capi.sqlite3_finalize(pStmt);
|
|
|
|
this.gotErr = e;
|
|
|
|
//throw e;
|
|
|
|
reject(e);
|
|
|
|
return;
|
2022-08-29 15:39:34 +03:00
|
|
|
}finally{
|
|
|
|
wasm.dealloc(pSqlBegin);
|
|
|
|
wasm.scopedAllocPop(stack);
|
|
|
|
this.blockControls(false);
|
|
|
|
}
|
2022-08-29 21:58:38 +03:00
|
|
|
metrics.evalFileEnd = performance.now();
|
|
|
|
metrics.evalTimeTotal = (metrics.evalFileEnd - metrics.evalFileStart);
|
2022-08-29 15:39:34 +03:00
|
|
|
this.logHtml("Metrics:");//,JSON.stringify(metrics, undefined, ' '));
|
|
|
|
this.logHtml("prepare() count:",metrics.stmtCount);
|
|
|
|
this.logHtml("Time in prepare_v2():",metrics.prepTotal,"ms",
|
|
|
|
"("+(metrics.prepTotal / metrics.stmtCount),"ms per prepare())");
|
|
|
|
this.logHtml("Time in step():",metrics.stepTotal,"ms",
|
|
|
|
"("+(metrics.stepTotal / metrics.stmtCount),"ms per step())");
|
2022-08-29 21:58:38 +03:00
|
|
|
this.logHtml("Total runtime:",metrics.evalTimeTotal,"ms");
|
2022-08-29 15:39:34 +03:00
|
|
|
this.logHtml("Overhead (time - prep - step):",
|
2022-08-29 21:58:38 +03:00
|
|
|
(metrics.evalTimeTotal - metrics.prepTotal - metrics.stepTotal)+"ms");
|
|
|
|
this.logHtml(banner,"End of",fn);
|
|
|
|
resolve(this);
|
|
|
|
}.bind(this);
|
|
|
|
let p;
|
|
|
|
if(1){
|
|
|
|
p = new Promise(function(res,rej){
|
|
|
|
setTimeout(()=>ff(res, rej), 50)/*give UI a chance to output the "running" banner*/;
|
|
|
|
});
|
|
|
|
}else{
|
|
|
|
p = new Promise(ff);
|
|
|
|
}
|
|
|
|
return p.catch((e)=>this.logErr("Error via evalFile("+fn+"):",e.message));
|
|
|
|
}/*evalFile()*/,
|
2022-08-29 15:39:34 +03:00
|
|
|
|
2022-09-13 22:27:03 +03:00
|
|
|
clearStorage: function(){
|
|
|
|
const sz = sqlite3.capi.sqlite3_web_kvvfs_size();
|
|
|
|
const n = sqlite3.capi.sqlite3_web_kvvfs_clear(this.db.filename || '');
|
|
|
|
this.logHtml("Cleared kvvfs local/sessionStorage:",
|
|
|
|
n,"entries totaling approximately",sz,"bytes.");
|
|
|
|
},
|
|
|
|
|
|
|
|
resetDb: function(){
|
|
|
|
if(this.db.ptr){
|
|
|
|
const fn = this.db.filename;
|
|
|
|
this.closeDb(true);
|
|
|
|
this.openDb(fn,false);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-08-29 15:39:34 +03:00
|
|
|
run: function(sqlite3){
|
2022-08-29 21:58:38 +03:00
|
|
|
delete this.run;
|
2022-08-29 15:39:34 +03:00
|
|
|
this.sqlite3 = sqlite3;
|
|
|
|
const capi = sqlite3.capi, wasm = capi.wasm;
|
|
|
|
this.logHtml("Loaded module:",capi.sqlite3_libversion(), capi.sqlite3_sourceid());
|
|
|
|
this.logHtml("WASM heap size =",wasm.heap8().length);
|
2022-08-29 21:58:38 +03:00
|
|
|
this.loadSqlList();
|
2022-09-13 22:27:03 +03:00
|
|
|
const pDir = 1 ? '' : capi.sqlite3_web_persistent_dir();
|
|
|
|
const dbFile = pDir ? pDir+"/speedtest.db" : (
|
|
|
|
sqlite3.capi.sqlite3_vfs_find('kvvfs') ? 'local' : ':memory:'
|
|
|
|
);
|
|
|
|
this.clearStorage();
|
|
|
|
if(pDir){
|
|
|
|
logHtml("Using persistent storage:",dbFile);
|
|
|
|
}else{
|
2022-08-29 21:58:38 +03:00
|
|
|
document.querySelector('#warn-opfs').remove();
|
2022-08-29 15:39:34 +03:00
|
|
|
}
|
2022-08-29 21:58:38 +03:00
|
|
|
this.openDb(dbFile, !!pDir);
|
2022-08-29 15:39:34 +03:00
|
|
|
const who = this;
|
2022-08-30 20:57:50 +03:00
|
|
|
const eReverseLogNotice = document.querySelector('#reverse-log-notice');
|
|
|
|
if(this.e.cbReverseLog.checked){
|
|
|
|
eReverseLogNotice.classList.remove('hidden');
|
|
|
|
this.e.output.classList.add('reverse');
|
|
|
|
}
|
|
|
|
this.e.cbReverseLog.addEventListener('change', function(){
|
|
|
|
if(this.checked){
|
|
|
|
who.e.output.classList.add('reverse');
|
|
|
|
eReverseLogNotice.classList.remove('hidden');
|
|
|
|
}else{
|
|
|
|
who.e.output.classList.remove('reverse');
|
|
|
|
eReverseLogNotice.classList.add('hidden');
|
|
|
|
}
|
|
|
|
}, false);
|
2022-08-29 15:39:34 +03:00
|
|
|
this.e.btnClear.addEventListener('click', ()=>this.cls(), false);
|
|
|
|
this.e.btnRun.addEventListener('click', function(){
|
|
|
|
if(!who.e.selSql.value) return;
|
|
|
|
who.evalFile(who.e.selSql.value);
|
|
|
|
}, false);
|
2022-08-29 21:58:38 +03:00
|
|
|
this.e.btnRunNext.addEventListener('click', function(){
|
|
|
|
++who.e.selSql.selectedIndex;
|
|
|
|
if(!who.e.selSql.value) return;
|
|
|
|
who.evalFile(who.e.selSql.value);
|
|
|
|
}, false);
|
|
|
|
this.e.btnReset.addEventListener('click', function(){
|
2022-09-13 22:27:03 +03:00
|
|
|
who.resetDb();
|
2022-08-29 21:58:38 +03:00
|
|
|
}, false);
|
2022-08-30 20:57:50 +03:00
|
|
|
this.e.btnExportMetrics.addEventListener('click', function(){
|
2022-09-03 14:41:44 +03:00
|
|
|
who.logHtml2('warning',"Triggering download of metrics CSV. Check your downloads folder.");
|
2022-08-30 20:57:50 +03:00
|
|
|
who.downloadMetrics();
|
2022-09-03 14:41:44 +03:00
|
|
|
//const m = who.metricsToArrays();
|
|
|
|
//console.log("Metrics:",who.metrics, m);
|
2022-08-30 20:57:50 +03:00
|
|
|
});
|
2022-08-29 21:58:38 +03:00
|
|
|
this.e.btnRunRemaining.addEventListener('click', async function(){
|
|
|
|
let v = who.e.selSql.value;
|
|
|
|
const timeStart = performance.now();
|
|
|
|
while(v){
|
|
|
|
await who.evalFile(v);
|
|
|
|
if(who.gotError){
|
|
|
|
who.logErr("Error handling script",v,":",who.gotError.message);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++who.e.selSql.selectedIndex;
|
|
|
|
v = who.e.selSql.value;
|
|
|
|
}
|
|
|
|
const timeTotal = performance.now() - timeStart;
|
|
|
|
who.logHtml("Run-remaining time:",timeTotal,"ms ("+(timeTotal/1000/60)+" minute(s))");
|
2022-09-13 22:27:03 +03:00
|
|
|
who.clearStorage();
|
2022-08-29 21:58:38 +03:00
|
|
|
}, false);
|
|
|
|
}/*run()*/
|
2022-08-29 15:39:34 +03:00
|
|
|
}/*App*/;
|
|
|
|
|
|
|
|
self.sqlite3TestModule.initSqlite3().then(function(theEmccModule){
|
|
|
|
self._MODULE = theEmccModule /* this is only to facilitate testing from the console */;
|
2022-09-13 22:27:03 +03:00
|
|
|
sqlite3 = theEmccModule.sqlite3;
|
2022-08-29 15:39:34 +03:00
|
|
|
App.run(theEmccModule.sqlite3);
|
|
|
|
});
|
|
|
|
})();
|