fix profiler.
This commit is contained in:
parent
26b3d92acf
commit
cb27964b3b
@ -15,10 +15,10 @@ var profiler = {};
|
|||||||
|
|
||||||
var utils = require('./utils');
|
var utils = require('./utils');
|
||||||
var assert = utils.assert;
|
var assert = utils.assert;
|
||||||
var fs, profiler;
|
var fs, v8profiler;
|
||||||
|
|
||||||
if (bcoin.profile && !bcoin.isBrowser) {
|
if (bcoin.profile && !bcoin.isBrowser) {
|
||||||
profiler = require('v8-' + 'profiler');
|
v8profiler = require('v8-' + 'profiler');
|
||||||
fs = require('f' + 's');
|
fs = require('f' + 's');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,10 +30,10 @@ if (bcoin.profile && !bcoin.isBrowser) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function Profile(name) {
|
function Profile(name) {
|
||||||
if (profiler) {
|
if (v8profiler) {
|
||||||
name = 'profile-' + (name ? name + '-' : '') + Profile.uid++;
|
name = 'profile-' + (name ? name + '-' : '') + Profile.uid++;
|
||||||
bcoin.debug('Starting CPU profile: %s', name);
|
bcoin.debug('Starting CPU profile: %s', name);
|
||||||
this.profile = profiler.startProfiling(name, true);
|
this.profile = v8profiler.startProfiling(name, true);
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -45,7 +45,7 @@ Profile.uid = 0;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Profile.prototype.stopProfiling = function stopProfiling() {
|
Profile.prototype.stopProfiling = function stopProfiling() {
|
||||||
if (!profiler)
|
if (!v8profiler)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
assert(this.profile);
|
assert(this.profile);
|
||||||
@ -58,7 +58,7 @@ Profile.prototype.stopProfiling = function stopProfiling() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Profile.prototype.del = function del() {
|
Profile.prototype.del = function del() {
|
||||||
if (!profiler)
|
if (!v8profiler)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
assert(this.profile);
|
assert(this.profile);
|
||||||
@ -76,7 +76,7 @@ Profile.prototype.save = function save(callback) {
|
|||||||
|
|
||||||
callback = utils.asyncify(callback);
|
callback = utils.asyncify(callback);
|
||||||
|
|
||||||
if (!profiler)
|
if (!v8profiler)
|
||||||
return callback();
|
return callback();
|
||||||
|
|
||||||
assert(this.profile);
|
assert(this.profile);
|
||||||
@ -106,10 +106,10 @@ Profile.prototype.save = function save(callback) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function Snapshot(name) {
|
function Snapshot(name) {
|
||||||
if (profiler) {
|
if (v8profiler) {
|
||||||
name = 'snapshot-' + (name ? name + '-' : '') + Snapshot.uid++;
|
name = 'snapshot-' + (name ? name + '-' : '') + Snapshot.uid++;
|
||||||
bcoin.debug('Taking heap snapshot: %s', name);
|
bcoin.debug('Taking heap snapshot: %s', name);
|
||||||
this.snapshot = profiler.takeSnapshot(name);
|
this.snapshot = v8profiler.takeSnapshot(name);
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -123,7 +123,7 @@ Snapshot.uid = 0;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Snapshot.prototype.compare = function compare(other) {
|
Snapshot.prototype.compare = function compare(other) {
|
||||||
if (!profiler)
|
if (!v8profiler)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
assert(this.snapshot);
|
assert(this.snapshot);
|
||||||
@ -137,7 +137,7 @@ Snapshot.prototype.compare = function compare(other) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Snapshot.prototype.getHeader = function getHeader() {
|
Snapshot.prototype.getHeader = function getHeader() {
|
||||||
if (!profiler)
|
if (!v8profiler)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
assert(this.snapshot);
|
assert(this.snapshot);
|
||||||
@ -150,7 +150,7 @@ Snapshot.prototype.getHeader = function getHeader() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Snapshot.prototype.del = function del() {
|
Snapshot.prototype.del = function del() {
|
||||||
if (!profiler)
|
if (!v8profiler)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
assert(this.snapshot);
|
assert(this.snapshot);
|
||||||
@ -168,7 +168,7 @@ Snapshot.prototype.save = function save(callback) {
|
|||||||
|
|
||||||
callback = utils.asyncify(callback);
|
callback = utils.asyncify(callback);
|
||||||
|
|
||||||
if (!profiler)
|
if (!v8profiler)
|
||||||
return callback();
|
return callback();
|
||||||
|
|
||||||
assert(this.snapshot);
|
assert(this.snapshot);
|
||||||
@ -233,7 +233,7 @@ profiler.snapshot = function snapshot(name, callback) {
|
|||||||
utils.mb(mem.rss - mem.heapTotal));
|
utils.mb(mem.rss - mem.heapTotal));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!profiler)
|
if (!v8profiler)
|
||||||
return callback ? utils.nextTick(callback) : null;
|
return callback ? utils.nextTick(callback) : null;
|
||||||
|
|
||||||
snapshot = new Snapshot(name);
|
snapshot = new Snapshot(name);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user