diff --git a/app/modules/crawler/lib/sync.ts b/app/modules/crawler/lib/sync.ts index 1cab9817ff344f4bf5534da1efee9e61f32d7c71..69d073a23e107ee909aad9db96dbb52f4246cae0 100644 --- a/app/modules/crawler/lib/sync.ts +++ b/app/modules/crawler/lib/sync.ts @@ -140,6 +140,7 @@ export class Synchroniser extends stream.Duplex { this.logger.info("Sync started."); const fullSync = !to; + const syncStartTime = Date.now(); //============ // Blockchain headers @@ -240,9 +241,10 @@ export class Synchroniser extends stream.Duplex { await this.syncStrategy.syncPeers(fullSync, to); } - this.watcher.end(); + const syncDuration = Date.now() - syncStartTime; + this.watcher.end(syncDuration); this.push({ sync: true }); - this.logger.info("Sync finished."); + this.logger.info("Sync finished (duration %s ms).", syncDuration); } catch (err) { this.push({ sync: false, msg: err }); err && diff --git a/app/modules/crawler/lib/sync/Watcher.ts b/app/modules/crawler/lib/sync/Watcher.ts index 796d99b2b3de5ec6196a75f1550d921db33258e4..c0cfac51f5bc82794be012d856c30872c960081c 100644 --- a/app/modules/crawler/lib/sync/Watcher.ts +++ b/app/modules/crawler/lib/sync/Watcher.ts @@ -11,7 +11,7 @@ export interface Watcher { appliedPercent(pct?: number): number; sbxPercent(pct?: number): number; peersPercent(pct?: number): number; - end(): void; + end(duration?: number): void; reserveNodes(nodesAvailable: P2pCandidate[]): void; @@ -114,8 +114,8 @@ export class EventWatcher extends events.EventEmitter implements Watcher { return method(pct); } - end(): void { - this.innerWatcher.end(); + end(syncDuration?: number): void { + this.innerWatcher.end(syncDuration); } onEvent(e: EventName, cb: (pct: number) => void) { @@ -261,8 +261,14 @@ export class MultimeterWatcher implements Watcher { return 0; } - end() { - this.multi.write("\nAll done.\n"); + end(duration?: number) { + if (duration) { + const durationSecs = Math.floor(duration / 1000); + const durationMillisRemain = duration % 1000; + this.multi.write("\nAll done in " + durationSecs + "." + durationMillisRemain + " seconds.\n"); + } else { + this.multi.write("\nAll done.\n"); + } this.multi.destroy(); }