Skip to content
This repository has been archived by the owner on May 10, 2021. It is now read-only.

Commit

Permalink
log: log out stage durations
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Feb 27, 2018
1 parent 41a4634 commit e1d20d3
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Installer {
// Stats
this.startTime = Date.now()
this.runTime = 0
this.timings = {}
this.pkgCount = 0

// Misc
Expand All @@ -38,17 +39,25 @@ class Installer {
this.failedDeps = new Set()
}

timedStage (name) {
const start = Date.now()
return BB.resolve(this[name].apply(this, [].slice.call(arguments, 1)))
.tap(() => {
this.timings[name] = Date.now() - start
this.log.info(name, `Done in ${this.timings[name] / 1000}s`)
})
}
run () {
const prefix = this.prefix
return this.prepare()
.then(() => this.extractTree(this.tree))
.then(() => this.buildTree(this.tree))
.then(() => this.garbageCollect(this.tree))
.then(() => this.runScript('prepublish', this.pkg, prefix))
.then(() => this.runScript('prepare', this.pkg, prefix))
.then(() => this.teardown())
return this.timedStage('prepare')
.then(() => this.timedStage('extractTree', this.tree))
.then(() => this.timedStage('buildTree', this.tree))
.then(() => this.timedStage('garbageCollect', this.tree))
.then(() => this.timedStage('runScript', 'prepublish', this.pkg, prefix))
.then(() => this.timedStage('runScript', 'prepare', this.pkg, prefix))
.then(() => this.timedStage('teardown'))
.then(() => { this.runTime = Date.now() - this.startTime })
.catch(err => { this.teardown(); throw err })
.catch(err => { this.timedStage('teardown'); throw err })
.then(() => this)
}

Expand Down

0 comments on commit e1d20d3

Please sign in to comment.