Пример #1
0
        /// <summary>
        /// Updates the graph.
        /// </summary>
        /// <param name="machineTrace">MachineActionTrace</param>
        void UpdateGraph(MachineActionTrace machineTrace)
        {
            int currentMachineVC = 0;

            Node cLatestAction = null;

            foreach (MachineActionInfo info in machineTrace)
            {
                if (info.Type != MachineActionType.SendAction && (info.ActionId != 0) && !(info.Type == MachineActionType.TaskMachineCreation))
                {
                    ThreadTrace matching = null;

                    try
                    {
                        matching = this.AllThreadTraces.Where(item => item.MachineId == info.MachineId &&
                                                              item.ActionId == info.ActionId).Single();
                    }
                    catch (Exception)
                    {
                        //TODO: check correctness
                        //In case entry and exit functions not defined.
                        //IO.PrintLine("Skipping entry/exit actions: " + mt.MachineId + " " + mt.ActionId + " " + mt.ActionName);
                        continue;
                    }

                    Node cn = new CActBegin(matching.MachineId, matching.ActionName,
                                            matching.ActionId, info.EventName, info.EventId);
                    if (matching.ActionId == 1)
                    {
                        ((CActBegin)cn).IsStart = true;
                    }

                    cn.VectorClock = new int[this.VcCount];
                    currentMachineVC++;

                    try
                    {
                        cn.VectorClock[info.MachineId] = currentMachineVC;
                    }
                    catch (Exception ex)
                    {
                        IO.PrintLine("failed: " + this.VcCount + " " + info.MachineId);
                        IO.PrintLine(ex.ToString());
                        Environment.Exit(Environment.ExitCode);
                    }

                    this.CGraph.AddVertex(cn);

                    if (cLatestAction != null)
                    {
                        this.CGraph.AddEdge(new Edge(cLatestAction, cn));
                    }

                    Node cLatest = cn;
                    cLatestAction = cn;


                    bool createNew = false;

                    foreach (ActionInstr ins in matching.Accesses)
                    {
                        // User trace send event.
                        Node cn1;

                        if (createNew)
                        {
                            Node cnn = new CActBegin(matching.MachineId, matching.ActionName,
                                                     matching.ActionId, info.EventName, info.EventId);
                            cnn.VectorClock = new int[this.VcCount];
                            currentMachineVC++;

                            try
                            {
                                cnn.VectorClock[info.MachineId] = currentMachineVC;
                            }
                            catch (Exception ex)
                            {
                                IO.PrintLine("failed: " + this.VcCount + " " + info.MachineId);
                                IO.PrintLine(ex.ToString());
                                Environment.Exit(Environment.ExitCode);
                            }

                            this.CGraph.AddVertex(cnn);

                            cn = cnn;
                            this.CGraph.AddEdge(new Edge(cLatest, cn));
                            createNew = false;
                            cLatest   = cn;
                        }

                        if (ins.IsSend)
                        {
                            MachineActionInfo machineSend = machineTrace.Where(
                                item => item.MachineId == matching.MachineId &&
                                item.SendId == ins.SendId).Single();

                            cn1 = new SendEvent(machineSend.MachineId, machineSend.SendId,
                                                machineSend.TargetMachineId, machineSend.SendEventName, machineSend.EventId);
                            cn1.VectorClock = new int[this.VcCount];
                            currentMachineVC++;

                            try
                            {
                                cn1.VectorClock[info.MachineId] = currentMachineVC;
                            }
                            catch (Exception ex)
                            {
                                IO.PrintLine("failed: " + this.VcCount + " " + info.MachineId);
                                IO.PrintLine(ex.ToString());
                                Environment.Exit(Environment.ExitCode);
                            }

                            this.CGraph.AddVertex(cn1);
                            this.CGraph.AddEdge(new Edge(cLatest, cn1));

                            createNew = true;
                        }
                        // User trace create machine.
                        else if (ins.IsCreate)
                        {
                            cn1             = new CreateMachine(ins.CreateMachineId);
                            cn1.VectorClock = new int[this.VcCount];
                            currentMachineVC++;

                            try
                            {
                                cn1.VectorClock[info.MachineId] = currentMachineVC;
                            }
                            catch (Exception ex)
                            {
                                IO.PrintLine("failed: " + this.VcCount + " " + info.MachineId);
                                IO.PrintLine(ex.ToString());
                                Environment.Exit(Environment.ExitCode);
                            }

                            this.CGraph.AddVertex(cn1);
                            this.CGraph.AddEdge(new Edge(cLatest, cn1));

                            createNew = true;
                        }
                        // User trace task creation.
                        else if (ins.IsTask)
                        {
                            cn1             = new CreateTask(ins.TaskId);
                            cn1.VectorClock = new int[this.VcCount];
                            currentMachineVC++;

                            try
                            {
                                cn1.VectorClock[info.MachineId] = currentMachineVC;
                            }
                            catch (Exception ex)
                            {
                                IO.PrintLine("failed: " + this.VcCount + " " + info.MachineId);
                                IO.PrintLine(ex.ToString());
                                Environment.Exit(Environment.ExitCode);
                            }

                            this.CGraph.AddVertex(cn1);
                            this.CGraph.AddEdge(new Edge(cLatest, cn1));


                            createNew = true;
                        }
                        // User trace reads/writes.
                        else
                        {
                            ((CActBegin)cn).Addresses.Add(new MemAccess(ins.IsWrite, ins.Location,
                                                                        ins.ObjHandle, ins.Offset, ins.SrcLocation, info.MachineId));
                            cn1 = cn;
                        }

                        cLatest       = cn1;
                        cLatestAction = cn1;
                    }
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Updates the graph cross edges.
 /// </summary>
 void UpdateGraphCrossEdges()
 {
     foreach (Node n in this.CGraph.Vertices)
     {
         if (n.GetType().ToString().Contains("SendEvent"))
         {
             IEnumerable <Node> actBegins = this.CGraph.Vertices.Where(item
                                                                       => item.GetType().ToString().Contains("CActBegin"));
             foreach (Node n1 in actBegins)
             {
                 SendEvent sendNode  = (SendEvent)n;
                 CActBegin beginNode = (CActBegin)n1;
                 if (sendNode.ToMachine == beginNode.MachineId &&
                     sendNode.SendEventId == beginNode.EventId)
                 {
                     this.CGraph.AddEdge(new Edge(sendNode, beginNode));
                     for (int i = 0; i < this.VcCount; i++)
                     {
                         beginNode.VectorClock[i] = Math.Max(beginNode.VectorClock[i],
                                                             sendNode.VectorClock[i]);
                     }
                 }
             }
         }
         else if (n.GetType().ToString().Contains("CreateMachine"))
         {
             IEnumerable <Node> actBegins = this.CGraph.Vertices.Where(item
                                                                       => item.GetType().ToString().Contains("CActBegin"));
             foreach (Node n1 in actBegins)
             {
                 CreateMachine createNode = (CreateMachine)n;
                 CActBegin     beginNode  = (CActBegin)n1;
                 if (createNode.CreateMachineId == beginNode.MachineId && beginNode.ActionId == 1)
                 {
                     this.CGraph.AddEdge(new Edge(createNode, beginNode));
                     for (int i = 0; i < this.VcCount; i++)
                     {
                         beginNode.VectorClock[i] = Math.Max(beginNode.VectorClock[i],
                                                             createNode.VectorClock[i]);
                     }
                 }
             }
         }
         else if (n.GetType().ToString().Contains("CreateTask"))
         {
             IEnumerable <Node> actBegins = this.CGraph.Vertices.Where(item
                                                                       => item.GetType().ToString().Contains("CActBegin"));
             foreach (Node n1 in actBegins)
             {
                 CreateTask createNode = (CreateTask)n;
                 CActBegin  beginNode  = (CActBegin)n1;
                 if (createNode.TaskId == beginNode.TaskId)
                 {
                     this.CGraph.AddEdge(new Edge(createNode, beginNode));
                     for (int i = 0; i < this.VcCount; i++)
                     {
                         beginNode.VectorClock[i] = Math.Max(beginNode.VectorClock[i],
                                                             createNode.VectorClock[i]);
                     }
                 }
             }
         }
     }
 }
Пример #3
0
        /// <summary>
        /// Updates the graph.
        /// </summary>
        /// <param name="machineTrace">MachineActionTrace</param>
        void UpdateGraph(MachineActionTrace machineTrace)
        {
            int currentMachineVC = 0;

            Node cLatestAction = null;
            foreach (MachineActionInfo info in machineTrace)
            {
                if (info.Type != MachineActionType.SendAction && (info.ActionId != 0)/* && !info.isTaskMachine*/)
                {
                    ThreadTrace matching = null;

                    try
                    {
                        matching = this.AllThreadTraces.Where(item => item.MachineId == info.MachineId &&
                            item.ActionId == info.ActionId).Single();
                    }
                    catch (Exception)
                    {
                        //TODO: check correctness
                        //In case entry and exit functions not defined.
                        //IO.PrintLine("Skipping entry/exit actions: " + mt.MachineId + " " + mt.ActionId + " " + mt.ActionName);
                        continue;
                    }

                    Node cn = new CActBegin(matching.MachineId, matching.ActionName,
                        matching.ActionId, info.EventName, info.EventId);
                    if(matching.ActionId == 1)
                    {
                        ((CActBegin)cn).IsStart = true;
                    }

                    cn.VectorClock = new int[this.VcCount];
                    currentMachineVC++;

                    try
                    {
                        cn.VectorClock[info.MachineId] = currentMachineVC;
                    }
                    catch (Exception ex)
                    {
                        IO.PrintLine("failed: " + this.VcCount + " " + info.MachineId);
                        IO.PrintLine(ex.ToString());
                        Environment.Exit(Environment.ExitCode);
                    }

                    this.CGraph.AddVertex(cn);

                    if(cLatestAction != null)
                    {
                        this.CGraph.AddEdge(new Edge(cLatestAction, cn));
                    }

                    Node cLatest = cn;
                    cLatestAction = cn;

                    bool createNew = false;

                    foreach (ActionInstr ins in matching.Accesses)
                    {
                        // User trace send event.
                        Node cn1;

                        if (createNew)
                        {
                            Node cnn = new CActBegin(matching.MachineId, matching.ActionName,
                                matching.ActionId, info.EventName, info.EventId);
                            cnn.VectorClock = new int[this.VcCount];
                            currentMachineVC++;

                            try
                            {
                                cnn.VectorClock[info.MachineId] = currentMachineVC;
                            }
                            catch (Exception ex)
                            {
                                IO.PrintLine("failed: " + this.VcCount + " " + info.MachineId);
                                IO.PrintLine(ex.ToString());
                                Environment.Exit(Environment.ExitCode);
                            }

                            this.CGraph.AddVertex(cnn);

                            cn = cnn;
                            this.CGraph.AddEdge(new Edge(cLatest, cn));
                            createNew = false;
                            cLatest = cn;
                        }

                        if (ins.IsSend)
                        {
                            MachineActionInfo machineSend = machineTrace.Where(
                                item => item.MachineId == matching.MachineId &&
                                item.SendId == ins.SendId).Single();

                            cn1 = new SendEvent(machineSend.MachineId, machineSend.SendId,
                                machineSend.TargetMachineId, machineSend.EventName, machineSend.EventId);
                            cn1.VectorClock = new int[this.VcCount];
                            currentMachineVC++;

                            try
                            {
                                cn1.VectorClock[info.MachineId] = currentMachineVC;
                            }
                            catch (Exception ex)
                            {
                                IO.PrintLine("failed: " + this.VcCount + " " + info.MachineId);
                                IO.PrintLine(ex.ToString());
                                Environment.Exit(Environment.ExitCode);
                            }

                            this.CGraph.AddVertex(cn1);
                            this.CGraph.AddEdge(new Edge(cLatest, cn1));

                            createNew = true;
                        }
                        // User trace create machine.
                        else if (ins.IsCreate)
                        {
                            cn1 = new CreateMachine(ins.CreateMachineId);
                            cn1.VectorClock = new int[this.VcCount];
                            currentMachineVC++;

                            try
                            {
                                cn1.VectorClock[info.MachineId] = currentMachineVC;
                            }
                            catch (Exception ex)
                            {
                                IO.PrintLine("failed: " + this.VcCount + " " + info.MachineId);
                                IO.PrintLine(ex.ToString());
                                Environment.Exit(Environment.ExitCode);
                            }

                            this.CGraph.AddVertex(cn1);
                            this.CGraph.AddEdge(new Edge(cLatest, cn1));

                            createNew = true;
                        }
                        // User trace task creation.
                        else if (ins.IsTask)
                        {
                            cn1 = new CreateTask(ins.TaskId);
                            cn1.VectorClock = new int[this.VcCount];
                            currentMachineVC++;

                            try
                            {
                                cn1.VectorClock[info.MachineId] = currentMachineVC;
                            }
                            catch (Exception ex)
                            {
                                IO.PrintLine("failed: " + this.VcCount + " " + info.MachineId);
                                IO.PrintLine(ex.ToString());
                                Environment.Exit(Environment.ExitCode);
                            }

                            this.CGraph.AddVertex(cn1);
                            this.CGraph.AddEdge(new Edge(cLatest, cn1));

                            createNew = true;
                        }
                        // User trace reads/writes.
                        else
                        {
                            ((CActBegin)cn).Addresses.Add(new MemAccess(ins.IsWrite, ins.Location,
                                ins.ObjHandle, ins.Offset, ins.SrcLocation, info.MachineId));
                            cn1 = cn;

                        }

                        cLatest = cn1;
                        cLatestAction = cn1;
                    }
                }
            }
        }