Esempio n. 1
0
        public JObject Query(string storeId, JObject query, string[] expand, int level)
        {
            using (var op = _storeOperationFactory.Write(storeId)) {
                try {
                    var(data, _, _) = GetSetGraphs(storeId);
                    ObjectQueryModel queryModel;
                    try {
                        queryModel = query.ToObject <ObjectQueryModel>();
                    } catch (Exception e) {
                        throw new StoreException(e.Message, _storeErrors.UnableToParseQuery);
                    }

                    var     result   = new ObjectQueryExecutor().Query(queryModel, data);
                    dynamic response = new
                    {
                        values = result.Values?.Select(x =>
                        {
                            var expanded = GraphOperator.Expand(data, x.Subject, level, expand);
                            var rspGraph = new MemoryGraph();
                            rspGraph.Assert(expanded).ToList();
                            return(TripleConverter.ToJson(x.Subject, rspGraph));
                        }),
                        continuation = result.Continuation,
                        aggregates   = result.Aggregates
                    };
                    return(JObject.FromObject(response));
                } catch (Exception e) {
                    _logger.LogError("Query failed. {Message}\n {StackTrace}", e.Message, e.StackTrace);
                    throw e;
                }
            }
        }
Esempio n. 2
0
        public void TestLiveEdgeDynamicGraphAddRemove1()
        {
            uint tagsId = 10;
            var graph = new MemoryGraph<LiveEdge>();
            var vertex1 = graph.AddVertex(51, 1);
            var vertex2 = graph.AddVertex(51, 2);

            graph.AddEdge(vertex1, vertex2, new LiveEdge()
            {
                Forward = true,
                Tags = tagsId
            }, null);

            // test forward edge.
            var arcs = graph.GetEdges(vertex1).ToKeyValuePairs();
            Assert.AreEqual(1, arcs.Length);
            Assert.AreEqual(tagsId, arcs[0].Value.Tags);
            Assert.AreEqual(vertex2, arcs[0].Key);
            Assert.AreEqual(true, arcs[0].Value.Forward);

            // remove edge again.
            graph.RemoveEdge(vertex1, vertex2);

            // check if the edge is gone.
            arcs = graph.GetEdges(vertex1).ToKeyValuePairs();
            Assert.AreEqual(0, arcs.Length);
        }
Esempio n. 3
0
        public ObjectViewer(MemoryGraph graph, RefGraph refGraph, List <NodeIndex> focusNodes = null)
        {
            InitializeComponent();

            // Wire up our behavior into the generic TreeViewGrid.  This defines the columns and how to get a child nodes.
            TreeViewGrid.SetController(new ObjectViewerTreeViewController(graph, refGraph, focusNodes));
        }
        public void TestSparseRemoval1()
        {
            // use one edge definition everywhere.
            var edge = new LiveEdge();
            edge.Forward = true;
            edge.Tags = 1;

            var graph = new MemoryGraph<LiveEdge>();
            uint vertex1 = graph.AddVertex(0, 0);
            uint vertex2 = graph.AddVertex(1, 1);
            uint vertex3 = graph.AddVertex(2, 2);

            graph.AddEdge(vertex1, vertex2, edge, null);
            graph.AddEdge(vertex2, vertex1, edge, null);
            graph.AddEdge(vertex2, vertex3, edge, null);
            graph.AddEdge(vertex3, vertex2, edge, null);

            // execute pre-processor.
            var preProcessor = new LiveEdgePreprocessor(graph);
            preProcessor.Start();

            // test resulting graph.
            Assert.AreEqual(2, graph.VertexCount);
            Assert.AreEqual(1, graph.GetEdges(1).ToKeyValuePairs().Length);
            Assert.AreEqual(2, graph.GetEdges(1).ToKeyValuePairs()[0].Key);
            Assert.AreEqual(1, graph.GetEdges(2).ToKeyValuePairs().Length);
            Assert.AreEqual(1, graph.GetEdges(2).ToKeyValuePairs()[0].Key);
        }
 public void Append(MemoryGraph memoryGraph, string etlName, string processNameOrId = null, double startTimeRelativeMSec = 0)
 {
     using (var source = TraceEventDispatcher.GetDispatcherFromFileName(etlName))
     {
         Append(memoryGraph, source, processNameOrId, startTimeRelativeMSec);
     }
 }
Esempio n. 6
0
        static void Main()
        {
            int         expectedNumberOfNodes = 1000;
            MemoryGraph memoryGraph           = new MemoryGraph(expectedNumberOfNodes);

            GrowableArray <NodeIndex> tempForChildren = new GrowableArray <NodeIndex>();


            // We can make a new Node index
            NodeIndex newNodeIdx = memoryGraph.CreateNode();

            NodeIndex childIdx = memoryGraph.CreateNode();


            //
            NodeTypeIndex newNodeType = memoryGraph.CreateType("MyChild");



            memoryGraph.SetNode(childIdx, newType, 100, tempForChildren);



            memoryGraph.AllowReading();

            // Serialize to a file
            memoryGraph.WriteAsBinaryFile("file.gcHeap");



            // Can unserialize easily.
            // var readBackIn = MemoryGraph.ReadFromBinaryFile("file.gcHeap");
        }
 public void Append(MemoryGraph memoryGraph, string javaScriptEtlName, int processId, double startTimeRelativeMSec = 0)
 {
     using (var source = new ETWTraceEventSource(javaScriptEtlName))
     {
         Append(memoryGraph, source, processId, startTimeRelativeMSec);
     }
 }
Esempio n. 8
0
        public DiagnosticsEventPipeProcessor(
            PipeMode mode,
            ILoggerFactory loggerFactory = null,                               // PipeMode = Logs
            LogLevel logsLevel           = LogLevel.Debug,                     // PipeMode = Logs
            IEnumerable <ICountersLogger> metricLoggers = null,                // PipeMode = Metrics
            int metricIntervalSeconds  = 10,                                   // PipeMode = Metrics
            CounterFilter metricFilter = null,                                 // PipeMode = Metrics
            MemoryGraph gcGraph        = null,                                 // PipeMode = GCDump
            MonitoringSourceConfiguration configuration = null,                // PipeMode = Nettrace
            Func <Stream, CancellationToken, Task> onStreamAvailable   = null, // PipeMode = Nettrace
            Func <string, CancellationToken, Task> processInfoCallback = null  // PipeMode = ProcessInfo
            )
        {
            _metricLoggers         = metricLoggers ?? Enumerable.Empty <ICountersLogger>();
            _mode                  = mode;
            _loggerFactory         = loggerFactory;
            _gcGraph               = gcGraph;
            _metricIntervalSeconds = metricIntervalSeconds;
            _logsLevel             = logsLevel;
            _processInfoCallback   = processInfoCallback;
            _userConfig            = configuration;
            _onStreamAvailable     = onStreamAvailable;
            _processInfoCallback   = processInfoCallback;
            _counterFilter         = metricFilter;

            _sessionStarted = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously);
        }
Esempio n. 9
0
        public void TestLiveEdgeDynamicGraphAddRemove1()
        {
            uint tagsId  = 10;
            var  graph   = new MemoryGraph <LiveEdge>();
            var  vertex1 = graph.AddVertex(51, 1);
            var  vertex2 = graph.AddVertex(51, 2);

            graph.AddEdge(vertex1, vertex2, new LiveEdge()
            {
                Forward = true,
                Tags    = tagsId
            }, null);

            // test forward edge.
            var arcs = graph.GetEdges(vertex1).ToKeyValuePairs();

            Assert.AreEqual(1, arcs.Length);
            Assert.AreEqual(tagsId, arcs[0].Value.Tags);
            Assert.AreEqual(vertex2, arcs[0].Key);
            Assert.AreEqual(true, arcs[0].Value.Forward);

            // remove edge again.
            graph.RemoveEdge(vertex1, vertex2);

            // check if the edge is gone.
            arcs = graph.GetEdges(vertex1).ToKeyValuePairs();
            Assert.AreEqual(0, arcs.Length);
        }
Esempio n. 10
0
        public void TestSparseRemoval1()
        {
            // use one edge definition everywhere.
            var edge = new LiveEdge();

            edge.Forward = true;
            edge.Tags    = 1;

            var  graph   = new MemoryGraph <LiveEdge>();
            uint vertex1 = graph.AddVertex(0, 0);
            uint vertex2 = graph.AddVertex(1, 1);
            uint vertex3 = graph.AddVertex(2, 2);

            graph.AddEdge(vertex1, vertex2, edge, null);
            graph.AddEdge(vertex2, vertex1, edge, null);
            graph.AddEdge(vertex2, vertex3, edge, null);
            graph.AddEdge(vertex3, vertex2, edge, null);

            // execute pre-processor.
            var preProcessor = new LiveEdgePreprocessor(graph);

            preProcessor.Start();

            // test resulting graph.
            Assert.AreEqual(2, graph.VertexCount);
            Assert.AreEqual(1, graph.GetEdges(1).ToKeyValuePairs().Length);
            Assert.AreEqual(2, graph.GetEdges(1).ToKeyValuePairs()[0].Key);
            Assert.AreEqual(1, graph.GetEdges(2).ToKeyValuePairs().Length);
            Assert.AreEqual(1, graph.GetEdges(2).ToKeyValuePairs()[0].Key);
        }
Esempio n. 11
0
        protected override void WriteHtmlBody(TraceLog dataFile, TextWriter writer, string fileName, TextWriter log)
        {
            m_log = log;

            m_htmlRaw = writer;

            m_heapDumpFile.OpenDump(log);

            writer.WriteLine("<H2>CLR Interop Objects</H2><p>");

            writer.WriteLine("<b>RCW</b>: Runtime Callable Wrapper: wrapping COM objects to be called by managed runtime.<p>");
            writer.WriteLine("<b>CCW</b>: COM Callable Wrapper: wrapping managed objects to be called by COM.<p>");

            m_graph   = m_heapDumpFile.m_gcDump.MemoryGraph;
            m_interop = m_heapDumpFile.m_gcDump.InteropInfo;

            if ((m_interop != null) && m_interop.InteropInfoExists())
            {
                writer.WriteLine("Interop data stream<p>");
                writer.WriteLine("<ul>");
                writer.WriteLine("<li>Heap dump file: {0}, {1:N0} nodes</li>", m_heapDumpFile.FilePath, (int)m_graph.NodeIndexLimit);
                writer.WriteLine("<li>CCW   : {0}</li>", m_interop.currentCCWCount);
                writer.WriteLine("<li>RCW   : {0}</li>", m_interop.currentRCWCount);
                writer.WriteLine("<li>Module: {0}</li>", m_interop.currentModuleCount);
                writer.WriteLine("</ul>");

                m_mainOutput = fileName;
                GenerateReports();
            }
            else
            {
                writer.WriteLine("<li>No Interop stream</li>");
            }
        }
Esempio n. 12
0
        public void TestAddingDuplicateEdge()
        {
            var graph = new MemoryGraph<LiveEdge>();

            var vertex1 = graph.AddVertex(51, 1);
            var vertex2 = graph.AddVertex(51, 2);

            graph.AddEdge(vertex1, vertex2, new LiveEdge()
            {
                Forward = true,
                Tags = 1
            }, null);

            // should overwrite.
            graph.AddEdge(vertex1, vertex2, new LiveEdge()
            {
                Forward = true,
                Tags = 2
            }, null);

            var edges = graph.GetEdges(vertex1, vertex2).ToKeyValuePairs();
            Assert.AreEqual(1, edges.Length);
            Assert.AreEqual(2, edges[0].Value.Tags);

            // should overwrite again.
            graph.AddEdge(vertex1, vertex2, new LiveEdge()
            {
                Forward = true,
                Tags = 1
            }, null);

            edges = graph.GetEdges(vertex1, vertex2).ToKeyValuePairs();
            Assert.AreEqual(1, edges.Length);
            Assert.AreEqual(1, edges[0].Value.Tags);
        }
Esempio n. 13
0
        public void TestLiveEdgeDynamicGraphAddReverse()
        {
            var graph = new MemoryGraph <LiveEdge>();

            var vertex1 = graph.AddVertex(51, 1);
            var vertex2 = graph.AddVertex(51, 2);

            graph.AddEdge(vertex1, vertex2, new LiveEdge()
            {
                Forward = true,
                Tags    = 1
            }, null);

            graph.AddEdge(vertex2, vertex1, new LiveEdge()
            {
                Forward = true,
                Tags    = 2
            }, null);

            LiveEdge edge;

            Assert.IsTrue(graph.GetEdge(vertex1, vertex2, out edge));
            Assert.AreEqual(2, edge.Tags);
            Assert.IsTrue(graph.GetEdge(vertex2, vertex1, out edge));
            Assert.AreEqual(2, edge.Tags);
        }
Esempio n. 14
0
    /// <summary>
    /// Writes the memory graph 'graph' as a .gcump file to 'outputFileName'
    /// 'toolName' is the name of the tool generating the data.  It is persisted in the GCDump file
    /// and can be used by the viewer to customize the view.
    ///
    /// TODO can't set the rest of the meta-data associated with the graph this way.
    /// </summary>
    public static void WriteMemoryGraph(MemoryGraph graph, string outputFileName, string toolName = null)
    {
        var dumper = new GCHeapDump(graph);

        dumper.CreationTool = toolName;
        dumper.Write(outputFileName);
    }
Esempio n. 15
0
    public static MemoryGraph ReadMemoryGraphFromXml(XmlReader reader)
    {
        if (reader.NodeType != XmlNodeType.Element)
        {
            throw new InvalidOperationException("Must advance to MemoryGraph element (e.g. call ReadToDescendant)");
        }

        var expectedSize = 1000;
        var nodeCount    = reader.GetAttribute("NodeCount");

        if (nodeCount != null)
        {
            expectedSize = int.Parse(nodeCount) + 1;        // 1 for undefined
        }

        MemoryGraph graph = new MemoryGraph(10);

        Debug.Assert((int)graph.NodeTypeIndexLimit == 1);
        var firstNode = graph.CreateNode();                             // Use one up

        Debug.Assert(firstNode == 0);
        Debug.Assert((int)graph.NodeIndexLimit == 1);

        var inputDepth = reader.Depth;

        reader.Read();      // Advance to children
        while (inputDepth < reader.Depth)
        {
            if (reader.NodeType == XmlNodeType.Element)
            {
                switch (reader.Name)
                {
                case "NodeTypes":
                    ReadNodeTypesFromXml(reader, graph);
                    break;

                case "Nodes":
                    ReadNodesFromXml(reader, graph);
                    break;

                case "RootIndex":
                    graph.RootIndex = (NodeIndex)reader.ReadElementContentAsInt();
                    break;

                default:
                    Debug.WriteLine("Skipping unknown element {0}", reader.Name);
                    reader.Skip();
                    break;
                }
            }
            else if (!reader.Read())
            {
                break;
            }
        }

        graph.AllowReading();
        return(graph);
    }
Esempio n. 16
0
    /// <summary>
    /// Read in the memory dump from javaScriptEtlName.   Since there can be more than one, choose the first one
    /// after double startTimeRelativeMSec.  If processId is non-zero only that process is considered, otherwise it considered
    /// the first heap dump regardless of process.
    /// </summary>
    public MemoryGraph Read(string javaScriptEtlName, int processId = 0, double startTimeRelativeMSec = 0)
    {
        var ret = new MemoryGraph(10000);

        Append(ret, javaScriptEtlName, processId, startTimeRelativeMSec);
        ret.AllowReading();
        return(ret);
    }
    public MemoryGraph Read(TraceEventDispatcher source, string processNameOrId = null, double startTimeRelativeMSec = 0)
    {
        var ret = new MemoryGraph(10000);

        Append(ret, source, processNameOrId, startTimeRelativeMSec);
        ret.AllowReading();
        return(ret);
    }
    /// <summary>
    /// Read in the memory dump from javaScriptEtlName.   Since there can be more than one, choose the first one
    /// after double startTimeRelativeMSec.  If processId is non-zero only that process is considered, otherwise it considered
    /// the first heap dump regardless of process.
    /// </summary>
    public MemoryGraph Read(string etlFilePath, string processNameOrId = null, double startTimeRelativeMSec = 0)
    {
        m_etlFilePath = etlFilePath;
        var ret = new MemoryGraph(10000);

        Append(ret, etlFilePath, processNameOrId, startTimeRelativeMSec);
        ret.AllowReading();
        return(ret);
    }
Esempio n. 19
0
        public void TestLiveEdgeDynamicGraphEdge1()
        {
            uint tagsId  = 10;
            var  graph   = new MemoryGraph <LiveEdge>();
            var  vertex1 = graph.AddVertex(51, 1);
            var  vertex2 = graph.AddVertex(51, 2);

            graph.AddEdge(vertex1, vertex2, new LiveEdge()
            {
                Forward = true,
                Tags    = tagsId
            }, null);

            // test forward edge.
            var arcs = graph.GetEdges(vertex1).ToKeyValuePairs();

            Assert.AreEqual(1, arcs.Length);
            Assert.AreEqual(tagsId, arcs[0].Value.Tags);
            Assert.AreEqual(vertex2, arcs[0].Key);
            Assert.AreEqual(true, arcs[0].Value.Forward);

            // test backward edge: backward edge is added automatically.
            arcs = graph.GetEdges(vertex2).ToKeyValuePairs();
            Assert.AreEqual(1, arcs.Length);
            Assert.AreEqual(tagsId, arcs[0].Value.Tags);
            Assert.AreEqual(vertex1, arcs[0].Key);
            Assert.AreEqual(false, arcs[0].Value.Forward);

            // add a third vertex.
            var vertex3 = graph.AddVertex(51, 2);
            var edge    = new LiveEdge()
            {
                Forward = true,
                Tags    = tagsId
            };

            graph.AddEdge(vertex1, vertex3, edge, null);

            // test forward edges.
            arcs = graph.GetEdges(vertex1).ToKeyValuePairs();
            Assert.AreEqual(2, arcs.Length);
            Assert.AreEqual(tagsId, arcs[0].Value.Tags);
            Assert.AreEqual(vertex2, arcs[0].Key);
            Assert.AreEqual(true, arcs[0].Value.Forward);
            Assert.AreEqual(tagsId, arcs[1].Value.Tags);
            Assert.AreEqual(vertex3, arcs[1].Key);
            Assert.AreEqual(true, arcs[1].Value.Forward);

            // test backward edge: backward edge is added automatically.
            arcs = graph.GetEdges(vertex3).ToKeyValuePairs();
            Assert.AreEqual(1, arcs.Length);
            Assert.AreEqual(tagsId, arcs[0].Value.Tags);
            Assert.AreEqual(vertex1, arcs[0].Key);
            Assert.AreEqual(false, arcs[0].Value.Forward);
        }
 public ScatterPlot()
 {
     InitializeComponent();
     m_Graph          = new MemoryGraph(ClientSize.Width, ClientSize.Height);
     m_Back           = new SolidBrush(Color.FromArgb(45, 45, 48));
     m_DataBrush      = new SolidBrush(Color.FromArgb(128, 128, 128));
     m_Font           = new Font("Lucida Console", 10, FontStyle.Regular);
     m_Pairs          = new ScatterPoints();
     this.RefreshRate = 20;
     m_RefreshSpeed   = 50;
 }
Esempio n. 21
0
 public LineGraph()
 {
     InitializeComponent();
     m_Graph     = new MemoryGraph(ClientSize.Width, ClientSize.Height);
     m_Back      = new SolidBrush(Color.FromArgb(45, 45, 48));
     m_DataBrush = new SolidBrush(Color.FromArgb(128, 128, 128));
     m_Line      = new Pen(Color.FromArgb(128, 153, 217, 234));
     m_Box       = new SolidBrush(Color.FromArgb(32, 153, 217, 234));
     m_DataPen   = new Pen(Color.FromArgb(192, 192, 192));
     m_Font      = new Font("Lucida Console", 10, FontStyle.Regular);
     m_SmallFont = new Font("Lucida Console", 8, FontStyle.Regular);
 }
Esempio n. 22
0
    /// <summary>
    /// Reads the NodeTypes element
    /// </summary>
    private static void ReadNodeTypesFromXml(XmlReader reader, MemoryGraph graph)
    {
        Debug.Assert(reader.NodeType == XmlNodeType.Element);
        var inputDepth = reader.Depth;

        reader.Read();      // Advance to children
        while (inputDepth < reader.Depth)
        {
            if (reader.NodeType == XmlNodeType.Element)
            {
                switch (reader.Name)
                {
                case "NodeType":
                {
                    NodeTypeIndex readTypeIndex = (NodeTypeIndex)FetchInt(reader, "Index", -1);
                    int           size          = FetchInt(reader, "Size");
                    string        typeName      = reader.GetAttribute("Name");
                    string        moduleName    = reader.GetAttribute("Module");

                    if (typeName == null)
                    {
                        throw new ApplicationException("NodeType element does not have a Name attribute");
                    }

                    if (readTypeIndex == NodeTypeIndex.Invalid)
                    {
                        throw new ApplicationException("NodeType element does not have a Index attribute.");
                    }

                    if (readTypeIndex != 0 || typeName != "UNDEFINED")
                    {
                        NodeTypeIndex typeIndex = graph.CreateType(typeName, moduleName, size);
                        if (readTypeIndex != typeIndex)
                        {
                            throw new ApplicationException("NodeType Indexes do not start at 1 and increase consecutively.");
                        }
                    }
                    reader.Skip();
                }
                break;

                default:
                    Debug.WriteLine("Skipping unknown element {0}", reader.Name);
                    reader.Skip();
                    break;
                }
            }
            else if (!reader.Read())
            {
                break;
            }
        }
    }
Esempio n. 23
0
    void Awake()
    {
        if (Instance == null)
            Instance = this;
        else
        {
            Destroy(this);
            throw new UnityException("Location Manager has already been declared! It cannot exist twice!");
        }

        SharedEventGraph = new MemoryGraph();
    }
Esempio n. 24
0
        public void TestLiveEdgeDynamicGraphAddRemove2()
        {
            uint tagsId  = 10;
            var  graph   = new MemoryGraph <LiveEdge>();
            var  vertex1 = graph.AddVertex(51, 1);
            var  vertex2 = graph.AddVertex(51, 2);
            var  vertex3 = graph.AddVertex(51, 3);

            graph.AddEdge(vertex1, vertex2, new LiveEdge()
            {
                Forward = true,
                Tags    = tagsId
            }, null);

            graph.AddEdge(vertex2, vertex3, new LiveEdge()
            {
                Forward = true,
                Tags    = tagsId
            }, null);

            // test edges.
            var edges = graph.GetEdges(vertex1).ToKeyValuePairs();

            Assert.AreEqual(1, edges.Length);
            Assert.AreEqual(tagsId, edges[0].Value.Tags);
            Assert.AreEqual(vertex2, edges[0].Key);
            Assert.AreEqual(true, edges[0].Value.Forward);
            edges = graph.GetEdges(vertex2).ToKeyValuePairs();
            Assert.AreEqual(2, edges.Length);
            edges = graph.GetEdges(vertex3).ToKeyValuePairs();
            Assert.AreEqual(1, edges.Length);
            Assert.AreEqual(tagsId, edges[0].Value.Tags);
            Assert.AreEqual(vertex2, edges[0].Key);
            Assert.AreEqual(false, edges[0].Value.Forward);

            // remove edge again.
            graph.RemoveEdge(vertex1, vertex2);

            // test edges.
            edges = graph.GetEdges(vertex1).ToKeyValuePairs();
            Assert.AreEqual(0, edges.Length);
            edges = graph.GetEdges(vertex2).ToKeyValuePairs();
            Assert.AreEqual(1, edges.Length);
            Assert.AreEqual(tagsId, edges[0].Value.Tags);
            Assert.AreEqual(vertex3, edges[0].Key);
            Assert.AreEqual(true, edges[0].Value.Forward);
            edges = graph.GetEdges(vertex3).ToKeyValuePairs();
            Assert.AreEqual(1, edges.Length);
            Assert.AreEqual(tagsId, edges[0].Value.Tags);
            Assert.AreEqual(vertex2, edges[0].Key);
            Assert.AreEqual(false, edges[0].Value.Forward);
        }
Esempio n. 25
0
        public IStoreGraph CreateGraph(string id, GraphType type)
        {
            string key = MakeKey(id, type);

            lock (_lockObject) {
                if (!_store.ContainsKey(key))
                {
                    _store[key] = new MemoryGraph();
                    return(_store[key]);
                }
                throw new InvalidOperationException($"Graph exists {id} {type}");
            }
        }
Esempio n. 26
0
 public void Init(MemoryGraph graph, TextWriter writer, TextWriter log)
 {
     m_graph   = graph;
     m_sccInfo = new SCCInfo[(int)graph.NodeIndexLimit];
     for (int i = 0; i < m_sccInfo.Length; i++)
     {
         m_sccInfo[i] = new SCCInfo();
     }
     index     = 1;
     m_stack   = new Stack <int>();
     m_htmlRaw = writer;
     m_log     = log;
 }
Esempio n. 27
0
 public DiagnosticsEventPipeProcessor(
     PipeMode mode,
     ILoggerFactory loggerFactory = null,
     IEnumerable <IMetricsLogger> metricLoggers = null,
     int metricIntervalSeconds = 10,
     MemoryGraph gcGraph       = null)
 {
     _metricLoggers         = metricLoggers ?? Enumerable.Empty <IMetricsLogger>();
     _mode                  = mode;
     _loggerFactory         = loggerFactory;
     _gcGraph               = gcGraph;
     _metricIntervalSeconds = metricIntervalSeconds;
 }
Esempio n. 28
0
        public void TestLiveEdgeDynamicGraphAddRemove2()
        {
            uint tagsId = 10;
            var graph = new MemoryGraph<LiveEdge>();
            var vertex1 = graph.AddVertex(51, 1);
            var vertex2 = graph.AddVertex(51, 2);
            var vertex3 = graph.AddVertex(51, 3);

            graph.AddEdge(vertex1, vertex2, new LiveEdge()
            {
                Forward = true,
                Tags = tagsId
            }, null);

            graph.AddEdge(vertex2, vertex3, new LiveEdge()
            {
                Forward = true,
                Tags = tagsId
            }, null);

            // test edges.
            var edges = graph.GetEdges(vertex1).ToKeyValuePairs();
            Assert.AreEqual(1, edges.Length);
            Assert.AreEqual(tagsId, edges[0].Value.Tags);
            Assert.AreEqual(vertex2, edges[0].Key);
            Assert.AreEqual(true, edges[0].Value.Forward);
            edges = graph.GetEdges(vertex2).ToKeyValuePairs();
            Assert.AreEqual(2, edges.Length);
            edges = graph.GetEdges(vertex3).ToKeyValuePairs();
            Assert.AreEqual(1, edges.Length);
            Assert.AreEqual(tagsId, edges[0].Value.Tags);
            Assert.AreEqual(vertex2, edges[0].Key);
            Assert.AreEqual(false, edges[0].Value.Forward);

            // remove edge again.
            graph.RemoveEdge(vertex1, vertex2);

            // test edges.
            edges = graph.GetEdges(vertex1).ToKeyValuePairs();
            Assert.AreEqual(0, edges.Length);
            edges = graph.GetEdges(vertex2).ToKeyValuePairs();
            Assert.AreEqual(1, edges.Length);
            Assert.AreEqual(tagsId, edges[0].Value.Tags);
            Assert.AreEqual(vertex3, edges[0].Key);
            Assert.AreEqual(true, edges[0].Value.Forward);
            edges = graph.GetEdges(vertex3).ToKeyValuePairs();
            Assert.AreEqual(1, edges.Length);
            Assert.AreEqual(tagsId, edges[0].Value.Tags);
            Assert.AreEqual(vertex2, edges[0].Key);
            Assert.AreEqual(false, edges[0].Value.Forward);
        }
Esempio n. 29
0
            public ObjectViewerTreeViewController(MemoryGraph graph, RefGraph refGraph, List <NodeIndex> focusNodes)
            {
                m_graph      = graph;
                m_refGraph   = refGraph;
                m_focusNodes = focusNodes;

                m_typeStorage    = m_graph.AllocTypeNodeStorage();
                m_nodeStorage    = m_graph.AllocNodeStorage();
                m_refNodeStorage = m_refGraph.AllocNodeStorage();
                m_columnNames    = new List <string>()
                {
                    "Value", "Size", "Type"
                };
            }
Esempio n. 30
0
    public static MemoryGraph Create(string dllPath, SymbolReader symbolReader)
    {
        var ret = new MemoryGraph(1000);

        string pdbPath = symbolReader.FindSymbolFilePathForModule(dllPath);

        symbolReader.Log.WriteLine("Got PDB path {0}", pdbPath);

        NativeSymbolModule module  = symbolReader.OpenNativeSymbolFile(pdbPath);
        List <Symbol>      symbols = new List <Symbol>();

        AddAllChildren(symbols, module.GlobalSymbol);

        symbols.Sort();

        /****** Make a graph out of the symbols ******/
        // Put all nodes under this root.
        var rootChildren = new GrowableArray <NodeIndex>(1000);

        // Create a node for each symbol
        uint   lastRVA  = 0;
        string lastName = "Header";
        var    empty    = new GrowableArray <NodeIndex>();

        foreach (var symbol in symbols)
        {
            var symRVA   = symbol.RVA;
            int lastSize = (int)symRVA - (int)lastRVA;

            NodeTypeIndex typeIdx = ret.CreateType(lastName, null, lastSize);
            NodeIndex     nodeIdx = ret.CreateNode();
            ret.SetNode(nodeIdx, typeIdx, lastSize, empty);
            rootChildren.Add(nodeIdx);

            lastName = symbol.Name;
            lastRVA  = symRVA;
        }
        // TODO FIX NOW dropping the last symbol.

        // Create the root node.
        NodeIndex     rootIdx     = ret.CreateNode();
        NodeTypeIndex rootTypeIdx = ret.CreateType("METHODS");

        ret.SetNode(rootIdx, rootTypeIdx, 0, rootChildren);
        ret.RootIndex = rootIdx;

        ret.AllowReading();

        return(ret);
    }
Esempio n. 31
0
        public void TestSparseRemoval2()
        {
            // use one edge definition everywhere.
            var edge = new LiveEdge();

            edge.Forward = true;
            edge.Tags    = 1;

            var  graph   = new MemoryGraph <LiveEdge>();
            uint vertex1 = graph.AddVertex(0, 0);
            uint vertex2 = graph.AddVertex(1, 1);
            uint vertex3 = graph.AddVertex(2, 2);
            uint vertex4 = graph.AddVertex(3, 3);
            uint vertex5 = graph.AddVertex(4, 4);
            uint vertex6 = graph.AddVertex(5, 5);

            graph.AddEdge(vertex1, vertex2, edge, null); // 1 <-> 2
            graph.AddEdge(vertex2, vertex1, edge, null); // 1 <-> 2
            graph.AddEdge(vertex2, vertex3, edge, null); // 2 <-> 3
            graph.AddEdge(vertex3, vertex2, edge, null); // 2 <-> 3
            graph.AddEdge(vertex3, vertex4, edge, null); // 3 <-> 4
            graph.AddEdge(vertex4, vertex3, edge, null); // 3 <-> 4
            graph.AddEdge(vertex4, vertex5, edge, null); // 4 <-> 5
            graph.AddEdge(vertex5, vertex4, edge, null); // 4 <-> 5
            graph.AddEdge(vertex3, vertex6, edge, null); // 3 <-> 6
            graph.AddEdge(vertex6, vertex3, edge, null); // 3 <-> 6

            // execute pre-processor.
            var preProcessor = new LiveEdgePreprocessor(graph);

            preProcessor.Start();

            // test resulting graph.
            Assert.AreEqual(4, graph.VertexCount);

            Assert.AreEqual(1, graph.GetEdges(1).ToKeyValuePairs().Length);
            Assert.AreEqual(2, graph.GetEdges(1).ToKeyValuePairs()[0].Key);

            Assert.AreEqual(3, graph.GetEdges(2).ToKeyValuePairs().Length);
            Assert.IsTrue(graph.GetEdges(2).ToKeyValuePairs().Any(x => x.Key == 1));
            Assert.IsTrue(graph.GetEdges(2).ToKeyValuePairs().Any(x => x.Key == 3));
            Assert.IsTrue(graph.GetEdges(2).ToKeyValuePairs().Any(x => x.Key == 4));

            Assert.AreEqual(1, graph.GetEdges(3).ToKeyValuePairs().Length);
            Assert.AreEqual(2, graph.GetEdges(3).ToKeyValuePairs()[0].Key);

            Assert.AreEqual(1, graph.GetEdges(4).ToKeyValuePairs().Length);
            Assert.AreEqual(2, graph.GetEdges(4).ToKeyValuePairs()[0].Key);
        }
Esempio n. 32
0
        internal static void WriteToStdOut(this MemoryGraph memoryGraph)
        {
            // Print summary
            WriteSummaryRow(memoryGraph.TotalSize, "GC Heap bytes");
            WriteSummaryRow(memoryGraph.NodeCount, "GC Heap objects");

            if (memoryGraph.TotalNumberOfReferences > 0)
            {
                WriteSummaryRow(memoryGraph.TotalNumberOfReferences, "Total references");
            }

            Console.WriteLine();

            // Print Details
            Console.Out.Write($"{"Object Bytes",15:N0}");
            Console.Out.Write($"  {"Count",8:N0}");
            Console.Out.Write("  Type");
            Console.WriteLine();

            var filteredTypes = GetReportItem(memoryGraph)
                                .OrderByDescending(t => t.SizeBytes)
                                .ThenByDescending(t => t.Count);

            foreach (var filteredType in filteredTypes)
            {
                WriteFixedWidth(filteredType.SizeBytes);
                Console.Out.Write("  ");
                if (filteredType.Count.HasValue)
                {
                    Console.Out.Write($"{filteredType.Count.Value,8:N0}");
                    Console.Out.Write("  ");
                }
                else
                {
                    Console.Out.Write($"{"",8}  ");
                }

                Console.Out.Write(filteredType.TypeName ?? "<UNKNOWN>");
                var dllName = GetDllName(filteredType.ModuleName ?? "");
                if (!dllName.IsEmpty)
                {
                    Console.Out.Write("  ");
                    Console.Out.Write('[');
                    Console.Out.Write(GetDllName(filteredType.ModuleName ?? ""));
                    Console.Out.Write(']');
                }

                Console.Out.WriteLine();
            }
Esempio n. 33
0
 public DiagnosticsEventPipeProcessor(
     ContextConfiguration contextConfig,
     PipeMode mode,
     ILoggerFactory loggerFactory = null,
     IEnumerable <IMetricsLogger> metricLoggers = null,
     MemoryGraph gcGraph = null)
 {
     _dimValues = new List <string> {
         contextConfig.Namespace, contextConfig.Node
     };
     _metricLoggers = metricLoggers ?? Enumerable.Empty <IMetricsLogger>();
     _mode          = mode;
     _loggerFactory = loggerFactory;
     _gcGraph       = gcGraph;
 }
Esempio n. 34
0
 public BarGraph()
 {
     InitializeComponent();
     m_Graph             = new MemoryGraph(ClientSize.Width, ClientSize.Height);
     m_Back              = new SolidBrush(Color.FromArgb(45, 45, 48));
     m_DataBrush         = new SolidBrush(Color.FromArgb(128, 128, 128));
     m_Line              = new Pen(Color.FromArgb(128, 153, 217, 234));
     m_Box               = new SolidBrush(Color.FromArgb(32, 153, 217, 234));
     m_DataPen           = new Pen(Color.FromArgb(192, 192, 192));
     m_Font              = new Font("Lucida Console", 10, FontStyle.Regular);
     m_SmallFont         = new Font("Lucida Console", 8, FontStyle.Regular);
     m_Pairs             = new List <Tuple <string, double> >();
     this.RefreshRate    = 20;
     m_RefreshSpeed      = 50;
     this.AnimationStyle = AnimationStyles.Decelerate;
 }
Esempio n. 35
0
        internal static bool TryCollectMemoryGraph(CancellationToken ct, int processId, int timeout, bool verbose,
                                                   out MemoryGraph memoryGraph)
        {
            var heapInfo = new DotNetHeapInfo();
            var log      = verbose ? Console.Out : TextWriter.Null;

            memoryGraph = new MemoryGraph(50_000);

            if (!EventPipeDotNetHeapDumper.DumpFromEventPipe(ct, processId, memoryGraph, log, timeout, heapInfo))
            {
                return(false);
            }

            memoryGraph.AllowReading();
            return(true);
        }
        public void TestSparseRemoval1Routing()
        {
            // use one edge definition everywhere.
            var tagsIndex = new TagsTableCollectionIndex();
            var tags = new TagsCollection(new Tag("highway","residential"));
            var edge = new LiveEdge();
            edge.Forward = true;
            edge.Tags = tagsIndex.Add(tags);

            var graph = new MemoryGraph<LiveEdge>();
            uint vertex1 = graph.AddVertex(51.267797f, 4.8013623f);
            uint vertex2 = graph.AddVertex(51.267702f, 4.8013396f);
            uint vertex3 = graph.AddVertex(51.267592f, 4.8013024f);

            graph.AddEdge(vertex1, vertex2, edge, null);
            graph.AddEdge(vertex2, vertex3, edge, null);
            graph.AddEdge(vertex3, vertex2, edge, null);

            // save vertex coordinates for later use.
            float latitude, longitude;
            graph.GetVertex(vertex1, out latitude, out longitude);
            var vertex1Coordinate = new GeoCoordinate(latitude, longitude);
            graph.GetVertex(vertex2, out latitude, out longitude);
            var vertex2Coordinate = new GeoCoordinate(latitude, longitude);
            graph.GetVertex(vertex3, out latitude, out longitude);
            var vertex3Coordinate = new GeoCoordinate(latitude, longitude);

            // execute pre-processor.
            var preProcessor = new LiveEdgePreprocessor(graph);
            preProcessor.Start();

            // create router.
            var source = new DynamicGraphRouterDataSource<LiveEdge>(
                graph, tagsIndex);
            var router = Router.CreateLiveFrom(source, new OsmRoutingInterpreter());

            // test some basic routing requests.
            // 1 -> 3: 1 -> 2 -> 3.
            var resolved1 = router.Resolve(Vehicle.Car, vertex1Coordinate);
            var resolved3 = router.Resolve(Vehicle.Car, vertex3Coordinate);
            var route = router.Calculate(Vehicle.Car, resolved1, resolved3);

            // verify the simple route result.
            Assert.IsNotNull(route);
            Assert.AreEqual(3, route.Segments.Length);
            Assert.AreEqual(vertex1Coordinate.Latitude, route.Segments[0].Latitude);
            Assert.AreEqual(vertex1Coordinate.Longitude, route.Segments[0].Longitude);
            Assert.AreEqual(vertex2Coordinate.Latitude, route.Segments[1].Latitude);
            Assert.AreEqual(vertex2Coordinate.Longitude, route.Segments[1].Longitude);
            Assert.AreEqual(vertex3Coordinate.Latitude, route.Segments[2].Latitude);
            Assert.AreEqual(vertex3Coordinate.Longitude, route.Segments[2].Longitude);

            // 1 -> 2: 1 -> 2.
            router = Router.CreateLiveFrom(source, new OsmRoutingInterpreter());
            resolved1 = router.Resolve(Vehicle.Car, vertex1Coordinate);
            var resolved2 = router.Resolve(Vehicle.Car, vertex2Coordinate);
            route = router.Calculate(Vehicle.Car, resolved1, resolved2);

            // verify the simple route result.
            Assert.IsNotNull(route);
            Assert.AreEqual(2, route.Segments.Length);
            Assert.AreEqual(vertex1Coordinate.Latitude, route.Segments[0].Latitude);
            Assert.AreEqual(vertex1Coordinate.Longitude, route.Segments[0].Longitude);
            Assert.AreEqual(vertex2Coordinate.Latitude, route.Segments[1].Latitude);
            Assert.AreEqual(vertex2Coordinate.Longitude, route.Segments[1].Longitude);
        }
Esempio n. 37
0
 public override void UpdateMemory(MemoryGraph memoryGraph, MemoryGraphNode retainedMemory, MemoryCue memCue, float UpdateFrequency)
 {
     LocationCue locInfo = (LocationCue)memCue; 
     
     base.UpdateMemory(memoryGraph, retainedMemory, memCue, UpdateFrequency);        
 }
Esempio n. 38
0
        public void TestLiveEdgeDynamicGraphRemoveMiddle()
        {
            var graph = new MemoryGraph<LiveEdge>();

            var vertex1 = graph.AddVertex(51, 1);
            var vertex2 = graph.AddVertex(51, 2);
            var vertex3 = graph.AddVertex(51, 3);
            var vertex4 = graph.AddVertex(51, 3);

            graph.AddEdge(vertex1, vertex2, new LiveEdge()
            {
                Forward = true,
                Tags = 1
            }, null);
            graph.AddEdge(vertex2, vertex3, new LiveEdge()
            {
                Forward = true,
                Tags = 2
            }, null);
            graph.AddEdge(vertex3, vertex4, new LiveEdge()
            {
                Forward = true,
                Tags = 3
            }, null);

            graph.AddEdge(vertex4, vertex2, new LiveEdge()
            {
                Forward = true,
                Tags = 4
            }, null);

            graph.RemoveEdge(vertex2, vertex3);
            Assert.IsFalse(graph.ContainsEdge(vertex2, vertex3));
            Assert.IsFalse(graph.ContainsEdge(vertex3, vertex2));

            Assert.AreEqual(graph.GetEdges(vertex1).ToKeyValuePairs().Length, 1);
            Assert.AreEqual(graph.GetEdges(vertex2).ToKeyValuePairs().Length, 2);
            Assert.AreEqual(graph.GetEdges(vertex3).ToKeyValuePairs().Length, 1);
            Assert.AreEqual(graph.GetEdges(vertex4).ToKeyValuePairs().Length, 2);
        }
Esempio n. 39
0
        public void TestLiveEdgeDynamicGraphRemoveAllOneVertex()
        {
            var graph = new MemoryGraph<LiveEdge>();

            var vertex1 = graph.AddVertex(51, 1);
            var vertex2 = graph.AddVertex(51, 2);
            var vertex3 = graph.AddVertex(51, 3);
            var vertex4 = graph.AddVertex(51, 3);

            graph.AddEdge(vertex1, vertex2, new LiveEdge()
            {
                Forward = true,
                Tags = 1
            });
            graph.AddEdge(vertex2, vertex3, new LiveEdge()
            {
                Forward = true,
                Tags = 2
            });
            graph.AddEdge(vertex3, vertex4, new LiveEdge()
            {
                Forward = true,
                Tags = 3
            });

            graph.AddEdge(vertex4, vertex2, new LiveEdge()
            {
                Forward = true,
                Tags = 4
            });

            graph.RemoveEdges(vertex2);
            Assert.IsFalse(graph.ContainsEdge(vertex2, vertex1));
            Assert.IsFalse(graph.ContainsEdge(vertex2, vertex3));
            Assert.IsFalse(graph.ContainsEdge(vertex4, vertex2));
            Assert.IsTrue(graph.ContainsEdge(vertex3, vertex4));
        }
Esempio n. 40
0
        public void TestLiveEdgeDynamicGraphEdge1()
        {
            uint tagsId = 10;
            var graph = new MemoryGraph<LiveEdge>();
            var vertex1 = graph.AddVertex(51, 1);
            var vertex2 = graph.AddVertex(51, 2);

            graph.AddEdge(vertex1, vertex2, new LiveEdge()
            {
                Forward = true,
                Tags = tagsId
            }, null);

            // test forward edge.
            var arcs = graph.GetEdges(vertex1).ToKeyValuePairs();
            Assert.AreEqual(1, arcs.Length);
            Assert.AreEqual(tagsId, arcs[0].Value.Tags);
            Assert.AreEqual(vertex2, arcs[0].Key);
            Assert.AreEqual(true, arcs[0].Value.Forward);

            // test backward edge: backward edge is added automatically.
            arcs = graph.GetEdges(vertex2).ToKeyValuePairs();
            Assert.AreEqual(1, arcs.Length);
            Assert.AreEqual(tagsId, arcs[0].Value.Tags);
            Assert.AreEqual(vertex1, arcs[0].Key);
            Assert.AreEqual(false, arcs[0].Value.Forward);

            // add a third vertex.
            var vertex3 = graph.AddVertex(51, 2);
            var edge = new LiveEdge()
            {
                Forward = true,
                Tags = tagsId
            };
            graph.AddEdge(vertex1, vertex3, edge, null);

            // test forward edges.
            arcs = graph.GetEdges(vertex1).ToKeyValuePairs();
            Assert.AreEqual(2, arcs.Length);
            Assert.AreEqual(tagsId, arcs[0].Value.Tags);
            Assert.AreEqual(vertex2, arcs[0].Key);
            Assert.AreEqual(true, arcs[0].Value.Forward);
            Assert.AreEqual(tagsId, arcs[1].Value.Tags);
            Assert.AreEqual(vertex3, arcs[1].Key);
            Assert.AreEqual(true, arcs[1].Value.Forward);

            // test backward edge: backward edge is added automatically.
            arcs = graph.GetEdges(vertex3).ToKeyValuePairs();
            Assert.AreEqual(1, arcs.Length);
            Assert.AreEqual(tagsId, arcs[0].Value.Tags);
            Assert.AreEqual(vertex1, arcs[0].Key);
            Assert.AreEqual(false, arcs[0].Value.Forward);
        }
Esempio n. 41
0
    public override void UpdateMemory(MemoryGraph memoryGraph, MemoryGraphNode retainedMemory, MemoryCue memCue, float UpdateFrequency)
    {
        if (IsMonster)
            return;         //Current, we've no need to update monsters.

        CharacterCue charInfo = (CharacterCue)memCue;
        base.UpdateMemory(memoryGraph, retainedMemory, memCue, UpdateFrequency);        
    }
Esempio n. 42
0
        public void TestLiveEdgeDynamicGraphCompressVertices()
        {
            var graph = new MemoryGraph<LiveEdge>();

            var vertex1 = graph.AddVertex(51, 1);
            var vertex2 = graph.AddVertex(51, 2);
            var vertex3 = graph.AddVertex(51, 3);
            var vertex4 = graph.AddVertex(51, 3);

            graph.AddEdge(vertex1, vertex2, new LiveEdge()
            {
                Forward = true,
                Tags = 1
            }, null);
            graph.AddEdge(vertex2, vertex3, new LiveEdge()
            {
                Forward = true,
                Tags = 2
            }, null);
            graph.AddEdge(vertex3, vertex4, new LiveEdge()
            {
                Forward = true,
                Tags = 3
            }, null);

            graph.AddEdge(vertex4, vertex2, new LiveEdge()
            {
                Forward = true,
                Tags = 4
            }, null);

            // make vertex4 obsolete.
            graph.RemoveEdges(vertex4);

            graph.Compress();

            Assert.AreEqual(3, graph.VertexCount);

            Assert.AreEqual(graph.GetEdges(vertex1).ToKeyValuePairs().Length, 1);
            Assert.AreEqual(graph.GetEdges(vertex2).ToKeyValuePairs().Length, 2);
            Assert.AreEqual(graph.GetEdges(vertex3).ToKeyValuePairs().Length, 1);
        }
Esempio n. 43
0
        public void TestLiveEdgeDynamicGraphAddReverse()
        {
            var graph = new MemoryGraph<LiveEdge>();

            var vertex1 = graph.AddVertex(51, 1);
            var vertex2 = graph.AddVertex(51, 2);

            graph.AddEdge(vertex1, vertex2, new LiveEdge()
            {
                Forward = true,
                Tags = 1
            }, null);

            graph.AddEdge(vertex2, vertex1, new LiveEdge()
            {
                Forward = true,
                Tags = 2
            }, null);

            LiveEdge edge;
            Assert.IsTrue(graph.GetEdge(vertex1, vertex2, out edge));
            Assert.AreEqual(2, edge.Tags);
            Assert.IsTrue(graph.GetEdge(vertex2, vertex1, out edge));
            Assert.AreEqual(2, edge.Tags);
        }
Esempio n. 44
0
    public MemoryType MemoryType;   //This tells us what type of memory this is about.

    public virtual void UpdateMemory(MemoryGraph memoryGraph, MemoryGraphNode retainedMemory, MemoryCue memCue, float UpdateFrequency)
    {
        //LastLocation = memCue.CurrentLocation;

        //if(memCue.CachedTransform != null)
        //    LastPosition = memCue.CachedTransform.position;

        retainedMemory.LastLocation = memCue.CurrentLocation;

        if (memCue.CachedTransform != null)
            retainedMemory.LastPosition = memCue.CachedTransform.position;

        retainedMemory.LastUpdated = Time.time;

        //Debug.Log("Making a memory connection between " + memCue.UniqueNodeID + " and " + LastLocation.ToString() + " - " + UpdateFrequency);

        //if (UpdateFrequency <= 0.0f)    //We want to strengthen the memory between the specific item and the place it has been observed.
        //    return;

        MemoryGraphNode locNode;
        string locString = retainedMemory.LastLocation.ToString();

        if (!memoryGraph.Contains(locString))
        {
            locNode = memoryGraph.AddNamedNodeToGraph(new LocationNode(retainedMemory.LastLocation));
            memoryGraph.AddUndirectedEdge(locNode, retainedMemory);
        }

        if (UpdateFrequency <= 0.0f)    //We want to strengthen the memory between the specific item and the place it has been observed.
            return;

        if (memoryGraph.Contains(locString))
            locNode = memoryGraph.GetNamedNodeFromGraph(locString);
        else
            locNode = memoryGraph.AddNamedNodeToGraph(new LocationNode(retainedMemory.LastLocation));

        //First make a connection between the place and the item.
        int index = locNode.Neighbours.IndexOf(retainedMemory);
        if (index == -1)
        {
            //Somehow the cue relationship has been broken!?
            //Rebuild it!
            memoryGraph.AddDirectedEdge(locNode, retainedMemory, UpdateFrequency, UpdateFrequency);
        }
        else
        {
            //Strengthing the memory based on the length of time it was active in the working set.
            locNode.StrengthenMemory(index, UpdateFrequency);
            //locNode.StrengthenOpinion(index, UpdateFrequency);   //We keep opinion strength updating here because it represents how strongly the agent believes the item / character etc. is connected to this location.
            //Debug.Log(string.Format("Node: {0}, NS: {1}, ES: {2}", retainedMemory.UID, locNode.NodeStrengths[index], locNode.EdgeStrengths[index]));
            //Debug.Log(string.Format("NS: {0}, ES: {1}", locNode.NodeStrengths[index], cueNode.EdgeStrengths[index]));
        }

        //Then between the item and the place.
        index = retainedMemory.Neighbours.IndexOf(locNode);
        if (index == -1)
        {
            //Somehow the cue relationship has been broken!?
            //Rebuild it!
            memoryGraph.AddDirectedEdge(retainedMemory, locNode, UpdateFrequency, UpdateFrequency);
        }
        else
        {
            //Strengthing the memory based on the length of time it was active in the working set.
            retainedMemory.StrengthenMemory(index, UpdateFrequency);
            //retainedMemory.StrengthenOpinion(index, UpdateFrequency);   //We keep opinion strength updating here because it represents how strongly the agent believes the item / character etc. is connected to this location.
            //Debug.Log(string.Format("Node: {0}, NS: {1}, ES: {2}", locNode.UID, retainedMemory.NodeStrengths[index], retainedMemory.EdgeStrengths[index]));
            //Debug.Log(string.Format("NS: {0}, ES: {1}", locNode.NodeStrengths[index], cueNode.EdgeStrengths[index]));
        }
    }
        public void TestSparseRemoval2()
        {
            // use one edge definition everywhere.
            var edge = new LiveEdge();
            edge.Forward = true;
            edge.Tags = 1;

            var graph = new MemoryGraph<LiveEdge>();
            uint vertex1 = graph.AddVertex(0, 0);
            uint vertex2 = graph.AddVertex(1, 1);
            uint vertex3 = graph.AddVertex(2, 2);
            uint vertex4 = graph.AddVertex(3, 3);
            uint vertex5 = graph.AddVertex(4, 4);
            uint vertex6 = graph.AddVertex(5, 5);

            graph.AddEdge(vertex1, vertex2, edge, null); // 1 <-> 2
            graph.AddEdge(vertex2, vertex1, edge, null); // 1 <-> 2
            graph.AddEdge(vertex2, vertex3, edge, null); // 2 <-> 3
            graph.AddEdge(vertex3, vertex2, edge, null); // 2 <-> 3
            graph.AddEdge(vertex3, vertex4, edge, null); // 3 <-> 4
            graph.AddEdge(vertex4, vertex3, edge, null); // 3 <-> 4
            graph.AddEdge(vertex4, vertex5, edge, null); // 4 <-> 5
            graph.AddEdge(vertex5, vertex4, edge, null); // 4 <-> 5
            graph.AddEdge(vertex3, vertex6, edge, null); // 3 <-> 6
            graph.AddEdge(vertex6, vertex3, edge, null); // 3 <-> 6

            // execute pre-processor.
            var preProcessor = new LiveEdgePreprocessor(graph);
            preProcessor.Start();

            // test resulting graph.
            Assert.AreEqual(4, graph.VertexCount);

            Assert.AreEqual(1, graph.GetEdges(1).ToKeyValuePairs().Length);
            Assert.AreEqual(2, graph.GetEdges(1).ToKeyValuePairs()[0].Key);

            Assert.AreEqual(3, graph.GetEdges(2).ToKeyValuePairs().Length);
            Assert.IsTrue(graph.GetEdges(2).ToKeyValuePairs().Any(x => x.Key == 1));
            Assert.IsTrue(graph.GetEdges(2).ToKeyValuePairs().Any(x => x.Key == 3));
            Assert.IsTrue(graph.GetEdges(2).ToKeyValuePairs().Any(x => x.Key == 4));

            Assert.AreEqual(1, graph.GetEdges(3).ToKeyValuePairs().Length);
            Assert.AreEqual(2, graph.GetEdges(3).ToKeyValuePairs()[0].Key);

            Assert.AreEqual(1, graph.GetEdges(4).ToKeyValuePairs().Length);
            Assert.AreEqual(2, graph.GetEdges(4).ToKeyValuePairs()[0].Key);
        }
Esempio n. 46
0
    public override void UpdateMemory(MemoryGraph memoryGraph, MemoryGraphNode retainedMemory, MemoryCue memCue, float UpdateFrequency)
    {
        ItemCue itemInfo = (ItemCue)memCue;

        status = itemInfo.Status;
        owner = itemInfo.Owner;
        durability = itemInfo.Durability;

        if (durability < 0.0f)
        {
            //Once durability starts to fall, a agent's affinity with an item will also drop.
            memoryGraph.UpdateCueOpinion(retainedMemory.MemoryNode, -UpdateFrequency);
        }

        base.UpdateMemory(memoryGraph, retainedMemory, memCue, UpdateFrequency);

        if (UpdateFrequency <= 0.0f || itemInfo.Owner == null)    //We want to strengthen the memory between the specific item and the place it has been observed.
            return;

        MemoryGraphNode charNode;
        if (memoryGraph.Contains(itemInfo.Owner.UniqueNodeID))
            charNode = memoryGraph.GetNamedNodeFromGraph(itemInfo.Owner.UniqueNodeID);
        else
            charNode = memoryGraph.AddNamedNodeToGraph(new CharacterNode(itemInfo.Owner));

        //First make a connection between the character and the item.
        int index = charNode.Neighbours.IndexOf(retainedMemory);
        if (index == -1)
            memoryGraph.AddDirectedEdge(charNode, retainedMemory, UpdateFrequency, UpdateFrequency);
        else
        {
            //Strengthing the memory based on the length of time it was active in the working set.
            charNode.StrengthenMemory(index, UpdateFrequency);
            //charNode.OpinionStrengths[index] += UpdateFrequency;
        }

        //Then between the item and the character.
        index = retainedMemory.Neighbours.IndexOf(charNode);
        if (index == -1)
            memoryGraph.AddDirectedEdge(retainedMemory, charNode, UpdateFrequency, UpdateFrequency);
        else
        {
            //Strengthing the memory based on the length of time it was active in the working set.
            retainedMemory.StrengthenMemory(index, UpdateFrequency);
            //retainedMemory.OpinionStrengths[index] += UpdateFrequency;
        }
    }
Esempio n. 47
0
    public override void UpdateMemory(MemoryGraph memoryGraph, MemoryGraphNode retainedMemory, MemoryCue memCue, float UpdateFrequency)
    {
        EventCue eventInfo = (EventCue)memCue;

        base.UpdateMemory(memoryGraph, retainedMemory, memCue, UpdateFrequency);
    }