Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/22/10 17:06:12 (13 years ago)
Author:
epitzer
Message:

Add operator trace view (#47)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.DebugEngine/DebugEngine.cs

    r4903 r4904  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Linq;
    2425using System.Threading;
     
    4849      Log = cloner.Clone(original.Log);
    4950      ExecutionStack = cloner.Clone(original.ExecutionStack);
     51      OperatorTrace = new ItemList<IOperator>(original.OperatorTrace.Select(op => cloner.Clone(op)));
     52      operatorParents = original.operatorParents.ToDictionary(kvp => cloner.Clone(kvp.Key), kvp => cloner.Clone(kvp.Value));
    5053      pausePending = original.pausePending;
    5154      stopPending = original.stopPending;
     
    6063      Log = new Log();
    6164      ExecutionStack = new ExecutionStack();
     65      OperatorTrace = new ItemList<IOperator>();
     66      operatorParents = new Dictionary<IAtomicOperation, IAtomicOperation>();
    6267      pausePending = stopPending = false;
    6368      timer = new System.Timers.Timer(100);
     
    110115    }
    111116
     117    [Storable]
     118    public ItemList<IOperator> OperatorTrace { get; private set; }
     119
     120    [Storable]
     121    private Dictionary<IAtomicOperation, IAtomicOperation> operatorParents;
     122
    112123    #endregion
    113124
     
    131142      ignoreNextBreakpoint = false;
    132143      CurrentOperation = null;
     144      OperatorTrace.Clear();
     145      operatorParents.Clear();
    133146      OnPrepared();
    134147    }
     
    140153      ignoreNextBreakpoint = false;
    141154      CurrentOperation = null;
     155      OperatorTrace.Clear();
     156      operatorParents.Clear();
    142157      OnPrepared();
    143158    }
     
    161176    public override void Start() {
    162177      base.Start();
    163       CurrentOperation = null;
    164178      ThreadPool.QueueUserWorkItem(new WaitCallback(Run), null);
    165179    }
     
    250264          ExpandOperationCollection(operations);
    251265        } else if (ExecutionStack.Count > 0) {
    252           Log.LogMessage("Poping execution stack");
     266          Log.LogMessage("Popping execution stack");
    253267          CurrentOperation = ExecutionStack.Last();
    254268          ExecutionStack.RemoveAt(ExecutionStack.Count - 1);
     
    256270          Log.LogMessage("Nothing to do");
    257271        }
     272        GenerateOperationTrace();
    258273      } catch (Exception x) {
    259274        OnExceptionOccurred(x);
     275      }
     276    }
     277
     278    private void GenerateOperationTrace() {
     279      var operation = CurrentOperation as IAtomicOperation;
     280      if (operation != null) {
     281        List<IOperator> trace = new List<IOperator>();
     282        while (operation != null) {
     283          trace.Add(operation.Operator);
     284          IAtomicOperation parent = null;
     285          operatorParents.TryGetValue(operation, out parent);
     286          operation = parent;
     287        }
     288        trace.Reverse();
     289        OperatorTrace.Clear();
     290        OperatorTrace.AddRange(trace);
    260291      }
    261292    }
     
    276307          currentOperator = operation.Operator;
    277308          IOperation successor = operation.Operator.Execute((IExecutionContext)operation);
    278           CurrentOperation = null;
    279           currentOperator = null;
    280309          if (successor != null) {
     310            AssignParents(operation, successor);
    281311            ExecutionStack.Add(successor);
    282312          }
     313          currentOperator = null;
     314          CurrentOperation = null;
    283315        } catch (Exception ex) {
    284316          OnExceptionOccurred(new OperatorExecutionException(operation.Operator, ex));
     
    288320    }
    289321
     322    private void AssignParents(IAtomicOperation parent, IOperation successor) {
     323      OperationCollection operations = successor as OperationCollection;
     324      if (operations != null)
     325        foreach (var op in operations)
     326          AssignParents(parent, op);
     327      IAtomicOperation atomicOperation = successor as IAtomicOperation;
     328      if (atomicOperation != null && atomicOperation.Operator != null && !operatorParents.ContainsKey(atomicOperation))
     329        operatorParents[atomicOperation] = parent;
     330    }
     331
    290332    protected virtual void ExpandOperationCollection(OperationCollection operations) {
    291333      ExecutionStack.AddRange(operations.Reverse());
Note: See TracChangeset for help on using the changeset viewer.