on master help sign in
fast scrubbing but the traces are still off
commit180d998c67a1922a71ef21b77e61818764a01834 authorMichael James <michael@michaelbjames.com> dateWed 23 Jul 2014, 19:07 (12 years ago) parenta79e903
1 file changed+55−10
runtime/Debugger.js+55−10
runtime/Debugger.js+55−10
@@ -20,6 +20,8 @@ Elm.debuggerAttach = function(module, hotSwapState /* =undefined */) {
2020 };
2121};
2222
23+var EVENTS_PER_SAVE = 100;
24+
2325function dispatchElmDebuggerInit() {
2426 if (parent.window) {
2527 var dispatch = function() {
@@ -38,8 +40,10 @@ function debugModule(module, runtime) {
3840 var programPaused = false;
3941 var recordedEvents = [];
4042 var asyncCallbacks = [];
43+ var snapshots = [];
4144 var watchTracker = Elm.Native.Debug.make(runtime).watchTracker;
4245 var pauseTime = 0;
46+ var eventsUntilSnapshot = EVENTS_PER_SAVE;
4347
4448 // runtime is the prototype of wrappedRuntime
4549 // so we can access all runtime properties too
@@ -66,6 +70,8 @@ function debugModule(module, runtime) {
6670 var signalGraphNodes = flattenSignalGraph(wrappedRuntime.inputs);
6771 var tracePath = tracePathInit(runtime, debuggedModule.main);
6872
73+ snapshots.push(snapshotSignalGraph(signalGraphNodes));
74+
6975 function wrapNotify(id, v) {
7076 var timestep = runtime.timer.now();
7177
@@ -77,6 +83,11 @@ function debugModule(module, runtime) {
7783 else {
7884 var changed = runtime.notify(id, v, timestep);
7985 recordEvent(id, v, timestep);
86+ if (eventsUntilSnapshot <= 1) {
87+ saveSnapshot();
88+ eventsUntilSnapshot = EVENTS_PER_SAVE;
89+ }
90+ eventsUntilSnapshot -= 1;
8091 if (parent.window) {
8192 parent.window.postMessage("elmNotify", window.location.origin);
8293 }
@@ -133,6 +144,20 @@ function debugModule(module, runtime) {
133144 recordedEvents = events.slice();
134145 }
135146
147+ function clearSnapshots() {
148+ snapshots = [snapshotSignalGraph(signalGraphNodes)];
149+ }
150+
151+ function getSnapshotAt(i) {
152+ var snapshotEvent = Math.floor(i / EVENTS_PER_SAVE);
153+ assert(snapshotEvent < snapshots.length && snapshotEvent >= 0, "Out of bounds index: " + snapshotEvent);
154+ return snapshots[snapshotEvent];
155+ }
156+
157+ function saveSnapshot() {
158+ snapshots.push(snapshotSignalGraph(signalGraphNodes));
159+ }
160+
136161 function setPaused() {
137162 programPaused = true;
138163 clearAsyncCallbacks();
@@ -147,6 +172,9 @@ function debugModule(module, runtime) {
147172 if (position > 0) {
148173 // If we're not unpausing at the head, then we need to dump the
149174 // events that are ahead of where we're continuing.
175+ var lastSnapshotPosition = Math.ceil(position / EVENTS_PER_SAVE);
176+ eventsUntilSnapshot = EVENTS_PER_SAVE - (position % EVENTS_PER_SAVE);
177+ snapshots = snapshots.slice(0, lastSnapshotPosition);
150178 recordedEvents = recordedEvents.slice(0, position);
151179 executeCallbacks(asyncCallbacks, false);
152180 }
@@ -169,6 +197,9 @@ function debugModule(module, runtime) {
169197 getRecordedEventAt: getRecordedEventAt,
170198 copyRecordedEvents: copyRecordedEvents,
171199 loadRecordedEvents: loadRecordedEvents,
200+ clearSnapshots: clearSnapshots,
201+ getSnapshotAt: getSnapshotAt,
202+ saveSnapshot: saveSnapshot,
172203 getPaused: getPaused,
173204 setPaused: setPaused,
174205 setContinue: setContinue,
@@ -180,17 +211,20 @@ function debugModule(module, runtime) {
180211function debuggerInit(debugModule, runtime, hotSwapState /* =undefined */) {
181212 var currentEventIndex = 0;
182213
183− function resetProgram() {
214+ function resetProgram(position) {
215+ var closestSnapshot = debugModule.getSnapshotAt(position);
184216 debugModule.clearAsyncCallbacks();
185− restoreSnapshot(debugModule.signalGraphNodes, debugModule.initialSnapshot);
217+ restoreSnapshot(debugModule.signalGraphNodes, closestSnapshot);
218+ // clear traces here.
186219 redrawGraphics();
187220 }
188221
189222 function restartProgram() {
190− resetProgram();
223+ resetProgram(0);
191224 debugModule.watchTracker.clear();
192225 debugModule.tracePath.clearTraces();
193226 debugModule.clearRecordedEvents();
227+ debugModule.clearSnapshots();
194228 debugModule.setContinue(0);
195229 executeCallbacks(debugModule.initialAsyncCallbacks, true);
196230 }
@@ -207,11 +241,10 @@ function debuggerInit(debugModule, runtime, hotSwapState /* =undefined */) {
207241 restartProgram();
208242 return;
209243 }
210− resetProgram();
244+ var closestSnapshotIndex = Math.floor(currentEventIndex / EVENTS_PER_SAVE) * EVENTS_PER_SAVE;
245+ resetProgram(currentEventIndex);
211246 var continueIndex = currentEventIndex;
212− currentEventIndex = 0;
213− debugModule.tracePath.clearTraces();
214− debugModule.tracePath.startRecording();
247+ currentEventIndex = closestSnapshotIndex;
215248 stepTo(continueIndex);
216249 debugModule.setContinue(currentEventIndex);
217250 }
@@ -228,8 +261,9 @@ function debuggerInit(debugModule, runtime, hotSwapState /* =undefined */) {
228261 }
229262
230263 if (index < currentEventIndex) {
231− resetProgram();
232− currentEventIndex = 0;
264+ var closestSnapshotIndex = Math.floor(index / EVENTS_PER_SAVE) * EVENTS_PER_SAVE;
265+ resetProgram(index);
266+ currentEventIndex = closestSnapshotIndex;
233267 }
234268
235269 while (currentEventIndex < index) {
@@ -277,10 +311,21 @@ function debuggerInit(debugModule, runtime, hotSwapState /* =undefined */) {
277311 var paused = top.debug.paused;
278312 debugModule.setPaused();
279313 debugModule.loadRecordedEvents(hotSwapState.recordedEvents);
314+ var index = getMaxSteps();
315+ var eventsUntilSnapshot = EVENTS_PER_SAVE;
280316
281317 // draw new trace path
282318 debugModule.tracePath.startRecording();
283− stepTo(getMaxSteps());
319+ while(currentEventIndex < index) {
320+ var nextEvent = debugModule.getRecordedEventAt(currentEventIndex);
321+ runtime.notify(nextEvent.id, nextEvent.value, nextEvent.timestep);
322+ if (eventsUntilSnapshot <= 1) {
323+ debugModule.saveSnapshot();
324+ eventsUntilSnapshot = EVENTS_PER_SAVE;
325+ }
326+ eventsUntilSnapshot -= 1;
327+ currentEventIndex += 1;
328+ }
284329 debugModule.tracePath.stopRecording();
285330
286331 stepTo(hotSwapState.currentEventIndex);