Example #1
0
		private ArrayList BuildLevels(Graph g)
		{
			ArrayList al = new ArrayList();
			for (int level = 0; level <= g.BottomVertex.level; level++)
			{
				al.Add(new ArrayList());
			}
			foreach (Vertex v in g.vertices.Values)
			{
				if (v.level <= g.BottomVertex.level)
				{
					ArrayList all = (ArrayList)al[v.level];
					all.Add(v);
				}
				else
				{
					Debug.Assert(v.level == int.MaxValue);
				}
			}
			foreach (ArrayList all in al)
			{
				all.Sort();
			}
			return al;
		}
Example #2
0
        internal void BuildAllocationTrace(Graph graph, int stackTraceIndex, int typeIndex, ulong size, Vertex[] typeVertex, Vertex[] funcVertex, ref Vertex[] vertexStack, FilterForm filterForm)
        {
            int stackPtr = BuildVertexStack(stackTraceIndex, funcVertex, ref vertexStack, 2);

            Vertex toVertex = graph.TopVertex;
            Vertex fromVertex;
            Edge edge;
            if ((typeVertex[typeIndex].interestLevel & InterestLevel.Interesting) == InterestLevel.Interesting
                && ReadNewLog.InterestingCallStack(vertexStack, stackPtr, filterForm))
            {
                vertexStack[stackPtr] = typeVertex[typeIndex];
                stackPtr++;
                stackPtr = ReadNewLog.FilterVertices(vertexStack, stackPtr);
                stackPtr = Vertex.SqueezeOutRepetitions(vertexStack, stackPtr);
                for (int i = 0; i < stackPtr; i++)
                {
                    fromVertex = toVertex;
                    toVertex = vertexStack[i];
                    edge = graph.FindOrCreateEdge(fromVertex, toVertex);
                    edge.AddWeight(size);
                }
                fromVertex = toVertex;
                toVertex = graph.BottomVertex;
                edge = graph.FindOrCreateEdge(fromVertex, toVertex);
                edge.AddWeight(size);
            }
        }
Example #3
0
        internal void ViewGraph(ReadLogResult logResult, string exeName, Graph.GraphType graphType)
        {
            string fileName = log.fileName;
            if (exeName != null)
                fileName = exeName;
            Graph graph = null;
            string title = "";
            switch (graphType)
            {
                case Graph.GraphType.CallGraph:
                    graph = logResult.callstackHistogram.BuildCallGraph(new FilterForm());
                    graph.graphType = Graph.GraphType.CallGraph;
                    title = "Call Graph for: ";
                    break;

                case Graph.GraphType.AssemblyGraph:
                    graph = logResult.callstackHistogram.BuildAssemblyGraph(new FilterForm());
                    graph.graphType = Graph.GraphType.AssemblyGraph;
                    title = "Assembly Graph for: ";
                    break;

                case Graph.GraphType.AllocationGraph:
                    graph = logResult.allocatedHistogram.BuildAllocationGraph(new FilterForm());
                    graph.graphType = Graph.GraphType.AllocationGraph;
                    title = "Allocation Graph for: ";
                    break;

                case Graph.GraphType.HeapGraph:
                    graph = logResult.objectGraph.BuildTypeGraph(new FilterForm());
                    title = "Heap Graph for: ";
                    break;

                case Graph.GraphType.FunctionGraph:
                    graph = logResult.functionList.BuildFunctionGraph(new FilterForm());
                    graph.graphType = Graph.GraphType.FunctionGraph;
                    title = "Function Graph for: ";
                    break;

                case Graph.GraphType.ModuleGraph:
                    graph = logResult.functionList.BuildModuleGraph(new FilterForm());
                    graph.graphType = Graph.GraphType.ModuleGraph;
                    title = "Module Graph for: ";
                    break;

                case Graph.GraphType.ClassGraph:
                    graph = logResult.functionList.BuildClassGraph(new FilterForm());
                    graph.graphType = Graph.GraphType.ClassGraph;
                    title = "Class Graph for: ";
                    break;

                default:
                    Debug.Assert(false);
                    break;
            }
            title += fileName;
            GraphViewForm graphViewForm = new GraphViewForm(graph, title);
            graphViewForm.Visible = true;
        }
Example #4
0
        internal Vertex(string name, string signature, string module, Graph containingGraph)
        {
            this.signature = signature;
            this.incomingEdges = new Dictionary<Vertex, Edge>();
            this.outgoingEdges = new Dictionary<Vertex, Edge>();
            this.level = Int32.MaxValue;
            this.weight = 0;
            this.containingGraph = containingGraph;
            this.moduleName = module;

            nameSpace = nameSpaceOf(name, out basicName);
            this.name = name;
            basicSignature = signature;
            if (nameSpace.Length > 0 && signature != null)
            {
                int index;
                while ((index = basicSignature.IndexOf(nameSpace)) >= 0)
                {
                    basicSignature = basicSignature.Remove(index, nameSpace.Length);
                }
            }
        }
Example #5
0
        internal Graph BuildAssemblyGraph(FilterForm filterForm)
        {
            Vertex[] assemblyVertex = new Vertex[1];
            Vertex[] funcVertex = new Vertex[1];
            Vertex[] typeVertex = new Vertex[1];
            Vertex[] vertexStack = new Vertex[1];

            Graph graph = new Graph(this);
            graph.graphType = Graph.GraphType.AssemblyGraph;

            int count = BuildAssemblyVertices(graph, ref assemblyVertex, filterForm);
            BuildTypeVertices(graph, ref typeVertex, filterForm);
            BuildFuncVertices(graph, ref funcVertex, filterForm);

            for(int i = 0; i < count; i++)
            {
                Vertex v = (Vertex)assemblyVertex[i], tv = null;

                string c = v.name;
                int stackid = readNewLog.assemblies[c];
                if(stackid < 0)
                {
                    int[] stacktrace = readNewLog.stacktraceTable.IndexToStacktrace(-stackid);
                    tv = typeVertex[stacktrace[0]];
                }
                BuildAssemblyTrace(graph, stackid, v, tv, funcVertex, ref vertexStack);
            }

            foreach (Vertex v in graph.vertices.Values)
            {
                v.active = true;
            }
            graph.BottomVertex.active = false;
            return graph;
        }
Example #6
0
 internal int BuildAssemblyVertices(Graph graph, ref Vertex[] typeVertex, FilterForm filterForm)
 {
     int count = 0;
     foreach(string c in readNewLog.assemblies.Keys)
     {
         readNewLog.AddTypeVertex(count++, c, graph, ref typeVertex, filterForm);
     }
     return count;
 }
Example #7
0
 internal void AddTypeVertex(int typeId, string typeName, Graph graph, ref Vertex[] typeVertex, FilterForm filterForm)
 {
     EnsureVertexCapacity(typeId, ref typeVertex);
     typeVertex[typeId] = graph.FindOrCreateVertex(typeName, null, null);
     typeVertex[typeId].interestLevel = filterForm.InterestLevelOfTypeName(typeName, null, finalizableTypes.ContainsKey(typeId));
 }
Example #8
0
        internal Graph BuildClassGraph(FilterForm filterForm)
        {
            Vertex[] funcVertex = new Vertex[1];
            Vertex[] vertexStack = new Vertex[1];

            Graph graph = new Graph(this);
            graph.graphType = Graph.GraphType.ClassGraph;

            BuildFuncVertices(graph, ref funcVertex, filterForm);

            foreach (FunctionDescriptor fd in functionList)
            {
                BuildClassTrace(graph, fd.funcCallStack, fd.functionId, fd.funcSize, funcVertex, ref vertexStack, filterForm);
            }

            foreach (Vertex v in graph.vertices.Values)
                v.active = true;
            graph.BottomVertex.active = false;

            return graph;
        }
Example #9
0
        void BuildModuleTrace(Graph graph, int stackTraceIndex, int modIndex, ulong size, Vertex[] funcVertex, Vertex[] modVertex, ref Vertex[] vertexStack, FilterForm filterForm)
        {
            int functionsToSkip = FunctionsInSameModule(modIndex, stackTraceIndex);
            int stackPtr = BuildVertexStack(stackTraceIndex, funcVertex, ref vertexStack, 0) - functionsToSkip;

            Vertex toVertex = graph.TopVertex;
            Vertex fromVertex;
            Edge edge;
            if (ReadNewLog.InterestingCallStack(vertexStack, stackPtr, filterForm))
            {
                vertexStack[stackPtr] = modVertex[modIndex];
                stackPtr++;
                stackPtr = ReadNewLog.FilterVertices(vertexStack, stackPtr);
                stackPtr = Vertex.SqueezeOutRepetitions(vertexStack, stackPtr);
                for (int i = 0; i < stackPtr; i++)
                {
                    fromVertex = toVertex;
                    toVertex = vertexStack[i];
                    edge = graph.FindOrCreateEdge(fromVertex, toVertex);
                    edge.AddWeight(size);
                }
                fromVertex = toVertex;
                toVertex = graph.BottomVertex;
                edge = graph.FindOrCreateEdge(fromVertex, toVertex);
                edge.AddWeight(size);
            }
        }
Example #10
0
 void BuildModVertices(Graph graph, ref Vertex[] modVertex, FilterForm filterForm)
 {
     for (int i = 0; i < readNewLog.modBasicName.Length; i++)
     {
         string basicName = readNewLog.modBasicName[i];
         string fullName = readNewLog.modFullName[i];
         if (basicName != null && fullName != null)
         {
             readNewLog.AddFunctionVertex(i, basicName, fullName, graph, ref modVertex, filterForm);
             modVertex[i].basicName = basicName;
             modVertex[i].basicSignature = fullName;
         }
     }
 }
Example #11
0
 private void readLogFile(ReadNewLog log, ReadLogResult logResult, string exeName, Graph.GraphType graphType)
 {
     log.ReadFile(logFileStartOffset, logFileEndOffset, logResult);
     ViewGraph(logResult, exeName, graphType);
 }
Example #12
0
        internal Graph BuildReferenceGraph(Graph orgGraph)
        {
            var graph = new Graph(this, Graph.GraphType.ReferenceGraph);

            Vertex[] pathFromRoot = new Vertex[32];

            GcObject rootObject = CreateRootObject();

            FindVertex(0, rootObject, graph, BuildTypeGraphOptions.LumpBySignature);
            rootObject.InterestLevel = InterestLevel.Interesting;

            foreach (GcObject gcObject in idToObject.Values)
            {
                gcObject.parent = null;
            }

            // We wish to find all references to certain selected objects,
            // or, to be precise, all references that keep these objects alive.
            // To do this, we use a breadth first traversal of the object graph, using
            // a queue of objects still to process. If we find a reference to one of the
            // selected objects, we don't actually include this object, but instead
            // just make note of the reference

            // Initialize
            rootObject.parent = null;

            var foundBeforeMarker = new GcObject();

            var queue = new Queue <GcObject>();

            queue.Enqueue(rootObject);

            // Loop
            while (queue.Count != 0)
            {
                GcObject head = queue.Dequeue();
                foreach (GcObject refObject in head.References)
                {
                    if (refObject.parent == null || refObject.parent == foundBeforeMarker)
                    {
                        // this is a reference to either one of the "selected" objects
                        // or just to a new object
                        if (refObject.vertex != null && refObject.vertex.selected &&
                            (refObject.InterestLevel & (InterestLevel.Interesting | InterestLevel.Display)) != InterestLevel.Ignore &&
                            refObject.AllocTickIndex > orgGraph.allocatedAfterTickIndex &&
                            refObject.AllocTickIndex < orgGraph.allocatedBeforeTickIndex)
                        {
                            // add <root> -> ... -> head -> refObject to the reference graph
                            int levels = 0;
                            for (GcObject pathObject = head; pathObject != null; pathObject = pathObject.parent)
                            {
                                levels++;
                            }

                            while (pathFromRoot.Length < levels + 2)
                            {
                                pathFromRoot = new Vertex[pathFromRoot.Length * 2];
                            }

                            pathFromRoot[levels + 1] = graph.FindOrCreateVertex(refObject.vertex.name, refObject.vertex.signature, refObject.vertex.moduleName);
                            int level = levels;
                            for (GcObject pathObject = head; pathObject != null; pathObject = pathObject.parent)
                            {
                                if ((pathObject.InterestLevel & (InterestLevel.Interesting | InterestLevel.Display)) == InterestLevel.Ignore ||
                                    pathObject.vertex == null)
                                {
                                    pathFromRoot[level] = null;
                                }
                                else
                                {
                                    pathFromRoot[level] = graph.FindOrCreateVertex(pathObject.vertex.name, pathObject.vertex.signature, pathObject.vertex.moduleName);
                                }

                                level--;
                            }

                            int nonZeroLevels = 0;
                            for (int j = 0; j <= levels + 1; j++)
                            {
                                if (pathFromRoot[j] != null)
                                {
                                    pathFromRoot[nonZeroLevels++] = pathFromRoot[j];
                                }
                            }

                            levels = Vertex.SqueezeOutRepetitions(pathFromRoot, nonZeroLevels);

                            for (int j = 0; j < levels - 1; j++)
                            {
                                Vertex fromVertex = pathFromRoot[j];
                                Vertex toVertex   = pathFromRoot[j + 1];
                                Edge   edge       = graph.FindOrCreateEdge(fromVertex, toVertex);
                                edge.AddWeight(1);
                            }

                            Vertex thisVertex = pathFromRoot[levels - 1];
                            thisVertex.basicWeight += 1;
                            if (refObject.parent == null)
                            {
                                thisVertex.count += 1;
                                refObject.parent  = foundBeforeMarker;
                            }
                        }
                        else
                        {
                            refObject.parent = head;
                            queue.Enqueue(refObject);
                        }
                    }
                }
            }

            foreach (Vertex v in graph.vertices.Values)
            {
                if (v.weight < v.outgoingWeight)
                {
                    v.weight = v.outgoingWeight;
                }

                if (v.weight < v.incomingWeight)
                {
                    v.weight = v.incomingWeight;
                }

                if (v.weightHistory == null)
                {
                    v.weightHistory = new ulong[1];
                }
            }

            foreach (Vertex v in graph.vertices.Values)
            {
                v.active = true;
            }

            graph.BottomVertex.active = false;

            return(graph);
        }
Example #13
0
        internal Graph BuildTypeGraph(int allocatedAfterTickIndex, int allocatedBeforeTickIndex, BuildTypeGraphOptions options, FilterForm filterForm)
        {
            Graph graph;

            if (filterForm.filterVersion != 0 ||
                options != BuildTypeGraphOptions.LumpBySignature ||
                allocatedAfterTickIndex > 0 ||
                allocatedBeforeTickIndex < int.MaxValue)
            {
                graph = new Graph(this, Graph.GraphType.HeapGraph);
                graph.previousGraphTickIndex = allocatedAfterTickIndex;
            }
            else
            {
                Graph previousGraph = cachedGraph;
                if (previousGraph != null && previousGraph.graphSource == this)
                {
                    return(previousGraph);
                }

                cachedGraph = graph = new Graph(this, Graph.GraphType.HeapGraph);
                if (previousGraph != null)
                {
                    graph.previousGraphTickIndex = ((ObjectGraph)previousGraph.graphSource).tickIndex;
                    foreach (Vertex v in previousGraph.vertices.Values)
                    {
                        Vertex newV = graph.FindOrCreateVertex(v.name, v.signature, v.moduleName);
                        if (v.weightHistory == null)
                        {
                            newV.weightHistory = new ulong[1];
                        }
                        else
                        {
                            ulong[] weightHistory = v.weightHistory;
                            newV.weightHistory = new ulong[Math.Min(weightHistory.Length + 1, historyDepth)];
                            for (int i = v.weightHistory.Length - 1; i > 0; i--)
                            {
                                newV.weightHistory[i] = weightHistory[i - 1];
                            }
                        }
                        newV.weightHistory[0] = v.weight;
                    }
                }
            }
            graph.typeGraphOptions = options;
            graph.filterVersion    = filterForm.filterVersion;
            if (graph.previousGraphTickIndex < graph.allocatedAfterTickIndex)
            {
                graph.previousGraphTickIndex = graph.allocatedAfterTickIndex;
            }

            graph.allocatedAfterTickIndex  = allocatedAfterTickIndex;
            graph.allocatedBeforeTickIndex = allocatedBeforeTickIndex;

            GcObject rootObject = CreateRootObject();

            for (int i = 0; i < rootCount; i++)
            {
                roots[i].InterestLevel = InterestLevel.Ignore;
            }
            foreach (GcObject gcObject in idToObject.Values)
            {
                gcObject.parent        = null;
                gcObject.vertex        = null;
                gcObject.InterestLevel = InterestLevel.Ignore;
            }

            AssignParents(rootObject);

            int index = 0;

            foreach (GcType gcType in typeIdToGcType.Values)
            {
                gcType.index = index++;
            }
            GcType[] gcTypes = new GcType[index];
            typeHintTable = new int[index];

            foreach (GcType gcType in typeIdToGcType.Values)
            {
                gcTypes[gcType.index] = gcType;
            }

            AssignInterestLevelsToTypes(options, filterForm);
            for (int i = 0; i < rootCount; i++)
            {
                AssignInterestLevelToObject(rootIDs[i], roots[i], options, filterForm, true);
            }

            foreach (KeyValuePair <ulong, GcObject> keyValuePair in idToObject)
            {
                GcObject gcObject = keyValuePair.Value;
                if (gcObject.AllocTickIndex > allocatedAfterTickIndex && gcObject.AllocTickIndex < allocatedBeforeTickIndex)
                {
                    AssignInterestLevelToObject(keyValuePair.Key, gcObject, options, filterForm, false);
                }
                else
                {
                    gcObject.InterestLevel = InterestLevel.Ignore;
                }
            }
            foreach (GcObject gcObject in idToObject.Values)
            {
                if (gcObject.InterestLevel == InterestLevel.Ignore)
                {
                    CheckForParentMarkingDescendant(gcObject);
                }
            }

            FindVertex(0, rootObject, graph, options);
            for (int i = 0; i < rootCount; i++)
            {
                roots[i].vertex = null;
                FindVertex(rootIDs[i], roots[i], graph, options);
            }

            foreach (KeyValuePair <ulong, GcObject> keyValuePair in idToObject)
            {
                ulong    id       = keyValuePair.Key;
                GcObject gcObject = keyValuePair.Value;
                if (gcObject.parent == null ||
                    (gcObject.InterestLevel & (InterestLevel.Interesting | InterestLevel.Display)) == InterestLevel.Ignore)
                {
                    continue;
                }
                FindVertex(id, gcObject, graph, options);
            }

            Vertex[] pathFromRoot = new Vertex[32];

            foreach (GcObject gcObject in idToObject.Values)
            {
                if (gcObject.parent == null ||
                    (gcObject.InterestLevel & (InterestLevel.Interesting | InterestLevel.Display)) == InterestLevel.Ignore ||
                    gcObject.AllocTickIndex <= allocatedAfterTickIndex ||
                    gcObject.AllocTickIndex >= allocatedBeforeTickIndex)
                {
                    continue;
                }

                int levels = 0;
                for (GcObject pathObject = gcObject; pathObject != null; pathObject = pathObject.parent)
                {
                    if (pathObject.vertex != null)
                    {
                        levels++;
                    }
                }

                while (pathFromRoot.Length < levels + 1)
                {
                    pathFromRoot = new Vertex[pathFromRoot.Length * 2];
                }

                int level = levels;
                for (GcObject pathObject = gcObject; pathObject != null; pathObject = pathObject.parent)
                {
                    if (pathObject.vertex != null)
                    {
                        level--;
                        pathFromRoot[level] = pathObject.vertex;
                    }
                }

                levels = Vertex.SqueezeOutRepetitions(pathFromRoot, levels);

                for (int j = 0; j < levels - 1; j++)
                {
                    Vertex fromVertex = pathFromRoot[j];
                    Vertex toVertex   = pathFromRoot[j + 1];
                    Edge   edge       = graph.FindOrCreateEdge(fromVertex, toVertex);
                    edge.AddWeight(gcObject.Size(this));
                }

                Vertex thisVertex = pathFromRoot[levels - 1];
                thisVertex.basicWeight += gcObject.Size(this);
                thisVertex.count       += 1;
            }

            foreach (Vertex v in graph.vertices.Values)
            {
                if (v.weight < v.outgoingWeight)
                {
                    v.weight = v.outgoingWeight;
                }

                if (v.weight < v.incomingWeight)
                {
                    v.weight = v.incomingWeight;
                }

                if (v.weightHistory == null)
                {
                    v.weightHistory = new ulong[1];
                }
            }

            foreach (Vertex v in graph.vertices.Values)
            {
                v.active = true;
            }

            graph.BottomVertex.active = false;

            return(graph);
        }
Example #14
0
		internal void GetAllocationGraph(ReadLogResult readLogResult)
		{
			graph = readLogResult.allocatedHistogram.BuildAllocationGraph(new FilterForm());
			PlaceVertices();
		}
        internal Graph BuildTypeGraph(int allocatedAfterTickIndex, int allocatedBeforeTickIndex, BuildTypeGraphOptions options)
        {
            if (graph == null || FilterForm.filterVersion != graphFilterVersion || allocatedAfterTickIndex >= 0 || allocatedBeforeTickIndex < int.MaxValue)
            {
                graph                        = new Graph(this);
                graph.graphType              = Graph.GraphType.HeapGraph;
                graphFilterVersion           = FilterForm.filterVersion;
                graph.previousGraphTickIndex = allocatedAfterTickIndex;
            }
            else
            {
                ObjectGraph previousGraph = (ObjectGraph)graph.graphSource;
                graph.previousGraphTickIndex = previousGraph.tickIndex;
                graph.graphSource            = this;
                foreach (Vertex v in graph.vertices.Values)
                {
                    if (v.weightHistory == null)
                    {
                        v.weightHistory = new uint[1];
                    }
                    else
                    {
                        uint[] weightHistory = v.weightHistory;
                        if (weightHistory.Length < historyDepth)
                        {
                            v.weightHistory = new uint[weightHistory.Length + 1];
                        }
                        for (int i = v.weightHistory.Length - 1; i > 0; i--)
                        {
                            v.weightHistory[i] = weightHistory[i - 1];
                        }
                    }
                    v.weightHistory[0] = v.weight;
                    v.weight           = v.incomingWeight = v.outgoingWeight = v.basicWeight = 0;
                    v.count            = 0;
                    foreach (Edge e in v.outgoingEdges.Values)
                    {
                        e.weight = 0;
                    }
                }
            }
            if (graph.previousGraphTickIndex < graph.allocatedAfterTickIndex)
            {
                graph.previousGraphTickIndex = graph.allocatedAfterTickIndex;
            }
            graph.allocatedAfterTickIndex  = allocatedAfterTickIndex;
            graph.allocatedBeforeTickIndex = allocatedBeforeTickIndex;

            GcType   rootType   = GetOrCreateGcType("<root>", 0);
            GcObject rootObject = GetOrCreateObject(0);

            rootObject.type       = rootType;
            rootObject.references = roots;

            foreach (GcObject gcObject in idToObject.Values)
            {
                gcObject.level  = int.MaxValue;
                gcObject.vertex = null;
            }

            AssignLevels(rootObject);

            AssignInterestLevels();

            int index = 0;

            foreach (GcType gcType in typeNameToGcType.Values)
            {
                gcType.index = index++;
            }
            GcType[] gcTypes = new GcType[index];
            typeHintTable = new int[index];

            foreach (GcType gcType in typeNameToGcType.Values)
            {
                gcTypes[gcType.index] = gcType;
            }

            Vertex[] pathFromRoot = new Vertex[32];
            foreach (GcObject gcObject in idToObject.Values)
            {
                if (gcObject.level == int.MaxValue ||
                    (gcObject.interestLevel & (InterestLevel.Interesting | InterestLevel.Display)) == InterestLevel.Ignore ||
                    gcObject.allocTickIndex <= allocatedAfterTickIndex ||
                    gcObject.allocTickIndex >= allocatedBeforeTickIndex)
                {
                    continue;
                }

                while (pathFromRoot.Length < gcObject.level + 1)
                {
                    pathFromRoot = new Vertex[pathFromRoot.Length * 2];
                }

                for (GcObject pathObject = gcObject; pathObject != null; pathObject = pathObject.parent)
                {
                    if ((pathObject.interestLevel & (InterestLevel.Interesting | InterestLevel.Display)) == InterestLevel.Ignore)
                    {
                        pathFromRoot[pathObject.level] = null;
                    }
                    else
                    {
                        pathFromRoot[pathObject.level] = FindVertex(pathObject, graph, options);
                    }
                }

                int levels = 0;
                for (int i = 0; i <= gcObject.level; i++)
                {
                    if (pathFromRoot[i] != null)
                    {
                        pathFromRoot[levels++] = pathFromRoot[i];
                    }
                }

                levels = Vertex.SqueezeOutRepetitions(pathFromRoot, levels);

                for (int i = 0; i < levels - 1; i++)
                {
                    Vertex fromVertex = pathFromRoot[i];
                    Vertex toVertex   = pathFromRoot[i + 1];
                    Edge   edge       = graph.FindOrCreateEdge(fromVertex, toVertex);
                    edge.AddWeight(gcObject.size);
                }

                Vertex thisVertex = pathFromRoot[levels - 1];
                thisVertex.basicWeight += gcObject.size;
                thisVertex.count       += 1;
            }

            foreach (Vertex v in graph.vertices.Values)
            {
                if (v.weight < v.outgoingWeight)
                {
                    v.weight = v.outgoingWeight;
                }
                if (v.weight < v.incomingWeight)
                {
                    v.weight = v.incomingWeight;
                }
                if (v.weightHistory == null)
                {
                    v.weightHistory = new uint[1];
                }
            }

            foreach (Vertex v in graph.vertices.Values)
            {
                v.active = true;
            }
            graph.BottomVertex.active = false;

            return(graph);
        }
Example #16
0
 void BuildFuncVertices(Graph graph, ref Vertex[] funcVertex, FilterForm filterForm)
 {
     for (int i = 0; i < readNewLog.funcName.Length; i++)
     {
         string name = readNewLog.funcName[i];
         string signature = readNewLog.funcSignature[i];
         if (name != null && signature != null)
             readNewLog.AddFunctionVertex(i, name, signature, graph, ref funcVertex, filterForm);
     }
 }
Example #17
0
 internal void AddTypeVertex(int typeId, string typeName, Graph graph, ref Vertex[] typeVertex, FilterForm filterForm)
 {
     EnsureVertexCapacity(typeId, ref typeVertex);
     typeVertex[typeId] = graph.FindOrCreateVertex(typeName, null, null);
     typeVertex[typeId].interestLevel = filterForm.IsInterestingTypeName(typeName, null, finalizableTypes.ContainsKey(typeId))
         ? InterestLevel.Interesting | filterForm.InterestLevelForParentsAndChildren() : InterestLevel.Ignore;
 }
Example #18
0
        internal void BuildHandleAllocationTrace(Graph graph, int stackTraceIndex, uint count, Vertex[] funcVertex, ref Vertex[] vertexStack, FilterForm filterForm)
        {
            int stackPtr = BuildVertexStack(stackTraceIndex, funcVertex, ref vertexStack, 0);

            Vertex handleVertex = graph.FindOrCreateVertex("Handle", null, null);
            handleVertex.interestLevel = InterestLevel.Interesting;

            Vertex toVertex = graph.TopVertex;
            Vertex fromVertex;
            Edge edge;
            if (ReadNewLog.InterestingCallStack(vertexStack, stackPtr, filterForm))
            {
                vertexStack[stackPtr] = handleVertex;
                stackPtr++;
                stackPtr = ReadNewLog.FilterVertices(vertexStack, stackPtr);
                stackPtr = Vertex.SqueezeOutRepetitions(vertexStack, stackPtr);
                for (int i = 0; i < stackPtr; i++)
                {
                    fromVertex = toVertex;
                    toVertex = vertexStack[i];
                    edge = graph.FindOrCreateEdge(fromVertex, toVertex);
                    edge.AddWeight(count);
                }
                fromVertex = toVertex;
                toVertex = graph.BottomVertex;
                edge = graph.FindOrCreateEdge(fromVertex, toVertex);
                edge.AddWeight(count);
            }
        }
        private void RefreshGraph()
        {
            Graph orgGraph = graph;
            if (orgGraph.graphSource is Graph)
            {
                orgGraph = (Graph)orgGraph.graphSource;
            }

            switch (orgGraph.graphType)
            {
                case Graph.GraphType.CallGraph:
                    graph = ((Histogram)orgGraph.graphSource).BuildCallGraph(filterForm);
                    graph.graphType = Graph.GraphType.CallGraph;
                    break;

                case Graph.GraphType.AllocationGraph:
                    graph = ((Histogram)orgGraph.graphSource).BuildAllocationGraph(filterForm);
                    graph.graphType = Graph.GraphType.AllocationGraph;
                    break;

                case Graph.GraphType.AssemblyGraph:
                    graph = ((Histogram)orgGraph.graphSource).BuildAssemblyGraph(filterForm);
                    graph.graphType = Graph.GraphType.AssemblyGraph;
                    break;

                case Graph.GraphType.HeapGraph:
                    graph = ((ObjectGraph)orgGraph.graphSource).BuildTypeGraph(orgGraph.allocatedAfterTickIndex, orgGraph.allocatedBeforeTickIndex, orgGraph.typeGraphOptions, filterForm);
                    graph.graphType = Graph.GraphType.HeapGraph;
                    break;

                case Graph.GraphType.HandleAllocationGraph:
                    graph = ((Histogram)orgGraph.graphSource).BuildHandleAllocationGraph(filterForm);
                    graph.graphType = Graph.GraphType.HandleAllocationGraph;
                    break;
            }
            placeVertices = placeEdges = true;
            graphPanel.Invalidate();
        }
Example #20
0
        void BuildClassTrace(Graph graph, int stackTraceIndex, int funcIndex, ulong size, Vertex[] funcVertex, ref Vertex[] vertexStack, FilterForm filterForm)
        {
            string className = ClassNameOfFunc(funcIndex);
            int functionsToSkip = FunctionsInSameClass(className, stackTraceIndex);
            int stackPtr = BuildVertexStack(stackTraceIndex, funcVertex, ref vertexStack, 0) - functionsToSkip;

            Vertex toVertex = graph.TopVertex;
            Vertex fromVertex;
            Edge edge;
            if (ReadNewLog.InterestingCallStack(vertexStack, stackPtr, filterForm))
            {
                vertexStack[stackPtr] = graph.FindOrCreateVertex(className, null, null);
                vertexStack[stackPtr].interestLevel = filterForm.InterestLevelOfMethodName(className, null);
                stackPtr++;
                stackPtr = ReadNewLog.FilterVertices(vertexStack, stackPtr);
                stackPtr = Vertex.SqueezeOutRepetitions(vertexStack, stackPtr);
                for (int i = 0; i < stackPtr; i++)
                {
                    fromVertex = toVertex;
                    toVertex = vertexStack[i];
                    edge = graph.FindOrCreateEdge(fromVertex, toVertex);
                    edge.AddWeight(size);
                }
                if (toVertex != graph.TopVertex)
                {
                    fromVertex = toVertex;
                    toVertex = graph.BottomVertex;
                    edge = graph.FindOrCreateEdge(fromVertex, toVertex);
                    edge.AddWeight(size);
                }
            }
        }
 private Vertex CloneVertex(Graph g, Vertex v)
 {
     Vertex vn = g.FindOrCreateVertex(v.name, v.signature, v.moduleName);
     vn.basicName = v.basicName;
     vn.basicSignature = v.basicSignature;
     vn.active = true;
     return vn;
 }
Example #22
0
 internal void BuildTypeVertices(Graph graph, ref Vertex[] typeVertex, FilterForm filterForm)
 {
     for (int i = 0; i < readNewLog.typeName.Length; i++)
     {
         string typeName = readNewLog.typeName[i];
         if (typeName == null)
             typeName = string.Format("???? type {0}", i);
         readNewLog.AddTypeVertex(i, typeName, graph, ref typeVertex, filterForm);
     }
 }
 private void ZoomVertex(Vertex v, string titlePrefix)
 {
     toolTip.Active = false;
     Graph g;
     if (graph.graphSource is Graph)
     {
         Graph orgGraph = (Graph)graph.graphSource;
         g = new Graph(orgGraph);
         v = orgGraph.FindOrCreateVertex(v.name, v.signature, v.moduleName);
     }
     else
         g = new Graph(graph);
     g.allocatedAfterTickIndex = graph.allocatedAfterTickIndex;
     g.allocatedBeforeTickIndex = graph.allocatedBeforeTickIndex;
     Vertex vn = CloneVertex(g, v);
     vn.count = v.count;
     if (v.incomingEdges.Count == 0)
     {
         if (v != graph.TopVertex)
             g.FindOrCreateEdge(g.TopVertex, vn).AddWeight(v.weight);
     }
     else
     {
         foreach (Edge e in v.incomingEdges.Values)
         {
             Vertex vin = CloneVertex(g, e.FromVertex);
             g.FindOrCreateEdge(vin, vn).AddWeight(e.weight);
             if (vin != g.TopVertex)
                 g.FindOrCreateEdge(g.TopVertex, vin).AddWeight(e.weight);
         }
     }
     if (v.outgoingEdges.Count == 0)
     {
         if (v != graph.BottomVertex)
             g.FindOrCreateEdge(vn, g.BottomVertex).AddWeight(v.weight);
     }
     else
     {
         foreach (Edge e in v.outgoingEdges.Values)
         {
             Vertex von = CloneVertex(g, e.ToVertex);
             g.FindOrCreateEdge(vn, von).AddWeight(e.weight);
             if (von != g.BottomVertex)
                 g.FindOrCreateEdge(von, g.BottomVertex).AddWeight(e.weight);
         }
     }
     g.BottomVertex.active = false;
     g.graphType = graph.graphType;
     g.typeGraphOptions = graph.typeGraphOptions;
     if (titlePrefix == null)
         titlePrefix = "Zoom to: ";
     string title = titlePrefix + v.name + " " + (v.signature != null? v.signature : "");
     GraphViewForm graphViewForm = new GraphViewForm(g, title);
     graphViewForm.Visible = true;
 }
Example #24
0
 internal void AddFunctionVertex(int funcId, string functionName, string signature, Graph graph, ref Vertex[] funcVertex, FilterForm filterForm)
 {
     EnsureVertexCapacity(funcId, ref funcVertex);
     int moduleId = funcModule[funcId];
     string moduleName = null;
     if (moduleId >= 0)
         moduleName = modBasicName[moduleId];
     funcVertex[funcId] = graph.FindOrCreateVertex(functionName, signature, moduleName);
     funcVertex[funcId].interestLevel = filterForm.InterestLevelOfMethodName(functionName, signature);
 }
        private void showInstancesMenuItem_Click(object sender, System.EventArgs e)
        {
            Graph orgGraph = graph;
            if (orgGraph.graphSource is Graph)
                orgGraph = (Graph)orgGraph.graphSource;
            ObjectGraph objectGraph = (ObjectGraph)orgGraph.graphSource;
            ObjectGraph.BuildTypeGraphOptions options; 
            if (graph.typeGraphOptions == ObjectGraph.BuildTypeGraphOptions.LumpBySignature)
            {
                options = ObjectGraph.BuildTypeGraphOptions.IndividualObjects;
            }
            else
            {
                options = ObjectGraph.BuildTypeGraphOptions.LumpBySignature;
            }
            graph = objectGraph.BuildTypeGraph(graph.allocatedAfterTickIndex, graph.allocatedBeforeTickIndex, options, filterForm);

            placeVertices = placeEdges = true;
            graphPanel.Invalidate();
            EnableDisableMenuItems();
        }       
Example #26
0
 internal void BuildFuncVertices(Graph graph, ref Vertex[] funcVertex, FilterForm filterForm)
 {
     for (int i = 0; i < readNewLog.funcName.Length; i++)
     {
         string name = readNewLog.funcName[i];
         string signature = readNewLog.funcSignature[i];
         if (name == null)
             name = string.Format("???? function {0}", i);
         if (signature == null)
             signature = "( ???????? )";
         readNewLog.AddFunctionVertex(i, name, signature, graph, ref funcVertex, filterForm);
     }
 }
        internal GraphViewForm(Graph graph, string title)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            toolTip = new ToolTip();
            toolTip.Active = false;
            toolTip.ShowAlways = true;
            toolTip.AutomaticDelay = 70;
            toolTip.ReshowDelay = 1;

            this.graph = graph;

            font = MainForm.instance.font;
            fontHeight = font.Height;

            Text = title;

            EnableDisableMenuItems();

            filterForm = new FilterForm();
            findForm = new FindRoutineForm();
        }
Example #28
0
        internal Graph BuildHandleAllocationGraph(FilterForm filterForm)
        {
            Vertex[] funcVertex = new Vertex[1];
            Vertex[] vertexStack = new Vertex[1];

            Graph graph = new Graph(this);
            graph.graphType = Graph.GraphType.HandleAllocationGraph;

            BuildFuncVertices(graph, ref funcVertex, filterForm);

            for (int i = 0; i < typeSizeStacktraceToCount.Length; i++)
            {
                if (typeSizeStacktraceToCount[i] > 0)
                {
                    int[] stacktrace = readNewLog.stacktraceTable.IndexToStacktrace(i);

                    uint count = (uint)typeSizeStacktraceToCount[i];

                    BuildHandleAllocationTrace(graph, i, count, funcVertex, ref vertexStack, filterForm);
                }
            }

            foreach (Vertex v in graph.vertices.Values)
                v.active = true;
            graph.BottomVertex.active = false;

            return graph;
        }
Example #29
0
        internal void BuildCallTrace(Graph graph, int stackTraceIndex, Vertex[] funcVertex, ref Vertex[] vertexStack, int count, FilterForm filterForm)
        {
            int stackPtr = BuildVertexStack(stackTraceIndex, funcVertex, ref vertexStack, 0);

            Vertex toVertex = graph.TopVertex;
            Vertex fromVertex;
            Edge edge;
            if (ReadNewLog.InterestingCallStack(vertexStack, stackPtr, filterForm))
            {
                stackPtr = ReadNewLog.FilterVertices(vertexStack, stackPtr);
                stackPtr = Vertex.SqueezeOutRepetitions(vertexStack, stackPtr);
                for (int i = 0; i < stackPtr; i++)
                {
                    fromVertex = toVertex;
                    toVertex = vertexStack[i];
                    edge = graph.FindOrCreateEdge(fromVertex, toVertex);
                    edge.AddWeight((uint)count);
                }
            }
        }
Example #30
0
        internal void BuildAssemblyTrace(Graph graph, int stackTraceIndex, Vertex assembly, Vertex typeVertex, Vertex[] funcVertex, ref Vertex[] vertexStack)
        {
            int stackPtr = BuildVertexStack(Math.Abs(stackTraceIndex), funcVertex, ref vertexStack, stackTraceIndex < 0 ? 2 : 0);

            Vertex toVertex = graph.TopVertex;
            Vertex fromVertex;
            Edge edge;

            if(typeVertex != null)
            {
                vertexStack[stackPtr++] = typeVertex;
            }
            vertexStack[stackPtr++] = assembly;

            stackPtr = ReadNewLog.FilterVertices(vertexStack, stackPtr);
            stackPtr = Vertex.SqueezeOutRepetitions(vertexStack, stackPtr);
            for (int i = 0; i < stackPtr; i++)
            {
                fromVertex = toVertex;
                toVertex = vertexStack[i];
                edge = graph.FindOrCreateEdge(fromVertex, toVertex);
                edge.AddWeight(1);
            }
            fromVertex = toVertex;
            toVertex = graph.BottomVertex;
            edge = graph.FindOrCreateEdge(fromVertex, toVertex);
            edge.AddWeight(1);
        }
        internal Vertex FindVertex(GcObject gcObject, Graph graph, BuildTypeGraphOptions options)
        {
            if (gcObject.vertex != null)
            {
                return(gcObject.vertex);
            }
            string        signature = null;
            StringBuilder sb        = new StringBuilder();

            if (gcObject.parent != null)
            {
                switch (options)
                {
                case    BuildTypeGraphOptions.IndividualObjects:
                    sb.AppendFormat("Address = 0x{0:x}, size = {1:n0} bytes", gcObject.id, gcObject.size);
                    break;

                case    BuildTypeGraphOptions.LumpBySignature:
                    sb.Append(gcObject.parent.type.name);
                    sb.Append("->");
                    sb.Append(gcObject.type.name);
                    if (gcObject.references != null)
                    {
                        sb.Append("->(");

                        ArrayList al              = new ArrayList();
                        string    separator       = "";
                        const int MAXREFTYPECOUNT = 3;
                        int       refTypeCount    = 0;
                        for (int i = 0; i < gcObject.references.Length; i++)
                        {
                            GcObject refObject = gcObject.references[i];
                            GcType   refType   = refObject.type;
                            if (typeHintTable[refType.index] < i && gcObject.references[typeHintTable[refType.index]].type == refType)
                            {
                                ;       // we already found this type - ignore further occurrences
                            }
                            else
                            {
                                typeHintTable[refType.index] = i;
                                refTypeCount++;
                                if (refTypeCount <= MAXREFTYPECOUNT)
                                {
                                    al.Add(refType.name);
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        al.Sort();
                        foreach (string typeName in al)
                        {
                            sb.Append(separator);
                            separator = ",";
                            sb.Append(typeName);
                        }

                        if (refTypeCount > MAXREFTYPECOUNT)
                        {
                            sb.Append(",...");
                        }

                        sb.Append(")");
                    }
                    break;

                default:
                    Debug.Assert(false);
                    break;
                }
                signature = sb.ToString();
            }

            gcObject.vertex = graph.FindOrCreateVertex(gcObject.type.name, signature, null);

            return(gcObject.vertex);
        }