fix profiler.

This commit is contained in:
Christopher Jeffrey 2016-04-15 07:54:29 -07:00
parent 26b3d92acf
commit cb27964b3b
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

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