Commit bdad659a authored by yann300's avatar yann300

add buildCallsPath to Util

parent 9f7bf14a
......@@ -85,7 +85,21 @@ module.exports = {
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
*/
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 ret = rootCall
callsPath.push(rootCall)
for (var k in calls) {
var subCall = rootCall.calls[calls[k]]
if (index >= subCall.start && index <= subCall.return) {
ret = findCall(index, subCall)
findCallInternal(index, subCall, callsPath)
break
}
}
......
......@@ -114,6 +114,16 @@ TraceManager.prototype.getCallDataAt = function (stepIndex, callback) {
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) {
var check = this.checkRequestedStep(stepIndex)
if (check) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment