Skip to content

Commit f98d4fd

Browse files
committed
added hooks to activate cumulative_mode from the web and command-line
1 parent 370f1ed commit f98d4fd

File tree

7 files changed

+31
-14
lines changed

7 files changed

+31
-14
lines changed

PyTutorGAE/css/pytutor.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,8 @@ div.stackFrame, div.zombieStackFrame {
454454
}
455455

456456
div.zombieStackFrame {
457-
border-left: 1px dotted #999999; /* make zombie borders thinner */
458-
color: #999999;
457+
border-left: 1px dotted #aaa; /* make zombie borders thinner */
458+
color: #aaa;
459459
}
460460

461461
div.highlightedStackFrame {

PyTutorGAE/generate_json_trace.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Generates a JSON trace that is compatible with the js/pytutor.js frontend
22

3+
CUMULATIVE_MODE = False
4+
5+
36
import sys, pg_logger, json
47

58

@@ -10,5 +13,5 @@ def json_finalizer(input_code, output_trace):
1013

1114

1215
for f in sys.argv[1:]:
13-
pg_logger.exec_script_str(open(f).read(), json_finalizer)
16+
pg_logger.exec_script_str(open(f).read(), CUMULATIVE_MODE, json_finalizer)
1417

PyTutorGAE/js/opt-frontend.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ $(document).ready(function() {
141141

142142

143143
$.get(backend_script,
144-
{user_script : pyInputCodeMirror.getValue()},
144+
{user_script : pyInputCodeMirror.getValue(),
145+
cumulative_mode: $('#cumulativeMode').prop('checked')},
145146
function(dataFromBackend) {
146147
var trace = dataFromBackend.trace;
147148

PyTutorGAE/pg_logger.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def filter_var_dict(d):
7878

7979
class PGLogger(bdb.Bdb):
8080

81-
def __init__(self, finalizer_func, cumulative_display=False):
81+
def __init__(self, cumulative_mode, finalizer_func):
8282
bdb.Bdb.__init__(self)
8383
self.mainpyfile = ''
8484
self._wait_for_mainpyfile = 0
@@ -90,7 +90,7 @@ def __init__(self, finalizer_func, cumulative_display=False):
9090
# if True, then displays ALL stack frames that have ever existed
9191
# rather than only those currently on the stack (and their
9292
# lexical parents)
93-
self.cumulative_display = cumulative_display
93+
self.cumulative_mode = cumulative_mode
9494

9595
# each entry contains a dict with the information for a single
9696
# executed line
@@ -109,7 +109,7 @@ def __init__(self, finalizer_func, cumulative_display=False):
109109
self.cur_frame_id = 1
110110

111111
# List of frames to KEEP AROUND after the function exits.
112-
# If cumulative_display is True, then keep ALL frames in
112+
# If cumulative_mode is True, then keep ALL frames in
113113
# zombie_frames; otherwise keep only frames where
114114
# nested functions were defined within them.
115115
self.zombie_frames = []
@@ -244,7 +244,7 @@ def interaction(self, frame, traceback, event_type):
244244
self.frame_ordered_ids[top_frame] = self.cur_frame_id
245245
self.cur_frame_id += 1
246246

247-
if self.cumulative_display:
247+
if self.cumulative_mode:
248248
self.zombie_frames.append(top_frame)
249249

250250

@@ -465,6 +465,10 @@ def create_encoded_stack_entry(cur_frame):
465465
# frame_id is UNIQUE, so it can disambiguate recursive calls
466466
hash_str += '_f' + str(e['frame_id'])
467467

468+
# needed to refresh GUI display ...
469+
if e['is_parent']:
470+
hash_str += '_p'
471+
468472
# TODO: this is no longer needed, right? (since frame_id is unique)
469473
#if e['parent_frame_id_list']:
470474
# hash_str += '_p' + '_'.join([str(i) for i in e['parent_frame_id_list']])
@@ -596,8 +600,8 @@ def finalize(self):
596600

597601

598602
# the MAIN meaty function!!!
599-
def exec_script_str(script_str, finalizer_func):
600-
logger = PGLogger(finalizer_func)
603+
def exec_script_str(script_str, cumulative_mode, finalizer_func):
604+
logger = PGLogger(cumulative_mode, finalizer_func)
601605

602606
try:
603607
logger._runscript(script_str)

PyTutorGAE/pythontutor.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,13 @@ def json_finalizer(self, input_code, output_trace):
5858
def get(self):
5959
self.response.headers['Content-Type'] = 'application/json'
6060
self.response.headers['Cache-Control'] = 'no-cache'
61-
pg_logger.exec_script_str(self.request.get('user_script'), self.json_finalizer)
61+
62+
# convert from string to a Python boolean ...
63+
cumulative_mode = (self.request.get('cumulative_mode') == 'true')
64+
65+
pg_logger.exec_script_str(self.request.get('user_script'),
66+
cumulative_mode,
67+
self.json_finalizer)
6268

6369

6470
app = webapp2.WSGIApplication([('/', TutorPage),

PyTutorGAE/tutor.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,12 @@
6666
<div id="codeInputPane"></div> <!-- populate with a CodeMirror instance -->
6767

6868
<p>
69-
7069
<button id="executeBtn" class="bigBtn" type="button">Visualize execution</button>
71-
7270
</p>
7371

72+
<p><input type="checkbox" id="cumulativeMode"/>Display exited functions</p>
73+
74+
7475
<p style="margin-top: 25px;">Try these small examples:<br/>
7576

7677
<a id="aliasExampleLink" href="#">aliasing</a> |

PyTutorGAE/web_exec.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@ def cgi_finalizer(input_code, output_trace):
2121
else:
2222
form = cgi.FieldStorage()
2323
user_script = form['user_script'].value
24+
# convert from string to a Python boolean ...
25+
cumulative_mode = (form['cumulative_mode'].value == 'true')
2426

25-
pg_logger.exec_script_str(user_script, cgi_finalizer)
27+
pg_logger.exec_script_str(user_script, cumulative_mode, cgi_finalizer)

0 commit comments

Comments
 (0)