Skip to content

Commit

Permalink
Improve perf start/stop recording
Browse files Browse the repository at this point in the history
  • Loading branch information
jlongster committed Aug 3, 2021
1 parent 042de4f commit 4b31243
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 22 deletions.
22 changes: 20 additions & 2 deletions dist/indexeddb-backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -829,17 +829,35 @@ class IndexedDBBackend {

async init() {
let argBuffer = new SharedArrayBuffer(4096 * 9);
writer = new Writer(argBuffer, { name: 'args (backend)', debug: false });
this.writer = new Writer(argBuffer, {
name: 'args (backend)',
debug: false
});

let resultBuffer = new SharedArrayBuffer(4096 * 9);
reader = new Reader(resultBuffer, { name: 'results', debug: false });
this.reader = new Reader(resultBuffer, { name: 'results', debug: false });

await startWorker(argBuffer, resultBuffer);
}

createFile(filename) {
return new File(filename, this.defaultBlockSize, new FileOps(filename));
}

startProfile() {
writer.string('profile-start');
writer.finalize();
reader.int32();
reader.done();
}

stopProfile() {
end();
writer.string('profile-end');
writer.finalize();
reader.int32();
reader.done();
}
}

export default IndexedDBBackend;
12 changes: 7 additions & 5 deletions dist/indexeddb-main-thread.js

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions dist/perf/indexeddb-main-thread.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "absurd-sql.js-backend",
"version": "0.0.10",
"version": "0.0.12",
"main": "./dist/index.js",
"scripts": {
"build": "rm -r dist && rollup -c rollup.config.js",
Expand Down
1 change: 0 additions & 1 deletion src/blocked-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ export class File {
}

startStats() {
perf.start();
this.ops.startStats();
}

Expand Down
24 changes: 22 additions & 2 deletions src/indexeddb/backend.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Reader, Writer } from './shared-channel';
import { File } from '../blocked-file';
import * as perf from '../perf';

// These are temporarily global, but will be easy to clean up later
let reader, writer;
Expand Down Expand Up @@ -233,15 +234,34 @@ export default class IndexedDBBackend {

async init() {
let argBuffer = new SharedArrayBuffer(4096 * 9);
writer = new Writer(argBuffer, { name: 'args (backend)', debug: false });
this.writer = new Writer(argBuffer, {
name: 'args (backend)',
debug: false
});

let resultBuffer = new SharedArrayBuffer(4096 * 9);
reader = new Reader(resultBuffer, { name: 'results', debug: false });
this.reader = new Reader(resultBuffer, { name: 'results', debug: false });

await startWorker(argBuffer, resultBuffer);
}

createFile(filename) {
return new File(filename, this.defaultBlockSize, new FileOps(filename));
}

startProfile() {
perf.start();
writer.string('profile-start');
writer.finalize();
reader.int32();
reader.done();
}

stopProfile() {
perf.end();
writer.string('profile-end');
writer.finalize();
reader.int32();
reader.done();
}
}
10 changes: 6 additions & 4 deletions src/indexeddb/main-thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ export function initBackend(worker) {
listenForPerfData(worker);

worker.addEventListener('message', e => {
if (e.data.type === 'spawn-idb-worker') {
startWorkerFromMain(e.data.argBuffer, e.data.resultBuffer).then(() => {
worker.postMessage({ type: 'worker-ready' });
});
switch (e.data.type) {
case 'spawn-idb-worker':
startWorkerFromMain(e.data.argBuffer, e.data.resultBuffer).then(() => {
worker.postMessage({ type: 'worker-ready' });
});
break;
}
});
}
5 changes: 3 additions & 2 deletions src/indexeddb/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ async function loadDb(name) {
function closeDb(name) {
let openDb = openDbs.get(name);
if (openDb) {
console.log('closing db');
openDb.close();
openDbs.delete(name);
}
Expand Down Expand Up @@ -603,7 +604,7 @@ async function listen(reader, writer) {
let method = reader.string();

switch (method) {
case 'stats-start': {
case 'profile-start': {
reader.done();

perf.start();
Expand All @@ -614,7 +615,7 @@ async function listen(reader, writer) {
break;
}

case 'stats': {
case 'profile-end': {
reader.done();

await perf.end();
Expand Down

0 comments on commit 4b31243

Please sign in to comment.