Skip to content

Commit

Permalink
fix(profiler): delete profiler after send
Browse files Browse the repository at this point in the history
  • Loading branch information
gergelyke committed Sep 1, 2016
1 parent 71fdede commit 68f0d67
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
12 changes: 6 additions & 6 deletions lib/agent/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,24 +137,24 @@ CollectorApi.prototype.sendApmMetrics = function (data) {
this._send(url, this._withInstanceInfo(data))
}

CollectorApi.prototype.sendMemorySnapshot = function (data) {
CollectorApi.prototype.sendMemorySnapshot = function (data, callback) {
if (!isNumber(this.serviceKey)) {
debug('Service id not present, cannot send heapdump')
return
return callback(new Error('serviceKey is missing'))
}

var url = util.format(this.COLLECTOR_API_PROFILER_MEMORY_HEAPDUMP, this.serviceKey)
this._send(url, this._withInstanceInfo(data))
this._send(url, this._withInstanceInfo(data), callback)
}

CollectorApi.prototype.sendCpuProfile = function (data) {
CollectorApi.prototype.sendCpuProfile = function (data, callback) {
if (!isNumber(this.serviceKey)) {
debug('Service id not present, cannot send cpu profile')
return
return callback(new Error('serviceKey is missing'))
}

var url = util.format(this.COLLECTOR_API_PROFILER_CPU_PROFILE, this.serviceKey)
this._send(url, this._withInstanceInfo(data))
this._send(url, this._withInstanceInfo(data), callback)
}

CollectorApi.prototype.sendExternalEdgeMetrics = function (data) {
Expand Down
3 changes: 2 additions & 1 deletion lib/agent/profiler/cpu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ CpuProfiler.prototype.sendProfile = function (command) {
cpuProfile: result,
time: Date.now(),
commandId: command.id
}, function () {
profile.delete()
})
profile.delete()
})
}, this.profileWindow)
}
Expand Down
5 changes: 4 additions & 1 deletion lib/agent/profiler/cpu/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ describe('The Cpu Profiler module', function () {
var msgBus = new EventEmitter()
var profileData = 'some-profile-data'
var collectorApi = {
sendCpuProfile: this.sandbox.spy()
sendCpuProfile: this.sandbox.spy(function (data, callback) {
callback()
})
}

var profile = {
export: function (cb) {
cb(null, profileData)
Expand Down
4 changes: 2 additions & 2 deletions lib/agent/profiler/memory/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ MemoryProfiler.prototype.sendSnapshot = function (command) {
heapSnapshot: result,
time: now,
commandId: command.id
}, function () {
snapshot.delete()
})

snapshot.delete()
})
}

Expand Down
4 changes: 3 additions & 1 deletion lib/agent/profiler/memory/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ describe('The Memory Profiler module', function () {
it('sends heapdump', function () {
var msgBus = new EventEmitter()
var collectorApi = {
sendMemorySnapshot: this.sandbox.spy()
sendMemorySnapshot: this.sandbox.spy(function (data, callback) {
callback()
})
}
var deleteSnapshotSpy = this.sandbox.spy()
var snapshotContent = 'snapshot'
Expand Down

0 comments on commit 68f0d67

Please sign in to comment.