Skip to content

Commit 3352907

Browse files
author
Philip Guo
committed
added a unique_hash field to the trace o.O
1 parent 5b09f1e commit 3352907

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

PyTutorGAE/js/pytutor.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,6 @@ ExecutionVisualizer.prototype.precomputeCurTraceLayouts = function() {
11021102
}
11031103

11041104

1105-
11061105
// The "3.0" version of renderDataStructures renders variables in
11071106
// a stack, values in a separate heap, and draws line connectors
11081107
// to represent both stack->heap object references and, more importantly,
@@ -1575,18 +1574,27 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
15751574
var stackDiv = myViz.domRootD3.select('#stack');
15761575

15771576
var stackFrameDiv = stackDiv.selectAll('div')
1578-
.data(curEntry.stack_to_render, function(frame, i) {
1579-
// use a frankenstein combination of frame identifiers and also the INDEX (stack position)
1580-
// as the join key, to properly handle closures and recursive calls of the same function
1581-
return frame.func_name + '_' + String(frame.frame_id) + '_' + String(frame.parent_frame_id_list) + '_' + String(frame.is_zombie) + '_' + i;
1577+
.data(curEntry.stack_to_render, function(frame) {
1578+
return frame.unique_hash; // VERY IMPORTANT for properly handling closures and nested functions
15821579
});
15831580

15841581
stackFrameDiv.enter().append('div')
15851582
.attr('class', function(d, i) {return d.is_zombie ? 'zombieStackFrame' : 'stackFrame';})
1586-
.attr('id', function(d, i) {return d.is_zombie ? myViz.generateID("zombie_stack" + i) : myViz.generateID("stack" + i);});
1583+
//.attr('id', function(d, i) {return d.is_zombie ? myViz.generateID("zombie_stack_" + htmlspecialchars(d.unique_hash))
1584+
// : myViz.generateID("stack_" + htmlspecialchars(d.unique_hash));
1585+
//})
1586+
.attr('id', function(d, i) {return d.is_zombie ? myViz.generateID("zombie_stack" + i)
1587+
: myViz.generateID("stack" + i);
1588+
})
15871589

15881590

1591+
1592+
/*
1593+
// I suspect I need to use .order() somewhere, but I can't seem to get it in the right place :(
15891594
stackFrameDiv
1595+
.each(function(frame, i) {
1596+
console.log('UPDATE stackFrameDiv', frame.unique_hash);
1597+
})
15901598
.append('div')
15911599
.attr('class', 'stackFrameHeader')
15921600
.html(function(frame, i) {
@@ -1605,9 +1613,13 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
16051613
}
16061614
16071615
return headerLabel;
1608-
});
1616+
})
1617+
*/
1618+
1619+
stackFrameDiv.exit().remove();
16091620

16101621

1622+
/*
16111623
stackFrameDiv
16121624
.append('div')
16131625
.attr('class', 'derrrr')
@@ -1637,9 +1649,9 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
16371649
});
16381650
16391651
stackVarTable.exit().remove();
1652+
*/
16401653

16411654

1642-
stackFrameDiv.exit().remove();
16431655

16441656
/*
16451657
stackFrame.enter()

PyTutorGAE/pg_logger.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,24 @@ def create_encoded_stack_entry(cur_frame):
436436

437437
stack_to_render.insert(j, e)
438438

439+
# create a unique hash for this stack entry, so that the
440+
# frontend can uniquely identify it when doing incremental
441+
# rendering. the strategy is to use a frankenstein-like mix of the
442+
# relevant fields to properly disambiguate closures and recursive
443+
# calls to the same function (stack_index is key for
444+
# disambiguating recursion!)
445+
for (stack_index, e) in enumerate(stack_to_render):
446+
hash_str = e['func_name']
447+
if e['frame_id']:
448+
hash_str += '_f' + str(e['frame_id'])
449+
if e['parent_frame_id_list']:
450+
hash_str += '_p' + '_'.join([str(i) for i in e['parent_frame_id_list']])
451+
if e['is_zombie']:
452+
hash_str += '_z'
453+
hash_str += '_i' + str(stack_index)
454+
455+
e['unique_hash'] = hash_str
456+
439457

440458
trace_entry = dict(line=lineno,
441459
event=event_type,

0 commit comments

Comments
 (0)