diff --git a/lib/core.js b/lib/core.js index 7e54d363..a9321955 100644 --- a/lib/core.js +++ b/lib/core.js @@ -38,6 +38,11 @@ module.exports = class Core { this.sessions = sessions this.globalCache = globalCache + this.stats = { + blocksAppended: 0, + bytesAppended: 0 + } + this._manifestFlushed = !!header.manifest this._maxOplogSize = 65536 this._autoFlush = 1 @@ -684,6 +689,7 @@ module.exports = class Core { } } + const initByteLength = this.tree.byteLength const byteLength = await this._appendBlocks(values) await this.oplog.append([entry], false) @@ -700,6 +706,11 @@ module.exports = class Core { if (this._shouldFlush()) await this._flushOplog() + this.stats.blocksAppended += values.length + + const bytesInBatch = byteLength - initByteLength // Safe because we're in a mutex + this.stats.bytesAppended += bytesInBatch + return { length: batch.length, byteLength } } finally { this._mutex.unlock() diff --git a/test/basic.js b/test/basic.js index 63eb7310..9ca825af 100644 --- a/test/basic.js +++ b/test/basic.js @@ -462,3 +462,13 @@ test('valid manifest passed to a session is stored', async function (t) { t.alike(b.manifest, core.manifest) }) + +test('basic - core stats', async function (t) { + const core = await create() + + await core.append('ok') + await core.append(['batch', 'here']) + + t.is(core.core.stats.bytesAppended, 11, 'bytesAppended') + t.is(core.core.stats.blocksAppended, 3, 'blocksAppended') +})