-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
47 lines (39 loc) · 1.14 KB
/
index.js
File metadata and controls
47 lines (39 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict'
let restify = require('restify')
let profiler = require('v8-profiler-node8')
module.exports = DebugServer
function DebugServer () {
if (!new.target) return new DebugServer()
let server = (this.server = restify.createServer())
server.use(restify.plugins.queryParser())
server.get('/snapshot', function (req, res, next) {
console.log('Take snapshot')
let snapshot = profiler.takeSnapshot()
snapshot.export().pipe(res).on('finish', () => {
snapshot.delete()
next()
})
})
server.get('/profile', function (req, res, next) {
let duration = req.query.duration || 1000
console.log('Start profiling')
profiler.startProfiling('')
setTimeout(() => {
let profile = profiler.stopProfiling('')
console.log(profile.getHeader())
profile.export().pipe(res).on('finish', () => {
profile.delete()
next()
})
}, duration)
})
}
DebugServer.prototype.start = function () {
let server = this.server
server.listen(1337, () => {
console.log(`DebugServer listening on ${server.url}`)
})
}
DebugServer.prototype.stop = function () {
this.server.destroy()
}