add buildCallsPath to Util

pull/7/head
yann300 8 years ago
parent 9f7bf14a68
commit bdad659a74
  1. 24
      src/helpers/util.js
  2. 10
      src/trace/traceManager.js

@ -85,7 +85,21 @@ module.exports = {
return index >= 0 ? array[index] : null return index >= 0 ? array[index] : null
}, },
findCall: findCall findCall: findCall,
buildCallsPath: buildCallsPath
}
/**
* Find calls path from @args rootCall which leads to @args index (recursive)
*
* @param {Int} index - index of the vmtrace
* @param {Object} rootCall - call tree, built by the trace analyser
* @return {Array} - return the calls path to @args index
*/
function buildCallsPath (index, rootCall) {
var ret = []
findCallInternal(index, rootCall, ret)
return ret
} }
/** /**
@ -96,12 +110,18 @@ module.exports = {
* @return {Object} - return the call which include the @args index * @return {Object} - return the call which include the @args index
*/ */
function findCall (index, rootCall) { function findCall (index, rootCall) {
var ret = buildCallsPath(index, rootCall)
return ret[ret.length - 1]
}
function findCallInternal (index, rootCall, callsPath) {
var calls = Object.keys(rootCall.calls) var calls = Object.keys(rootCall.calls)
var ret = rootCall var ret = rootCall
callsPath.push(rootCall)
for (var k in calls) { for (var k in calls) {
var subCall = rootCall.calls[calls[k]] var subCall = rootCall.calls[calls[k]]
if (index >= subCall.start && index <= subCall.return) { if (index >= subCall.start && index <= subCall.return) {
ret = findCall(index, subCall) findCallInternal(index, subCall, callsPath)
break break
} }
} }

@ -114,6 +114,16 @@ TraceManager.prototype.getCallDataAt = function (stepIndex, callback) {
callback(null, [this.traceCache.callsData[callDataChange]]) callback(null, [this.traceCache.callsData[callDataChange]])
} }
TraceManager.prototype.buildCallsPath = function (stepIndex, callback) {
var check = this.checkRequestedStep(stepIndex)
if (check) {
return callback(check, null)
}
var callsPath = util.buildCallsPath(stepIndex, this.traceCache.callsTree.call)
if (callsPath === null) return callback('no call path built', null)
callback(null, callsPath)
}
TraceManager.prototype.getCallStackAt = function (stepIndex, callback) { TraceManager.prototype.getCallStackAt = function (stepIndex, callback) {
var check = this.checkRequestedStep(stepIndex) var check = this.checkRequestedStep(stepIndex)
if (check) { if (check) {

Loading…
Cancel
Save