Skip to content

Commit

Permalink
add blocks per second to logging
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed Mar 3, 2024
1 parent 8dc278f commit dc1919f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
11 changes: 10 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ export async function action(options: CSVRunOptions ) {
let resolvedStartBlock = 0;
let maxParallelWorkers = 0;
let runningJobs = 0;
let last_seconds = 0;
let start = Math.floor(Date.now() / 1000); // seconds
let last_update = 0;

emitter.on("session", (session) => {
fs.writeFileSync(sessionFile, JSON.stringify(session, null, 2));
Expand Down Expand Up @@ -96,6 +99,7 @@ export async function action(options: CSVRunOptions ) {
const { block_num, block_id, timestamp, seconds } = parseClock(clock);
last_block_num = block_num;
last_timestamp = timestamp;
last_seconds = seconds;

// block header
for ( const entityChange of EntityChanges.parse(data).entityChanges ) {
Expand Down Expand Up @@ -132,7 +136,12 @@ export async function action(options: CSVRunOptions ) {
});

function log() {
logUpdate(JSON.stringify({last_block_num, last_timestamp, blocks, rows, totalBytesRead, totalBytesWritten, runningJobs}));
const now = Math.floor(Date.now() / 1000);
if ( last_update != now) {
last_update = now;
const blocksPerSecond = Math.floor(blocks / (last_update - start));
logUpdate(JSON.stringify({last_block_num, last_timestamp, blocks, rows, blocksPerSecond, totalBytesRead, totalBytesWritten, runningJobs}));
}
}

fileCursor.onCursor(emitter, cursorFile);
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"dependencies": {
"@substreams/sink-entity-changes": "^0.3.9",
"log-update": "latest",
"substreams-sink": "^0.15.1"
"substreams-sink": "^0.15.2"
},
"devDependencies": {
"@types/bun": "latest",
Expand Down

0 comments on commit dc1919f

Please sign in to comment.